Dictionary<string, object> DoServiceCall(string method, params object[] parameters)
        {
            var callId = Interlocked.Increment (ref this.callId);

            var callObject = new Dictionary<string, object> {
                {"id", callId},
                {"method", method},
                {"params", parameters}
            };

            #if DEBUG
            Console.Error.Write ("Serializing JSON-RPC call object...");
            Stopwatch s = new Stopwatch ();
            s.Start ();
            #endif
            string jsonPayload = new Serializer (callObject).Serialize ();
            #if DEBUG
            s.Stop ();
            Console.Error.WriteLine ("done in {0}.", s.Elapsed);
            Console.Error.WriteLine ("Serialized payload: {0}", jsonPayload);
            #endif

            var serviceClient = new CookieClient ();

            if (cookies != null)
                serviceClient.Cookies = cookies;

            serviceClient.Headers.Add (HttpRequestHeader.ContentType, "application/json");

            #if DEBUG
            Console.Error.Write ("Making request...");
            s.Reset ();
            s.Start ();
            #endif

            string responseJson = serviceClient.UploadString (ServiceUri, jsonPayload);

            #if DEBUG
            s.Stop ();
            Console.Error.WriteLine ("done in {0}.", s.Elapsed);
            Console.Error.WriteLine ("Response: {0}", responseJson);
            #endif

            cookies = serviceClient.Cookies;

            #if DEBUG
            s.Reset ();
            Console.Error.Write ("Deserializing result...");
            s.Start ();
            #endif
            var response = new Deserializer (responseJson).Deserialize () as Dictionary<string, object>;
            #if DEBUG
            s.Stop ();
            Console.Error.WriteLine ("done in {0}.", s.Elapsed);
            #endif

            if ((long)response ["id"] != callId)
                throw new ApplicationException (string.Format ("Response ID and original call ID don't match. Expected {0}, received {1}.", callId, response ["id"]));

            if (response ["error"] != null)
                throw new ApplicationException (string.Format ("Received error message from Bugzilla. Message: {0}", ((JsonObject)response ["error"]) ["message"]));

            return response;
        }
Esempio n. 2
0
        Dictionary <string, object> DoServiceCall(string method, params object[] parameters)
        {
            var callId = Interlocked.Increment(ref this.callId);

            var callObject = new Dictionary <string, object> {
                { "id", callId },
                { "method", method },
                { "params", parameters }
            };

                        #if DEBUG
            Console.Error.Write("Serializing JSON-RPC call object...");
            Stopwatch s = new Stopwatch();
            s.Start();
                        #endif
            string jsonPayload = new Serializer(callObject).Serialize();
                        #if DEBUG
            s.Stop();
            Console.Error.WriteLine("done in {0}.", s.Elapsed);
            Console.Error.WriteLine("Serialized payload: {0}", jsonPayload);
                        #endif

            var serviceClient = new CookieClient();

            if (cookies != null)
            {
                serviceClient.Cookies = cookies;
            }

            serviceClient.Headers.Add(HttpRequestHeader.ContentType, "application/json");

                        #if DEBUG
            Console.Error.Write("Making request...");
            s.Reset();
            s.Start();
                        #endif

            string responseJson = serviceClient.UploadString(ServiceUri, jsonPayload);

                        #if DEBUG
            s.Stop();
            Console.Error.WriteLine("done in {0}.", s.Elapsed);
            Console.Error.WriteLine("Response: {0}", responseJson);
                        #endif

            cookies = serviceClient.Cookies;

                        #if DEBUG
            s.Reset();
            Console.Error.Write("Deserializing result...");
            s.Start();
                        #endif
            var response = new Deserializer(responseJson).Deserialize() as Dictionary <string, object>;
                        #if DEBUG
            s.Stop();
            Console.Error.WriteLine("done in {0}.", s.Elapsed);
                        #endif

            if ((long)response ["id"] != callId)
            {
                throw new ApplicationException(string.Format("Response ID and original call ID don't match. Expected {0}, received {1}.", callId, response ["id"]));
            }

            if (response ["error"] != null)
            {
                throw new ApplicationException(string.Format("Received error message from Bugzilla. Message: {0}", ((JsonObject)response ["error"]) ["message"]));
            }

            return(response);
        }