예제 #1
0
        private async void ButtonTurnOnSynchronization_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            try
            {
                ButtonTurnOnSynchronization.IsLoading = true;

                AccountSession session = await oneDriveClient.AuthenticateAsync();

                if (session.AccountType == AccountType.MicrosoftAccount)
                {
                    ISynchronizer synchronizer = new OneDriveSynchronizer(oneDriveClient);
                    await synchronizer.Setup();

                    mainPage.Navigate(typeof(SetupSynchronizationPage), new object[] { synchronizer, mainPage });
                }
            }
            catch (OneDriveException ex)
            {
                ButtonTurnOnSynchronization.IsLoading = false;

                if (!ex.IsMatch(OneDriveErrorCode.Unauthenticated.ToString()) && !ex.IsMatch(OneDriveErrorCode.AccessDenied.ToString()) && !ex.IsMatch(OneDriveErrorCode.AuthenticationCancelled.ToString()) && !ex.IsMatch(OneDriveErrorCode.AuthenticationFailure.ToString()))
                {
                    MainPage.AddBanner(new Banner(BannerType.Danger, ResourceLoader.GetForCurrentView().GetString("UnknownErrorWhileAuthenticating"), true));
                }
            }
        }
예제 #2
0
        public MainPage()
        {
            InitializeComponent();

            instance = this;

            // Navigate to the first page
            Navigate(typeof(AccountsPage), this);

            if (SettingsManager.Get <bool>(Setting.UseCloudSynchronization))
            {
                PasswordVault vault = new PasswordVault();
                IReadOnlyList <PasswordCredential> credentials = vault.RetrieveAll();

                if (credentials.Any())
                {
                    credentials[0].RetrievePassword();

                    ISynchronizer synchronizer = new OneDriveSynchronizer(OneDriveClientExtensions.GetUniversalClient(new[] { "onedrive.appfolder" }));
                    IEncrypter    encrypter    = new AESEncrypter();

                    synchronizer.SetEncrypter(encrypter, credentials[0].Password);

                    AccountStorage.Instance.SetSynchronizer(synchronizer);
                }
            }

            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
        }
예제 #3
0
        private async void ButtonRemoveCloudSynchronization_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            MessageDialog dialog = new MessageDialog(ResourceLoader.GetForCurrentView().GetString("RemoveSynchronizationMessage"), ResourceLoader.GetForCurrentView().GetString("RemoveSynchronizationTitle"));

            dialog.Commands.Add(new UICommand()
            {
                Label = ResourceLoader.GetForCurrentView().GetString("Delete"), Id = 0
            });
            dialog.Commands.Add(new UICommand()
            {
                Label = ResourceLoader.GetForCurrentView().GetString("Cancel"), Id = 1
            });

            dialog.CancelCommandIndex  = 1;
            dialog.DefaultCommandIndex = 1;

            IUICommand selectedCommand = await dialog.ShowAsync();

            if ((int)selectedCommand.Id == 0)
            {
                Banner banner = new Banner();
                bool   result = false;

                try
                {
                    MainPage.ShowLoader(ResourceLoader.GetForCurrentView().GetString("AccountsAreBeingRemovedFromCloud"));

                    ISynchronizer synchronizer = new OneDriveSynchronizer(oneDriveClient);
                    result = await synchronizer.Remove();
                }
                catch (NetworkException)
                {
                    result = false;
                }

                if (result)
                {
                    banner.BannerText  = ResourceLoader.GetForCurrentView().GetString("SynchronizationRemoved");
                    banner.BannerType  = BannerType.Success;
                    banner.Dismissable = true;
                }
                else
                {
                    banner.BannerText  = ResourceLoader.GetForCurrentView().GetString("SynchronizationRemovedError");
                    banner.BannerType  = BannerType.Danger;
                    banner.Dismissable = true;
                }

                MainPage.AddBanner(banner);

                await DisableSynchronization();

                ShowInformation();

                MainPage.HideLoader();
            }
        }