Beispiel #1
0
        private async void DisconnectGoogleHandler()
        {
            if (SelectedProfile.SelectedGoogleAccount == null)
            {
                MessageService.ShowMessageAsync("No account selected");
                return;
            }

            var dialogResult =
                await
                MessageService.ShowConfirmMessage(
                    "Disconnection of Google account cannot be reverted.\nClick Yes to continue.");

            if (dialogResult == MessageDialogResult.Negative)
            {
                return;
            }

            var result = AccountAuthenticationService.DisconnectGoogle(SelectedProfile.SelectedGoogleAccount.Name);

            if (result)
            {
                //Remove google account
                var googleAccount =
                    GoogleAccounts.FirstOrDefault(account => account.Name == SelectedProfile.SelectedGoogleAccount.Name);

                if (googleAccount != null)
                {
                    foreach (var profileViewModel in SyncProfileList)
                    {
                        if (profileViewModel.SelectedGoogleAccount != null &&
                            profileViewModel.SelectedGoogleAccount.Name.Equals(googleAccount.Name))
                        {
                            profileViewModel.SelectedGoogleAccount = null;
                            profileViewModel.GoogleCalendars       = null;
                            profileViewModel.SelectedCalendar      = null;
                        }
                    }

                    GoogleAccounts.Remove(googleAccount);

                    await MessageService.ShowMessage("Google account successfully disconnected");

                    foreach (var calendarSyncProfile in Settings.SyncProfiles)
                    {
                        if (calendarSyncProfile.GoogleAccount != null &&
                            calendarSyncProfile.GoogleAccount.Name.Equals(googleAccount.Name))
                        {
                            calendarSyncProfile.GoogleAccount = null;
                        }
                    }

                    await SettingsSerializationService.SerializeSettingsAsync(Settings);
                }
            }
            else
            {
                MessageService.ShowMessageAsync("Account wasn't authenticated earlier or disconnection failed.");
            }
        }
Beispiel #2
0
        private async void AddGoogleAccountDetailsToApplication(string accountName)
        {
            var account = new GoogleAccount {
                Name = accountName
            };

            Settings.GoogleAccounts.Add(account.DeepClone());
            LastSavedSettings.GoogleAccounts.Add(account);

            await SettingsSerializationService.SerializeSettingsAsync(LastSavedSettings);
        }
Beispiel #3
0
        private async void AddGoogleAccountDetailsToApplication(string accountName)
        {
            var account = new GoogleAccount {
                Name = accountName
            };

            if (GoogleAccounts == null)
            {
                GoogleAccounts = new ObservableCollection <GoogleAccount>();
            }
            GoogleAccounts.Add(account);
            SelectedProfile.SelectedGoogleAccount = account;
            SelectedProfile.GoogleCalendars       = null;
            SelectedProfile.GetGoogleCalendar();

            Settings.GoogleAccounts = GoogleAccounts;

            await SettingsSerializationService.SerializeSettingsAsync(Settings);
        }
Beispiel #4
0
        private async void DisconnectGoogleHandler(object parameter)
        {
            var googleAccount = parameter as GoogleAccount;

            if (googleAccount == null)
            {
                MessageService.ShowMessageAsync("No account selected");
                return;
            }
            var accountName = googleAccount.Name;

            var dialogResult =
                await
                MessageService.ShowConfirmMessage(
                    "Disconnection of Google account cannot be reverted.\nClick Yes to continue.");

            if (dialogResult == MessageDialogResult.Negative)
            {
                return;
            }

            var result = AccountAuthenticationService.DisconnectGoogle(googleAccount.Name);

            if (result)
            {
                foreach (var profile in Settings.CalendarSyncProfiles)
                {
                    if (profile.GoogleSettings.GoogleAccount != null &&
                        profile.GoogleSettings.GoogleAccount.Name.Equals(googleAccount.Name))
                    {
                        profile.GoogleSettings.GoogleAccount   = null;
                        profile.GoogleSettings.GoogleCalendar  = null;
                        profile.GoogleSettings.GoogleCalendars = null;
                    }
                    profile.IsLoaded = false;
                }

                //Remove google account
                googleAccount = Settings.GoogleAccounts.FirstOrDefault(account =>
                                                                       account.Name == accountName);

                if (googleAccount != null)
                {
                    Settings.GoogleAccounts.Remove(googleAccount);
                }

                googleAccount = LastSavedSettings.GoogleAccounts.FirstOrDefault(account =>
                                                                                account.Name == accountName);

                if (googleAccount != null)
                {
                    LastSavedSettings.GoogleAccounts.Remove(googleAccount);
                }

                await MessageService.ShowMessage("Google account successfully disconnected");

                await SettingsSerializationService.SerializeSettingsAsync(LastSavedSettings);
            }
            else
            {
                MessageService.ShowMessageAsync("Account wasn't authenticated earlier or disconnection failed.");
            }
        }
Beispiel #5
0
        private async void SaveSettings()
        {
            IsLoading     = true;
            SettingsSaved = false;

            Settings.SettingsVersion = ApplicationInfo.Version;

            ApplyProxySettings();
            if (Settings.AppSettings.RunApplicationAtSystemStartup)
            {
                WindowsStartupService.RunAtWindowsStartup();
            }
            else
            {
                WindowsStartupService.RemoveFromWindowsStartup();
            }

            try
            {
                foreach (var calendarSyncProfile in Settings.CalendarSyncProfiles)
                {
                    calendarSyncProfile.SetSourceDestTypes();
                }

                foreach (var calendarSyncProfile in Settings.TaskSyncProfiles)
                {
                    calendarSyncProfile.SetSourceDestTypes();
                }

                foreach (var calendarSyncProfile in Settings.ContactSyncProfiles)
                {
                    calendarSyncProfile.SetSourceDestTypes();
                }

                var result = await SettingsSerializationService.SerializeSettingsAsync(Settings);

                if (result)
                {
                    LastSavedSettings = Settings;
                    Settings          = LastSavedSettings.DeepClone();
                }
                Init = true;
                await MessageService.ShowMessage(result? "Settings Saved Successfully" : "Error Saving Settings",
                                                 "Settings");

                SettingsSaved = true;
            }
            catch (AggregateException exception)
            {
                SettingsSaved = false;
                var flattenException = exception.Flatten();
                MessageService.ShowMessageAsync(flattenException.Message);
            }
            catch (Exception exception)
            {
                SettingsSaved = false;
                MessageService.ShowMessageAsync(exception.Message);
            }
            finally
            {
                IsLoading = false;
            }
        }
Beispiel #6
0
        private async void SaveSettings()
        {
            IsLoading                = true;
            SettingsSaved            = false;
            Settings.GoogleAccounts  = GoogleAccounts;
            Settings.SettingsVersion = ApplicationInfo.Version;
            Settings.AppSettings.MinimizeToSystemTray          = MinimizeToSystemTray;
            Settings.AppSettings.HideSystemTrayTooltip         = HideSystemTrayTooltip;
            Settings.AppSettings.CheckForUpdates               = CheckForUpdates;
            Settings.AppSettings.CheckForAlphaReleases         = CheckForAlphaReleases;
            Settings.AppSettings.RunApplicationAtSystemStartup = RunApplicationAtSystemStartup;
            Settings.AppSettings.StartMinimized          = StartMinimized;
            Settings.AppSettings.IsManualSynchronization = IsManualSynchronization;
            Settings.AllowManualAuthentication           = AllowManualGoogleAuth;
            Settings.AppSettings.ProxySettings           = new ProxySetting
            {
                BypassOnLocal         = ProxySettings.BypassOnLocal,
                Domain                = ProxySettings.Domain,
                Password              = ProxySettings.Password,
                Port                  = ProxySettings.Port,
                ProxyAddress          = ProxySettings.ProxyAddress,
                ProxyType             = ProxySettings.ProxyType,
                UseDefaultCredentials = ProxySettings.UseDefaultCredentials,
                UserName              = ProxySettings.UserName
            };
            ApplyProxySettings();
            Settings.SyncProfiles.Clear();
            foreach (var profileViewModel in SyncProfileList)
            {
                Settings.SyncProfiles.Add(profileViewModel.SaveCurrentSyncProfile());
            }

            if (RunApplicationAtSystemStartup)
            {
                WindowsStartupService.RunAtWindowsStartup();
            }
            else
            {
                WindowsStartupService.RemoveFromWindowsStartup();
            }

            try
            {
                var result = await SettingsSerializationService.SerializeSettingsAsync(Settings);

                await
                MessageService.ShowMessage(result? "Settings Saved Successfully" : "Error Saving Settings",
                                           "Settings");

                SettingsSaved = true;
            }
            catch (AggregateException exception)
            {
                SettingsSaved = false;
                var flattenException = exception.Flatten();
                MessageService.ShowMessageAsync(flattenException.Message);
            }
            catch (Exception exception)
            {
                SettingsSaved = false;
                MessageService.ShowMessageAsync(exception.Message);
            }
            finally
            {
                IsLoading = false;
            }
        }