/// <summary> /// Tries to read element from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>True if appropriate element was read.</returns> internal override bool TryReadElementFromXml(EwsServiceXmlReader reader) { switch (reader.LocalName) { case XmlElementNames.NumberOfMembers: this.numberOfMembers = reader.ReadElementValue <int>(); return(true); case XmlElementNames.NumberOfMembersAvailable: this.numberOfMembersAvailable = reader.ReadElementValue <int>(); return(true); case XmlElementNames.NumberOfMembersWithConflict: this.numberOfMembersWithConflict = reader.ReadElementValue <int>(); return(true); case XmlElementNames.NumberOfMembersWithNoData: this.numberOfMembersWithNoData = reader.ReadElementValue <int>(); return(true); case XmlElementNames.BusyType: this.freeBusyStatus = reader.ReadElementValue <LegacyFreeBusyStatus>(); return(true); default: return(false); } }
/// <summary> /// Loads from json. /// </summary> /// <param name="jsonProperty">The json property.</param> /// <param name="service"></param> internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service) { foreach (string key in jsonProperty.Keys) { switch (key) { case XmlElementNames.NumberOfMembers: this.numberOfMembers = jsonProperty.ReadAsInt(key); break; case XmlElementNames.NumberOfMembersAvailable: this.numberOfMembersAvailable = jsonProperty.ReadAsInt(key); break; case XmlElementNames.NumberOfMembersWithConflict: this.numberOfMembersWithConflict = jsonProperty.ReadAsInt(key); break; case XmlElementNames.NumberOfMembersWithNoData: this.numberOfMembersWithNoData = jsonProperty.ReadAsInt(key); break; case XmlElementNames.BusyType: this.freeBusyStatus = jsonProperty.ReadEnumValue <LegacyFreeBusyStatus>(key); break; default: break; } } }
bool TryReadElementFromXml(EwsServiceXmlReader reader) { switch (reader.LocalName) { case XmlElementNames.StartTime: this.startTime = reader.ReadElementValueAsUnbiasedDateTimeScopedToServiceTimeZone(); return(true); case XmlElementNames.EndTime: this.endTime = reader.ReadElementValueAsUnbiasedDateTimeScopedToServiceTimeZone(); return(true); case XmlElementNames.BusyType: this.freeBusyStatus = reader.ReadElementValue <LegacyFreeBusyStatus>(); return(true); case XmlElementNames.CalendarEventDetails: this.details = new CalendarEventDetails(); this.details.LoadFromXml(reader, reader.LocalName); return(true); default: return(false); } }
/// <summary> /// Loads from json. /// </summary> /// <param name="jsonProperty">The json property.</param> /// <param name="service"></param> internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service) { foreach (string key in jsonProperty.Keys) { switch (key) { case XmlElementNames.StartTime: this.startTime = EwsUtilities.ParseAsUnbiasedDatetimescopedToServicetimeZone( jsonProperty.ReadAsString(key), service); break; case XmlElementNames.EndTime: this.endTime = EwsUtilities.ParseAsUnbiasedDatetimescopedToServicetimeZone( jsonProperty.ReadAsString(key), service); break; case XmlElementNames.BusyType: this.freeBusyStatus = jsonProperty.ReadEnumValue <LegacyFreeBusyStatus>(key); break; case XmlElementNames.CalendarEventDetails: this.details = new CalendarEventDetails(); this.details.LoadFromJson(jsonProperty.ReadAsJsonObject(key), service); break; default: break; } } }
/// <summary> /// Tries to read element from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>True if appropriate element was read.</returns> internal override bool TryReadElementFromXml(EwsServiceXmlReader reader) { switch (reader.LocalName) { case XmlElementNames.NumberOfMembers: this.numberOfMembers = reader.ReadElementValue<int>(); return true; case XmlElementNames.NumberOfMembersAvailable: this.numberOfMembersAvailable = reader.ReadElementValue<int>(); return true; case XmlElementNames.NumberOfMembersWithConflict: this.numberOfMembersWithConflict = reader.ReadElementValue<int>(); return true; case XmlElementNames.NumberOfMembersWithNoData: this.numberOfMembersWithNoData = reader.ReadElementValue<int>(); return true; case XmlElementNames.BusyType: this.freeBusyStatus = reader.ReadElementValue<LegacyFreeBusyStatus>(); return true; default: return false; } }
private void GetCalendarEvents(ExchangeService service) { // Use a view to retrieve calendar events within 60 days from today DateTime startDate = DateTime.Now.AddDays(-60); DateTime endDate = DateTime.Now.AddDays(60); Mailbox userMailbox = new Mailbox(Resources.EWSUserMailbox); FolderId calendar = new FolderId(WellKnownFolderName.Calendar, userMailbox); CalendarView cView = new CalendarView(startDate, endDate); cView.PropertySet = new PropertySet(AppointmentSchema.ICalUid, AppointmentSchema.Organizer, AppointmentSchema.Subject, AppointmentSchema.Location, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.LegacyFreeBusyStatus, AppointmentSchema.AppointmentState, AppointmentSchema.IsCancelled, AppointmentSchema.IsAllDayEvent); FindItemsResults <Item> items = null; items = service.FindItems(calendar, cView); // Set up a datatable to store appointments DataTable appointmentsData = new DataTable("Appointments"); // ICalUid Column DataColumn iCalUidColumn = new DataColumn(); iCalUidColumn.DataType = Type.GetType("System.String"); iCalUidColumn.ColumnName = "ICalUid"; appointmentsData.Columns.Add(iCalUidColumn); // Account name column DataColumn accountNameColumn = new DataColumn(); accountNameColumn.DataType = Type.GetType("System.String"); accountNameColumn.ColumnName = "AccountName"; appointmentsData.Columns.Add(accountNameColumn); // Subject column DataColumn subjectColumn = new DataColumn(); subjectColumn.DataType = Type.GetType("System.String"); subjectColumn.ColumnName = "Subject"; appointmentsData.Columns.Add(subjectColumn); // Location column DataColumn locationColumn = new DataColumn(); locationColumn.DataType = Type.GetType("System.String"); locationColumn.ColumnName = "Location"; appointmentsData.Columns.Add(locationColumn); // Start time column DataColumn startTimeColumn = new DataColumn(); startTimeColumn.DataType = Type.GetType("System.DateTime"); startTimeColumn.ColumnName = "StartTime"; appointmentsData.Columns.Add(startTimeColumn); // End time column DataColumn endTimeColumn = new DataColumn(); endTimeColumn.DataType = Type.GetType("System.DateTime"); endTimeColumn.ColumnName = "EndTime"; appointmentsData.Columns.Add(endTimeColumn); // Status column DataColumn statusColumn = new DataColumn(); statusColumn.DataType = Type.GetType("System.String"); statusColumn.ColumnName = "Status"; appointmentsData.Columns.Add(statusColumn); // Appointment State column DataColumn appointmentStateColumn = new DataColumn(); appointmentStateColumn.DataType = Type.GetType("System.Int32"); appointmentStateColumn.ColumnName = "AppointmentState"; appointmentsData.Columns.Add(appointmentStateColumn); // Is Cancelled Column DataColumn isCancelledColumn = new DataColumn(); isCancelledColumn.DataType = Type.GetType("System.Boolean"); isCancelledColumn.ColumnName = "IsCancelled"; appointmentsData.Columns.Add(isCancelledColumn); // Is All Day Event Column DataColumn isAllDayEventColumn = new DataColumn(); isAllDayEventColumn.DataType = Type.GetType("System.Boolean"); isAllDayEventColumn.ColumnName = "IsAllDayEvent"; appointmentsData.Columns.Add(isAllDayEventColumn); // ChangeKey Column DataColumn changeKeyColumn = new DataColumn(); changeKeyColumn.DataType = Type.GetType("System.String"); changeKeyColumn.ColumnName = "ChangeKey"; appointmentsData.Columns.Add(changeKeyColumn); // UniqueId Column DataColumn uniqueIdColumn = new DataColumn(); uniqueIdColumn.DataType = Type.GetType("System.String"); uniqueIdColumn.ColumnName = "UniqueID"; appointmentsData.Columns.Add(uniqueIdColumn); List <ResolvedEmailAddress> resolvedEmailAddresses = new List <ResolvedEmailAddress>(); int i = 0; using (SqlBulkCopy bulkCopy = new SqlBulkCopy(Resources.SqlConnectionString, SqlBulkCopyOptions.KeepNulls & SqlBulkCopyOptions.KeepIdentity)) { bulkCopy.BatchSize = items.Count(); bulkCopy.DestinationTableName = "dbo.TimeOffCalendarTemp"; bulkCopy.ColumnMappings.Clear(); bulkCopy.ColumnMappings.Add("ICalUid", "ICalUid"); bulkCopy.ColumnMappings.Add("AccountName", "AccountName"); bulkCopy.ColumnMappings.Add("Subject", "Subject"); bulkCopy.ColumnMappings.Add("Location", "Location"); bulkCopy.ColumnMappings.Add("StartTime", "StartTime"); bulkCopy.ColumnMappings.Add("EndTime", "EndTime"); bulkCopy.ColumnMappings.Add("Status", "Status"); bulkCopy.ColumnMappings.Add("AppointmentState", "AppointmentState"); bulkCopy.ColumnMappings.Add("IsCancelled", "IsCancelled"); bulkCopy.ColumnMappings.Add("IsAllDayEvent", "IsAllDayEvent"); bulkCopy.ColumnMappings.Add("ChangeKey", "ChangeKey"); bulkCopy.ColumnMappings.Add("UniqueID", "UniqueID"); foreach (Item item in items) { try { i++; DataRow appointmentRow = appointmentsData.NewRow(); EmailAddress accountName = null; ItemId itemId = null; string iCalUid, subject, location = null; DateTime startTime, endTime = new DateTime(); LegacyFreeBusyStatus status = new LegacyFreeBusyStatus(); int appointmentState; bool isCancelled, isAllDayEvent; item.TryGetProperty(AppointmentSchema.ICalUid, out iCalUid); if (iCalUid != null) { appointmentRow["ICalUid"] = iCalUid; } item.TryGetProperty(AppointmentSchema.Organizer, out accountName); if (accountName != null) { if (resolvedEmailAddresses.Where(re => re.EWSAddress == accountName.Address).Count() < 1) { NameResolutionCollection nd = service.ResolveName(accountName.Address); if (nd.Count > 0) { ResolvedEmailAddress resAddress = new ResolvedEmailAddress { EWSAddress = accountName.Address, SMTPAddress = nd[0].Mailbox.Address }; resolvedEmailAddresses.Add(resAddress); appointmentRow["AccountName"] = resAddress.SMTPAddress; } } else { ResolvedEmailAddress resAddress = resolvedEmailAddresses.First(re => re.EWSAddress == accountName.Address); appointmentRow["AccountName"] = resAddress.SMTPAddress; } } item.TryGetProperty(AppointmentSchema.Subject, out subject); if (subject != null) { appointmentRow["Subject"] = subject; } item.TryGetProperty(AppointmentSchema.Location, out location); if (location != null) { appointmentRow["Location"] = location; } item.TryGetProperty(AppointmentSchema.Start, out startTime); if (startTime != null) { appointmentRow["StartTime"] = startTime; } item.TryGetProperty(AppointmentSchema.End, out endTime); if (endTime != null) { appointmentRow["EndTime"] = endTime; } item.TryGetProperty(AppointmentSchema.LegacyFreeBusyStatus, out status); if (status != null) { appointmentRow["Status"] = status; } item.TryGetProperty(AppointmentSchema.AppointmentState, out appointmentState); appointmentRow["AppointmentState"] = appointmentState; item.TryGetProperty(AppointmentSchema.IsCancelled, out isCancelled); appointmentRow["IsCancelled"] = isCancelled; item.TryGetProperty(AppointmentSchema.IsAllDayEvent, out isAllDayEvent); appointmentRow["IsAllDayEvent"] = isAllDayEvent; itemId = item.Id; appointmentRow["ChangeKey"] = itemId.ChangeKey; appointmentRow["UniqueID"] = itemId.UniqueId; appointmentsData.Rows.Add(appointmentRow); int percentComplete = 0; if (items.Count() > 0) { percentComplete = ((i + 1) * 100 / items.Count()); } else { percentComplete = 100; } UpdateProgress(percentComplete); } catch (Exception ex) { Util.LogError("GetCalendarEvents failed with message: " + ex.Message); } } bulkCopy.WriteToServer(appointmentsData); using (SqlConnection conn = new SqlConnection(Resources.SqlConnectionString)) { using (SqlCommand command = new SqlCommand(Resources.MergeStoredProcedureName, conn) { CommandType = CommandType.StoredProcedure }) { conn.Open(); command.ExecuteNonQuery(); } } } }
public bool IsShowAsAllowed(LegacyFreeBusyStatus flag) { return((ShowAsFlags & (1 << (int)flag)) != 0); }
/// <summary> /// Attempts to read the element at the reader's current position. /// </summary> /// <param name="reader">The reader used to read the element.</param> /// <returns>True if the element was read, false otherwise.</returns> internal override bool TryReadElementFromXml(EwsServiceXmlReader reader) { switch (reader.LocalName) { case XmlElementNames.StartTime: this.startTime = reader.ReadElementValueAsUnbiasedDateTimeScopedToServiceTimeZone(); return true; case XmlElementNames.EndTime: this.endTime = reader.ReadElementValueAsUnbiasedDateTimeScopedToServiceTimeZone(); return true; case XmlElementNames.BusyType: this.freeBusyStatus = reader.ReadElementValue<LegacyFreeBusyStatus>(); return true; case XmlElementNames.CalendarEventDetails: this.details = new CalendarEventDetails(); this.details.LoadFromXml(reader, reader.LocalName); return true; default: return false; } }
public bool IsShowAsAllowed(LegacyFreeBusyStatus flag) { return (ShowAsFlags & (1 << (int)flag)) != 0; }