Esempio n. 1
0
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="jsonBody">The json body.</param>
        /// <returns>Response object.</returns>
        internal override object ParseResponse(JsonObject jsonBody)
        {
            ServiceResponseCollection <TResponse> serviceResponses = new ServiceResponseCollection <TResponse>();

            object[] jsonResponseMessages = jsonBody.ReadAsJsonObject(XmlElementNames.ResponseMessages).ReadAsArray(XmlElementNames.Items);

            int responseCtr = 0;

            foreach (object jsonResponseObject in jsonResponseMessages)
            {
                TResponse response = this.CreateServiceResponse(this.Service, responseCtr);

                response.LoadFromJson(jsonResponseObject as JsonObject, this.Service);

                // Add the response to the list after it has been deserialized because the response
                // list updates an overall result as individual responses are added to it.
                serviceResponses.Add(response);

                responseCtr++;
            }

            if (serviceResponses.Count < this.GetExpectedResponseMessageCount())
            {
                if ((serviceResponses.Count == 1) && (serviceResponses[0].Result == ServiceResult.Error))
                {
                    throw new ServiceResponseException(serviceResponses[0]);
                }
                else
                {
                    throw new ServiceJsonDeserializationException();
                }
            }

            return(serviceResponses);
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of CreateAttachmentException.
 /// </summary>
 /// <param name="serviceResponses">The list of responses to be associated with this exception.</param>
 /// <param name="message">The message that describes the error.</param>
 /// <param name="innerException">The exception that is the cause of the current exception.</param>
 internal CreateAttachmentException(
     ServiceResponseCollection <CreateAttachmentResponse> serviceResponses,
     string message,
     Exception innerException)
     : base(serviceResponses, message, innerException)
 {
 }
Esempio n. 3
0
        /// <summary>
        /// Obtains a grouped list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="queryString">query string to be used for indexed search</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <param name="groupBy">The grouping criteria.</param>
        /// <returns>A collection of grouped items representing the contents of this folder.</returns>
        public async Task <GroupedFindItemsResults <Item> > FindItems(string queryString, ItemView view, Grouping groupBy)
        {
            EwsUtilities.ValidateParam(groupBy, "groupBy");

            ServiceResponseCollection <FindItemResponse <Item> > responses = await this.InternalFindItems <Item>(queryString, view, groupBy).ConfigureAwait(false);

            return(responses[0].GroupedFindResults);
        }
Esempio n. 4
0
        /// <summary>
        /// Obtains a list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="queryString">query string to be used for indexed search</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public async Task <FindItemsResults <Item> > FindItems(string queryString, ItemView view)
        {
            EwsUtilities.ValidateParamAllowNull(queryString, "queryString");

            ServiceResponseCollection <FindItemResponse <Item> > responses = await this.InternalFindItems <Item>(queryString, view, null /* groupBy */).ConfigureAwait(false);

            return(responses[0].Results);
        }
Esempio n. 5
0
        /// <summary>
        /// Obtains a grouped list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="queryString">query string to be used for indexed search</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <param name="groupBy">The grouping criteria.</param>
        /// <returns>A collection of grouped items representing the contents of this folder.</returns>
        public GroupedFindItemsResults <Item> FindItems(string queryString, ItemView view, Grouping groupBy)
        {
            EwsUtilities.ValidateParam(groupBy, "groupBy");

            ServiceResponseCollection <FindItemResponse <Item> > responses = this.InternalFindItems <Item>(queryString, view, groupBy);

            return(responses[0].GroupedFindResults);
        }
Esempio n. 6
0
        /// <summary>
        /// Obtains a list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="queryString">query string to be used for indexed search</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public FindItemsResults <Item> FindItems(string queryString, ItemView view)
        {
            EwsUtilities.ValidateParamAllowNull(queryString, "queryString");

            ServiceResponseCollection <FindItemResponse <Item> > responses = this.InternalFindItems <Item>(queryString, view, null /* groupBy */);

            return(responses[0].Results);
        }
Esempio n. 7
0
        /// <summary>
        /// Obtains a list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public FindItemsResults <Item> FindItems(ItemView view)
        {
            ServiceResponseCollection <FindItemResponse <Item> > responses = this.InternalFindItems <Item>(
                (SearchFilter)null,
                view,
                null /* groupBy */);

            return(responses[0].Results);
        }
Esempio n. 8
0
        /// <summary>
        /// Obtains a list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public async Task <FindItemsResults <Item> > FindItems(ItemView view)
        {
            ServiceResponseCollection <FindItemResponse <Item> > responses = await this.InternalFindItems <Item>(
                (SearchFilter)null,
                view,
                null /* groupBy */).ConfigureAwait(false);

            return(responses[0].Results);
        }
Esempio n. 9
0
        /// <summary>
        /// Obtains a list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="searchFilter">The search filter. Available search filter classes
        /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and
        /// SearchFilter.SearchFilterCollection</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public FindItemsResults <Item> FindItems(SearchFilter searchFilter, ItemView view)
        {
            EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter");

            ServiceResponseCollection <FindItemResponse <Item> > responses = this.InternalFindItems <Item>(
                searchFilter,
                view,
                null /* groupBy */);

            return(responses[0].Results);
        }
Esempio n. 10
0
        /// <summary>
        /// Obtains a list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="searchFilter">The search filter. Available search filter classes
        /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and
        /// SearchFilter.SearchFilterCollection</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public async Task <FindItemsResults <Item> > FindItems(SearchFilter searchFilter, ItemView view)
        {
            EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter");

            ServiceResponseCollection <FindItemResponse <Item> > responses = await this.InternalFindItems <Item>(
                searchFilter,
                view,
                null /* groupBy */).ConfigureAwait(false);

            return(responses[0].Results);
        }
Esempio n. 11
0
        /// <summary>
        /// Obtains a list of appointments by searching the contents of this folder and performing recurrence expansion
        /// for recurring appointments. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="view">The view controlling the range of appointments returned.</param>
        /// <returns>An object representing the results of the search operation.</returns>
        public async Task <FindItemsResults <Appointment> > FindAppointments(CalendarView view)
        {
            EwsUtilities.ValidateParam(view, "view");

            ServiceResponseCollection <FindItemResponse <Appointment> > responses = await this.InternalFindItems <Appointment>(
                (SearchFilter)null,
                view,
                null /* groupBy */).ConfigureAwait(false);

            return(responses[0].Results);
        }
        /// <summary>
        /// Initializes a new instance of MultiServiceResponseException.
        /// </summary>
        /// <param name="serviceResponses">The list of responses to be associated with this exception.</param>
        /// <param name="message">The message that describes the error.</param>
        internal BatchServiceResponseException(
            ServiceResponseCollection <TResponse> serviceResponses,
            string message)
            : base(message)
        {
            EwsUtilities.Assert(
                serviceResponses != null,
                "MultiServiceResponseException.ctor",
                "serviceResponses is null");

            this.responses = serviceResponses;
        }
Esempio n. 13
0
        /// <summary>
        /// Obtains a grouped list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="searchFilter">The search filter. Available search filter classes
        /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and
        /// SearchFilter.SearchFilterCollection</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <param name="groupBy">The grouping criteria.</param>
        /// <returns>A collection of grouped items representing the contents of this folder.</returns>
        public GroupedFindItemsResults <Item> FindItems(SearchFilter searchFilter, ItemView view, Grouping groupBy)
        {
            EwsUtilities.ValidateParam(groupBy, "groupBy");
            EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter");

            ServiceResponseCollection <FindItemResponse <Item> > responses = this.InternalFindItems <Item>(
                searchFilter,
                view,
                groupBy);

            return(responses[0].GroupedFindResults);
        }
Esempio n. 14
0
        /// <summary>
        /// Binds to item.
        /// </summary>
        /// <param name="itemId">The item id.</param>
        /// <param name="propertySet">The property set.</param>
        /// <returns>Item.</returns>
        internal async Task <Item> BindToItemAsync(ItemId itemId, PropertySet propertySet)
        {
            EwsUtilities.ValidateParam(itemId, "itemId");
            EwsUtilities.ValidateParam(propertySet, "propertySet");

            ServiceResponseCollection <GetItemResponse> responses = await this.InternalBindToItemsAsync(
                new ItemId[] { itemId },
                propertySet,
                null, /* anchorMailbox */
                ServiceErrorHandling.ThrowOnError);

            return(responses[0].Item);
        }
Esempio n. 15
0
        /// <summary>
        /// Obtains a grouped list of items by searching the contents of this folder. Calling this method results in a call to EWS.
        /// </summary>
        /// <param name="searchFilter">The search filter. Available search filter classes
        /// include SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and
        /// SearchFilter.SearchFilterCollection</param>
        /// <param name="view">The view controlling the number of items returned.</param>
        /// <param name="groupBy">The grouping criteria.</param>
        /// <returns>A collection of grouped items representing the contents of this folder.</returns>
        public async Task <GroupedFindItemsResults <Item> > FindItems(SearchFilter searchFilter, ItemView view, Grouping groupBy, CancellationToken token = default(CancellationToken))
        {
            EwsUtilities.ValidateParam(groupBy, "groupBy");
            EwsUtilities.ValidateParamAllowNull(searchFilter, "searchFilter");

            ServiceResponseCollection <FindItemResponse <Item> > responses = await this.InternalFindItems <Item>(
                searchFilter,
                view,
                groupBy,
                token).ConfigureAwait(false);

            return(responses[0].GroupedFindResults);
        }
Esempio n. 16
0
        /// <summary>
        /// Parses the response.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Service response collection.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            ServiceResponseCollection <TResponse> serviceResponses = new ServiceResponseCollection <TResponse>();

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            for (int i = 0; i < this.GetExpectedResponseMessageCount(); i++)
            {
                // Read ahead to see if we've reached the end of the response messages early.
                reader.Read();
                if (reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages))
                {
                    break;
                }

                TResponse response = this.CreateServiceResponse(reader.Service, i);

                response.LoadFromXml(reader, this.GetResponseMessageXmlElementName());

                // Add the response to the list after it has been deserialized because the response
                // list updates an overall result as individual responses are added to it.
                serviceResponses.Add(response);
            }

            // If there's a general error in batch processing,
            // the server will return a single response message containing the error
            // (for example, if the SavedItemFolderId is bogus in a batch CreateItem
            // call). In this case, throw a ServiceResponsException. Otherwise this
            // is an unexpected server error.
            if (serviceResponses.Count < this.GetExpectedResponseMessageCount())
            {
                if ((serviceResponses.Count == 1) && (serviceResponses[0].Result == ServiceResult.Error))
                {
                    throw new ServiceResponseException(serviceResponses[0]);
                }
                else
                {
                    throw new ServiceXmlDeserializationException(
                              string.Format(
                                  Strings.TooFewServiceReponsesReturned,
                                  this.GetResponseMessageXmlElementName(),
                                  this.GetExpectedResponseMessageCount(),
                                  serviceResponses.Count));
                }
            }

            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            return(serviceResponses);
        }
Esempio n. 17
0
        /// <summary>
        /// Parses the response.
        /// See O15:324151 on why we need to override ParseResponse here instead of calling the one in MultiResponseServiceRequest.cs
        /// </summary>
        /// <param name="jsonBody">The json body.</param>
        /// <returns>Response object.</returns>
        internal override object ParseResponse(JsonObject jsonBody)
        {
            ServiceResponseCollection <SearchMailboxesResponse> serviceResponses = new ServiceResponseCollection <SearchMailboxesResponse>();

            object[] jsonResponseMessages = jsonBody.ReadAsJsonObject(XmlElementNames.ResponseMessages).ReadAsArray(XmlElementNames.Items);

            foreach (object jsonResponseObject in jsonResponseMessages)
            {
                SearchMailboxesResponse response = new SearchMailboxesResponse();
                response.LoadFromJson(jsonResponseObject as JsonObject, this.Service);
                serviceResponses.Add(response);
            }

            return(serviceResponses);
        }
Esempio n. 18
0
        /// <summary>
        /// Ends executing this async request.
        /// </summary>
        /// <param name="asyncResult">The async result</param>
        /// <returns>Service response collection.</returns>
        internal ServiceResponseCollection <TResponse> EndExecute(IAsyncResult asyncResult)
        {
            ServiceResponseCollection <TResponse> serviceResponses = (ServiceResponseCollection <TResponse>) this.EndInternalExecute(asyncResult);

            if (this.ErrorHandlingMode == ServiceErrorHandling.ThrowOnError)
            {
                EwsUtilities.Assert(
                    serviceResponses.Count == 1,
                    "MultiResponseServiceRequest.Execute",
                    "ServiceErrorHandling.ThrowOnError error handling is only valid for singleton request");

                serviceResponses[0].ThrowIfNecessary();
            }

            return(serviceResponses);
        }
Esempio n. 19
0
        /// <summary>
        /// Executes this request.
        /// </summary>
        /// <returns>Service response collection.</returns>
        internal async Task <ServiceResponseCollection <TResponse> > ExecuteAsync(CancellationToken token)
        {
            ServiceResponseCollection <TResponse> serviceResponses = (ServiceResponseCollection <TResponse>) await this.InternalExecuteAsync(token).ConfigureAwait(false);

            if (this.ErrorHandlingMode == ServiceErrorHandling.ThrowOnError)
            {
                EwsUtilities.Assert(
                    serviceResponses.Count == 1,
                    "MultiResponseServiceRequest.Execute",
                    "ServiceErrorHandling.ThrowOnError error handling is only valid for singleton request");

                serviceResponses[0].ThrowIfNecessary();
            }

            return(serviceResponses);
        }
        /// <summary>
        /// Calls the CreateAttachment web method to create a list of attachments.
        /// </summary>
        /// <param name="parentItemId">The Id of the parent item of the new attachments.</param>
        /// <param name="attachments">The attachments to create.</param>
        private void InternalCreateAttachments(string parentItemId, IEnumerable <Attachment> attachments)
        {
            ServiceResponseCollection <CreateAttachmentResponse> responses = this.owner.Service.CreateAttachments(parentItemId, attachments);

            foreach (CreateAttachmentResponse response in responses)
            {
                // We remove all attachments that were successfully created from the change log. We should never
                // receive a warning from EWS, so we ignore them.
                if (response.Result != ServiceResult.Error)
                {
                    this.RemoveFromChangeLog(response.Attachment);
                }
            }

            // TODO : Should we throw for warnings as well?
            if (responses.OverallResult == ServiceResult.Error)
            {
                throw new CreateAttachmentException(responses, Strings.AttachmentCreationFailed);
            }
        }
        /// <summary>
        /// Calls the DeleteAttachment web method to delete a list of attachments.
        /// </summary>
        /// <param name="attachments">The attachments to delete.</param>
        private void InternalDeleteAttachments(IEnumerable <Attachment> attachments)
        {
            ServiceResponseCollection <DeleteAttachmentResponse> responses = this.owner.Service.DeleteAttachments(attachments);

            foreach (DeleteAttachmentResponse response in responses)
            {
                // We remove all attachments that were successfully deleted from the change log. We should never
                // receive a warning from EWS, so we ignore them.
                if (response.Result != ServiceResult.Error)
                {
                    this.RemoveFromChangeLog(response.Attachment);
                }
            }

            // TODO : Should we throw for warnings as well?
            if (responses.OverallResult == ServiceResult.Error)
            {
                throw new DeleteAttachmentException(responses, Strings.AtLeastOneAttachmentCouldNotBeDeleted);
            }
        }
        /// <summary>
        /// Parses the response.
        /// See O15:324151 on why we need to override ParseResponse here instead of calling the one in MultiResponseServiceRequest.cs
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>Service response collection.</returns>
        internal override object ParseResponse(EwsServiceXmlReader reader)
        {
            ServiceResponseCollection <SearchMailboxesResponse> serviceResponses = new ServiceResponseCollection <SearchMailboxesResponse>();

            reader.ReadStartElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            while (true)
            {
                // Read ahead to see if we've reached the end of the response messages early.
                reader.Read();
                if (reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.ResponseMessages))
                {
                    break;
                }

                SearchMailboxesResponse response = new SearchMailboxesResponse();
                response.LoadFromXml(reader, this.GetResponseMessageXmlElementName());
                serviceResponses.Add(response);
            }

            reader.ReadEndElementIfNecessary(XmlNamespace.Messages, XmlElementNames.ResponseMessages);

            return(serviceResponses);
        }
Esempio n. 23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Microsoft.Exchange.WebServices.Data.BatchServiceResponseException"/> class with serialized data.
 /// </summary>
 /// <param name="info">The object that holds the serialized object data.</param>
 /// <param name="context">The contextual information about the source or destination.</param>
 protected BatchServiceResponseException(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.responses = (ServiceResponseCollection <TResponse>)info.GetValue("Responses", typeof(ServiceResponseCollection <TResponse>));
 }
Esempio n. 24
0
 /// <summary>
 /// Initializes a new instance of DeleteAttachmentException.
 /// </summary>
 /// <param name="serviceResponses">The list of responses to be associated with this exception.</param>
 /// <param name="message">The message that describes the error.</param>
 internal DeleteAttachmentException(
     ServiceResponseCollection <DeleteAttachmentResponse> serviceResponses,
     string message)
     : base(serviceResponses, message)
 {
 }