public Event(CalendarEvent c) { this.Title = c.Details.Subject; this.Description = c.Details.Subject; this.Location = c.Details.Location; this.Type = c.GetType().Name; this.Start = c.StartTime; this.End = c.EndTime; this.Id = c.Details.StoreId; this.ResponseRequired = false; }
/// <summary> /// Loads the free busy view from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="viewType">Type of free/busy view.</param> internal void LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView); string viewTypeString = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.FreeBusyViewType); this.viewType = (FreeBusyViewType)Enum.Parse(typeof(FreeBusyViewType), viewTypeString, false); do { reader.Read(); if (reader.IsStartElement()) { switch (reader.LocalName) { case XmlElementNames.MergedFreeBusy: string mergedFreeBusy = reader.ReadElementValue(); for (int i = 0; i < mergedFreeBusy.Length; i++) { this.mergedFreeBusyStatus.Add((LegacyFreeBusyStatus)Byte.Parse(mergedFreeBusy[i].ToString())); } break; case XmlElementNames.CalendarEventArray: do { reader.Read(); if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CalendarEvent)) { CalendarEvent calendarEvent = new CalendarEvent(); calendarEvent.LoadFromXml(reader, XmlElementNames.CalendarEvent); this.calendarEvents.Add(calendarEvent); } } while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.CalendarEventArray)); break; case XmlElementNames.WorkingHours: this.workingHours = new WorkingHours(); this.workingHours.LoadFromXml(reader, reader.LocalName); break; } } } while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView)); }
public static List<CalendarEvent> GetAllEvents(String exchangeurl, String user, String pass) { List<CalendarEvent> events = new List<CalendarEvent>(); ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack; ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); service.Credentials = new WebCredentials(user, pass); service.TraceEnabled = true; service.TraceFlags = TraceFlags.All; service.TraceListener = new TraceListener(); //When attempting to connect to EWS, it is much quicker to just use the url directly //rather than using the auto-resolve. So we will first attempt the url, if that works //then we are golden otherwise we will go for the auto-resolve. CalendarFolder calendar = null; if (exchangeurl != "") { service.Url = new Uri(exchangeurl); try { // Try to initialize the calendar folder object with only the folder ID. calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); } catch (Exception exp) { service.TraceListener.Trace("ExchangeUrlBindFail", exp.Message); } } //calendar will still be null if we still have not bound correctly if (calendar == null) { service.AutodiscoverUrl(user, RedirectionUrlValidationCallback); // Try to initialize the calendar folder object with only the folder ID. calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet()); } CalendarEvent cEvent = null; // Initialize values for the start and end times, and the number of appointments to retrieve. const int NUM_APPTS = 1000; // Set the start and end time and number of appointments to retrieve. CalendarView cView = new CalendarView(CalendarGlobals.StartDate, CalendarGlobals.EndDate, NUM_APPTS); // Limit the properties returned to the appointment's subject, start time, and end time. (Body cannot be loaded with FindAppointments, we need to do that later) cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.IsRecurring, AppointmentSchema.Id, AppointmentSchema.Location); cView.PropertySet.RequestedBodyType = BodyType.Text; // Retrieve a collection of appointments by using the calendar view. FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView); Console.WriteLine("\nThe first " + NUM_APPTS + " appointments on your calendar from " + CalendarGlobals.StartDate.Date.ToShortDateString() + " to " + CalendarGlobals.EndDate.Date.ToShortDateString() + " are: \n"); //Now that we have found the appointments that we want, we will be able to load the body cView.PropertySet.Add(AppointmentSchema.Body); service.LoadPropertiesForItems(appointments, cView.PropertySet); foreach (Appointment a in appointments) { cEvent = new CalendarEvent(a.Id.ToString(), a.Start, a.End, a.Location, a.Subject, a.Body); events.Add(cEvent); } return events; }
/// <summary> /// Loads the free busy view from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="viewType">Type of free/busy view.</param> internal void LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView); string viewTypeString = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.FreeBusyViewType); this.viewType = (FreeBusyViewType)Enum.Parse(typeof(FreeBusyViewType), viewTypeString, false); do { reader.Read(); if (reader.IsStartElement()) { switch (reader.LocalName) { case XmlElementNames.MergedFreeBusy: string mergedFreeBusy = reader.ReadElementValue(); for (int i = 0; i < mergedFreeBusy.Length; i++) { this.mergedFreeBusyStatus.Add((LegacyFreeBusyStatus)Byte.Parse(mergedFreeBusy[i].ToString())); } break; case XmlElementNames.CalendarEventArray: do { reader.Read(); // Sometimes Exchange Online returns blank CalendarEventArray tag like bellow. // <CalendarEventArray xmlns="http://schemas.microsoft.com/exchange/services/2006/types" /> // So we have to check the end of CalendarEventArray tag. if (reader.LocalName == XmlElementNames.FreeBusyView) { // There is no the end tag of CalendarEventArray, but the reader is reading the end tag of FreeBusyView. break; } else if (reader.LocalName == XmlElementNames.WorkingHours) { // There is no the end tag of CalendarEventArray, but the reader is reading the start tag of WorkingHours. goto case XmlElementNames.WorkingHours; } if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.CalendarEvent)) { CalendarEvent calendarEvent = new CalendarEvent(); calendarEvent.LoadFromXml(reader, XmlElementNames.CalendarEvent); this.calendarEvents.Add(calendarEvent); } }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.CalendarEventArray)); break; case XmlElementNames.WorkingHours: this.workingHours = new WorkingHours(); this.workingHours.LoadFromXml(reader, reader.LocalName); break; } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FreeBusyView)); }