示例#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);
        }
示例#2
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);
        }
示例#3
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);
        }
        /// <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);
        }