本文整理汇总了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);
}
示例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();
}
});
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
示例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");
}
示例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");
}
示例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;
}
}
}
}
示例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()");
}
示例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;
}
示例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);
}
示例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;
}
}
}
示例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");
}
示例14: Header
private static int Header(Engine scriptScope, string header)
{
((ClientHttpResponse) scriptScope.GetValue("response").ToObject()).SendHeader(header);
return 0;
}
示例15: EndHeaders
private static int EndHeaders(Engine scriptScope)
{
((ClientHttpResponse) scriptScope.GetValue("response").ToObject()).SendEndHeaders();
return 0;
}