Пример #1
0
        public async void LoadData(Account account) {
            _account = account;
            AccountName = _account.Name;

            var webDav = new WebDAVClient(_account.GetUri(), await _accountService.GetCredentials(_account));
            try {
                var files = await webDav.GetEntries(_account.WebDAVPath, true);
                Files = new ObservableCollection<WebDAVFile>
                    // except current folder
                    (files.Where(x => x.FilePath.ToString() != _account.WebDAVPath));
            } catch {

            }
        }
Пример #2
0
 /// <summary>
 /// Encrypts username and password text
 /// </summary>
 public async Task UpdateCredentials(Account account) {
     if (!account.IsAnonymous) {
         if (!string.IsNullOrEmpty(account.UsernamePlain)) {
             account.Username = await _protectedDataService.EncryptString(account.UsernamePlain);
         } else {
             account.Username = string.Empty;
         }
         if (!string.IsNullOrEmpty(account.PasswordPlain)) {
             account.Password = await _protectedDataService.EncryptString(account.PasswordPlain);
         } else {
             account.Password = string.Empty;
         }
     } else {
         account.Username = account.Password = string.Empty;
     }
 }
Пример #3
0
        public AddAccountViewModel(ConnectionService connectionService, AccountService accountService, INavigationService navigationService) {
            _connectionService = connectionService;
            _accountService = accountService;
            _navigationService = navigationService;

            AnonymousAccess = false;
            IsHostValid = false;

            CheckHostCommand = new RelayCommand(async () => {
                // TODO: check if really changed
                IsHostValid = false;
                var host = Host;
                if (!host.EndsWith("/")) host = host + "/";

                _connectionInfo = await _connectionService.GetConnectionInfo(host);
                if (_connectionInfo != null) {
                    var auth = await _connectionService.GetAuthenticationInfo(_connectionInfo);
                    if (auth != AuthenticationMethod.Unknown)
                        IsHostValid = true;
                    AnonymousAccess = auth == AuthenticationMethod.None;
                }
            });

            AddAccountCommand = new RelayCommand(async () => {
                var newAccount = new Account {
                    IsAnonymous = AnonymousAccess,
                    Protocol = _connectionInfo.WebDAVUrl.Scheme,
                    ServerDomain = _connectionInfo.WebDAVUrl.Host,
                    WebDAVPath = _connectionInfo.WebDAVUrl.LocalPath
                };

                if (!AnonymousAccess) {
                    newAccount.UsernamePlain = UserName;
                    newAccount.PasswordPlain = Password;
                    await _accountService.UpdateCredentials(newAccount);
                }
                _accountService.AddAccount(newAccount);
                await _accountService.SaveAccounts();

                if (_navigationService.CanGoBack)
                    _navigationService.GoBack();
                else
                    _navigationService.Navigate(typeof(MainPage));
            }, () => IsHostValid &&
                        (AnonymousAccess ||
                        (!string.IsNullOrWhiteSpace(UserName) &&
                             !string.IsNullOrEmpty(Password))));
        }
Пример #4
0
 public async Task DeleteAccount(Account account) {
     var accountInList = await GetAccountByID(account.GUID);
     _accounts.Remove(accountInList);
 }
Пример #5
0
 public void AddAccount(Account account) {
     account.GUID = Guid.NewGuid();
     _accounts.Add(account);
 }
Пример #6
0
 /// <summary>
 /// Decrypts username and password text
 /// </summary>
 public async Task RestoreCredentials(Account account) {
     if (!account.IsAnonymous && (string.IsNullOrEmpty(account.UsernamePlain)|| string.IsNullOrEmpty(account.PasswordPlain))) {
         account.UsernamePlain = await _protectedDataService.DecryptString(account.Username);
         account.PasswordPlain = await _protectedDataService.DecryptString(account.Password);
     }
 }
Пример #7
0
 /// <summary>
 /// Returns the Username & Password for
 /// the account. This works also in encrypted mode.
 /// </summary>
 /// <returns></returns>
 public async Task<NetworkCredential> GetCredentials(Account account) {
     var copy = account.GetCopy();
     if (!copy.IsAnonymous) await RestoreCredentials(copy);
     return copy.IsAnonymous ? new NetworkCredential() : new NetworkCredential(copy.UsernamePlain, copy.PasswordPlain);
 }