/// <summary> /// Writes an EWS SetUpdate opeartion for the specified property. /// </summary> /// <param name="writer">The writer to write the update to.</param> /// <param name="propertyDefinition">The property fro which to write the update.</param> private void WriteSetUpdateToXml(EwsServiceXmlWriter writer, PropertyDefinition propertyDefinition) { // The following test should not be necessary since the property bag prevents // properties to be updated if they don't have the CanUpdate flag, but it // doesn't hurt... if (propertyDefinition.HasFlag(PropertyDefinitionFlags.CanUpdate)) { object propertyValue = this[propertyDefinition]; bool handled = false; ICustomUpdateSerializer updateSerializer = propertyValue as ICustomUpdateSerializer; if (updateSerializer != null) { handled = updateSerializer.WriteSetUpdateToXml( writer, this.Owner, propertyDefinition); } if (!handled) { writer.WriteStartElement(XmlNamespace.Types, this.Owner.GetSetFieldXmlElementName()); propertyDefinition.WriteToXml(writer); writer.WriteStartElement(XmlNamespace.Types, this.Owner.GetXmlElementName()); propertyDefinition.WritePropertyValueToXml(writer, this, true /* isUpdateOperation */); writer.WriteEndElement(); writer.WriteEndElement(); } } }
/// <summary> /// Writes an EWS DeleteUpdate opeartion for the specified property. /// </summary> /// <param name="writer">The writer to write the update to.</param> /// <param name="propertyDefinition">The property fro which to write the update.</param> /// <param name="propertyValue">The current value of the property.</param> private void WriteDeleteUpdateToXml( EwsServiceXmlWriter writer, PropertyDefinition propertyDefinition, object propertyValue) { // The following test should not be necessary since the property bag prevents // properties to be deleted (set to null) if they don't have the CanDelete flag, // but it doesn't hurt... if (propertyDefinition.HasFlag(PropertyDefinitionFlags.CanDelete)) { bool handled = false; ICustomUpdateSerializer updateSerializer = propertyValue as ICustomUpdateSerializer; if (updateSerializer != null) { handled = updateSerializer.WriteDeleteUpdateToXml(writer, this.Owner); } if (!handled) { writer.WriteStartElement(XmlNamespace.Types, this.Owner.GetDeleteFieldXmlElementName()); propertyDefinition.WriteToXml(writer); writer.WriteEndElement(); } } }
/// <summary> /// Writes the update to XML. /// </summary> /// <param name="writer">The writer.</param> /// <param name="ewsObject">The ews object.</param> /// <param name="propertyDefinition">Property definition.</param> /// <returns>True if property generated serialization.</returns> bool ICustomUpdateSerializer.WriteSetUpdateToXml( EwsServiceXmlWriter writer, ServiceObject ewsObject, PropertyDefinition propertyDefinition) { // If the collection is empty, delete the property. if (this.Count == 0) { writer.WriteStartElement(XmlNamespace.Types, ewsObject.GetDeleteFieldXmlElementName()); propertyDefinition.WriteToXml(writer); writer.WriteEndElement(); return(true); } // Otherwise, use the default XML serializer. else { return(false); } }