Example #1
0
    private Microsoft.Office.Interop.Outlook.Items GetAppointmentsInRange(
        Microsoft.Office.Interop.Outlook.Folder folder, DateTime startTime, DateTime endTime)
    {
        string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'";

        //Response.Write(filter);
        try
        {
            Microsoft.Office.Interop.Outlook.Items calItems = folder.Items;
            calItems.IncludeRecurrences = true;
            calItems.Sort("[Start]", Type.Missing);
            Microsoft.Office.Interop.Outlook.Items restrictItems = calItems.Restrict(filter);
            if (restrictItems.Count > 0)
            {
                return(restrictItems);
            }
            else
            {
                return(null);
            }
        }
        catch
        {
            return(null);
        }
    }
Example #2
0
        private static Appointment LookForNextAppointment(string textToSearch)
        {
            Microsoft.Office.Interop.Outlook.Application oApp = null;
            Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
            Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

            oApp = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace = oApp.GetNamespace("MAPI"); ;
            CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.Sort("[Start]");
            var now = DateTime.Now.Date.ToString("g");
            var nowIn1Year = DateTime.Now.Date.AddYears(1).ToString("g");
            outlookCalendarItems = outlookCalendarItems.Restrict($"[Start] >= \"{now}\" AND [End] < \"{nowIn1Year}\" ");

            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
            {
                var subject = item.Subject;
                if (subject.IndexOf(textToSearch,StringComparison.InvariantCultureIgnoreCase)!=-1)
                {
                    return new Appointment() { Subject = subject, Start = item.Start };
                }
            }
            return null;
        }
Example #3
0
        private void InitOutlookService()
        {
            if (!ifAlreadyInit)
            {
                oApp          = new Microsoft.Office.Interop.Outlook.Application();
                mapiNamespace = oApp.GetNamespace("MAPI");
                ;
                calendarFolder =
                    mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                outlookCalendarItems = calendarFolder.Items;

                outlookCalendarItems.Sort("[Start]");
                outlookCalendarItems.IncludeRecurrences = true;

                string s1           = GetDateInString(minTime);
                string s2           = GetDateInString(maxTime);
                var    filterString = "[Start] >= '" + s1 + "' AND [End] < '" + s2 + "'";
                outlookCalendarItems = outlookCalendarItems.Restrict(filterString);
                ifAlreadyInit        = true;
            }
        }
        public static void UpdateCache(bool resetException = false)
        {
            if (resetException)
            {
                OutlookException = null;
            }

            if (OutlookException != null)
            {
                return;
            }

            var events = new List <OutlookItem>();

            Microsoft.Office.Interop.Outlook.Application oApp                 = null;
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNamespace        = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  calendarFolder       = null;
            Microsoft.Office.Interop.Outlook.Items       outlookCalendarItems = null;

            try
            {
                oApp                 = new Microsoft.Office.Interop.Outlook.Application();
                mapiNamespace        = oApp.GetNamespace("MAPI");
                calendarFolder       = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                outlookCalendarItems = calendarFolder.Items;
                outlookCalendarItems.Sort("[Start]");
                outlookCalendarItems.IncludeRecurrences = true;
                //var filter = String.Format("[Start] >= \"{0}\" and [Start] <= \"{1}\"", DateTime.Today, DateTime.Today.AddDays(1));
                //outlookCalendarItems = outlookCalendarItems.Find(filter);

                foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
                {
                    if (item.Start >= CacheRangeStart)
                    {
                        if (item.Start.Date > CacheRangeEnd)
                        {
                            break;
                        }

                        var parsed = LyncMeeting.ParseEmail(item.Body ?? string.Empty, item.Subject);
                        events.Add(new OutlookItem()
                        {
                            Start              = item.Start,
                            End                = item.End,
                            Subject            = item.Subject,
                            LyncMeeting        = parsed,
                            OutlookAppointment = item
                        });
                    }
                }

                events = events.OrderBy(e => e.Start).ToList();
                lock (Lock)
                {
                    _cache = events;
                    _cacheLastUpdateTime = DateTime.Now;
                }
            }
            catch (COMException e)
            {
                OutlookException = e;
            }
            finally
            {
                Marshal.ReleaseComObject(oApp);
            }
        }