Esempio n. 1
0
        /// <summary>
        /// This function attempts to load a script from the unloaded script cache
        /// </summary>
        /// <param name="scriptAssetId">The asset ID for the script to be loaded</param>
        /// <param name="lrq">The request that is causing the load</param>
        /// <returns></returns>
        private bool TryStartScriptFromUnloadedCache(UUID scriptAssetId, LoadUnloadRequest lrq)
        {
            CompiledScript compiledScript;

            if (_unloadedScriptCache.TryGetValue(scriptAssetId, out compiledScript))
            {
                _log.InfoFormat("[Phlox]: Starting recovered script {0} in item {1} group {2} part {3}", scriptAssetId, lrq.ItemId, lrq.Prim.ParentGroup.LocalId, lrq.Prim.LocalId);

                //remove the script from the unloaded cache for good measure since it is now loaded again
                _unloadedScriptCache.Remove(scriptAssetId);

                //check the part in the load request for this script.
                //even though we're not using the passed in script asset,
                //we should still do cleanup
                ClearSerializedScriptData(lrq, scriptAssetId);

                BeginScriptRun(lrq, compiledScript);
                _loadedScripts[scriptAssetId] = new LoadedScript {
                    Script = compiledScript, RefCount = 1
                };
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        public JavaScriptLogic()
        {
            routeMap = new Dictionary <string, object>();
            NiL.JS.Core.Context.GlobalContext.InitField("mapRoute").Assign(new ExternalFunction(mapRoute));
            var initpath = WebConfigurationManager.AppSettings["jsLogicInit"];

            if (!string.IsNullOrWhiteSpace(initpath))
            {
                var initScript = new LoadedScript(initpath);
                initScript.Script.Invoke();
            }
        }
Esempio n. 3
0
        public override void Process(HttpRequest request, HttpResponse response, HttpApplication application)
        {
            object processor = null;

            if (routeMap.TryGetValue(request.Path, out processor))
            {
                if (processor is string)
                {
                    processor = new LoadedScript(processor.ToString());
                    routeMap[request.Path] = processor;
                }
                if (processor is NiL.JS.Core.BaseTypes.Function)
                {
                    (processor as NiL.JS.Core.BaseTypes.Function).Invoke(new NiL.JS.Core.BaseTypes.Array(new object[] { request, response, application }));
                    return;
                }
                else if (processor is LoadedScript)
                {
                    var sc = (processor as LoadedScript).Script;
                    sc.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                    sc.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                    sc.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                    sc.Invoke();
                    return;
                }
            }

            if (defaultScript == null)
            {
                try
                {
                    defaultScript = new LoadedScript(defaultPath);
                }
                catch
                {
                    response.BinaryWrite(System.Text.Encoding.Default.GetBytes(new Http.ErrorPage(Http.ResponseCode.SERVICE_UNAVAILABLE, "Service unavailable.").ToString()));
                    response.StatusCode = (int)Http.ResponseCode.SERVICE_UNAVAILABLE;
                }
            }
            lock (defaultScript)
            {
                var script = defaultScript.Script;
                script.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                script.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                script.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                script.Invoke();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Try to load a script from disk and start it up
        /// </summary>
        /// <param name="scriptAssetId"></param>
        /// <param name="lrq"></param>
        /// <returns></returns>
        private bool TryStartCachedScript(UUID scriptAssetId, LoadUnloadRequest lrq)
        {
            //check in the cache directory for compiled scripts
            if (ScriptIsCached(scriptAssetId))
            {
                CompiledScript script = LoadScriptFromDisk(scriptAssetId);

                _log.InfoFormat("[Phlox]: Starting cached script {0} in item {1} owner {2} part {3}", scriptAssetId, lrq.ItemId, lrq.Prim.ParentGroup.OwnerID, lrq.Prim.LocalId);

                BeginScriptRun(lrq, script);
                _loadedScripts[scriptAssetId] = new LoadedScript {
                    Script = script, RefCount = 1
                };
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        private bool TryStartScriptFromSerializedData(UUID scriptAssetId, LoadUnloadRequest lrq)
        {
            if (lrq.Prim.SerializedScriptByteCode == null)
            {
                return(false);
            }

            byte[] serializedCompiledScript;
            if (lrq.Prim.SerializedScriptByteCode.TryGetValue(scriptAssetId, out serializedCompiledScript))
            {
                //deserialize and load
                using (MemoryStream ms = new MemoryStream(serializedCompiledScript))
                {
                    Serialization.SerializedScript script = ProtoBuf.Serializer.Deserialize <Serialization.SerializedScript>(ms);
                    if (script == null)
                    {
                        _log.ErrorFormat("[Phlox]: LOADER: Script data contained in prim failed to deserialize");
                        ClearSerializedScriptData(lrq, scriptAssetId);
                        return(false);
                    }
                    else
                    {
                        CompiledScript compiledScript = script.ToCompiledScript();

                        _log.InfoFormat("[Phlox]: Starting contained script {0} in item {1} group {2} part {3}", scriptAssetId, lrq.ItemId, lrq.Prim.ParentGroup.LocalId, lrq.Prim.LocalId);

                        BeginScriptRun(lrq, compiledScript);
                        _loadedScripts[scriptAssetId] = new LoadedScript {
                            Script = compiledScript, RefCount = 1
                        };
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 6
0
        public override void Process(HttpRequest request, HttpResponse response, HttpApplication application)
        {
            object processor = null;
            if (routeMap.TryGetValue(request.Path, out processor))
            {
                if (processor is string)
                {
                    processor = new LoadedScript(processor.ToString());
                    routeMap[request.Path] = processor;
                }
                if (processor is NiL.JS.Core.BaseTypes.Function)
                {
                    (processor as NiL.JS.Core.BaseTypes.Function).Invoke(new NiL.JS.Core.BaseTypes.Array(new object[] { request, response, application }));
                    return;
                }
                else if (processor is LoadedScript)
                {
                    var sc = (processor as LoadedScript).Script;
                    sc.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                    sc.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                    sc.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                    sc.Invoke();
                    return;
                }
            }

            if (defaultScript == null)
            {
                try
                {
                    defaultScript = new LoadedScript(defaultPath);
                }
                catch
                {
                    response.BinaryWrite(System.Text.Encoding.Default.GetBytes(new Http.ErrorPage(Http.ResponseCode.SERVICE_UNAVAILABLE, "Service unavailable.").ToString()));
                    response.StatusCode = (int)Http.ResponseCode.SERVICE_UNAVAILABLE;
                }
            }
            lock (defaultScript)
            {
                var script = defaultScript.Script;
                script.Context.InitField("application").Assign(TypeProxy.Proxy(application));
                script.Context.InitField("request").Assign(TypeProxy.Proxy(request));
                script.Context.InitField("response").Assign(TypeProxy.Proxy(response));
                script.Invoke();
            }
        }
Esempio n. 7
0
 public JavaScriptLogic()
 {
     routeMap = new Dictionary<string, object>();
     NiL.JS.Core.Context.GlobalContext.InitField("mapRoute").Assign(new ExternalFunction(mapRoute));
     var initpath = WebConfigurationManager.AppSettings["jsLogicInit"];
     if (!string.IsNullOrWhiteSpace(initpath))
     {
         var initScript = new LoadedScript(initpath);
         initScript.Script.Invoke();
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Try to load a script from disk and start it up
        /// </summary>
        /// <param name="scriptAssetId"></param>
        /// <param name="lrq"></param>
        /// <returns></returns>
        private bool TryStartCachedScript(UUID scriptAssetId, LoadUnloadRequest lrq)
        {
            //check in the cache directory for compiled scripts
            if (ScriptIsCached(scriptAssetId))
            {
                CompiledScript script = LoadScriptFromDisk(scriptAssetId);

                _log.InfoFormat("[Phlox]: Starting cached script {0} in item {1} owner {2} part {3}", scriptAssetId, lrq.ItemId, lrq.Prim.ParentGroup.OwnerID, lrq.Prim.LocalId);

                BeginScriptRun(lrq, script);
                _loadedScripts[scriptAssetId] = new LoadedScript { Script = script, RefCount = 1 };
                return true;
            }

            return false;
        }
Esempio n. 9
0
        private bool TryStartScriptFromSerializedData(UUID scriptAssetId, LoadUnloadRequest lrq)
        {
            if (lrq.Prim.SerializedScriptByteCode == null) return false;

            byte[] serializedCompiledScript;
            if (lrq.Prim.SerializedScriptByteCode.TryGetValue(scriptAssetId, out serializedCompiledScript))
            {
                //deserialize and load
                using (MemoryStream ms = new MemoryStream(serializedCompiledScript))
                {
                    Serialization.SerializedScript script = ProtoBuf.Serializer.Deserialize<Serialization.SerializedScript>(ms);
                    if (script == null)
                    {
                        _log.ErrorFormat("[Phlox]: LOADER: Script data contained in prim failed to deserialize");
                        ClearSerializedScriptData(lrq, scriptAssetId);
                        return false;
                    }
                    else
                    {
                        CompiledScript compiledScript = script.ToCompiledScript();

                        _log.InfoFormat("[Phlox]: Starting contained script {0} in item {1} group {2} part {3}", scriptAssetId, lrq.ItemId, lrq.Prim.ParentGroup.LocalId, lrq.Prim.LocalId);

                        BeginScriptRun(lrq, compiledScript);
                        _loadedScripts[scriptAssetId] = new LoadedScript { Script = compiledScript, RefCount = 1 };
                        return true;
                    }
                }
            }

            return false;
        }
Esempio n. 10
0
        /// <summary>
        /// This function attempts to load a script from the unloaded script cache
        /// </summary>
        /// <param name="scriptAssetId">The asset ID for the script to be loaded</param>
        /// <param name="lrq">The request that is causing the load</param>
        /// <returns></returns>
        private bool TryStartScriptFromUnloadedCache(UUID scriptAssetId, LoadUnloadRequest lrq)
        {
            CompiledScript compiledScript;

            if (_unloadedScriptCache.TryGetValue(scriptAssetId, out compiledScript))
            {
                _log.InfoFormat("[Phlox]: Starting recovered script {0} in item {1} group {2} part {3}", scriptAssetId, lrq.ItemId, lrq.Prim.ParentGroup.LocalId, lrq.Prim.LocalId);

                //remove the script from the unloaded cache for good measure since it is now loaded again
                _unloadedScriptCache.Remove(scriptAssetId);

                //check the part in the load request for this script.
                //even though we're not using the passed in script asset, 
                //we should still do cleanup
                ClearSerializedScriptData(lrq, scriptAssetId);

                BeginScriptRun(lrq, compiledScript);
                _loadedScripts[scriptAssetId] = new LoadedScript { Script = compiledScript, RefCount = 1 };
                return true;
            }

            return false;
        }