Beispiel #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static JSONRpcCall ParseRPC(TextReader reader)
        {
            JSONRpcCall call = new JSONRpcCall();
            object obj = ParseJSON(reader);
            Hashtable jsonRpc = (Hashtable)obj;

            call.Method = (string)jsonRpc["method"];
            call.Id = (string)jsonRpc["id"];
            object objParams = jsonRpc["params"];
            if (objParams is Hashtable) // reflects new structure of request for TinyMCE 4.x
            {
                Hashtable hParams = (Hashtable)objParams;
                call.Args = (ArrayList)hParams["words"];
                call.Lang = hParams["lang"].ToString();
            }
            else // TinyMCE 3.x
            {
                call.Args = (ArrayList)jsonRpc["params"];
            }

            return call;
        }
Beispiel #2
0
        // this article describes the TinyMCE 4 changes vs TinyMCE 3
        //http://achorniy.wordpress.com/2013/05/27/tinymce-4-spellchecker-integration/

        public void ProcessRequest(HttpContext context)
        {
            HttpRequest        request      = context.Request;
            HttpResponse       response     = context.Response;
            JSONRpcCall        call         = JSON.ParseRPC(new System.IO.StreamReader(request.InputStream));
            object             result       = null;
            GoogleSpellChecker spellchecker = new GoogleSpellChecker();

            switch (call.Method)
            {
            case "checkWords":
                result = spellchecker.CheckWords((string)call.Args[0], (string[])((ArrayList)call.Args[1]).ToArray(typeof(string)));
                break;

            case "getSuggestions":
                result = spellchecker.GetSuggestions((string)call.Args[0], (string)call.Args[1]);
                break;

            //TinyMCE 4 version is like combination
            // it passes words and expects suggestions in the response
            case "spellcheck":
                string[] words = (string[])call.Args.ToArray(typeof(string));
                result = spellchecker.SpellCheck(call.Id, call.Lang, words);

                response.ContentType = "application/json";
                response.Write(result);

                return;
            }

            // Serialize RPC output
            JSON.SerializeRPC(
                call.Id,
                null,
                result,
                response.OutputStream
                );
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static JSONRpcCall ParseRPC(TextReader reader)
        {
            JSONRpcCall call    = new JSONRpcCall();
            object      obj     = ParseJSON(reader);
            Hashtable   jsonRpc = (Hashtable)obj;

            call.Method = (string)jsonRpc["method"];
            call.Id     = (string)jsonRpc["id"];
            object objParams = jsonRpc["params"];

            if (objParams is Hashtable) // reflects new structure of request for TinyMCE 4.x
            {
                Hashtable hParams = (Hashtable)objParams;
                call.Args = (ArrayList)hParams["words"];
                call.Lang = hParams["lang"].ToString();
            }
            else // TinyMCE 3.x
            {
                call.Args = (ArrayList)jsonRpc["params"];
            }


            return(call);
        }