Beispiel #1
2
 public static void JsReflection(string tsFileName, string jsonMapFn) {
   using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) {
     engine.Execute("typescript.js", File.ReadAllText(@"d:\LMCom\rew\Web4\JsLib\Scripts\typescript.js"));
     engine.Execute("underscore.js", File.ReadAllText(@"d:\LMCom\rew\Web4\JsLib\Scripts\underscore.js"));
     engine.Execute("GenerateReflection.js", File.ReadAllText(@"d:\LMCom\rew\Web4\Author\GenerateReflection.js"));
     var par = new reflectionObj { inpTSCode = File.ReadAllText(tsFileName) };
     engine.AddHostObject("inpTSCode", par);
     File.WriteAllText(jsonMapFn + ".json", (string)engine.Evaluate("author.parseReflection(inpTSCode.inpTSCode, false)"));
     File.WriteAllText(jsonMapFn + ".debug.json", (string)engine.Evaluate("author.parseReflection(inpTSCode.inpTSCode, true)"));
   }
 }
Beispiel #2
2
 public static string JSON2RJSON(string inpJson) {
   using (var engine = new Microsoft.ClearScript.V8.V8ScriptEngine()) {
     var script = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\RJSON.js";
     if (!File.Exists(script)) script = Machines.rootPath + @"JsLib\JS\External\RJSON.js";
     engine.Execute(script, File.ReadAllText(script));
     var par = new rjsonObj { inpJson = inpJson };
     engine.AddHostObject("inpJson", par);
     return (string)engine.Evaluate("JSON.stringify(RJSON.pack(JSON.parse(inpJson.inpJson)))");
   }
 }
Beispiel #3
0
        public bool ClearScript(Parameter parameter)
        {
            using (Microsoft.ClearScript.V8.V8ScriptEngine engine = new Microsoft.ClearScript.V8.V8ScriptEngine())
            {
                List <int> results = new List <int>(parameter.Statements.Length);
                foreach (string statement in parameter.Statements)
                {
                    int result = Convert.ToInt32(engine.Evaluate(statement));

                    results.Add(result);
                }

                return(Assert(results, parameter.Sum));
            }
        }
Beispiel #4
0
        public bool ClearScript(Parameter parameter)
        {
            using (Microsoft.ClearScript.V8.V8ScriptEngine engine = new Microsoft.ClearScript.V8.V8ScriptEngine())
            {
                List <int> results = new List <int>(parameter.Numbers.Length);
                engine.Script["n"] = parameter.Numbers;
                foreach (int number in parameter.Numbers)
                {
                    int result = Convert.ToInt32(engine.Evaluate(parameter.Statements[number]));

                    results.Add(result);
                }

                return(Assert(results, parameter.Sum));
            }
        }
Beispiel #5
0
        internal static void MakeRequest(DynamicObject config, DynamicObject callback, Microsoft.ClearScript.V8.V8ScriptEngine engine)
        {
            var options = new NodeHttpRequestOptions(config);
            var uriObj  = new Uri((config.GetMember <object>("uri") ?? config.GetMember <object>("url")).ToString());

            options.url      = (config.GetMember <object>("uri") ?? config.GetMember <object>("url"));
            options.host     = uriObj.Host;
            options.hostname = uriObj.Host;
            options.scheme   = uriObj.Scheme;
            options.path     = uriObj.PathAndQuery;
            options.port     = uriObj.Port;
            options.method   = config.GetMember("method", "GET");
            options.headers  = config.GetMember <DynamicObject>("headers");
            bool isJson = config.GetMember("json", false);

            var req = new NodeHttpRequest(new HttpClient(), new HttpRequestMessage(), options);
            Action <NodeHttpResponse> wrapperCallback = resp =>
            {
                if (callback == null)
                {
                    return;
                }
                //    string body = null;
                object body    = null;
                var    apiResp = resp.GetHttpResponseMessage();
                if (apiResp.Content != null && apiResp.Content.Headers.ContentLength > 0)
                {
                    if (isJson)
                    {
                        string xxx    = apiResp.Content.ReadAsStringAsync().Result;
                        var    parser = (dynamic)engine.Evaluate("JSON.parse");
                        body = parser(xxx);
                    }
                    else
                    {
                        body = apiResp.Content.ReadAsStringAsync().Result;
                    }
                }

                callback.AsDynamic().call(null, null, resp, body);
            };

            req.@on("response", wrapperCallback);

            req.end();
        }
Beispiel #6
0
        public bool ClearScriptCompiled(Parameter parameter)
        {
            using (Microsoft.ClearScript.V8.V8ScriptEngine engine = new Microsoft.ClearScript.V8.V8ScriptEngine())
            {
                Microsoft.ClearScript.V8.V8Script script = engine.Compile(EXPRESSION);

                List <int> results = new List <int>(parameter.Numbers.Length);
                foreach (int number in parameter.Numbers)
                {
                    engine.Script["n"] = number;

                    int result = Convert.ToInt32(engine.Evaluate(script));

                    results.Add(result);
                }

                return(Assert(results, parameter.Sum));
            }
        }
Beispiel #7
0
        protected override object InnerEvaluate(string expression, string documentName)
        {
            object result;

            try
            {
                result = _jsEngine.Evaluate(documentName, false, expression);
            }
            catch (OriginalException e)
            {
                throw WrapScriptEngineException(e);
            }
            catch (OriginalInterruptedException e)
            {
                throw WrapScriptInterruptedException(e);
            }

            result = MapToHostType(result);

            return(result);
        }
Beispiel #8
0
        private object ConvertHours(string inputString)
        {
            var engine = new Microsoft.ClearScript.V8.V8ScriptEngine();

            return(engine.Evaluate(GetConvertScript() + $"convertHours('{inputString}')"));
        }