Example #1
0
        /// <summary>
        /// Called by an implementation of IJsonizable to store a data member which implements IJsonizable.
        /// </summary>
        /// <param name="name">The object member's name</param>
        /// <param name="item">The object to store</param>
        /// <param name="isFinal">Is this the last member the caller will add?</param>
        internal void AddMember(string name, IJsonizable item, bool isFinal)
        {
            Jsonizer subJsonizer = new Jsonizer(item);

            builder.AppendFormat("\"{0}\": {1}", name, subJsonizer.ToJsonString());
            if (!isFinal)
            {
                builder.Append(",");
            }
        }
Example #2
0
        /// <summary>
        /// Entry point for handling the HTTP request.  ProcessRequest manages the process of
        /// determining which method was requested, invoking it, and returning a JSON response.
        /// Part of IHttpHandler
        /// </summary>
        /// <param name="context">Object containing the details of current HTTP request and response.</param>
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            try
            {
                // Get the particular method being invoked.
                ApiMethodType method = ParseApiMethod(request);

                // Get object for invoking the specific dictionary method.
                Invoker invoker = Invoker.Create(method, request);

                // Invoke the requested dictionary method.
                IJsonizable result = invoker.Invoke();

                // Put together the JSON response.
                Jsonizer json = new Jsonizer(result);

                response.ContentType = "application/json";
                response.Write(json.ToJsonString());
            }
            // There was something wrong with the request that prevented us from
            // being able to invoke a method.
            catch (HttpParseException ex)
            {
                response.Status     = ex.Message;
                response.StatusCode = 400;
            }
            // Something went wrong in our code.
            catch (Exception ex)
            {
                log.ErrorFormat(errorProcessFormat, ex, request.RawUrl);
                response.StatusDescription = "Error processing dictionary request.";
                response.StatusCode        = 500;
            }
        }
Example #3
0
 /// <summary>
 /// Initialization.
 /// </summary>
 /// <param name="rootItem">The object hierarchy's root item.</param>
 internal Jsonizer(IJsonizable rootItem)
 {
     builder.Append("{");
     rootItem.Jsonize(this);
     builder.Append("}");
 }