Revision 3ddbb7b8 trunk/Pithos.Client.WPF/Preferences/AddAccountViewModel.cs

b/trunk/Pithos.Client.WPF/Preferences/AddAccountViewModel.cs
1 1
using System;
2 2
using System.Collections.Generic;
3
using System.ComponentModel;
3 4
using System.ComponentModel.Composition;
5
using System.IO;
4 6
using System.Linq;
5 7
using System.Text;
6
using Caliburn.Micro;
8
using System.Windows;
9
using System.Windows.Controls;
10
using System.Windows.Forms;
11
using Pithos.Client.WPF.Properties;
12
using Pithos.Core;
13
using MessageBox = System.Windows.MessageBox;
14
using Screen = Caliburn.Micro.Screen;
7 15

  
8 16
namespace Pithos.Client.WPF.Preferences
9 17
{
......
18 26
            {
19 27
                _accountName = value;
20 28
                NotifyOfPropertyChange(()=>AccountName);
29
                NotifyOfPropertyChange(() => HasCredentials);
21 30
            }
22 31
        }
23 32

  
......
29 38
            {
30 39
                _token = value;
31 40
                NotifyOfPropertyChange(()=>Token);
41
                NotifyOfPropertyChange(() => HasCredentials);
32 42
            }
33 43
        }
34 44

  
......
39 49
            set
40 50
            {
41 51
                _accountPath = value;
42
                NotifyOfPropertyChange(()=>AccountPath);
52
                NotifyOfPropertyChange(() => AccountPath);
53
                NotifyOfPropertyChange(() => HasAccountPath);
43 54
            }
44 55
        }
56

  
57

  
58
        public bool HasAccountPath
59
        {
60
            get { return !String.IsNullOrWhiteSpace(AccountPath); }
61
        }
62

  
63
        public bool HasCredentials
64
        {
65
            get { return !(String.IsNullOrWhiteSpace(AccountName) || String.IsNullOrWhiteSpace(Token) ) ; }
66
        }
67

  
68

  
69
        private bool  _isConfirmed;
70

  
71
        public bool IsConfirmed
72
        {
73
            get { return _isConfirmed; }
74
            set
75
            {
76
                _isConfirmed = value;
77
                NotifyOfPropertyChange(() => IsConfirmed);
78
            }
79
        }
80

  
81

  
82
        private bool _isAccountActive;
83

  
84
        public bool IsAccountActive
85
        {
86
            get { return _isAccountActive; }
87
            set
88
            {
89
                _isAccountActive = value;
90
                NotifyOfPropertyChange(() => IsAccountActive);
91
            }
92
        }
93

  
94
        public void SelectAccount()
95
        {
96
            using (var dlg = new FolderBrowserDialog())
97
            {
98
                //Ask the user to select a folder
99
                //Note: We need a parent window here, which we retrieve with GetView            
100
                var view = (Window)GetView();
101
                if (DialogResult.OK != dlg.ShowDialog(new Wpf32Window(view)))
102
                    return;
103

  
104
                AccountPath= dlg.SelectedPath;
105
            }
106
        }
107

  
108

  
109
        private bool _isRetrieving;
110
        public bool IsRetrieving
111
        {
112
            get { return _isRetrieving; }
113
            set
114
            {
115
                _isRetrieving = value;
116
                NotifyOfPropertyChange(() => IsRetrieving);
117
            }
118
        }
119

  
120
        public async void RetrieveCredentials()
121
        {
122
            IsRetrieving = true;
123
            IsConfirmed = false;
124

  
125
            try
126
            {
127
                var credentials = await PithosAccount.RetrieveCredentialsAsync(Settings.Default.PithosLoginUrl);
128
                AccountName = credentials.UserName;
129
                Token = credentials.Password;
130

  
131
                IsConfirmed = true;
132
            }
133
            catch (Exception exc)
134
            {
135
                IsConfirmed = false;
136
                MessageBox.Show(exc.ToString(), "Error");
137
                throw;
138
            }
139
            IsRetrieving = false;
140

  
141
        }
142
        
143

  
45 144
    }
46 145
}

Also available in: Unified diff