/// <summary> /// Tries to load from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="propertyDefinition">The property definition.</param> /// <returns>True if property was loaded.</returns> internal static bool TryLoadFromXml(EwsServiceXmlReader reader, ref PropertyDefinitionBase propertyDefinition) { switch (reader.LocalName) { case XmlElementNames.FieldURI: propertyDefinition = ServiceObjectSchema.FindPropertyDefinition(reader.ReadAttributeValue(XmlAttributeNames.FieldURI)); reader.SkipCurrentElement(); return(true); case XmlElementNames.IndexedFieldURI: propertyDefinition = new IndexedPropertyDefinition( reader.ReadAttributeValue(XmlAttributeNames.FieldURI), reader.ReadAttributeValue(XmlAttributeNames.FieldIndex)); reader.SkipCurrentElement(); return(true); case XmlElementNames.ExtendedFieldURI: propertyDefinition = new ExtendedPropertyDefinition(); (propertyDefinition as ExtendedPropertyDefinition).LoadFromXml(reader); return(true); default: return(false); } }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="localElementName">Name of the local element.</param> internal override void LoadFromXml(EwsServiceXmlReader reader, string localElementName) { reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, localElementName); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { TItem item = EwsUtilities.CreateEwsObjectFromXmlElementName <Item>( reader.Service, reader.LocalName) as TItem; if (item == null) { reader.SkipCurrentElement(); } else { item.LoadFromXml(reader, true /* clearPropertyBag */); this.items.Add(item); } } }while (!reader.IsEndElement(XmlNamespace.Types, localElementName)); } }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="localElementName">Name of the local element.</param> internal override void LoadFromXml(EwsServiceXmlReader reader, string localElementName) { reader.EnsureCurrentNodeIsStartElement(XmlNamespace.Types, localElementName); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.IsStartElement()) { TEntry entry = this.CreateEntry(reader); if (entry != null) { entry.LoadFromXml(reader, reader.LocalName); this.InternalAdd(entry); } else { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(XmlNamespace.Types, localElementName)); } }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="xmlNamespace">The XML namespace.</param> /// <param name="localElementName">Name of the local element.</param> internal override void LoadFromXml( EwsServiceXmlReader reader, XmlNamespace xmlNamespace, string localElementName) { reader.EnsureCurrentNodeIsStartElement(xmlNamespace, localElementName); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.IsStartElement()) { TComplexProperty complexProperty = this.CreateComplexProperty(reader.LocalName); if (complexProperty != null) { complexProperty.LoadFromXml(reader, reader.LocalName); this.InternalAdd(complexProperty, true); } else { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(xmlNamespace, localElementName)); } }
/// <summary> /// Loads from XML /// </summary> /// <param name="reader">The reader.</param> /// <param name="xmlNamespace">The XML namespace.</param> /// <param name="xmlElementName">Name of the XML element.</param> /// <param name="readAction"></param> private void InternalLoadFromXml( EwsServiceXmlReader reader, XmlNamespace xmlNamespace, string xmlElementName, Func <EwsServiceXmlReader, bool> readAction) { reader.EnsureCurrentNodeIsStartElement(xmlNamespace, xmlElementName); this.ReadAttributesFromXml(reader); if (!reader.IsEmptyElement) { do { reader.Read(); switch (reader.NodeType) { case XmlNodeType.Element: if (!readAction(reader)) { reader.SkipCurrentElement(); } break; case XmlNodeType.Text: this.ReadTextValueFromXml(reader); break; } }while (!reader.IsEndElement(xmlNamespace, xmlElementName)); } }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsServiceXmlReader reader) { EwsUtilities.Assert( reader != null, "UserConfiguration.LoadFromXml", "reader is null"); reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.UserConfiguration); reader.Read(); // Position at first property element do { if (reader.NodeType == XmlNodeType.Element) { switch (reader.LocalName) { case XmlElementNames.UserConfigurationName: string responseName = reader.ReadAttributeValue(XmlAttributeNames.Name); EwsUtilities.Assert( string.Compare(this.name, responseName, StringComparison.Ordinal) == 0, "UserConfiguration.LoadFromXml", "UserConfigurationName does not match: Expected: " + this.name + " Name in response: " + responseName); reader.SkipCurrentElement(); break; case XmlElementNames.ItemId: this.itemId = new ItemId(); this.itemId.LoadFromXml(reader, XmlElementNames.ItemId); break; case XmlElementNames.Dictionary: this.dictionary.LoadFromXml(reader, XmlElementNames.Dictionary); break; case XmlElementNames.XmlData: this.xmlData = Convert.FromBase64String(reader.ReadElementValue()); break; case XmlElementNames.BinaryData: this.binaryData = Convert.FromBase64String(reader.ReadElementValue()); break; default: EwsUtilities.Assert( false, "UserConfiguration.LoadFromXml", "Xml element not supported: " + reader.LocalName); break; } } // If XmlData was loaded, read is skipped because GetXmlData positions the reader at the next property. reader.Read(); }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.UserConfiguration)); }
/// <summary> /// Read Personas from XML. /// </summary> /// <param name="reader">The reader.</param> internal override void ReadElementsFromXml(EwsServiceXmlReader reader) { EwsUtilities.Assert( this.Results.Personas != null, "FindPeopleResponse.ReadElementsFromXml", "Personas is null."); reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.People); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { Persona item = EwsUtilities.CreateEwsObjectFromXmlElementName <Persona>(reader.Service, reader.LocalName); if (item == null) { reader.SkipCurrentElement(); } else { // Don't clear propertyBag because all properties have been initialized in the persona constructor. item.LoadFromXml(reader, false, null, false); this.Results.Personas.Add(item); } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.People)); } reader.Read(); if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.TotalNumberOfPeopleInView) && !reader.IsEmptyElement) { this.Results.TotalCount = reader.ReadElementValue <int>(); reader.Read(); } if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FirstMatchingRowIndex) && !reader.IsEmptyElement) { this.Results.FirstMatchingRowIndex = reader.ReadElementValue <int>(); reader.Read(); } if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FirstLoadedRowIndex) && !reader.IsEmptyElement) { this.Results.FirstLoadedRowIndex = reader.ReadElementValue <int>(); reader.Read(); } }
/// <summary> /// Reads response elements from XML. /// </summary> /// <param name="reader">The reader.</param> internal override void ReadElementsFromXml(EwsServiceXmlReader reader) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ReturnValue); using (XmlReader returnValueReader = reader.GetXmlReaderForNode()) { this.ReturnValue = new SafeXmlDocument(); this.ReturnValue.Load(returnValueReader); } reader.SkipCurrentElement(); reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.ReturnValue); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsServiceXmlReader reader) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Notification); do { NotificationGroup notifications = new NotificationGroup(); notifications.SubscriptionId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SubscriptionId); notifications.Events = new Collection <NotificationEvent>(); lock (this) { this.events.Add(notifications); } do { reader.Read(); if (reader.IsStartElement()) { string eventElementName = reader.LocalName; EventType eventType; if (GetEventsResults.XmlElementNameToEventTypeMap.TryGetValue(eventElementName, out eventType)) { if (eventType == EventType.Status) { // We don't need to return status events reader.ReadEndElementIfNecessary(XmlNamespace.Types, eventElementName); } else { this.LoadNotificationEventFromXml( reader, eventElementName, eventType, notifications); } } else { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notification)); reader.Read(); }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notifications)); }
/// <summary> /// Loads properties from XML and inserts them in the bag. /// </summary> /// <param name="reader">The reader from which to read the properties.</param> /// <param name="clear">Indicates whether the bag should be cleared before properties are loaded.</param> /// <param name="requestedPropertySet">The requested property set.</param> /// <param name="onlySummaryPropertiesRequested">Indicates whether summary or full properties were requested.</param> internal void LoadFromXml( EwsServiceXmlReader reader, bool clear, PropertySet requestedPropertySet, bool onlySummaryPropertiesRequested) { if (clear) { this.Clear(); } // Put the property bag in "loading" mode. When in loading mode, no checking is done // when setting property values. this.loading = true; this.requestedPropertySet = requestedPropertySet; this.onlySummaryPropertiesRequested = onlySummaryPropertiesRequested; try { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { PropertyDefinition propertyDefinition; if (this.Owner.Schema.TryGetPropertyDefinition(reader.LocalName, out propertyDefinition)) { propertyDefinition.LoadPropertyValueFromXml(reader, this); this.loadedProperties.Add(propertyDefinition); } else { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(XmlNamespace.Types, this.Owner.GetXmlElementName())); this.ClearChangeLog(); } finally { this.loading = false; } }
/// <summary> /// Reads response elements from XML. /// </summary> /// <param name="reader">The reader.</param> internal override void ReadElementsFromXml(EwsServiceXmlReader reader) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.RootFolder); this.results.TotalCount = reader.ReadAttributeValue <int>(XmlAttributeNames.TotalItemsInView); this.results.MoreAvailable = !reader.ReadAttributeValue <bool>(XmlAttributeNames.IncludesLastItemInRange); // Ignore IndexedPagingOffset attribute if MoreAvailable is false. this.results.NextPageOffset = results.MoreAvailable ? reader.ReadNullableAttributeValue <int>(XmlAttributeNames.IndexedPagingOffset) : null; reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Folders); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { Folder folder = EwsUtilities.CreateEwsObjectFromXmlElementName <Folder>(reader.Service, reader.LocalName); if (folder == null) { reader.SkipCurrentElement(); } else { folder.LoadFromXml( reader, true, /* clearPropertyBag */ this.propertySet, true /* summaryPropertiesOnly */); this.results.Folders.Add(folder); } } }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.Folders)); } reader.ReadEndElement(XmlNamespace.Messages, XmlElementNames.RootFolder); }
/// <summary> /// Loads from XML. /// </summary> /// <param name="reader">The reader.</param> internal void LoadFromXml(EwsServiceXmlReader reader) { reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Notification); this.subscriptionId = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.SubscriptionId); this.previousWatermark = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.PreviousWatermark); this.moreEventsAvailable = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.MoreEvents); do { reader.Read(); if (reader.IsStartElement()) { string eventElementName = reader.LocalName; EventType eventType; if (xmlElementNameToEventTypeMap.Member.TryGetValue(eventElementName, out eventType)) { this.newWatermark = reader.ReadElementValue(XmlNamespace.Types, XmlElementNames.Watermark); if (eventType == EventType.Status) { // We don't need to return status events reader.ReadEndElementIfNecessary(XmlNamespace.Types, eventElementName); } else { this.LoadNotificationEventFromXml( reader, eventElementName, eventType); } } else { reader.SkipCurrentElement(); } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Notification)); }
/// <summary> /// Read items from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="propertySet">The property set.</param> /// <param name="destinationList">The list in which to add the read items.</param> private static void InternalReadItemsFromXml( EwsServiceXmlReader reader, PropertySet propertySet, IList <TItem> destinationList) { EwsUtilities.Assert( destinationList != null, "FindItemResponse.InternalReadItemsFromXml", "destinationList is null."); reader.ReadStartElement(XmlNamespace.Types, XmlElementNames.Items); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { TItem item = EwsUtilities.CreateEwsObjectFromXmlElementName <TItem>(reader.Service, reader.LocalName); if (item == null) { reader.SkipCurrentElement(); } else { item.LoadFromXml( reader, true, /* clearPropertyBag */ propertySet, true /* summaryPropertiesOnly */); destinationList.Add(item); } } }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.Items)); } }
/// <summary> /// Loads response from XML. /// </summary> /// <param name="reader">The reader.</param> /// <param name="xmlElementName">Name of the XML element.</param> internal void LoadFromXml(EwsServiceXmlReader reader, string xmlElementName) { if (!reader.IsStartElement(XmlNamespace.Messages, xmlElementName)) { reader.ReadStartElement(XmlNamespace.Messages, xmlElementName); } this.result = reader.ReadAttributeValue <ServiceResult>(XmlAttributeNames.ResponseClass); if (this.result == ServiceResult.Success || this.result == ServiceResult.Warning) { if (this.result == ServiceResult.Warning) { this.errorMessage = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.MessageText); } else { reader.ReadElementValue(); if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.MessageText)) { this.errorMessage = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.MessageText); } } this.errorCode = reader.ReadElementValue <ServiceError>(XmlNamespace.Messages, XmlElementNames.ResponseCode); if (this.result == ServiceResult.Warning) { reader.ReadElementValue <int>(XmlNamespace.Messages, XmlElementNames.DescriptiveLinkKey); } // If batch processing stopped, EWS returns an empty element. Skip over it. if (this.BatchProcessingStopped) { do { reader.Read(); }while (!reader.IsEndElement(XmlNamespace.Messages, xmlElementName)); } else { this.ReadElementsFromXml(reader); reader.ReadEndElementIfNecessary(XmlNamespace.Messages, xmlElementName); } } else { this.errorMessage = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.MessageText); this.errorCode = reader.ReadElementValue <ServiceError>(XmlNamespace.Messages, XmlElementNames.ResponseCode); reader.ReadElementValue <int>(XmlNamespace.Messages, XmlElementNames.DescriptiveLinkKey); while (!reader.IsEndElement(XmlNamespace.Messages, xmlElementName)) { reader.Read(); if (reader.IsStartElement()) { if (!this.LoadExtraErrorDetailsFromXml(reader, reader.LocalName)) { reader.SkipCurrentElement(); } } } } this.MapErrorCodeToErrorMessage(); this.Loaded(); }
/// <summary> /// Reads response elements from XML. /// </summary> /// <param name="reader">The reader.</param> internal override void ReadElementsFromXml(EwsServiceXmlReader reader) { this.Changes.SyncState = reader.ReadElementValue(XmlNamespace.Messages, XmlElementNames.SyncState); this.Changes.MoreChangesAvailable = !reader.ReadElementValue <bool>(XmlNamespace.Messages, this.GetIncludesLastInRangeXmlElementName()); reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Changes); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.IsStartElement()) { TChange change = this.CreateChangeInstance(); switch (reader.LocalName) { case XmlElementNames.Create: change.ChangeType = ChangeType.Create; break; case XmlElementNames.Update: change.ChangeType = ChangeType.Update; break; case XmlElementNames.Delete: change.ChangeType = ChangeType.Delete; break; case XmlElementNames.ReadFlagChange: change.ChangeType = ChangeType.ReadFlagChange; break; default: reader.SkipCurrentElement(); break; } if (change != null) { reader.Read(); reader.EnsureCurrentNodeIsStartElement(); switch (change.ChangeType) { case ChangeType.Delete: case ChangeType.ReadFlagChange: change.Id = change.CreateId(); change.Id.LoadFromXml(reader, change.Id.GetXmlElementName()); if (change.ChangeType == ChangeType.ReadFlagChange) { reader.Read(); reader.EnsureCurrentNodeIsStartElement(); ItemChange itemChange = change as ItemChange; EwsUtilities.Assert( itemChange != null, "SyncResponse.ReadElementsFromXml", "ReadFlagChange is only valid on ItemChange"); itemChange.IsRead = reader.ReadElementValue <bool>(XmlNamespace.Types, XmlElementNames.IsRead); } break; default: change.ServiceObject = EwsUtilities.CreateEwsObjectFromXmlElementName <TServiceObject>( reader.Service, reader.LocalName); change.ServiceObject.LoadFromXml( reader, true, /* clearPropertyBag */ this.propertySet, this.SummaryPropertiesOnly); break; } reader.ReadEndElementIfNecessary(XmlNamespace.Types, change.ChangeType.ToString()); this.changes.Add(change); } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Changes)); } }
/// <summary> /// Read Conversations from XML. /// </summary> /// <param name="reader">The reader.</param> internal override void ReadElementsFromXml(EwsServiceXmlReader reader) { EwsUtilities.Assert( this.Results.Conversations != null, "FindConversationResponse.ReadElementsFromXml", "conversations is null."); EwsUtilities.Assert( this.Results.HighlightTerms != null, "FindConversationResponse.ReadElementsFromXml", "highlightTerms is null."); reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.Conversations); if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { Conversation item = EwsUtilities.CreateEwsObjectFromXmlElementName <Conversation>(reader.Service, reader.LocalName); if (item == null) { reader.SkipCurrentElement(); } else { item.LoadFromXml( reader, true, /* clearPropertyBag */ null, false /* summaryPropertiesOnly */); this.Results.Conversations.Add(item); } } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.Conversations)); } reader.Read(); if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms) && !reader.IsEmptyElement) { do { reader.Read(); if (reader.NodeType == XmlNodeType.Element) { HighlightTerm term = new HighlightTerm(); term.LoadFromXml( reader, XmlNamespace.Types, XmlElementNames.HighlightTerm); this.Results.HighlightTerms.Add(term); } }while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.HighlightTerms)); } if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.TotalConversationsInView) && !reader.IsEmptyElement) { this.Results.TotalCount = reader.ReadElementValue <int>(); reader.Read(); } if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.IndexedOffset) && !reader.IsEmptyElement) { this.Results.IndexedOffset = reader.ReadElementValue <int>(); reader.Read(); } }