/// <summary> /// Read items from JSON. /// </summary> /// <param name="jsonObject">The JSON object containing items.</param> /// <param name="propertySet">The property set.</param> /// <param name="service">Exchange service.</param> /// <param name="destinationList">The list in which to add the read items.</param> private void InternalReadItemsFromJson( JsonObject jsonObject, PropertySet propertySet, ExchangeService service, IList <TItem> destinationList) { EwsUtilities.Assert( destinationList != null, "FindItemResponse.InternalReadItemsFromJson", "destinationList is null."); if (jsonObject.ContainsKey(XmlElementNames.Items)) { List <TItem> items = new EwsServiceJsonReader(service).ReadServiceObjectsCollectionFromJson <TItem>( jsonObject, XmlElementNames.Items, this.CreateItemInstance, true, /* clearPropertyBag */ this.propertySet, /* requestedPropertySet */ true); /* summaryPropertiesOnly */ items.ForEach((item) => destinationList.Add(item)); } }
/// <summary> /// Initializes a new instance of the <see cref="OAuthCredentials"/> class. /// </summary> /// <param name="token"></param> /// <param name="verbatim"></param> internal OAuthCredentials(string token, bool verbatim) { EwsUtilities.ValidateParam(token, "token"); string rawToken; if (verbatim) { rawToken = token; } else { int whiteSpacePosition = token.IndexOf(' '); if (whiteSpacePosition == -1) { rawToken = token; } else { string authType = token.Substring(0, whiteSpacePosition); if (string.Compare(authType, BearerAuthenticationType, StringComparison.OrdinalIgnoreCase) != 0) { throw new ArgumentException(Strings.InvalidAuthScheme); } rawToken = token.Substring(whiteSpacePosition + 1); } if (!validTokenPattern.IsMatch(rawToken)) { throw new ArgumentException(Strings.InvalidOAuthToken); } } this.token = BearerAuthenticationType + " " + rawToken; }
/// <summary> /// Parses the specified value. /// </summary> /// <param name="value">The value.</param> /// <returns>TaskDelegationState value.</returns> internal override object Parse(string value) { switch (value) { case NoMatch: return(TaskDelegationState.NoDelegation); case OwnNew: return(TaskDelegationState.Unknown); case Owned: return(TaskDelegationState.Accepted); case Accepted: return(TaskDelegationState.Declined); default: EwsUtilities.Assert( false, "TaskDelegationStatePropertyDefinition.Parse", string.Format("TaskDelegationStatePropertyDefinition.Parse(): value {0} cannot be handled.", value)); return(null); // To keep the compiler happy } }
/// <summary> /// Sends this e-mail message and saves a copy of it in the specified folder. SendAndSaveCopy does not work if the /// message has unsaved attachments. In that case, the message must first be saved and then sent. Calling this method /// results in a call to EWS. /// </summary> /// <param name="destinationFolderId">The Id of the folder in which to save the copy.</param> public void SendAndSaveCopy(FolderId destinationFolderId) { EwsUtilities.ValidateParam(destinationFolderId, "destinationFolderId"); this.InternalSend(destinationFolderId, MessageDisposition.SendAndSaveCopy); }
/// <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.MeetingTime: this.meetingTime = reader.ReadElementValueAsUnbiasedDateTimeScopedToServiceTimeZone(); return(true); case XmlElementNames.IsWorkTime: this.isWorkTime = reader.ReadElementValue <bool>(); return(true); case XmlElementNames.SuggestionQuality: this.quality = reader.ReadElementValue <SuggestionQuality>(); return(true); case XmlElementNames.AttendeeConflictDataArray: if (!reader.IsEmptyElement) { do { reader.Read(); if (reader.IsStartElement()) { Conflict conflict = null; switch (reader.LocalName) { case XmlElementNames.UnknownAttendeeConflictData: conflict = new Conflict(ConflictType.UnknownAttendeeConflict); break; case XmlElementNames.TooBigGroupAttendeeConflictData: conflict = new Conflict(ConflictType.GroupTooBigConflict); break; case XmlElementNames.IndividualAttendeeConflictData: conflict = new Conflict(ConflictType.IndividualAttendeeConflict); break; case XmlElementNames.GroupAttendeeConflictData: conflict = new Conflict(ConflictType.GroupConflict); break; default: EwsUtilities.Assert( false, "TimeSuggestion.TryReadElementFromXml", string.Format("The {0} element name does not map to any AttendeeConflict descendant.", reader.LocalName)); // The following line to please the compiler break; } conflict.LoadFromXml(reader, reader.LocalName); this.conflicts.Add(conflict); } }while (!reader.IsEndElement(XmlNamespace.Types, XmlElementNames.AttendeeConflictDataArray)); } return(true); default: return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="SubscriptionBase"/> class. /// </summary> /// <param name="service">The service.</param> internal SubscriptionBase(ExchangeService service) { EwsUtilities.ValidateParam(service, "service"); this.service = service; }
/// <summary> /// Validate request. /// </summary> internal override void Validate() { base.Validate(); EwsUtilities.ValidateParam(this.userConfiguration, "userConfiguration"); }
/// <summary> /// Processes the web exception. /// </summary> /// <param name="webException">The web exception.</param> private void ProcessWebException(WebException webException) { if (webException.Response != null) { IEwsHttpWebResponse httpWebResponse = this.Service.HttpWebRequestFactory.CreateExceptionResponse(webException); SoapFaultDetails soapFaultDetails = null; if (httpWebResponse.StatusCode == HttpStatusCode.InternalServerError) { this.Service.ProcessHttpResponseHeaders(TraceFlags.EwsResponseHttpHeaders, httpWebResponse); // If tracing is enabled, we read the entire response into a MemoryStream so that we // can pass it along to the ITraceListener. Then we parse the response from the // MemoryStream. if (this.Service.IsTraceEnabledFor(TraceFlags.EwsResponse)) { using (MemoryStream memoryStream = new MemoryStream()) { using (Stream serviceResponseStream = ServiceRequestBase.GetResponseStream(httpWebResponse)) { // Copy response to in-memory stream and reset position to start. EwsUtilities.CopyStream(serviceResponseStream, memoryStream); memoryStream.Position = 0; } this.TraceResponseXml(httpWebResponse, memoryStream); EwsServiceXmlReader reader = new EwsServiceXmlReader(memoryStream, this.Service); soapFaultDetails = this.ReadSoapFault(reader); } } else { using (Stream stream = ServiceRequestBase.GetResponseStream(httpWebResponse)) { EwsServiceXmlReader reader = new EwsServiceXmlReader(stream, this.Service); soapFaultDetails = this.ReadSoapFault(reader); } } if (soapFaultDetails != null) { switch (soapFaultDetails.ResponseCode) { case ServiceError.ErrorInvalidServerVersion: throw new ServiceVersionException(Strings.ServerVersionNotSupported); case ServiceError.ErrorSchemaValidation: // If we're talking to an E12 server (8.00.xxxx.xxx), a schema validation error is the same as a version mismatch error. // (Which only will happen if we send a request that's not valid for E12). if ((this.Service.ServerInfo != null) && (this.Service.ServerInfo.MajorVersion == 8) && (this.Service.ServerInfo.MinorVersion == 0)) { throw new ServiceVersionException(Strings.ServerVersionNotSupported); } break; case ServiceError.ErrorIncorrectSchemaVersion: // This shouldn't happen. It indicates that a request wasn't valid for the version that was specified. EwsUtilities.Assert( false, "ServiceRequestBase.ProcessWebException", "Exchange server supports requested version but request was invalid for that version"); break; case ServiceError.ErrorServerBusy: throw new ServerBusyException(new ServiceResponse(soapFaultDetails)); default: // Other error codes will be reported as remote error break; } // General fall-through case: throw a ServiceResponseException throw new ServiceResponseException(new ServiceResponse(soapFaultDetails)); } } else { this.Service.ProcessHttpErrorResponse(httpWebResponse, webException); } } }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyDefinition">The property definition.</param> /// <param name="exception">Exception that would be raised if there's an error retrieving the property.</param> /// <returns>Propert value. May be null.</returns> private object GetPropertyValueOrException(PropertyDefinition propertyDefinition, out ServiceLocalException exception) { object propertyValue = null; exception = null; if (propertyDefinition.Version > this.Owner.Service.RequestedServerVersion) { exception = new ServiceVersionException( string.Format( Strings.PropertyIncompatibleWithRequestVersion, propertyDefinition.Name, propertyDefinition.Version)); return(null); } if (this.TryGetValue(propertyDefinition, out propertyValue)) { // If the requested property is in the bag, return it. return(propertyValue); } else { if (propertyDefinition.HasFlag(PropertyDefinitionFlags.AutoInstantiateOnRead)) { // The requested property is an auto-instantiate-on-read property ComplexPropertyDefinitionBase complexPropertyDefinition = propertyDefinition as ComplexPropertyDefinitionBase; EwsUtilities.Assert( complexPropertyDefinition != null, "PropertyBag.get_this[]", "propertyDefinition is marked with AutoInstantiateOnRead but is not a descendant of ComplexPropertyDefinitionBase"); propertyValue = complexPropertyDefinition.CreatePropertyInstance(this.Owner); if (propertyValue != null) { this.InitComplexProperty(propertyValue as ComplexProperty); this.properties[propertyDefinition] = propertyValue; } } else { // If the property is not the Id (we need to let developers read the Id when it's null) and if has // not been loaded, we throw. if (propertyDefinition != this.Owner.GetIdPropertyDefinition()) { if (!this.IsPropertyLoaded(propertyDefinition)) { exception = new ServiceObjectPropertyException(Strings.MustLoadOrAssignPropertyBeforeAccess, propertyDefinition); return(null); } // Non-nullable properties (int, bool, etc.) must be assigned or loaded; cannot return null value. if (!propertyDefinition.IsNullable) { string errorMessage = this.IsRequestedProperty(propertyDefinition) ? Strings.ValuePropertyNotLoaded : Strings.ValuePropertyNotAssigned; exception = new ServiceObjectPropertyException(errorMessage, propertyDefinition); } } } return(propertyValue); } }
/// <summary> /// Creates a new instance of the <see cref="EmailAddress"/> class. /// </summary> /// <param name="smtpAddress">The SMTP address used to initialize the PersonaEmailAddress.</param> PersonaEmailAddress(String smtpAddress) : this() { EwsUtilities.ValidateParam(smtpAddress, "smtpAddress"); this.Address = smtpAddress; }
/// <summary> /// Validates request. /// </summary> internal override void Validate() { EwsUtilities.ValidateParam(this.sourceFolderId, "SourceFolderId"); this.sourceFolderId.Validate(this.Service.RequestedServerVersion); }
/// <summary> /// Sends this response and saves a copy in the specified folder. Calling this method results in a call to EWS. /// </summary> /// <param name="destinationFolderId">The Id of the folder in which to save the copy of the message.</param> public System.Threading.Tasks.Task SendAndSaveCopy(FolderId destinationFolderId) { EwsUtilities.ValidateParam(destinationFolderId, "destinationFolderId"); return(this.InternalCreate(destinationFolderId, MessageDisposition.SendAndSaveCopy)); }
/// <summary> /// Saves the response in the specified folder. Calling this method results in a call to EWS. /// </summary> /// <param name="destinationFolderId">The Id of the folder in which to save the response.</param> /// <returns>A TMessage that represents the response.</returns> public async Task <TMessage> Save(FolderId destinationFolderId) { EwsUtilities.ValidateParam(destinationFolderId, "destinationFolderId"); return((await this.InternalCreate(destinationFolderId, MessageDisposition.SaveOnly).ConfigureAwait(false))[0] as TMessage); }
/// <summary> /// Removes a person insight from the collection. /// </summary> /// <param name="insight">The person sight to remove.</param> /// <returns>Whether removed from the collection</returns> public bool Remove(PersonInsight insight) { EwsUtilities.ValidateParam(insight, "insight"); return(this.InternalRemove(insight)); }
/// <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> /// Constructs a dictionary object (key or entry value) from the specified type and String list. /// </summary> /// <param name="type">Object type to construct.</param> /// <param name="value">Value of the dictionary object as a String list</param> /// <param name="service">The service.</param> /// <returns>Dictionary object.</returns> /* private */ object ConstructObject( UserConfigurationDictionaryObjectType type, List <string> value, ExchangeService service) { EwsUtilities.Assert( value != null, "UserConfigurationDictionary.ConstructObject", "value is null"); EwsUtilities.Assert( (value.Count == 1 || type == UserConfigurationDictionaryObjectType.StringArray), "UserConfigurationDictionary.ConstructObject", "value is array but type is not StringArray"); object dictionaryObject = null; switch (type) { case UserConfigurationDictionaryObjectType.Boolean: dictionaryObject = bool.Parse(value[0]); break; case UserConfigurationDictionaryObjectType.Byte: dictionaryObject = byte.Parse(value[0]); break; case UserConfigurationDictionaryObjectType.ByteArray: dictionaryObject = Convert.FromBase64String(value[0]); break; case UserConfigurationDictionaryObjectType.DateTime: DateTime?dateTime = service.ConvertUniversalDateTimeStringToLocalDateTime(value[0]); if (dateTime.HasValue) { dictionaryObject = dateTime.Value; } else { EwsUtilities.Assert( false, "UserConfigurationDictionary.ConstructObject", "DateTime is null"); } break; case UserConfigurationDictionaryObjectType.Integer32: dictionaryObject = int.Parse(value[0]); break; case UserConfigurationDictionaryObjectType.Integer64: dictionaryObject = long.Parse(value[0]); break; case UserConfigurationDictionaryObjectType.String: dictionaryObject = value[0]; break; case UserConfigurationDictionaryObjectType.StringArray: dictionaryObject = value.ToArray(); break; case UserConfigurationDictionaryObjectType.UnsignedInteger32: dictionaryObject = uint.Parse(value[0]); break; case UserConfigurationDictionaryObjectType.UnsignedInteger64: dictionaryObject = ulong.Parse(value[0]); break; default: EwsUtilities.Assert( false, "UserConfigurationDictionary.ConstructObject", "Type not recognized: " + type.ToString()); break; } return(dictionaryObject); }
/// <summary> /// Validate request. /// </summary> internal override void Validate() { base.Validate(); EwsUtilities.ValidateParam(this.FolderIds, "FolderIds"); this.FolderIds.Validate(this.Service.RequestedServerVersion); }
/// <summary> /// Creates a new instance of the <see cref="PersonaEmailAddress"/> class. /// </summary> /// <param name="name">The name used to initialize the PersonaEmailAddress.</param> /// <param name="smtpAddress">The SMTP address used to initialize the PersonaEmailAddress.</param> PersonaEmailAddress(String name, String smtpAddress) : this(smtpAddress) { EwsUtilities.ValidateParam(name, "name"); this.Name = name; }
/// <summary> /// Reads the SOAP fault. /// </summary> /// <param name="reader">The reader.</param> /// <returns>SOAP fault details.</returns> protected SoapFaultDetails ReadSoapFault(EwsServiceXmlReader reader) { SoapFaultDetails soapFaultDetails = null; try { this.ReadXmlDeclaration(reader); reader.Read(); if (!reader.IsStartElement() || (reader.LocalName != XmlElementNames.SOAPEnvelopeElementName)) { return(soapFaultDetails); } // EWS can sometimes return SOAP faults using the SOAP 1.2 namespace. Get the // namespace URI from the envelope element and use it for the rest of the parsing. // If it's not 1.1 or 1.2, we can't continue. XmlNamespace soapNamespace = EwsUtilities.GetNamespaceFromUri(reader.NamespaceUri); if (soapNamespace == XmlNamespace.NotSpecified) { return(soapFaultDetails); } reader.Read(); // EWS doesn't always return a SOAP header. If this response contains a header element, // read the server version information contained in the header. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.Read(); if (reader.IsStartElement(XmlNamespace.Types, XmlElementNames.ServerVersionInfo)) { this.Service.ServerInfo = ExchangeServerInfo.Parse(reader); } }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); // Queue up the next read reader.Read(); } // Parse the fault element contained within the SOAP body. if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.Read(); // Parse Fault element if (reader.IsStartElement(soapNamespace, XmlElementNames.SOAPFaultElementName)) { soapFaultDetails = SoapFaultDetails.Parse(reader, soapNamespace); } }while (!reader.IsEndElement(soapNamespace, XmlElementNames.SOAPBodyElementName)); } reader.ReadEndElement(soapNamespace, XmlElementNames.SOAPEnvelopeElementName); } catch (XmlException) { // If response doesn't contain a valid SOAP fault, just ignore exception and // return null for SOAP fault details. } return(soapFaultDetails); }
/// <summary> /// Validates this view. /// </summary> /// <param name="request">The request using this view.</param> internal override void InternalValidate(ServiceRequestBase request) { base.InternalValidate(request); EwsUtilities.ValidateEnumVersionValue(this.traversal, request.Service.RequestedServerVersion); }
/// <summary> /// Gets the expected response message count. /// </summary> /// <returns>Number of expected response messages.</returns> internal override int GetExpectedResponseMessageCount() { return(EwsUtilities.GetEnumeratedObjectCount(this.Items)); }
/// <summary> /// Validate request.. /// </summary> internal override void Validate() { base.Validate(); EwsUtilities.ValidateParam(this.ParentItemId, "ParentItemId"); }
/// <summary> /// Validates this instance. /// </summary> internal void Validate() { EwsUtilities.ValidateParam(this.flagStatus, "FlagStatus"); }
/// <summary> /// Validate request. /// </summary> void Validate() { EwsUtilities.ValidateParam(this.ConversationId, "conversationId"); }
/// <summary> /// Loads from json. /// </summary> /// <param name="jsonProperty">The json property.</param> /// <param name="service">The service.</param> internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service) { foreach (string key in jsonProperty.Keys) { switch (key) { case XmlElementNames.MeetingTime: this.meetingTime = EwsUtilities.ParseAsUnbiasedDatetimescopedToServicetimeZone(jsonProperty.ReadAsString(key), service); break; case XmlElementNames.IsWorkTime: this.isWorkTime = jsonProperty.ReadAsBool(key); break; case XmlElementNames.SuggestionQuality: this.quality = jsonProperty.ReadEnumValue <SuggestionQuality>(key); break; case XmlElementNames.AttendeeConflictDataArray: object[] jsonConflictArray = jsonProperty.ReadAsArray(key); foreach (object conflictObject in jsonConflictArray) { JsonObject jsonConflict = conflictObject as JsonObject; if (jsonConflict != null) { Conflict conflict = null; switch (jsonConflict.ReadTypeString()) { case XmlElementNames.UnknownAttendeeConflictData: conflict = new Conflict(ConflictType.UnknownAttendeeConflict); break; case XmlElementNames.TooBigGroupAttendeeConflictData: conflict = new Conflict(ConflictType.GroupTooBigConflict); break; case XmlElementNames.IndividualAttendeeConflictData: conflict = new Conflict(ConflictType.IndividualAttendeeConflict); break; case XmlElementNames.GroupAttendeeConflictData: conflict = new Conflict(ConflictType.GroupConflict); break; default: EwsUtilities.Assert( false, "TimeSuggestion.TryReadElementFromJson", string.Format("The {0} element name does not map to any AttendeeConflict descendant.", jsonConflict.ReadTypeString())); // The following line to please the compiler break; } conflict.LoadFromJson(jsonConflict, service); this.conflicts.Add(conflict); } } break; default: break; } } }
/// <summary> /// Writes XML elements. /// </summary> /// <param name="writer">The writer.</param> void WriteElementsToXml(EwsServiceXmlWriter writer) { writer.WriteStartElement( XmlNamespace.Types, XmlElementNames.ConversationAction); try { String actionValue = String.Empty; switch (this.Action) { case ConversationActionType.AlwaysCategorize: actionValue = XmlElementNames.AlwaysCategorize; break; case ConversationActionType.AlwaysDelete: actionValue = XmlElementNames.AlwaysDelete; break; case ConversationActionType.AlwaysMove: actionValue = XmlElementNames.AlwaysMove; break; case ConversationActionType.Delete: actionValue = XmlElementNames.Delete; break; case ConversationActionType.Copy: actionValue = XmlElementNames.Copy; break; case ConversationActionType.Move: actionValue = XmlElementNames.Move; break; case ConversationActionType.SetReadState: actionValue = XmlElementNames.SetReadState; break; case ConversationActionType.SetRetentionPolicy: actionValue = XmlElementNames.SetRetentionPolicy; break; case ConversationActionType.Flag: actionValue = XmlElementNames.Flag; break; default: throw new ArgumentError("ConversationAction"); } // Emit the action element writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.Action, actionValue); // Emit the conversation id element this.ConversationId.WriteToXml( writer, XmlNamespace.Types, XmlElementNames.ConversationId); if (this.Action == ConversationActionType.AlwaysCategorize || this.Action == ConversationActionType.AlwaysDelete || this.Action == ConversationActionType.AlwaysMove) { // Emit the ProcessRightAway element writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.ProcessRightAway, EwsUtilities.BoolToXSBool(this.ProcessRightAway)); } if (this.Action == ConversationActionType.AlwaysCategorize) { // Emit the categories element if (this.Categories != null && this.Categories.Count > 0) { this.Categories.WriteToXml( writer, XmlNamespace.Types, XmlElementNames.Categories); } } else if (this.Action == ConversationActionType.AlwaysDelete) { // Emit the EnableAlwaysDelete element writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.EnableAlwaysDelete, EwsUtilities.BoolToXSBool(this.EnableAlwaysDelete)); } else if (this.Action == ConversationActionType.AlwaysMove) { // Emit the Move Folder Id if (this.DestinationFolderId != null) { writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.DestinationFolderId); this.DestinationFolderId.WriteToXml(writer); writer.WriteEndElement(); } } else { if (this.ContextFolderId != null) { writer.WriteStartElement( XmlNamespace.Types, XmlElementNames.ContextFolderId); this.ContextFolderId.WriteToXml(writer); writer.WriteEndElement(); } if (this.ConversationLastSyncTime.HasValue) { writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.ConversationLastSyncTime, this.ConversationLastSyncTime.Value); } if (this.Action == ConversationActionType.Copy) { EwsUtilities.Assert( this.DestinationFolderId != null, "ApplyconversationActionRequest", "DestinationFolderId should be set when performing copy action"); writer.WriteStartElement( XmlNamespace.Types, XmlElementNames.DestinationFolderId); this.DestinationFolderId.WriteToXml(writer); writer.WriteEndElement(); } else if (this.Action == ConversationActionType.Move) { EwsUtilities.Assert( this.DestinationFolderId != null, "ApplyconversationActionRequest", "DestinationFolderId should be set when performing move action"); writer.WriteStartElement( XmlNamespace.Types, XmlElementNames.DestinationFolderId); this.DestinationFolderId.WriteToXml(writer); writer.WriteEndElement(); } else if (this.Action == ConversationActionType.Delete) { EwsUtilities.Assert( this.DeleteType.HasValue, "ApplyconversationActionRequest", "DeleteType should be specified when deleting a conversation."); writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.DeleteType, this.DeleteType.Value); } else if (this.Action == ConversationActionType.SetReadState) { EwsUtilities.Assert( this.IsRead.HasValue, "ApplyconversationActionRequest", "IsRead should be specified when marking/unmarking a conversation as read."); writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.IsRead, this.IsRead.Value); if (this.SuppressReadReceipts.HasValue) { writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.SuppressReadReceipts, this.SuppressReadReceipts.Value); } } else if (this.Action == ConversationActionType.SetRetentionPolicy) { EwsUtilities.Assert( this.RetentionPolicyType.HasValue, "ApplyconversationActionRequest", "RetentionPolicyType should be specified when setting a retention policy on a conversation."); writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.RetentionPolicyType, this.RetentionPolicyType.Value); if (this.RetentionPolicyTagId.HasValue) { writer.WriteElementValue( XmlNamespace.Types, XmlElementNames.RetentionPolicyTagId, this.RetentionPolicyTagId.Value); } } else if (this.Action == ConversationActionType.Flag) { EwsUtilities.Assert( this.Flag != null, "ApplyconversationActionRequest", "Flag should be specified when flagging conversation items."); writer.WriteStartElement(XmlNamespace.Types, XmlElementNames.Flag); this.Flag.WriteElementsToXml(writer); writer.WriteEndElement(); } } } finally { writer.WriteEndElement(); } }
/// <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(); } if (reader.IsStartElement(XmlNamespace.Messages, XmlElementNames.FindPeopleTransactionId) && !reader.IsEmptyElement) { this.TransactionId = reader.ReadElementValue <string>(); reader.Read(); } // Future proof by skipping any additional elements before returning while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.FindPeopleResponse)) { reader.Read(); } }
/// <summary> /// Validates this instance. /// </summary> internal override void InternalValidate() { EwsUtilities.ValidateParam(this.ConversationId, "ConversationId"); }
/// <summary> /// Initializes a new instance of the <see cref="ClientCertificateCredentials"/> class. /// </summary> /// <param name="clientCertificates">The client certificates.</param> public ClientCertificateCredentials(X509CertificateCollection clientCertificates) { EwsUtilities.ValidateParam(clientCertificates, "clientCertificates"); this.clientCertificates = clientCertificates; }
/// <summary> /// Validate this instance. /// </summary> internal override void InternalValidate() { EwsUtilities.ValidateParam(this.Mailbox, "mailbox"); }