Example #1
0
        private async Task CreateOneDriveAsync()
        {
            var userAccount = authProvider.CurrentUserAccount;

            if (TreeItemVMs.Any(vm => vm.Item.Name == userAccount.Username))
            {
                MessageBox.Show("User has already signed in.");
                return;
            }
            var user = await graphManager.GetMeAsync().ConfigureAwait(true);

            if (user == null)
            {
                return;
            }
            if (authProvider.UserIdAccountRegistry.ContainsKey(user.Id))
            {
                MessageBox.Show("User has already signed in.");
                return;
            }
            var root = await graphManager.GetDriveRootAsync().ConfigureAwait(true);

            if (root == null)
            {
                return;
            }

            authProvider.UserIdAccountRegistry.Add(user.Id, userAccount);
            var item = OneDriveItemFactory.CreateRoot(root, user);

            TreeItemVMs.Add(new ItemVM(item));
            CurrentItemVMs.Add(new ItemVM(item));
        }
Example #2
0
        public async Task LogoutOneDriveAsync()
        {
            SpinnerVisibility = Visibility.Visible;
            var treeVM = TreeItemVMs.First(vm => vm.Item.Type == ItemTypes.OneDrive);
            var item   = treeVM.Item as OneDriveItem;

            if (await authProvider.LogoutAsync(item.UserId).ConfigureAwait(true))
            {
                TreeItemVMs.Remove(treeVM);
                CurrentItemVMs.Remove(CurrentItemVMs.FirstOrDefault(vm => vm == treeVM));
            }
            SpinnerVisibility = Visibility.Collapsed;
        }
Example #3
0
 /// <summary>
 /// Attach all local drives to <see cref="TreeItemVMs"/>. This method should be called at the startup of application.
 /// </summary>
 public void GetLocalDrives()
 {
     string[] drivePaths = null;
     try {
         drivePaths = Directory.GetLogicalDrives();
     } catch (UnauthorizedAccessException ex) {
         MessageBox.Show(ex.Message);
     }
     foreach (var drivePath in drivePaths)
     {
         var item = LocalItemFactory.Create(drivePath);
         TreeItemVMs.Add(new ItemVM(item));
         CurrentItemVMs.Add(new ItemVM(item));
     }
 }
Example #4
0
 /// <summary>
 /// Reset <see cref="TreeItemVMs"/> and <see cref="CurrentItemVMs"/>.
 /// </summary>
 public void Reset()
 {
     TreeItemVMs.Clear();
     CurrentItemVMs.Clear();
 }