private void processOutlookExceptions(ref AppointmentItem ai, Event ev, Boolean forceCompare)
        {
            if (!HasExceptions(ev, checkLocalCacheOnly: true))
            {
                return;
            }

            RecurrencePattern oPattern = null;

            try {
                oPattern = ai.GetRecurrencePattern();
                foreach (Event gExcp in Recurrence.Instance.googleExceptions.Where(exp => exp.RecurringEventId == ev.Id))
                {
                    DateTime oExcpDate = gExcp.OriginalStartTime.DateTime ?? DateTime.Parse(gExcp.OriginalStartTime.Date);
                    log.Fine("Found Google exception for " + oExcpDate.ToString());

                    AppointmentItem newAiExcp = null;
                    try {
                        getOutlookInstance(oPattern, oExcpDate, ref newAiExcp);
                        if (newAiExcp == null)
                        {
                            continue;
                        }

                        if (gExcp.Status == "cancelled")
                        {
                            Forms.Main.Instance.Console.Update(OutlookOgcs.Calendar.GetEventSummary(newAiExcp) + "<br/>Deleted.", Console.Markup.calendar);
                            newAiExcp.Delete();
                        }
                        else if (Settings.Instance.ExcludeDeclinedInvites && gExcp.Attendees != null && gExcp.Attendees.Count(a => a.Self == true && a.ResponseStatus == "declined") == 1)
                        {
                            Forms.Main.Instance.Console.Update(OutlookOgcs.Calendar.GetEventSummary(newAiExcp) + "<br/>Declined.", Console.Markup.calendar);
                            newAiExcp.Delete();
                        }
                        else
                        {
                            int itemModified = 0;
                            OutlookOgcs.Calendar.Instance.UpdateCalendarEntry(ref newAiExcp, gExcp, ref itemModified, forceCompare);
                            if (itemModified > 0)
                            {
                                try {
                                    newAiExcp.Save();
                                } catch (System.Exception ex) {
                                    OGCSexception.Analyse(ex);
                                    if (ex.Message == "Cannot save this item.")
                                    {
                                        Forms.Main.Instance.Console.Update("Uh oh! Outlook wasn't able to save this recurrence exception! " +
                                                                           "You may have two occurences on the same day, which it doesn't allow.", Console.Markup.warning);
                                    }
                                }
                            }
                        }
                    } finally {
                        newAiExcp = (AppointmentItem)OutlookOgcs.Calendar.ReleaseObject(newAiExcp);
                    }
                }
            } finally {
                oPattern = (RecurrencePattern)OutlookOgcs.Calendar.ReleaseObject(oPattern);
            }
        }
Exemple #2
0
        public void DeleteAllAppointments()
        {
            _Application app          = null;
            _NameSpace   session      = null;
            MAPIFolder   folder       = null;
            Items        contactItems = null;

            app          = new Application();
            session      = app.Session;
            folder       = session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
            contactItems = folder.Items;

            try
            {
                //++++++++++++Begin Edit Area+++++++++++++++

                foreach (object item in contactItems)
                {
                    AppointmentItem appointmentItem = item as AppointmentItem;

                    appointmentItem.Delete();
                }

                //++++++++++++End Edit Area+++++++++++++++
            }
            catch (System.Exception ex)
            {
            }
        }
        /// <summary>
        /// Hard-deletes all meetings newer than today that the add-in created.
        /// </summary>
        public int DeleteFutureMeetings()
        {
            Log.WriteDebug("Deleting all future meetings");

            Outlook.MAPIFolder calendar = Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
            Outlook.Items      items    = calendar.Items;

            // start deleting from 11:59pm the previous night to capture the all-day events
            DateTime startDate = DateTime.Now.Date.AddMinutes(-1);

            string filter = String.Format("[Start] >= '{0}' and [MessageClass] = '{1}'",
                                          String.Format("{0} {1}", startDate.ToShortDateString(), startDate.ToShortTimeString()), CUSTOM_MESSAGE_CLASS);

            items = items.Restrict(filter);

            // https://msdn.microsoft.com/en-us/library/office/microsoft.office.interop.outlook._appointmentitem.delete(v=office.15).aspx
            // https://social.msdn.microsoft.com/Forums/office/en-US/53a07e5d-ab16-4930-90bf-52215f084d59/appointmentitemrecipientsremoveindex-question?forum=outlookdev
            // Seriously Outlook Object Model? So the index starts at 1 and we have to always decrement instead of increment.
            for (int j = items.Count; j >= 1; j--)
            {
                AppointmentItem item = items[j] as AppointmentItem;
                item.Delete();
            }

            PurgeMeetingsFromDeletedItems();

            Log.WriteEntry("Deleted all future meetings");

            return(items.Count);
        }
        private void calender_events_table_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 8)
            {
                Show_Calendar_Events ce = new Show_Calendar_Events();
                ce.subject_lb.Text       = this.calender_events_table.CurrentRow.Cells[0].Value.ToString();
                ce.organizer_lb.Text     = this.calender_events_table.CurrentRow.Cells[1].Value.ToString();
                ce.location_lb.Text      = this.calender_events_table.CurrentRow.Cells[2].Value.ToString();
                ce.start_time_lb.Text    = this.calender_events_table.CurrentRow.Cells[3].Value.ToString();
                ce.end_time_lb.Text      = this.calender_events_table.CurrentRow.Cells[4].Value.ToString();
                ce.start_date_lb.Text    = this.calender_events_table.CurrentRow.Cells[5].Value.ToString();
                ce.end_date_lb.Text      = this.calender_events_table.CurrentRow.Cells[6].Value.ToString();
                ce.all_day_event_lb.Text = this.calender_events_table.CurrentRow.Cells[7].Value.ToString();
                ce.ShowDialog();
            }
            else if (e.ColumnIndex == 9)
            {
                Microsoft.Office.Interop.Outlook.Application OlApp = new Microsoft.Office.Interop.Outlook.Application();
                NameSpace  OlNamspace        = OlApp.GetNamespace("MAPI");
                MAPIFolder AppointmentFolder = OlNamspace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

                AppointmentFolder.Items.IncludeRecurrences = true;

                Items calendarItems = AppointmentFolder.Items;

                AppointmentItem item = calendarItems[this.calender_events_table.CurrentRow.Cells[0].Value.ToString()] as AppointmentItem;

                item.Delete();
                MessageBox.Show("Calendar event has been deleted.");
                calender_events_table.Rows.Remove(calender_events_table.CurrentRow);
                calender_events_table.Update();
                calender_events_table.Refresh();
            }
        }
Exemple #5
0
        public void CompareOutlookPattern(Event ev, ref RecurrencePattern aiOpattern, SyncDirection syncDirection, System.Text.StringBuilder sb, ref int itemModified)
        {
            if (ev.Recurrence == null)
            {
                return;
            }

            log.Fine("Building a temporary recurrent Appointment generated from Event");
            AppointmentItem evAI = OutlookCalendar.Instance.IOutlook.UseOutlookCalendar().Items.Add() as AppointmentItem;

            evAI.Start = DateTime.Parse(ev.Start.Date ?? ev.Start.DateTime);

            RecurrencePattern evOpattern = null;

            try {
                buildOutlookPattern(ev, evAI, out evOpattern);
                log.Fine("Comparing Google recurrence to Outlook equivalent");

                if (MainForm.CompareAttribute("Recurrence Type", syncDirection,
                                              evOpattern.RecurrenceType.ToString(), aiOpattern.RecurrenceType.ToString(), sb, ref itemModified))
                {
                    aiOpattern.RecurrenceType = evOpattern.RecurrenceType;
                }
                if (MainForm.CompareAttribute("Recurrence Interval", syncDirection,
                                              evOpattern.Interval.ToString(), aiOpattern.Interval.ToString(), sb, ref itemModified))
                {
                    aiOpattern.Interval = evOpattern.Interval;
                }
                if (MainForm.CompareAttribute("Recurrence Instance", syncDirection,
                                              evOpattern.Instance.ToString(), aiOpattern.Instance.ToString(), sb, ref itemModified))
                {
                    aiOpattern.Instance = evOpattern.Instance;
                }
                if (MainForm.CompareAttribute("Recurrence DoW", syncDirection,
                                              evOpattern.DayOfWeekMask.ToString(), aiOpattern.DayOfWeekMask.ToString(), sb, ref itemModified))
                {
                    aiOpattern.DayOfWeekMask = evOpattern.DayOfWeekMask;
                }
                if (MainForm.CompareAttribute("Recurrence MoY", syncDirection,
                                              evOpattern.MonthOfYear.ToString(), aiOpattern.MonthOfYear.ToString(), sb, ref itemModified))
                {
                    aiOpattern.MonthOfYear = evOpattern.MonthOfYear;
                }
                if (MainForm.CompareAttribute("Recurrence NoEndDate", syncDirection,
                                              evOpattern.NoEndDate, aiOpattern.NoEndDate, sb, ref itemModified))
                {
                    aiOpattern.NoEndDate = evOpattern.NoEndDate;
                }
                if (MainForm.CompareAttribute("Recurrence Occurences", syncDirection,
                                              evOpattern.Occurrences.ToString(), aiOpattern.Occurrences.ToString(), sb, ref itemModified))
                {
                    aiOpattern.Occurrences = evOpattern.Occurrences;
                }
            } finally {
                evOpattern = (RecurrencePattern)OutlookCalendar.ReleaseObject(evOpattern);
                evAI.Delete();
                evAI = (AppointmentItem)OutlookCalendar.ReleaseObject(evAI);
            }
        }
Exemple #6
0
        private void processOutlookExceptions(AppointmentItem ai, Event ev, Boolean forceCompare)
        {
            if (!HasExceptions(ev, checkLocalCacheOnly: true))
            {
                return;
            }

            if (!ai.Saved)
            {
                ai.Save();
            }

            RecurrencePattern oPattern = ai.GetRecurrencePattern();

            foreach (Event gExcp in Recurrence.Instance.googleExceptions.Where(exp => exp.RecurringEventId == ev.Id))
            {
                log.Fine("Found Google exception for " + (gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date));

                DateTime        oExcpDate = DateTime.Parse(gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date);
                AppointmentItem newAiExcp = getOutlookInstance(oPattern, oExcpDate);
                if (newAiExcp == null)
                {
                    continue;
                }

                if (gExcp.Status != "cancelled")
                {
                    int itemModified = 0;
                    newAiExcp = OutlookCalendar.Instance.UpdateCalendarEntry(newAiExcp, gExcp, ref itemModified, forceCompare);
                    if (itemModified > 0)
                    {
                        try {
                            newAiExcp.Save();
                        } catch (System.Exception ex) {
                            log.Warn(ex.Message);
                            if (ex.Message == "Cannot save this item.")
                            {
                                MainForm.Instance.Logboxout("Uh oh! Outlook wasn't able to save this recurrence exception! " +
                                                            "You may have two occurences on the same day, which it doesn't allow.");
                            }
                        }
                    }
                }
                else
                {
                    MainForm.Instance.Logboxout(OutlookCalendar.GetEventSummary(ai) + "\r\nDeleted.");
                    newAiExcp.Delete();
                }
                newAiExcp = (AppointmentItem)OutlookCalendar.ReleaseObject(newAiExcp);
            }
            if (!ai.Saved)
            {
                ai.Save();
            }
            oPattern = (RecurrencePattern)OutlookCalendar.ReleaseObject(oPattern);
        }
        /// <summary>
        /// Finds all meetings created by our add-in inside Deleted Items and deletes them.
        /// </summary>
        private void PurgeMeetingsFromDeletedItems()
        {
            Outlook.MAPIFolder deletedItems = Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
            Outlook.Items      itemsToPurge = deletedItems.Items;
            itemsToPurge = itemsToPurge.Restrict(String.Format("[MessageClass] = '{0}'", CUSTOM_MESSAGE_CLASS));

            for (int j = itemsToPurge.Count; j >= 1; j--)
            {
                AppointmentItem item = itemsToPurge[j] as AppointmentItem;
                item.Delete();
            }
        }
        /// <summary>
        /// Applies the appropiate rule to the meeting parameter
        /// </summary>
        /// <param name="meetingItem">The meeting that needs processing</param>
        /// <param name="rule">the associated decline rule for the folder of this meetingItem</param>
        private static void ProcessRule(MeetingItem meetingItem, DeclineRuleSetting rule)
        {
            // if it's a Cancelation, delete it from calendar
            if (meetingItem.Class == OlObjectClass.olMeetingCancellation)
            {
                if (meetingItem.GetAssociatedAppointment(false) != null)
                {
                    meetingItem.GetAssociatedAppointment(false).Delete(); return;
                }
                meetingItem.Delete(); return; // if deleted by user/app, delete the whole message
            }

            // get associated appointment
            AppointmentItem appointment         = meetingItem.GetAssociatedAppointment(false);
            string          globalAppointmentID = appointment.GlobalAppointmentID;

            // optional, send notification back to sender
            appointment.ResponseRequested &= rule.SendResponse;

            // set decline to the meeting
            MeetingItem responseMeeting = appointment.Respond(rule.Response, true);

            // https://msdn.microsoft.com/en-us/VBA/Outlook-VBA/articles/appointmentitem-respond-method-outlook
            // says that Respond() will return a new meeting object for Tentative response

            // optional, add a meesage to the Body
            if (!String.IsNullOrEmpty(rule.Message))
            {
                (responseMeeting ?? meetingItem).Body = rule.Message;
            }

            // send decline
            //if(rule.Response == OlMeetingResponse.olMeetingDeclined)
            (responseMeeting ?? meetingItem).Send();

            // and delete the appointment if tentative
            if (rule.Response == OlMeetingResponse.olMeetingTentative)
            {
                appointment.Delete();
            }

            // after Sending the response, sometimes the appointment doesn't get deleted from calendar,
            // but appointmnent could become and invalid object, so we need to search for it and delete it
            AppointmentItem newAppointment = (AppointmentItem)Globals.AddIn.Application.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar).Items
                                             .Find("@SQL=\"http://schemas.microsoft.com/mapi/id/{6ED8DA90-450B-101B-98DA-00AA003F1305}/00030102\" = '"
                                                   + globalAppointmentID + "' ");

            if (newAppointment != null)
            {
                newAppointment.Delete();
            }
        }
Exemple #9
0
        public override bool DeleteCalendarItem(string content)
        {
            string reservationsNumber = "ReservationsNumber not found";
            //<div><strong>Reservation #:</strong> 1322312<br>
            string pattern = "<strong>Reservation #:</strong> (\\d+)<br>";
            Regex  regex   = new Regex(pattern);
            Match  match   = regex.Match(content);

            if ((match.Success) && (match.Groups.Count > 1))
            {
                reservationsNumber = match.Groups[1].Value;
                ConEx.Log("DeleteCalendarItem: reservationsNumber={0}", reservationsNumber);

                Items items = GetAppointmentsByReservationNumber(reservationsNumber);
                if ((items != null) && (items.Count > 0))
                {
                    AppointmentItem item = items.GetFirst();
                    item.Delete();
                    return(true);
                    //
                }

                else
                {
                    return(false);
                }

                //
            }

            /*  if using the Body   this alternative is not thoroughly implemented through this code
             * pattern = "(Reservation #: (\\d+))";
             * regex = new Regex( pattern );
             * match = regex.Match( content );
             * if( ( match.Success ) && ( match.Groups.Count > 1 ) )
             * {
             *  reservationsNumber = match.Groups[2].Value;
             *  Items items = GetAppointmentsByReservationNumber( reservationsNumber );
             *  if( ( items != null ) && ( items.Count > 0 ) )
             *      items.GetFirst().Delete();
             *
             *  return;
             *  //
             * }
             */

            return(false);
            //
        }
        private void processOutlookExceptions(AppointmentItem ai, Event ev, Boolean forceCompare)
        {
            if (!HasExceptions(ev, checkLocalCacheOnly: true))
            {
                return;
            }

            if (!ai.Saved)
            {
                ai.Save();
            }

            RecurrencePattern oPattern = ai.GetRecurrencePattern();

            foreach (Event gExcp in Recurrence.Instance.googleExceptions.Where(exp => exp.RecurringEventId == ev.Id))
            {
                log.Fine("Found Google exception for " + (gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date));

                DateTime        oExcpDate = DateTime.Parse(gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date);
                AppointmentItem newAiExcp = getOutlookInstance(oPattern, oExcpDate);
                if (newAiExcp == null)
                {
                    continue;
                }

                if (gExcp.Status != "cancelled")
                {
                    int itemModified = 0;
                    newAiExcp = OutlookCalendar.Instance.UpdateCalendarEntry(newAiExcp, gExcp, ref itemModified, forceCompare);
                    if (itemModified > 0)
                    {
                        newAiExcp.Save();
                    }
                }
                else
                {
                    MainForm.Instance.Logboxout(OutlookCalendar.GetEventSummary(ai) + "\r\nDeleted.");
                    newAiExcp.Delete();
                }
                newAiExcp = (AppointmentItem)OutlookCalendar.ReleaseObject(newAiExcp);
            }
            if (!ai.Saved)
            {
                ai.Save();
            }
            oPattern = (RecurrencePattern)OutlookCalendar.ReleaseObject(oPattern);
        }
Exemple #11
0
        public static void DeleteEventOutlook(CancelMeetingRoomForm data)
        {
            try
            {
                Application app = new Application();

                MAPIFolder        calendar      = app.Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
                Items             calendarItems = calendar.Items;
                AppointmentItem   item          = calendarItems["Test Appointment"] as AppointmentItem;
                RecurrencePattern pattern       = item.GetRecurrencePattern();
                AppointmentItem   itemDelete    = pattern.GetOccurrence(new DateTime(2006, 6, 28, 8, 0, 0));

                if (itemDelete != null)
                {
                    itemDelete.Delete();
                }
            }
            catch (System.Exception)
            {
            }
        }
Exemple #12
0
        public void CompareOutlookPattern(Event ev, ref RecurrencePattern aiOpattern, Sync.Direction syncDirection, System.Text.StringBuilder sb, ref int itemModified)
        {
            if (ev.Recurrence == null)
            {
                return;
            }

            log.Fine("Building a temporary recurrent Appointment generated from Event");
            AppointmentItem evAI = OutlookOgcs.Calendar.Instance.IOutlook.UseOutlookCalendar().Items.Add() as AppointmentItem;

            evAI.Start = ev.Start.DateTime ?? DateTime.Parse(ev.Start.Date);

            RecurrencePattern evOpattern = null;

            try {
                buildOutlookPattern(ev, evAI, out evOpattern);
                log.Fine("Comparing Google recurrence to Outlook equivalent");

                //Some versions of Outlook are erroring when 2-way syncing weekday recurring series.
                //Even though Outlook has Interval of zero, which is illegal, when this is updated, it won't save. Issue #398
                Boolean skipIntervalCheck = false;
                if (aiOpattern.RecurrenceType == OlRecurrenceType.olRecursWeekly && aiOpattern.DayOfWeekMask == getDOWmask("BYDAY=MO,TU,WE,TH,FR") && aiOpattern.Interval == 0 &&
                    evOpattern.RecurrenceType == aiOpattern.RecurrenceType && evOpattern.DayOfWeekMask == aiOpattern.DayOfWeekMask && evOpattern.Interval == 1)
                {
                    skipIntervalCheck = true;
                }

                if (Sync.Engine.CompareAttribute("Recurrence Type", syncDirection,
                                                 evOpattern.RecurrenceType.ToString(), aiOpattern.RecurrenceType.ToString(), sb, ref itemModified))
                {
                    aiOpattern.RecurrenceType = evOpattern.RecurrenceType;
                }
                if (!skipIntervalCheck && Sync.Engine.CompareAttribute("Recurrence Interval", syncDirection,
                                                                       evOpattern.Interval.ToString(), aiOpattern.Interval.ToString(), sb, ref itemModified))
                {
                    aiOpattern.Interval = evOpattern.Interval;
                }
                if (Sync.Engine.CompareAttribute("Recurrence Instance", syncDirection,
                                                 evOpattern.Instance.ToString(), aiOpattern.Instance.ToString(), sb, ref itemModified))
                {
                    aiOpattern.Instance = evOpattern.Instance;
                }
                if (Sync.Engine.CompareAttribute("Recurrence DoW", syncDirection,
                                                 evOpattern.DayOfWeekMask.ToString(), aiOpattern.DayOfWeekMask.ToString(), sb, ref itemModified))
                {
                    aiOpattern.DayOfWeekMask = evOpattern.DayOfWeekMask;
                }
                if (Sync.Engine.CompareAttribute("Recurrence MoY", syncDirection,
                                                 evOpattern.MonthOfYear.ToString(), aiOpattern.MonthOfYear.ToString(), sb, ref itemModified))
                {
                    aiOpattern.MonthOfYear = evOpattern.MonthOfYear;
                }
                if (Sync.Engine.CompareAttribute("Recurrence NoEndDate", syncDirection,
                                                 evOpattern.NoEndDate, aiOpattern.NoEndDate, sb, ref itemModified))
                {
                    aiOpattern.NoEndDate = evOpattern.NoEndDate;
                }
                if (Sync.Engine.CompareAttribute("Recurrence Occurences", syncDirection,
                                                 evOpattern.Occurrences.ToString(), aiOpattern.Occurrences.ToString(), sb, ref itemModified))
                {
                    aiOpattern.Occurrences = evOpattern.Occurrences;
                }
            } finally {
                evOpattern = (RecurrencePattern)OutlookOgcs.Calendar.ReleaseObject(evOpattern);
                evAI.Delete();
                evAI = (AppointmentItem)OutlookOgcs.Calendar.ReleaseObject(evAI);
            }
        }
        private static void UpdateOutlookAppointment(AppointmentItem appointment, string mtg_id, MeetingRequest request, bool reload_pattern = false)
        {
            int mrbs_id = -1;

            int.TryParse(mtg_id.Substring(0, mtg_id.IndexOf(";")), out mrbs_id);

            // appointment.Subject = request.Description;

            if ((appointment.RecurrenceState != OlRecurrenceState.olApptMaster) || (appointment.EntryID == ""))
            {
                appointment.Start = request.Start;
                appointment.End   = request.End;
            }

            appointment.Location = String.Format("{0} - {1}", Database.GetAreaNameByRoomId(request.RoomId), Database.GetRoomNameById(request.RoomId));

            if (request.RepeatTypeId > 0)
            {
                RecurrencePattern pattern;

                if (reload_pattern)
                {
                    appointment.ClearRecurrencePattern();
                }

                pattern = appointment.GetRecurrencePattern();

                switch (request.RepeatTypeId)
                {
                case 1:
                    pattern.RecurrenceType = OlRecurrenceType.olRecursDaily;
                    pattern.Interval       = 1;
                    break;

                case 2:
                    char[] rev = request.RepeatWeeklyCode.ToCharArray();

                    pattern.RecurrenceType = OlRecurrenceType.olRecursWeekly;
                    pattern.Interval       = request.RepeatNumberOfWeeks;
                    pattern.DayOfWeekMask  = (OlDaysOfWeek)Convert.ToInt32(new string(request.RepeatWeeklyCode.ToCharArray().Reverse().ToArray()), 2);
                    break;

                case 3:
                    if (request.RepeatMonthlyByWeekday)
                    {
                        pattern.RecurrenceType = OlRecurrenceType.olRecursMonthNth;
                        pattern.Interval       = 1;
                        pattern.DayOfWeekMask  = (OlDaysOfWeek)((int)Math.Pow(2, request.RepeatWeekdayOfMonth));
                        pattern.Instance       = request.RepeatWeekdaysOfMonth;
                    }
                    else
                    {
                        pattern.RecurrenceType = OlRecurrenceType.olRecursMonthly;
                        pattern.Interval       = 1;
                        pattern.DayOfMonth     = request.RepeatDayOfMonth;
                    }
                    break;

                case 4:
                    pattern.RecurrenceType = OlRecurrenceType.olRecursYearly;
                    break;
                }

                pattern.Duration         = (request.End - request.Start).Minutes;
                pattern.EndTime          = request.RepeatEnd.Date + request.End.TimeOfDay;
                pattern.NoEndDate        = false;
                pattern.PatternStartDate = request.Start;
                pattern.PatternEndDate   = request.RepeatEnd + request.End.TimeOfDay;
                pattern.StartTime        = request.Start;
            }

            try
            {
                appointment.UserProperties.Add("MJ-MRBS-ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
            }
            catch (UnauthorizedAccessException)
            {
                //appointment.UserProperties.Add("MJ-MRBS-ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
            }

            appointment.UserProperties["MJ-MRBS-ID"].Value = mtg_id;
            if (!appointment.Body.Contains("has been linked to a reservation in MRBS."))
            {
                appointment.Body += String.Format("\n\n\n***** This {0} has been linked to a reservation in MRBS. To change the {0} location, you must use the Modify Reservation button in the ribbon. *****", appointment.MeetingStatus == OlMeetingStatus.olNonMeeting ? "appointment" : "meeting");
            }

            appointment.Save();
            if (request.RepeatTypeId > 0)
            {
                RecurrencePattern pattern   = appointment.GetRecurrencePattern();
                List <Entry>      entries   = Database.GetAllEntries(mrbs_id);
                List <Entry>      conflicts = Database.FindConflicts(request, mrbs_id);

                foreach (Entry conflict in conflicts)
                {
                    DateTime start_time = Database.UnixTimeStampToDateTime(conflict.start_time);

                    AppointmentItem item = pattern.GetOccurrence(start_time);
                    item.Delete();
                }

                foreach (Entry entry in entries)
                {
                    try
                    {
                        DateTime        start_time = Database.UnixTimeStampToDateTime(entry.start_time);
                        AppointmentItem item       = pattern.GetOccurrence(start_time);
                        item.UserProperties.Add("MJ-MRBS-ID", OlUserPropertyType.olText, true, OlFormatText.olFormatTextText);
                        item.UserProperties["MJ-MRBS-ID"].Value = String.Format("{0};{1}", entry.id, entry.ical_uid);
                        item.Save();
                    }
                    catch { }
                }

                appointment.Save();
            }
        }
Exemple #14
0
 private void deleteCalendarEntry_save(AppointmentItem ai)
 {
     ai.Delete();
 }
        public bool deleteCalendarEntry(AppointmentItem ai)
        {
            ai.Delete();

            return(true);
        }
 private void deleteCalendarEntry_save(AppointmentItem ai)
 {
     ai.Delete();
 }
        private static AppointmentItem createOrUpdateReminder(AppointmentItem item, Reminder reminder)
        {
            if (reminder.is_deleted != null && reminder.is_deleted.CompareTo("0") != 0 && reminder.is_deleted.ToLower().CompareTo("false") != 0)
            {
                item.Delete();
                return(null);
            }

            if (item.UserProperties.Find(ASPEC_REMINDER_UUID) == null)
            {
                item.UserProperties.Add(ASPEC_REMINDER_UUID, OlUserPropertyType.olText, true, true);
            }
            item.UserProperties[ASPEC_REMINDER_UUID].Value = reminder.uuid;

            if (item.UserProperties.Find(ASPEC_REMINDER_FLAG) == null)
            {
                item.UserProperties.Add(ASPEC_REMINDER_FLAG, OlUserPropertyType.olYesNo, true, true);
            }
            item.UserProperties[ASPEC_REMINDER_FLAG].Value = true;

            item.Subject = reminder.subject;

            if ((reminder.start_time == null && reminder.end_time == null) ||
                (reminder.start_time != null && reminder.end_time != null &&
                 reminder.start_time.CompareTo("00:00") == 0 && reminder.end_time.CompareTo("00:00") == 0))
            {
                item.AllDayEvent = true;

                DateTime start = DateTime.ParseExact(reminder.reminder_date + " 00:00", "yyyy-MM-dd HH:mm", null);
                DateTime end   = start.AddDays(1);

                item.Start = start;
                item.End   = end;
            }
            else if (reminder.start_time != null && reminder.end_time != null)
            {
                DateTime start = DateTime.ParseExact(reminder.reminder_date + " " + reminder.start_time + " UTC", "yyyy-MM-dd HH:mm UTC", CultureInfo.InvariantCulture);
                DateTime end   = DateTime.ParseExact(reminder.reminder_date + " " + reminder.end_time + " UTC", "yyyy-MM-dd HH:mm UTC", CultureInfo.InvariantCulture);//"Z", "yyyy-MM-dd HH:mmK", null);

                item.StartUTC = (start < end) ? start : end;
                item.EndUTC   = (start < end) ? end : start;
            }

            if (reminder.priority_id != null)
            {
                item.Importance = getPriority(reminder.priority_id.Value).Value;
            }

            item.Body = reminder.notes;

            if (item.UserProperties.Find(ASPEC_REMINDER_EMAIL_NOTIFICATION_VALUE) == null)
            {
                item.UserProperties.Add(ASPEC_REMINDER_EMAIL_NOTIFICATION_VALUE, OlUserPropertyType.olText, true, true);
            }
            item.UserProperties[ASPEC_REMINDER_EMAIL_NOTIFICATION_VALUE].Value = reminder.email_notification_value;

            if (item.UserProperties.Find(ASPEC_REMINDER_EMAIL_NOTIFICATION_UNIT) == null)
            {
                item.UserProperties.Add(ASPEC_REMINDER_EMAIL_NOTIFICATION_UNIT, OlUserPropertyType.olText, true, true);
            }
            item.UserProperties[ASPEC_REMINDER_EMAIL_NOTIFICATION_UNIT].Value = reminder.email_notification_unit;

            item.Save();

            return(item);
        }