/// <summary>
        /// Initializes a new JsonServiceDocumentSerializer, ready to write
        /// out the Service Document for a data provider.
        /// </summary>
        /// <param name="output">Stream to which output should be sent.</param>
        /// <param name="provider">Data provider from which metadata should be gathered.</param>
        /// <param name="encoding">Text encoding for the response.</param>
        internal JsonServiceDocumentSerializer(
            Stream output,
            DataServiceProviderWrapper provider,
            Encoding encoding)
        {
            Debug.Assert(output != null, "output != null");
            Debug.Assert(provider != null, "provider != null");

            this.writer = new JsonWriter(new StreamWriter(output, encoding));
            this.provider = provider;
        }
        /// <summary>
        /// Initializes a new <see cref="JsonSerializer"/>, ready to write out a description.
        /// </summary>
        /// <param name="requestDescription">Description for the requested results.</param>
        /// <param name="output">Stream to which output should be sent.</param>
        /// <param name="absoluteServiceUri">Absolute URI to the service entry point.</param>
        /// <param name="service">Service with configuration and provider from which metadata should be gathered.</param>
        /// <param name="encoding">Text encoding for the response.</param>
        /// <param name="httpETagHeaderValue">HTTP ETag header value.</param>
        internal JsonSerializer(
            RequestDescription requestDescription, 
            Stream output, 
            Uri absoluteServiceUri,
            IDataService service,
            Encoding encoding,
            string httpETagHeaderValue)
            : base(requestDescription, absoluteServiceUri, service, httpETagHeaderValue)
        {
            Debug.Assert(output != null, "output != null");
            Debug.Assert(encoding != null, "encoding != null");

            this.writer = new JsonWriter(new StreamWriter(output, encoding));
        }
Beispiel #3
0
 private static void SerializeJsonException(JsonWriter writer, Exception exception)
 {
     string name = "innererror";
     int num = 0;
     while (exception != null)
     {
         writer.WriteName(name);
         writer.StartObjectScope();
         num++;
         string s = exception.Message ?? string.Empty;
         writer.WriteName("message");
         writer.WriteValue(s);
         string fullName = exception.GetType().FullName;
         writer.WriteName("type");
         writer.WriteValue(fullName);
         string str4 = exception.StackTrace ?? string.Empty;
         writer.WriteName("stacktrace");
         writer.WriteValue(str4);
         exception = exception.InnerException;
         name = "internalexception";
     }
     while (num > 0)
     {
         writer.EndScope();
         num--;
     }
 }
Beispiel #4
0
 private void SerializeJsonErrorToStream(Stream stream)
 {
     JsonWriter writer = new JsonWriter(new StreamWriter(stream, this.encoding));
     try
     {
         this.SerializeJsonError(writer);
     }
     finally
     {
         writer.Flush();
     }
 }
Beispiel #5
0
 private void SerializeJsonError(JsonWriter writer)
 {
     string str;
     string str2;
     string str3;
     writer.StartObjectScope();
     writer.WriteName("error");
     DataServiceException exception = ExtractErrorValues(this.exceptionArgs.Exception, out str, out str2, out str3);
     writer.StartObjectScope();
     writer.WriteName("code");
     writer.WriteValue(str);
     writer.WriteName("message");
     writer.StartObjectScope();
     writer.WriteName("lang");
     writer.WriteValue(str3);
     writer.WriteName("value");
     writer.WriteValue(str2);
     writer.EndScope();
     if (this.exceptionArgs.UseVerboseErrors)
     {
         Exception exception2 = (exception == null) ? this.exceptionArgs.Exception : exception.InnerException;
         SerializeJsonException(writer, exception2);
     }
     writer.EndScope();
     writer.EndScope();
     writer.Flush();
 }
Beispiel #6
0
 /// <summary>Serializes the current exception description to the specified <paramref name="stream"/>.</summary>
 /// <param name="stream">Stream to write to.</param>
 private void SerializeJsonErrorToStream(Stream stream)
 {
     Debug.Assert(stream != null, "stream != null");
     JsonWriter jsonWriter = new JsonWriter(new StreamWriter(stream, this.encoding));
     try
     {
         SerializeJsonError(jsonWriter);
     }
     finally
     {
         // We should not close the writer, since the stream is owned by the underlying host.
         jsonWriter.Flush();
     }
 }
Beispiel #7
0
        /// <summary>Serializes an error in JSON format.</summary>
        /// <param name='writer'>Writer to which error should be serialized.</param>
        private void SerializeJsonError(JsonWriter writer)
        {
            Debug.Assert(writer != null, "writer != null");
            writer.StartObjectScope();  // Wrapper for error.
            writer.WriteName(XmlConstants.JsonError);

            string errorCode, message, messageLang;
            DataServiceException dataException = ExtractErrorValues(this.exceptionArgs.Exception, out errorCode, out message, out messageLang);
            writer.StartObjectScope();

            writer.WriteName(XmlConstants.JsonErrorCode);
            writer.WriteValue(errorCode);

            writer.WriteName(XmlConstants.JsonErrorMessage);
            writer.StartObjectScope();
            writer.WriteName(XmlConstants.XmlLangAttributeName);
            writer.WriteValue(messageLang);
            writer.WriteName(XmlConstants.JsonErrorValue);
            writer.WriteValue(message);
            writer.EndScope();  // </message>

            if (this.exceptionArgs.UseVerboseErrors)
            {
                Exception exception = (dataException == null) ? this.exceptionArgs.Exception : dataException.InnerException;
                SerializeJsonException(writer, exception);
            }

            writer.EndScope();  // </error>
            writer.EndScope();  // </error wrapper>
            writer.Flush();
        }
Beispiel #8
0
        /// <summary>Serializes an exception in JSON format.</summary>
        /// <param name='writer'>Writer to which error should be serialized.</param>
        /// <param name='exception'>Exception to serialize.</param>
        private static void SerializeJsonException(JsonWriter writer, Exception exception)
        {
            string elementName = XmlConstants.JsonErrorInner;
            int nestingDepth = 0;
            while (exception != null)
            {
                writer.WriteName(elementName);
                writer.StartObjectScope();
                nestingDepth++;

                string exceptionMessage = exception.Message ?? String.Empty;
                writer.WriteName(XmlConstants.JsonErrorMessage);
                writer.WriteValue(exceptionMessage);

                string exceptionType = exception.GetType().FullName;
                writer.WriteName(XmlConstants.JsonErrorType);
                writer.WriteValue(exceptionType);

                string exceptionStackTrace = exception.StackTrace ?? String.Empty;
                writer.WriteName(XmlConstants.JsonErrorStackTrace);
                writer.WriteValue(exceptionStackTrace);

                exception = exception.InnerException;
                elementName = XmlConstants.JsonErrorInternalException;
            }

            while (nestingDepth > 0)
            {
                writer.EndScope();  // </innererror>
                nestingDepth--;
            }
        }
Beispiel #9
0
 /// <summary>Serializes an error in JSON format.</summary>
 /// <param name='args'>Arguments describing the error.</param>
 /// <param name='writer'>Writer to which error should be serialized.</param>
 internal static void SerializeJsonError(HandleExceptionArgs args, JsonWriter writer)
 {
     Debug.Assert(args != null, "args != null");
     Debug.Assert(writer != null, "writer != null");
     ErrorHandler serializer = new ErrorHandler(args, null);
     serializer.SerializeJsonError(writer);
 }
Beispiel #10
0
 public Scope(JsonWriter.ScopeType type)
 {
     this.type = type;
 }