예제 #1
0
        private void UpdateTime()
        {
            // Make sure all alerts update to reflect time change
            ReminderQueue.Populate();

            ((MainWindow)MainWindow).UpdateTimeFormat();
        }
        private void detail_OnEndEditEvent(object sender, EventArgs e)
        {
            stackPanel.Margin = new Thickness(0, 5, 0, 5);

            MonthDetail _sender     = (MonthDetail)sender;
            Appointment appointment = _sender.Appointment;

            if (!_forceSave && string.IsNullOrEmpty(appointment.Subject) &&
                !appointment.IsRepeating &&
                !AppointmentDatabase.AppointmentExists(appointment))
            {
                stackPanel.Children.Remove(_sender);
                AppointmentDatabase.Delete(appointment);
                ReminderQueue.RemoveItem(appointment.ID, appointment.IsRepeating ? appointment.RepresentingDate.Add(appointment.StartDate.TimeOfDay) : appointment.StartDate, ReminderType.Appointment);
            }
            else
            {
                Appointment exception = AppointmentDatabase.UpdateAppointment(appointment);

                if (exception != null)
                {
                    _sender.Appointment = exception;
                }

                ReminderQueue.Populate();
            }

            _forceSave = false;

            EndEditEvent(e);

            _activeDetail = null;
        }
예제 #3
0
 public bool AddReminder(Reminder reminder)
 {
     if (reminder.DateTime < this.dateTime)
     {
         Console.WriteLine($"Clock::AddReminder ({Type}) Can not set reminder to the past. Clock datetime = {DateTime.ToString("dd.MM.yyyy HH:mm:ss.ffff")} Reminder datetime = {reminder.DateTime.ToString("dd.MM.yyyy HH: mm:ss.ffff")} Reminder object = {reminder.Data}");
         return(false);
     }
     reminder.Clock = this;
     ReminderQueue.Enqueue(reminder);
     return(true);
 }
예제 #4
0
        private void deleteTask(TreeViewItem item, bool deleteFromDatabase = true)
        {
            // Delete the task from the file
            if (deleteFromDatabase)
            {
                UserTask task = item.Header as UserTask;
                TaskDatabase.Delete(task);
                ReminderQueue.RemoveItem(task.ID, task.StartDate, ReminderType.Task);
            }
            // else, we just want to use the animation.

            TreeViewItem parent = item.Parent as TreeViewItem;

            if (parent.Items.Count > 1)
            {
                if (Settings.AnimationsEnabled)
                {
                    AnimationHelpers.DeleteAnimation deleteAnim = new AnimationHelpers.DeleteAnimation(item);
                    deleteAnim.OnAnimationCompletedEvent += deleteAnim_OnAnimationCompletedEvent;
                    deleteAnim.Animate();
                }
                else
                {
                    parent.Items.Remove(item);
                }
            }
            else
            {
                if (Settings.AnimationsEnabled)
                {
                    AnimationHelpers.DeleteAnimation parentDeleteAnim = new AnimationHelpers.DeleteAnimation(parent);
                    parentDeleteAnim.OnAnimationCompletedEvent += parentDeleteAnim_OnAnimationCompletedEvent;
                    parentDeleteAnim.Animate();

                    if (tasksTreeView.Items.Count <= 1)
                    {
                        statusText.Text = "We didn't find anything to show here.";
                        new AnimationHelpers.Fade(statusText, AnimationHelpers.FadeDirection.In);
                    }
                }
                else
                {
                    tasksTreeView.Items.Remove(parent);
                    if (tasksTreeView.Items.Count == 0)
                    {
                        statusText.Text       = "We didn't find anything to show here.";
                        statusText.Visibility = Visibility.Visible;
                        statusText.Opacity    = 1;
                    }
                }
            }
        }
예제 #5
0
        public void AnimatedDelete(bool deleteFromDatabase = true)
        {
            if (_isDeleting)
            {
                return;
            }

            CloseToolTip();

            if (deleteFromDatabase && _appointment != null)
            {
                if (_appointment.IsRepeating)
                {
                    EditRecurring dlg = new EditRecurring(Application.Current.MainWindow, EditingType.Delete);

                    if (dlg.ShowDialog() == false)
                    {
                        return;
                    }

                    if (dlg.EditResult == EditResult.Single)
                    {
                        AppointmentDatabase.DeleteOne(_appointment, _appointment.RepresentingDate);
                    }
                    else
                    {
                        AppointmentDatabase.Delete(_appointment);
                    }
                }
                else
                {
                    AppointmentDatabase.Delete(_appointment);
                }

                ReminderQueue.RemoveItem(_appointment.ID, _appointment.IsRepeating ? _appointment.RepresentingDate.Add(_appointment.StartDate.TimeOfDay) : _appointment.StartDate, ReminderType.Appointment);
            }

            _isDeleting = true;
            DeleteStartEvent(EventArgs.Empty);

            if (Settings.AnimationsEnabled)
            {
                AnimationHelpers.DeleteAnimation delAnim = new AnimationHelpers.DeleteAnimation(this);
                delAnim.OnAnimationCompletedEvent += delAnim_OnAnimationCompletedEvent;
                delAnim.Animate();
            }
            else
            {
                DeleteEndEvent(EventArgs.Empty);
            }
        }
예제 #6
0
        public void Delete(EditResult?result = null)
        {
            CloseToolTip();

            if (_appointment != null)
            {
                if (_appointment.IsRepeating)
                {
                    if (!result.HasValue)
                    {
                        EditRecurring dlg = new EditRecurring(Window.GetWindow(this), EditingType.Delete);

                        if (dlg.ShowDialog() == false)
                        {
                            return;
                        }

                        if (dlg.EditResult == EditResult.Single)
                        {
                            AppointmentDatabase.DeleteOne(_appointment, _appointment.RepresentingDate);
                        }
                        else
                        {
                            AppointmentDatabase.Delete(_appointment);
                        }
                    }
                    else
                    {
                        if (result.Value == EditResult.Single)
                        {
                            AppointmentDatabase.DeleteOne(_appointment, _appointment.RepresentingDate);
                        }
                        else
                        {
                            AppointmentDatabase.Delete(_appointment);
                        }
                    }
                }
                else
                {
                    AppointmentDatabase.Delete(_appointment);
                }

                ReminderQueue.RemoveItem(_appointment.ID, _appointment.IsRepeating ? _appointment.RepresentingDate.Add(_appointment.StartDate.TimeOfDay) : _appointment.StartDate, ReminderType.Appointment);
            }

            IsHitTestVisible = false;

            DeleteStartEvent(EventArgs.Empty);
            DeleteEndEvent(EventArgs.Empty);
        }
        /// <summary>
        /// Delete any MonthDetail that is currently in edit mode.
        /// </summary>
        public void DeleteActive()
        {
            if (_activeDetail != null)
            {
                EndEditEvent(EventArgs.Empty);

                stackPanel.Margin = new Thickness(0, 5, 0, 5);

                stackPanel.Children.Remove(_activeDetail);
                AppointmentDatabase.Delete(_activeDetail.Appointment);

                ReminderQueue.RemoveItem(_activeDetail.Appointment.ID, _activeDetail.Appointment.IsRepeating ? _activeDetail.Appointment.RepresentingDate.Add(_activeDetail.Appointment.StartDate.TimeOfDay) : _activeDetail.Appointment.StartDate, ReminderType.Appointment);

                _activeDetail = null;
            }
        }
예제 #8
0
        private void RunBackgroundTasks()
        {
            ReminderQueue.InitializeAlerts();
            ShowConnectivity();

            if (Settings.WorkOffline)
            {
                return;
            }

            _delayTimer = new Timer(state =>
            {
                Task.Factory.StartNew(CheckForUpdates);
                _delayTimer = null;
            }, null, 30000, Timeout.Infinite);
        }
        public void DeleteAllAppointments()
        {
            foreach (MonthDetail each in stackPanel.Children)
            {
                if (!each.Appointment.ReadOnly && !each.Appointment.Category.ReadOnly)
                {
                    if (each.Appointment.IsRepeating)
                    {
                        AppointmentDatabase.DeleteOne(each.Appointment, each.Appointment.RepresentingDate);
                    }
                    else
                    {
                        AppointmentDatabase.Delete(each.Appointment);
                    }

                    ReminderQueue.RemoveItem(each.Appointment.ID, each.Appointment.IsRepeating ? each.Appointment.RepresentingDate.Add(each.Appointment.StartDate.TimeOfDay) : each.Appointment.StartDate, ReminderType.Appointment);

                    each.Delete(false);
                }
            }
        }
        public void Delete()
        {
            if (closeButton.IsEnabled == false)
            {
                return;
            }

            closeButton.IsEnabled = false;

            if (Settings.AnimationsEnabled)
            {
                AnimationHelpers.ZoomDisplay zoomDelete = new AnimationHelpers.ZoomDisplay(this, _crossZoom);
                zoomDelete.OnAnimationCompletedEvent += zoomDelete_OnAnimationCompletedEvent;
                zoomDelete.SwitchViews(AnimationHelpers.ZoomDirection.Out);
            }
            else
            {
                _crossZoom.Visibility = Visibility.Visible;
                Visibility            = Visibility.Collapsed;
                AppointmentDatabase.Delete(_appointment);
                ReminderQueue.RemoveItem(_appointment.ID, _appointment.IsRepeating ? _appointment.RepresentingDate.Add(_appointment.StartDate.TimeOfDay) : _appointment.StartDate, ReminderType.Appointment);
                CancelEditEvent(EventArgs.Empty);
            }
        }
 private void zoomDelete_OnAnimationCompletedEvent(object sender, EventArgs e)
 {
     AppointmentDatabase.Delete(_appointment);
     ReminderQueue.RemoveItem(_appointment.ID, _appointment.IsRepeating ? _appointment.RepresentingDate.Add(_appointment.StartDate.TimeOfDay) : _appointment.StartDate, ReminderType.Appointment);
     CancelEditEvent(e);
 }
        public async Task EndEdit(bool animate)
        {
            if (closeButton.IsEnabled == false)
            {
                return;
            }

            if (!IsRecurrenceRangeValid())
            {
                new TaskDialog(Window.GetWindow(this),
                               "Validation Check Failed",
                               "The duration of the appointment must be shorter than the recurrence frequency.",
                               MessageType.Error,
                               false).ShowDialog();

                return;
            }

            closeButton.IsEnabled = false;


            if (editStartDate.IsKeyboardFocusWithin)
            {
                DateTime start;

                if (DateTime.TryParse(editStartDate.Text, out start))
                {
                    editStartDate.SelectedDate = start;
                }
            }

            if (editEndDate.IsKeyboardFocusWithin)
            {
                DateTime end;

                if (DateTime.TryParse(editEndDate.Text, out end))
                {
                    editEndDate.SelectedDate = end;
                }
            }


            if (calendarSelector.SelectedIndex > 0)
            {
                PersistentGoogleCalendar gCal = (PersistentGoogleCalendar)((FrameworkElement)calendarSelector.SelectedItem).Tag;
                _appointment.CalendarUrl = gCal.Url;
                _appointment.Owner       = gCal.Owner;
                _appointment.Sync        = true;
            }
            else
            {
                _appointment.CalendarUrl = _appointment.Owner = "";

                //if (calendarSelector.SelectedIndex == 0)
                _appointment.Sync = false;
            }

            _appointment.Subject  = editSubject.Text;
            _appointment.Location = editLocation.Text;

            _appointment.StartDate = editStartDate.SelectedDate.Value.Add(TimeSpan.Parse(editStartTime.TextDisplay));

            DateTime endDate = editEndDate.SelectedDate.Value.Add(TimeSpan.Parse(editEndTime.TextDisplay));

            if (allDayEvent.IsChecked == true)
            {
                endDate = endDate.AddDays(1);
            }

            _appointment.EndDate = endDate;
            _appointment.AllDay  = (bool)allDayEvent.IsChecked;

            TimeSpan?reminder = editReminder.SelectedTime;

            _appointment.Reminder = reminder.HasValue ? reminder.Value : TimeSpan.FromSeconds(-1);

            if (editDetails.HasContentChanged)
            {
                await _appointment.SetDetailsDocumentAsync(editDetails.Document);
            }

            _appointment.LastModified = DateTime.UtcNow;

            Appointment exception = AppointmentDatabase.UpdateAppointment(_appointment);

            if (exception != null)
            {
                _appointment.CopyFrom(exception);
            }

            ReminderQueue.Populate();

            if (animate && Settings.AnimationsEnabled)
            {
                AnimationHelpers.ZoomDisplay zoomEnd = new AnimationHelpers.ZoomDisplay(this, _crossZoom);
                zoomEnd.OnAnimationCompletedEvent += zoomEnd_OnAnimationCompletedEvent;
                zoomEnd.SwitchViews(AnimationHelpers.ZoomDirection.Out);
            }
            else
            {
                _crossZoom.Visibility = Visibility.Visible;
                Visibility            = Visibility.Collapsed;
                EndEditEvent(EventArgs.Empty);
            }
        }
예제 #13
0
        /// <summary>
        /// Downloads data from server, and uploads local data to server for all linked Google accounts.
        /// </summary>
        private void GlobalResync(CancellationToken token)
        {
            DateTime lastSync = Settings.LastSuccessfulSync;

            try
            {
                GoogleAccount[] accounts = GoogleAccounts.AllAccounts();

                if (accounts == null || accounts.Length == 0)
                {
                    Done = true;
                    return;
                }

                ThrowIfNetworkUnavailable();

                // Lock the last sync in now; any events created during the
                // sync process will be ignored, and will be handled by the
                // next sync.
                Settings.LastSuccessfulSync = DateTime.UtcNow;

                SyncObject[] upload = SyncDatabase.AllSyncObjects();

                token.ThrowIfCancellationRequested();

                //
                // Calendars
                //
                Status = "Downloading calendar list";

                int calendars = SyncCalendars(accounts, token);
                _total    = calendars * 3 + 2;
                _progress = 1;
                RaiseEvent(ProgressChangedEvent);

                token.ThrowIfCancellationRequested();

                //
                // Events
                //
                foreach (GoogleAccount gAccount in accounts)
                {
                    string email = gAccount.Email;

                    foreach (string feedUrl in gAccount.LinkedCalendars)
                    {
                        //
                        // Update new account
                        //
                        if (SyncDatabase.GetSyncObject(email) != null)
                        {
                            Status = "Syncing " + email;

                            CalendarHelper.MergeCalendar(email, gAccount.Password, feedUrl, token);
                            SyncDatabase.Delete(email);

                            token.ThrowIfCancellationRequested();

                            _progress += 3;
                            RaiseEvent(ProgressChangedEvent);
                        }

                        //
                        // Update existing account
                        //
                        else
                        {
                            CalendarService calendarService = CalendarHelper.GetService(GlobalData.GoogleDataAppName,
                                                                                        email, gAccount.Password);

                            Status = "Uploading local calendar";

                            foreach (SyncObject each in upload)
                            {
                                switch (each.SyncType)
                                {
                                case SyncType.Create:
                                case SyncType.Modify:
                                {
                                    if (each.OldUrl != "")
                                    {
                                        // We don't know which account owned this calendar; try to delete it
                                        // from every account.
                                        try
                                        {
                                            IEnumerable <EventEntry> entries = CalendarHelper.GetElementsByDaytimerID(
                                                each.ReferenceID, calendarService, each.OldUrl,
                                                token);

                                            if (entries != null)
                                            {
                                                foreach (EventEntry entry in entries)
                                                {
                                                    entry.Delete();
                                                }
                                            }
                                        }
                                        catch { }
                                    }

                                    Appointment appt = AppointmentDatabase.GetAppointment(each.ReferenceID);

                                    //if (appt != null && appt.Sync && (appt.Owner == "" || appt.Owner == email))
                                    //	CalendarHelper.AddEvent(calendarService, feedUrl, appt);

                                    // Uncomment the following method after UI is implemented
                                    // which allows user to select where to upload event.

                                    if (appt != null && appt.Sync && appt.Owner == email)                                                    // && (appt.Owner == "" || appt.Owner == email))
                                    {
                                        CalendarHelper.AddEvent(calendarService,
                                                                appt.CalendarUrl != "" ? appt.CalendarUrl : feedUrl, appt,
                                                                token);
                                    }
                                }
                                break;

                                case SyncType.Delete:
                                {
                                    IEnumerable <EventEntry> entries = CalendarHelper.GetElementsByDaytimerID(
                                        each.ReferenceID, calendarService, each.Url != "" ? each.Url : feedUrl,
                                        token);

                                    if (entries != null)
                                    {
                                        foreach (EventEntry entry in entries)
                                        {
                                            entry.Delete();
                                        }
                                    }
                                }
                                break;

                                default:
                                    break;
                                }
                            }

                            token.ThrowIfCancellationRequested();

                            _progress++;
                            RaiseEvent(ProgressChangedEvent);

                            Status = "Downloading " + email;

                            IEnumerable <EventEntry> download = CalendarHelper.GetAllEventsModifiedSince(calendarService, feedUrl, lastSync, token);

                            token.ThrowIfCancellationRequested();

                            _progress++;
                            RaiseEvent(ProgressChangedEvent);

                            CalendarHelper.DownloadMergeCalendar(download, email, calendarService, feedUrl, token);

                            token.ThrowIfCancellationRequested();

                            _progress++;
                            RaiseEvent(ProgressChangedEvent);
                        }
                    }
                }

                Status = "Cleaning up";

                // Clear sync queue
                foreach (SyncObject each in upload)
                {
                    SyncDatabase.Delete(each);
                }

                _progress++;
                RaiseEvent(ProgressChangedEvent);
            }
            catch (Exception exc)
            {
                _error = exc;
                Settings.LastSuccessfulSync = lastSync;
            }
            finally
            {
                ReminderQueue.Populate();
                Done = true;
            }
        }