当前位置: 首页>>代码示例>>C#>>正文


C# Engine.GetValue方法代码示例

本文整理汇总了C#中Jint.Engine.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.GetValue方法的具体用法?C# Engine.GetValue怎么用?C# Engine.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Jint.Engine的用法示例。


在下文中一共展示了Engine.GetValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessMessage

		public void ProcessMessage(object source, Message message)
		{
			string jsonScript = "var msg = " + JsonConvert.SerializeXmlNode(message.GetXmlDocument(), Formatting.Indented, true);

			Engine engine = new Engine();
			engine.SetValue("message", message);
			engine.Execute(jsonScript);
			engine.Execute(Script);
			engine.Execute("var jsonMsg = JSON.stringify(msg);");
			JsValue obj = engine.GetValue("jsonMsg");

			string jsonString = obj.AsString();
			var document = JsonConvert.DeserializeXNode(jsonString, "HL7Message");
			message.SetValueFrom(document);
		}
开发者ID:NiclasOlofsson,项目名称:HIE,代码行数:15,代码来源:JavaScriptTransformer.cs

示例2: UpdateKcInfo

        private static Task UpdateKcInfo(double cacheHour = 1)
        {
            return Task.Run(() => {
                infoLock.EnterUpgradeableReadLock();
                if((DateTimeOffset.Now - lastUpdate).TotalHours < cacheHour) {
                    infoLock.ExitUpgradeableReadLock();
                    return;
                }
                infoLock.EnterWriteLock();
                try {
                    if((DateTimeOffset.Now - lastUpdate).TotalHours < cacheHour) {
                        return;
                    }

                    Engine interpreter = new Engine(cfg => cfg
                        .LocalTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"))
                        .Culture(System.Globalization.CultureInfo.GetCultureInfo("ja-JP"))
                        .MaxStatements(100)
                        .LimitRecursion(2));

                    var hwr = Forwarder.CreateRequest(KcsConstantsJs);
                    hwr.Method = "GET";
                    using(var resp = hwr.GetResponse())
                    using(var jsRdr = new StreamReader(resp.GetResponseStream()))
                        interpreter.Execute(jsRdr.ReadToEnd());

                    var urlInfo = interpreter.GetValue("ConstURLInfo");
                    kcLoginUrl = interpreter.GetValue(urlInfo, "LoginURL").AsString();
                    //kcTokenUrl = interpreter.GetValue(urlInfo, "GetTokenURL").AsString();
                    kcWorldUrl = interpreter.GetValue(urlInfo, "GetUserWorldURL").AsString();

                    var maintenanceInfo = interpreter.GetValue("MaintenanceInfo");
                    maintenanceOngoing = interpreter.GetValue(maintenanceInfo, "IsDoing").AsNumber() != 0;
                    maintenanceStart = UnixTimestamp.MillisecondTimestampToDateTimeOffset(interpreter.GetValue(maintenanceInfo, "StartDateTime").AsNumber());
                    maintenanceEnd = UnixTimestamp.MillisecondTimestampToDateTimeOffset(interpreter.GetValue(maintenanceInfo, "EndDateTime").AsNumber());

                    servers.Clear();
                    var serverInfo = interpreter.GetValue("ConstServerInfo");
                    foreach(var kv in serverInfo.AsObject().GetOwnProperties()) {
                        if(kv.Value.Value?.IsString() != true) continue;
                        servers.Add(kv.Key, kv.Value.Value.Value.AsString());
                    }

                    lastUpdate = DateTimeOffset.UtcNow;
                } finally {
                    infoLock.ExitWriteLock();
                    infoLock.ExitUpgradeableReadLock();
                }
            });
        }
开发者ID:trhyfgh,项目名称:OoiSharp,代码行数:50,代码来源:KcAuth.cs

示例3: Echo

 private static int Echo(Engine scriptScope, object echoStr)
 {
     var response = (ClientHttpResponse) scriptScope.GetValue("response").ToObject();
     if (!response.HasFinishedSendingHeaders)
         response.SendDefaultHeaders();
     response.OutputStream.WriteLine(echoStr.ToString());
     return 0;
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:8,代码来源:WebUtils.cs

示例4: session_destroy

 internal void session_destroy(Engine scriptScope)
 {
     var response = (ClientHttpResponse) scriptScope.GetValue("response").ToObject();
     var cookieString = response.RequestHttpHeaders["Cookie"];
     var hostString = response.RequestHttpHeaders["Host"];
     var currentClientcookies = GetAllCookiesFromHeader(cookieString, hostString);
     var existingSession = currentClientcookies[SessionIdVarName];
     if (existingSession != null)
     {
         var existingSessionId = existingSession.Value;
         //Cookie exists
         if (_session_hasSessionOnDisk(existingSessionId))
         {
             //Session exists
             _sessions.Remove(existingSessionId);
             _session_destroySessionOnDisk(existingSessionId);
         }
     }
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:19,代码来源:Session.cs

示例5: session_start

 internal void session_start(Engine scriptScope)
 {
     var response = (ClientHttpResponse) scriptScope.GetValue("response").ToObject();
     _session_initSession(scriptScope);
     //Check if a session exists for user:
     if (response.RequestHttpHeaders.ContainsKey("Cookie"))
     {
         var cookieString = response.RequestHttpHeaders["Cookie"];
         var hostString = response.RequestHttpHeaders["Host"];
         var currentClientcookies = GetAllCookiesFromHeader(cookieString, hostString);
         var existingSession = currentClientcookies[SessionIdVarName];
         if (existingSession != null)
         {
             var existingSessionId = existingSession.Value;
             //Cookie exists
             if (_session_hasSessionOnDisk(existingSessionId))
             {
                 //Session exists
                 response.SendHeader("HTTP/1.1 200 OK"); //Send OK like the other code path
                 if (_sessions.ContainsKey(existingSessionId))
                     scriptScope.SetValue("_SESSION", _sessions[existingSessionId]); //Assign _SESSION variable
                 else
                     _session_createSession(scriptScope);
             }
             else
             {
                 //Have to recreate
                 _session_createSession(scriptScope);
             }
         }
         else
         {
             _session_createSession(scriptScope);
         }
     }
     else
     {
         _session_createSession(scriptScope);
     }
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:40,代码来源:Session.cs

示例6: OutputLog

		private void OutputLog(Engine engine)
		{
			var arr = engine.GetValue("debug_outputs");
			if (arr == JsValue.Null || arr.IsArray() == false)
				return;

			foreach (var property in arr.AsArray().Properties)
			{
				if (property.Key == "length")
					continue;

				var jsInstance = property.Value.Value;
				if (!jsInstance.HasValue)
					continue;

				var output = jsInstance.Value.IsNumber() ? jsInstance.Value.AsNumber().ToString() : jsInstance.Value.AsString();

				Debug.Add(output);
			}

			engine.Invoke("clear_debug_outputs");
		}
开发者ID:ReginaBricker,项目名称:ravendb,代码行数:22,代码来源:ScriptedJsonPatcher.cs

示例7: OutputLog

		private void OutputLog(Engine engine)
		{
			var arr = engine.GetValue("debug_outputs");
			if (arr == JsValue.Null || arr.IsArray() == false)
				return;

			foreach (var property in arr.AsArray().Properties)
			{
				if (property.Key == "length")
					continue;

				var jsInstance = property.Value.Value;
				if (!jsInstance.HasValue)
					continue;				
				
				var output = jsInstance.Value.IsNumber() ? 
					jsInstance.Value.AsNumber().ToString(CultureInfo.InvariantCulture) : 
								(jsInstance.Value.IsBoolean() ? //if the parameter is boolean, we need to take it into account, 
																//since jsInstance.Value.AsString() will not work for boolean values
										jsInstance.Value.AsBoolean().ToString() : 
										jsInstance.Value.AsString());

				Debug.Add(output);
			}

			engine.Invoke("clear_debug_outputs");
		}
开发者ID:felipeleusin,项目名称:ravendb,代码行数:27,代码来源:ScriptedJsonPatcher.cs

示例8: ExecuteScript

        public void ExecuteScript(string fullPath, Dictionary<string, string> urlParameters,
            ClientHttpResponse response, string extension, string mimeType, HTTPMethod method, string postData,
            string documentRoot, dynamic serverHandle, ScriptExecutionParameters executionParameters)
        {
            //Prepare JSScript
            var scriptContents = File.ReadAllText(fullPath);
            var scriptDir = Path.GetDirectoryName(fullPath);
            var jsEngine = new Engine(cfg => cfg.AllowClr());

            var undefined = Undefined.Instance;

            //Inject variables
            if (method == HTTPMethod.Get)
            {
                jsEngine.SetValue("_GET", urlParameters);
                jsEngine.SetValue("_SERVER", response.RequestHttpHeaders);
                jsEngine.SetValue("_POST", undefined);
            }
            if (method == HTTPMethod.Post)
            {
                jsEngine.SetValue("_GET", undefined);
                jsEngine.SetValue("_SERVER", response.RequestHttpHeaders);
                jsEngine.SetValue("_POST", urlParameters);
                jsEngine.SetValue("POST_DATA", postData);
            }

            //Globals
            jsEngine.SetValue("DocumentRoot", documentRoot);
            jsEngine.SetValue("__dirname__", scriptDir);

            switch (extension)
            {
                case ".jscx": //Fully-controlled script
                {
                    try
                    {
                        //Manipulate Scope
                        jsEngine.SetValue("response", response);
                        jsEngine.SetValue("FireHTTPServer", serverHandle);
                        jsEngine.SetValue("_mimeTypeMappings", CommonVariables.MimeTypeMappings);
                        jsEngine.SetValue("dirSep", _dirSep);
                        DefineScriptingApi(jsEngine);
                        jsEngine.Execute(scriptContents);
                        break;
                    }
                    catch (DeadRequestException)
                    {
                        throw; //Don't catch these.
                    }
                    catch (Exception ex)
                    {
                        var level = (int) jsEngine.GetValue("__error_reporting_level").AsNumber();
                        if (level > 0)
                        {
                            if (!response.HasFinishedSendingHeaders)
                            {
                                //If headers not sent, send default headers.
                                response.SendHeader("HTTP/1.1 200 OK");
                                response.SendHeader("Content-Type: text/plain");
                                response.SendEndHeaders();
                            }
                            response.OutputStream.WriteLine("Error in script execution. Stack trace:");
                            response.OutputStream.WriteLine(ex.ToString());
                            break;
                        }
                        throw;
                    }
                }
            }
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:70,代码来源:JSScriptPlugin.cs

示例9: startGame

        private static void startGame(GameManager gameManager)
        {
            Engine engine = new Engine();
            var promise = getFile(@"./js/promise.js");
            var sevens = getFile(@"./js/sevens.js");

            var dataClass = new DataClass(gameManager);
            engine.SetValue("shuff", dataClass);
            engine.SetValue("exports", new { });
            engine.SetValue("require", new Func<string, JsValue>((file) =>
             {
                 var txt = getFile([email protected]"./js/{file}.js");
                 engine.SetValue("shuff", dataClass);
                 engine.Execute("var exports={};" + txt);
                 return engine.GetValue("exports");
             }));

            engine.Execute(promise + "; " + sevens);
            engine.Execute("Main.run()");
        }
开发者ID:Shuffle-Game,项目名称:AnyCardGame,代码行数:20,代码来源:GameServerProgram.cs

示例10: CreateEngine

        private Engine CreateEngine(Engine engine, params string[] sharedVariables)
        {
            var newEngine = CreateDefaultEngine();
            if (sharedVariables != null)
            {
                foreach(var sharedVariable in sharedVariables)
                {
                    newEngine.SetValue(sharedVariable, engine.GetValue(sharedVariable));
                }
            }

            return newEngine;
        }
开发者ID:dotnet,项目名称:docfx,代码行数:13,代码来源:TemplateJintPreprocessor.cs

示例11: _session_createSession

 private void _session_createSession(Engine scriptScope)
 {
     var response = (ClientHttpResponse) scriptScope.GetValue("response").ToObject();
     var sessionId = Guid.NewGuid().ToString("N");
     response.SendHeader("HTTP/1.1 200 OK");
     response.SendHeader("Set-Cookie: " + SessionIdVarName + "=" + sessionId + ";path=/");
     var currentSessionDict = new SessionData();
     _sessions.Add(sessionId, currentSessionDict); //Add a new session dictionary
     scriptScope.SetValue("_SESSION", currentSessionDict);
     _session_dumpSession(sessionId, currentSessionDict);
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:11,代码来源:Session.cs

示例12: GetChallengeAndSaltAsync

        private async Task<Tuple<string, string>> GetChallengeAndSaltAsync()
        {
            Uri loginUri = new Uri(this.endpoint.ToString() + LoginPath);
            using (var webClient = new WebClient())
            {
                webClient.Headers.Add("X-FBX-FREEBOX0S", "1");
                string jsonString = await webClient.DownloadStringTaskAsync(loginUri);
                dynamic jsonObject = JObject.Parse(jsonString);

                if (jsonObject.success != true)
                {
                    throw new Exception("Failed to fetch challenge. Response: " + jsonString);
                }

                string salt = jsonObject.result.password_salt;
                string challenge = string.Empty;

                // The challenge is an array of javacript code.
                // The code in each cell is executed an the results concatenated.
                try
                {
                    foreach (var challengeEntry in jsonObject.result.challenge)
                    {
                        var engine = new Engine();
                        engine.SetValue("challengeEntry", challengeEntry.ToString());
                        engine.SetValue("result", "");
                        engine.SetValue("unescape", (StringTranform)delegate(string s) { return HttpUtility.UrlDecode(s); });
                        string script = @"
                            result = eval(challengeEntry)";
                        engine.Execute(script);
                        challenge += engine.GetValue("result").AsString();
                    }

                    return new Tuple<string, string>(challenge, salt);
                }
                catch (Exception exception)
                {
                    return null;
                }
            }
        }
开发者ID:JRBANCEL,项目名称:FreeboxLogin,代码行数:41,代码来源:FreeboxOS.cs

示例13: OutputLog

        private void OutputLog(Engine engine)
        {
            var arr = engine.GetValue("debug_outputs");
            if (arr == JsValue.Null || arr.IsArray() == false)
                return;

            foreach (var property in arr.AsArray().Properties)
            {
                if (property.Key == "length")
                    continue;

                var jsInstance = property.Value.Value;
                if (!jsInstance.HasValue)
                    continue;

                var value = jsInstance.Value;
                string output = null;
                switch (value.Type)
                {
                    case Types.Boolean:
                        output = value.AsBoolean().ToString();
                        break;
                    case Types.Null:
                    case Types.Undefined:
                        output = value.ToString();
                        break;
                    case Types.Number:
                        output = value.AsNumber().ToString(CultureInfo.InvariantCulture);
                        break;
                    case Types.String:
                        output = value.AsString();
                        break;
                }

                if (output != null)
                    Debug.Add(output);
            }

            engine.Invoke("clear_debug_outputs");
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:40,代码来源:ScriptedJsonPatcher.cs

示例14: Header

 private static int Header(Engine scriptScope, string header)
 {
     ((ClientHttpResponse) scriptScope.GetValue("response").ToObject()).SendHeader(header);
     return 0;
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:5,代码来源:WebUtils.cs

示例15: EndHeaders

 private static int EndHeaders(Engine scriptScope)
 {
     ((ClientHttpResponse) scriptScope.GetValue("response").ToObject()).SendEndHeaders();
     return 0;
 }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:5,代码来源:WebUtils.cs


注:本文中的Jint.Engine.GetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。