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;
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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;
            }
        }
        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);
 }
Ejemplo n.º 8
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();
                }
            }
        }