/// <summary>
        /// Converts the given exception response to a <see cref="ManagementServiceExceptionInfo"/>.
        /// </summary>
        /// <param name="response">The response containing the xml serialized error information.</param>
        /// <returns>The converted <see cref="ManagementServiceExceptionInfo"/> containing errors from the exception.</returns>
        public static ManagementServiceExceptionInfo Parse(OperationResponse response)
        {
            if (response == null)
            {
                throw new ArgumentNullException("response");
            }

            if (response.Error == null)
            {
                throw new ArgumentException(Resources.InvalidErrorInResponse, "response");
            }

            ManagementServiceExceptionInfo info;
            if (ManagementServiceExceptionInfo.TryParse(response, out info))
            {
                return info;
            }
            else
            {
                throw new FormatException(Resources.InvalidExceptionMessageFormat);
            }
        }
        /// <summary>
        /// Tries to convert the given exception response to a <see cref="ManagementServiceExceptionInfo"/>.
        /// </summary>
        /// <param name="response">The response containing the xml serialized error information.</param>
        /// <param name="info">The converted <see cref="ManagementServiceExceptionInfo"/> containing errors from the exception.</param>
        /// <returns><c>true</c> if parsing succeeded.</returns>
        public static bool TryParse(OperationResponse response, out ManagementServiceExceptionInfo info)
        {
            if (response != null && response.Error != null)
            {
                return ManagementServiceExceptionInfo.TryParse(response.Error.Message, out info);
            }

            info = default(ManagementServiceExceptionInfo);
            return false;
        }
 internal virtual void HandleResponse(ODataClient client, OperationResponse operationResponse)
 {
     _requestState = RequestState.Completed;
     if (operationResponse.Error != null)
     {
         if (operationResponse.StatusCode != 404)
         {
             _requestState = RequestState.CompletedWithError;
             Exception = operationResponse.Error;
         }
     }
     else if (operationResponse.StatusCode < 200 || operationResponse.StatusCode > 250)
     {
         _requestState = RequestState.CompletedWithError;
     }
 }
 /// <summary>
 /// In batch operations, this method is called to determine if this <see cref="ODataClientRequest"/>
 /// matches the specified <see cref="OperationResponse"/>.
 /// </summary>
 /// <param name="operationResponse"></param>
 /// <returns></returns>
 internal abstract bool IsRequestFor(OperationResponse operationResponse);
        private static string FormatOperationResponse(OperationResponse response)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("---------------------------------").AppendLine()
                .Append("Type: ").Append(response.GetType().Name).AppendLine()
                .Append("Status Code: ").Append(response.StatusCode).AppendLine()
                .Append("Has Errors: ").Append(response.HasErrors).AppendLine()
                .AppendLine();

            builder.Append(FormatHeaders(response.Headers));

            if (response is ChangesetResponse)
            {
                builder.Append(FormatEntityDescriptors(response.Cast<EntityDescriptor>()));
            }

            return builder.ToString();
        }
 /// <summary>
 /// Extracts the replica session key header from the serviceResponse.
 /// </summary>
 /// <param name="operationResponse">Data service serviceResponse (query or changeResponse).</param>
 public void ProcessResponseHeader(OperationResponse operationResponse)
 {
     string replicaSessionKeyHeader;
     if (operationResponse.Headers.TryGetValue(ActiveDirectoryConstants.HeaderNameReplicaSessionKey, out replicaSessionKeyHeader))
     {
         Properties.ReplicaSessionKeyHeader = replicaSessionKeyHeader;
     }
 }