/// <summary>
 /// This method populates HTTP header fields from AnetError object.
 /// </summary>
 /// <param name="context">The context</param>
 /// <param name="error">The AnetError object</param>
 private void EmitErrorState(HttpActionExecutedContext context,  AnetError error)
 {
     var request = context.Request;
     if (request != null)
     {
         context.Response = request.CreateResponse<AnetError>(error);
         context.Response.StatusCode = error.Status;
         context.Response.ReasonPhrase = error.Reason;
     }
 }
        /// <summary>
        /// This method retrieves information from XML mapping file for specified HTTP status code.
        /// </summary>
        /// <param name="httpCode">The HTTP status code</param>
        /// <returns>The AnetError object</returns>
        private AnetError GetAnetErrorForHttpCode(int httpCode)
        {
            Stream stream = this.GetType().Assembly.GetManifestResourceStream(Constants.AnetError.HttpErrorMappingDocumentPath);
            var document = XDocument.Load(stream);
            
            var namespaceManager = new XmlNamespaceManager(new NameTable());
            XElement name = document.XPathSelectElement(Constants.AnetError.XmlPathForElementWithGivenStatusCode + httpCode + "]", namespaceManager);
            AnetError anetError = new AnetError();
            if (name.Descendants(Constants.AnetError.Reason).Count() != 0 && name.Descendants(Constants.AnetError.Reason).First() != null)
            {
                anetError.Reason = name.Descendants(Constants.AnetError.Reason).First().Value;
            }

            if (name.Descendants(Constants.AnetError.Message).Count() != 0 
                    && name.Descendants(Constants.AnetError.Message).First() != null)
            {
                anetError.Message = name.Descendants(Constants.AnetError.Message).First().Value;
            }

            anetError.Status = (HttpStatusCode)httpCode;
            anetError.CorrelationId = AnetConfiguration.CorrelationId.Value;
            return anetError;
        }
        /// <summary>
        /// This method is not currently in use.
        /// </summary>
        /// <param name="context">The context</param>
        /// <param name="code">The status code</param>
        /// <param name="reason">The reason</param>
        /// <param name="message">The message</param>
        /// <param name="correlationId">The correlation-id</param>
        /// <param name="details">The details</param>
        private void EmitErrorState(HttpActionExecutedContext context, HttpStatusCode code, string reason, string message, Guid correlationId, List<AnetErrorDetail> details)
        {
            AnetError error = new AnetError();
            error.Status = code;
            error.Message = message;
            error.Reason = reason;
            error.CorrelationId = correlationId;
            error.Details.AddRange(details);

            this.EmitErrorState(context, error);
        }