コード例 #1
0
        private void RecoverAppointment(Appointment appointment)
        {
            FlowDocument document = appointment.DetailsDocument;

            appointment.SaveChangesToDisk = true;
            appointment.DetailsDocument   = document;

            AppointmentDatabase.UpdateAppointment(appointment);
            new RecoveryDatabase(RecoveryVersion.LastRun).RecoveryAppointment = null;

            if (calendarDisplayMode == CalendarMode.Day)
            {
                if ((appointment.IsRepeating && appointment.OccursOnDate(dayView.Date)) ||
                    (!appointment.IsRepeating && appointment.StartDate <= dayView.Date && appointment.EndDate >= dayView.Date))
                {
                    dayView.Refresh();
                }
            }
            else if (calendarDisplayMode == CalendarMode.Month)
            {
                // TODO: Only refresh if appointment occurs in specified month.
                monthView.Refresh();
            }
            else if (calendarDisplayMode == CalendarMode.Week)
            {
                // TODO: Only refresh in appointment occurs in specified week.
                weekView.Refresh();
            }

            CalendarPeekContent.RefreshAll();
        }
コード例 #2
0
        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
        private void privateMenuItem_Click(object sender, RoutedEventArgs e)
        {
            if (CheckReadOnly())
            {
                return;
            }

            _appointment.Private = privateMenuItem.IsChecked == true;
            AppointmentDatabase.UpdateAppointment(_appointment);
        }
コード例 #4
0
        private void Resize_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_isResized)
            {
                _isResized = false;
                AppointmentDatabase.UpdateAppointment(_appointment);
                CalendarPeekContent.RefreshAll();
            }

            Mouse.Capture(null);
        }
コード例 #5
0
        private void ChangeShowAs(ShowAs showAs)
        {
            if (CheckReadOnly())
            {
                return;
            }

            _appointment.ShowAs = showAs;
            AppointmentDatabase.UpdateAppointment(_appointment);

            showAsStrip.SetResourceReference(Border.BackgroundProperty, _appointment.ShowAs.ToString() + "Fill");
            RaiseShowAsChangedEvent();
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        public static void DownloadMergeCalendar(IEnumerable <EventEntry> entries, string owner, CalendarService calendarService, string feedUrl, CancellationToken token)
        {
            if (entries == null)
            {
                return;
            }

            foreach (EventEntry each in entries)
            {
                for (int i = 0; i < MaxTries; i++)
                {
                    try
                    {
                        if (each.Status.Value != EventEntry.EventStatus.CANCELED_VALUE)
                        {
                            if (!each.IsDraft)
                            {
                                // Always get a fresh event, in case it has been modified elsewhere.
                                EventEntry entry = each;

                                try { entry = GetElementByGoogleID(each.EventId, calendarService, feedUrl, each.Etag); }
                                catch (GDataNotModifiedException) { }

                                string   id             = GetDaytimerID(entry);
                                DateTime serverModified = entry.Edited.DateValue;
                                DateTime localModified  = DateTime.MinValue;
                                bool     exists         = false;

                                Appointment appt = new Appointment(false);

                                if (string.IsNullOrEmpty(id))
                                {
                                    appt.ID = IDGenerator.GenerateID();
                                    AddExtendedProperty(entry, DaytimerID, appt.ID);
                                }
                                else
                                {
                                    Appointment existing = AppointmentDatabase.GetAppointment(id);

                                    if (existing != null)
                                    {
                                        localModified = existing.LastModified;
                                        exists        = true;
                                        appt          = new Appointment(existing);
                                    }
                                    else
                                    {
                                        appt.ID = id;
                                    }
                                }

                                if (serverModified > localModified)
                                {
                                    // Prevent hangup where after first sync, all events would have
                                    // the same owner as the first synced account.
                                    if (!exists)
                                    {
                                        appt.Owner       = owner;
                                        appt.CalendarUrl = feedUrl;
                                    }

                                    if (entry.Times.Count > 0)
                                    {
                                        When when = entry.Times[0];

                                        appt.StartDate = when.StartTime;                                    //.ToLocalTime();
                                        appt.EndDate   = when.EndTime;                                      //.ToLocalTime();
                                        appt.AllDay    = when.AllDay;
                                    }

                                    if (entry.Reminders.Count > 0)
                                    {
                                        Reminder reminder = GetReminder(entry.Reminders,
                                                                        new Reminder.ReminderMethod[] { Reminder.ReminderMethod.alert, Reminder.ReminderMethod.all });                //entry.Reminders[0];

                                        if (reminder == null)
                                        {
                                            reminder = entry.Reminders[0];
                                        }

                                        appt.Reminder = reminder.Method == Reminder.ReminderMethod.none
                                                                                        ? TimeSpan.FromSeconds(-1)
                                                                                        : new TimeSpan(reminder.Days, reminder.Hours, reminder.Minutes, 0);
                                    }
                                    else
                                    {
                                        appt.Reminder = TimeSpan.FromSeconds(-1);
                                    }

                                    appt.Subject      = entry.Title.Text;
                                    appt.Location     = entry.Locations[0].ValueString;
                                    appt.ReadOnly     = entry.ReadOnly;
                                    appt.LastModified = serverModified;

                                    // Google only supports two "show as" values: Busy and Free.
                                    if (entry.EventTransparency.Value == EventEntry.Transparency.OPAQUE_VALUE)
                                    {
                                        appt.ShowAs = ShowAs.Busy;
                                    }
                                    else
                                    {
                                        if (appt.ShowAs == ShowAs.Busy)
                                        {
                                            appt.ShowAs = ShowAs.Free;
                                        }
                                        else
                                        {
                                            ExtendedProperty showas = GetExtendedProperty(entry, DaytimerShowAs);

                                            if (showas != null)
                                            {
                                                appt.ShowAs = (ShowAs)Enum.Parse(typeof(ShowAs), showas.Value, true);
                                            }
                                        }
                                    }

                                    if (entry.Recurrence != null)
                                    {
                                        appt.SetRecurrenceValues(entry.Recurrence.Value);
                                    }
                                    else
                                    {
                                        appt.IsRepeating = false;
                                    }

                                    if (entry.OriginalEvent != null)
                                    {
                                        EventEntry rEntry = GetElementByGoogleID(entry.OriginalEvent.IdOriginal, calendarService, feedUrl);

                                        string rID = GetDaytimerID(rEntry);

                                        if (string.IsNullOrEmpty(rID))
                                        {
                                            AddExtendedProperty(rEntry, DaytimerID, rID = IDGenerator.GenerateID());
                                        }

                                        appt.RepeatID = rID;
                                    }
                                    else
                                    {
                                        appt.RepeatID = null;
                                    }

                                    //ExtendedProperty details = GetExtendedProperty(entry, DaytimerDetails);
                                    //FlowDocument detailsDocument = null;

                                    //if (details != null)
                                    //	detailsDocument = FlowDocumentDeserialize(details.Value);

                                    if (!string.IsNullOrEmpty(entry.Content.Content))
                                    {
                                        // Since Google does not support text formatting,
                                        // don't change the document unless the text content
                                        // is different.
                                        if (appt.Details != entry.Content.Content)
                                        {
                                            // Edited through the Google UI or another application.
                                            //if (new TextRange(detailsDocument.ContentStart, detailsDocument.ContentEnd).Text != entry.Content.Content)
                                            appt.DetailsDocument = new FlowDocument(new Paragraph(new Run(entry.Content.Content)));

                                            //// Edited through another Daytimer application.
                                            //else
                                            //	appt.DetailsDocument = detailsDocument;
                                        }
                                    }
                                    else
                                    {
                                        //if (detailsDocument != null && string.IsNullOrEmpty(new TextRange(detailsDocument.ContentStart, detailsDocument.ContentEnd).Text))
                                        //	appt.DetailsDocument = detailsDocument;
                                        //else
                                        appt.DetailsDocument = new FlowDocument();
                                    }

                                    //
                                    // Custom attributes
                                    //
                                    ExtendedProperty category = GetExtendedProperty(entry, DaytimerCategory);
                                    ExtendedProperty priority = GetExtendedProperty(entry, DaytimerPriority);

                                    if (category != null)
                                    {
                                        appt.CategoryID = category.Value;
                                    }

                                    if (priority != null)
                                    {
                                        appt.Priority = (Priority)Enum.Parse(typeof(Priority), priority.Value, true);
                                    }


                                    if (exists)
                                    {
                                        AppointmentDatabase.UpdateAppointment(appt, false);
                                    }
                                    else
                                    {
                                        AppointmentDatabase.Add(appt, false);
                                    }
                                }
                            }
                        }
                        else
                        {
                            if (each.OriginalEvent != null)
                            {
                                EventEntry rEntry = GetElementByGoogleID(each.OriginalEvent.IdOriginal, calendarService, feedUrl);

                                if (rEntry != null)
                                {
                                    string rID = GetDaytimerID(rEntry);

                                    if (string.IsNullOrEmpty(rID))
                                    {
                                        AddExtendedProperty(rEntry, DaytimerID, rID = IDGenerator.GenerateID());
                                    }

                                    Appointment appt = AppointmentDatabase.GetAppointment(rID);

                                    if (appt == null)
                                    {
                                        appt             = new Appointment(false);
                                        appt.ID          = rID;
                                        appt.Owner       = owner;
                                        appt.CalendarUrl = feedUrl;
                                    }
                                    else if (appt.Owner != owner || (appt.CalendarUrl != "" && appt.CalendarUrl != feedUrl))
                                    {
                                        break;
                                    }

                                    DateTime[] skip = appt.Recurrence.Skip;

                                    if (skip == null)
                                    {
                                        skip = new DateTime[] { each.Times[0].StartTime.Date }
                                    }
                                    ;
                                    else
                                    {
                                        if (Array.IndexOf(skip, each.Times[0].StartTime.Date) == -1)
                                        {
                                            Array.Resize <DateTime>(ref skip, skip.Length + 1);
                                            skip[skip.Length - 1] = each.Times[0].StartTime.Date;
                                        }
                                    }

                                    appt.Recurrence.Skip = skip;
                                    appt.IsRepeating     = true;
                                    AppointmentDatabase.UpdateAppointment(appt, false);


                                    //if (!string.IsNullOrEmpty(rID))
                                    //{
                                    //// If the appointment is null, it will be synced later; we don't have to worry about
                                    //// reading the skip dates now.
                                    //if (appt != null)
                                    //{
                                    //	DateTime[] skip = appt.RepeatSkip;

                                    //	if (skip == null)
                                    //		skip = new DateTime[] { each.Times[0].StartTime.Date };
                                    //	else
                                    //	{
                                    //		if (Array.IndexOf(skip, each.Times[0].StartTime.Date) == -1)
                                    //		{
                                    //			Array.Resize<DateTime>(ref skip, skip.Length + 1);
                                    //			skip[skip.Length - 1] = each.Times[0].StartTime.Date;
                                    //		}
                                    //	}

                                    //	appt.RepeatSkip = skip;
                                    //	AppointmentDatabase.UpdateAppointment(appt, false);
                                    //}
                                    //}
                                }
                                else
                                {
                                    string id = GetDaytimerID(each);

                                    if (id != null)
                                    {
                                        Appointment del = AppointmentDatabase.GetAppointment(id);

                                        if (del != null && del.Owner == owner && (del.CalendarUrl == feedUrl || del.CalendarUrl == ""))
                                        {
                                            AppointmentDatabase.Delete(id, false);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                string id = GetDaytimerID(each);

                                if (id != null)
                                {
                                    Appointment del = AppointmentDatabase.GetAppointment(id);

                                    if (del != null &&
                                        del.Owner == owner && (del.CalendarUrl == feedUrl || del.CalendarUrl == ""))
                                    {
                                        AppointmentDatabase.Delete(id, false);
                                    }
                                }
                            }
                        }

                        break;
                    }
                    catch
                    {
                        if (i == MaxTries - 1)
                        {
                            throw;
                        }

                        Thread.Sleep(AttemptDelay);
                    }

                    token.ThrowIfCancellationRequested();
                }
            }
        }