Exemplo n.º 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.");
            }
        }
Exemplo n.º 2
0
        public async void LoadSyncProfile()
        {
            if (SelectedProfile == null)
            {
                return;
            }

            IsLoading = true;

            if (SelectedProfile.SyncFrequency != null)
            {
                SelectedFrequency = SelectedProfile.SyncFrequency.Name;
            }

            if (!SelectedProfile.IsLoaded)
            {
                if (!SelectedProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultProfile))
                {
                    await GetOutlookProfileListInternal();
                }

                if (!SelectedProfile.OutlookSettings.OutlookOptions.HasFlag(OutlookOptionsEnum.DefaultMailBoxCalendar))
                {
                    await GetOutlookMailBoxesInternal();
                }

                if (SelectedProfile.GoogleSettings.GoogleAccount != null)
                {
                    SelectedProfile.GoogleSettings.GoogleAccount = GoogleAccounts.FirstOrDefault(t =>
                                                                                                 t.Name.Equals(SelectedProfile.GoogleSettings.GoogleAccount.Name));

                    if (SelectedProfile.GoogleSettings.GoogleCalendar != null)
                    {
                        await GetGoogleCalendarInternal();
                    }
                }

                SelectedProfile.IsLoaded = true;
            }

            if (SelectedProfile.EventCategory != null)
            {
                SelectedProfile.EventCategory =
                    Categories.First(t => t.CategoryName.Equals(SelectedProfile.EventCategory.CategoryName));
            }

            IsLoading = false;
        }
Exemplo n.º 3
0
        private GoogleAccount GetGoogleAccount(CalendarSyncProfile syncProfile)
        {
            GoogleAccount googleAccount = null;

            if (syncProfile.GoogleAccount != null)
            {
                if (GoogleAccounts.Any())
                {
                    googleAccount = GoogleAccounts.FirstOrDefault(
                        account => account.Name == syncProfile.GoogleAccount.Name);
                }
            }

            if (googleAccount != null)
            {
                googleAccount.GoogleCalendar = syncProfile.GoogleAccount.GoogleCalendar;
            }
            return(googleAccount);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Send an HTML email.
        /// </summary>
        /// <param name="from">A string representation of the email address used to send the email.</param>
        /// <param name="sender">A string representation of the email address which the email appears to be sent from.</param>
        /// <param name="to">A comma-delimited array of string representations of email addresses which the email should be sent to.</param>
        /// <param name="cc">A comma-delimited array of string representations of email addresses which a carbon copy of the email should be sent to.</param>
        /// <param name="bcc">A comma-delimited array of string representations of email addresses which a blind carbon copy of the email should be sent to.</param>
        /// <param name="subject">The subject of the email.</param>
        /// <param name="message">The body of the email, in HTML.</param>
        /// <param name="attachments">An array of attachments.</param>
        /// <param name="priority">The priority of the email.</param>
        public static void SendHtmlEmail(string from, string sender, string to, string cc, string bcc, string subject, string message, AttachmentCollection attachments, MailPriority priority)
        {
            MailMessage mailMessage = new MailMessage();

            mailMessage.To.Add(to);
            mailMessage.CC.Add(cc);
            mailMessage.Bcc.Add(bcc);
            mailMessage.Subject    = subject;
            mailMessage.From       = new MailAddress(from);
            mailMessage.Sender     = new MailAddress(sender);
            mailMessage.IsBodyHtml = true;
            mailMessage.Body       = message;
            mailMessage.Priority   = priority;

            foreach (Attachment each in attachments)
            {
                mailMessage.Attachments.Add(each);
            }

            SendEmail(mailMessage, from, GoogleAccounts.Account(from).Password);
        }
Exemplo n.º 5
0
        private void mainWindow_ContentRendered(object sender, EventArgs e)
        {
            if (_isFirstTime)
            {
                _isFirstTime = false;

                Dispatcher.BeginInvoke(() =>
                {
                    InitializeAutoSave();
                    CheckActivation();

                    _delayTimer = new Timer(state => Task.Factory.StartNew(RunBackgroundTasks),
                                            null, 2000, Timeout.Infinite);

                    DispatcherTimer syncTimer = new DispatcherTimer(DispatcherPriority.Background);
                    syncTimer.Tick           += (timer, args) =>
                    {
                        Task.Factory.StartNew(() =>
                        {
                            if (GoogleAccounts.Exist() && !Settings.WorkOffline)
                            {
                                syncTimer.Stop();
                                SyncWithServer();

                                SyncHelper.LastUsedSyncHelper.OnCompletedEvent += (sync, syncArgs) =>
                                {
                                    syncTimer.Interval = TimeSpan.FromMinutes(1.5);
                                    syncTimer.Start();
                                };
                            }
                        });
                    };
                    syncTimer.Interval = TimeSpan.FromSeconds(5);
                    syncTimer.Start();
                });
            }
        }