static void Main(string[] args) { string PublicFolderPath = @"Professional Services\iSolutions\ITIL Processes\Change\Forward Schedule of Change"; FilterSetting FilterOptions = new FilterSetting(); // TODO : Read in the following as arugments //FilterOptions.SubjectFilter = "(iss-)|(Migrations)"; FilterOptions.SubjectFilter = "(Building|Bld|Bldg) [0-9][0-9]"; //string[] CategoryFilter = { "DBA", "EST", "DST" }; //FilterOptions.CategoryFilter = CategoryFilter; FilterOptions.SearchStartDate = DateTime.Now; FilterOptions.SearchEndDate = DateTime.Now.AddDays(10); // Initialise web service instance. // NOTE: This is an overloaded method - alternate versions take credentials/username+password - switch out if needed ExchangeService WebService = ExchangeWebServiceWrapper.GetWebServiceInstance(); // Retrieve calendar folder Console.WriteLine("Getting calendar..."); CalendarFolder Calendar = ExchangeWebServiceWrapper.GetCalendarFolder(WebService, PublicFolderPath); if (Calendar == null) { throw new Exception("Could not find calendar folder."); } // Retrieve appointments Console.WriteLine("Getting appointments..."); FindItemsResults<Appointment> Appointments = Calendar.FindAppointments(new CalendarView(FilterOptions.SearchStartDate, FilterOptions.SearchEndDate)); iCalWrapper iCal = new iCalWrapper(); iCal.AddEventsToCalendar(Appointments, FilterOptions); Console.WriteLine(iCal.GenerateString()); Console.WriteLine("\n\nDone"); Console.ReadLine(); }
/// <summary> /// Add a list of Exchange appointment objects to an iCal object, whilst applying a set of filters. /// </summary> /// <param name="ExchangeAppointments">List of Exchange Appointment objects to add</param> /// <param name="FilterOptions">Filter settings to apply</param> public void AddEventsToCalendar(IEnumerable <Appointment> ExchangeAppointments, FilterSetting FilterOptions) { Regex SubjectRegEx = null; Regex LocationRegEx = null; // If the subject filter has been set, initialise the subject regex if (FilterOptions.SubjectFilterSet) { SubjectRegEx = new Regex(FilterOptions.SubjectFilter); } // If the location filter has been set, initialise the location regex if (FilterOptions.LocationFilterSet) { LocationRegEx = new Regex(FilterOptions.LocationFilter); } // Iterate over the list of Exchange Appointment objects... foreach (Appointment ExchangeAppointment in ExchangeAppointments) { // If there is a subject filter... if (FilterOptions.SubjectFilterSet) { // ... Check this appointment's subject matches it - if not ... if (SubjectRegEx.IsMatch(ExchangeAppointment.Subject) == false) { // ... move on to the next appointment ... continue; } } // If there is a location filter... if (FilterOptions.LocationFilterSet) { // ... Check this appointment's location matches it - if not ... if (LocationRegEx.IsMatch(ExchangeAppointment.Location) == false) { // ... move on to the next appointment ... continue; } } // If there's a category filter ... if (FilterOptions.CategoryFilterFilterSet) { bool FilterCategoryFound = false; // Iterate over the categories to filter by ... foreach (string CategoryFilter in FilterOptions.CategoryFilter) { // ... if one of the appointment's categories matches ... if (ExchangeAppointment.Categories.Contains(CategoryFilter)) { // ... mark this appointment as includable, and stop checking FilterCategoryFound = true; break; } } // If we didn't find any category matches, move on to the next appointment ... if (FilterCategoryFound == false) { continue; } } // If we got here, all of the filter conditions passed, so add the appointment to the iCal object AddEventToCalendar(ExchangeAppointment); } }
/// <summary> /// Add a list of Exchange appointment objects to an iCal object, whilst applying a set of filters. /// </summary> /// <param name="ExchangeAppointments">List of Exchange Appointment objects to add</param> /// <param name="FilterOptions">Filter settings to apply</param> public void AddEventsToCalendar(IEnumerable<Appointment> ExchangeAppointments, FilterSetting FilterOptions) { Regex SubjectRegEx = null; Regex LocationRegEx = null; // If the subject filter has been set, initialise the subject regex if (FilterOptions.SubjectFilterSet) { SubjectRegEx = new Regex(FilterOptions.SubjectFilter); } // If the location filter has been set, initialise the location regex if (FilterOptions.LocationFilterSet) { LocationRegEx = new Regex(FilterOptions.LocationFilter); } // Iterate over the list of Exchange Appointment objects... foreach (Appointment ExchangeAppointment in ExchangeAppointments) { // If there is a subject filter... if (FilterOptions.SubjectFilterSet) { // ... Check this appointment's subject matches it - if not ... if (SubjectRegEx.IsMatch(ExchangeAppointment.Subject) == false) { // ... move on to the next appointment ... continue; } } // If there is a location filter... if (FilterOptions.LocationFilterSet) { // ... Check this appointment's location matches it - if not ... if (LocationRegEx.IsMatch(ExchangeAppointment.Location) == false) { // ... move on to the next appointment ... continue; } } // If there's a category filter ... if (FilterOptions.CategoryFilterFilterSet) { bool FilterCategoryFound = false; // Iterate over the categories to filter by ... foreach (string CategoryFilter in FilterOptions.CategoryFilter) { // ... if one of the appointment's categories matches ... if (ExchangeAppointment.Categories.Contains(CategoryFilter)) { // ... mark this appointment as includable, and stop checking FilterCategoryFound = true; break; } } // If we didn't find any category matches, move on to the next appointment ... if (FilterCategoryFound == false) { continue; } } // If we got here, all of the filter conditions passed, so add the appointment to the iCal object AddEventToCalendar(ExchangeAppointment); } }