예제 #1
0
        //[Ignore] // Bug # 475921
        public void ResolveSourceFile_Test()
        {
            // Adjust DLRPATH and place a file in this directory
            // After looking at the source code I see that I need to leave off
            // the file extension.

            string tempFile = Path.GetTempFileName();
            string newFile  = Path.ChangeExtension(tempFile, ".py");

            File.WriteAllText(newFile, "print \"Hello\"");

            //e.g., 'foo.py' string in dlrpath
            string fileNameWithExtension = Path.GetFileName(newFile);
            //e.g., 'foo'  string though this file name doesn't exists
            string fileNameWithoutExtension = fileNameWithExtension.Replace(".py", "");

            // Adjust the environment
            Environment.SetEnvironmentVariable("DLRPATH", Path.GetDirectoryName(newFile));

            ScriptRuntimeSetup setup = new ScriptRuntimeSetup(true);

            setup.HostType = typeof(ScriptHostBasicSubTest);
            // Are HostArgs ment to be arguments to a loaded script i.e.
            // passing paramters to argv?
            setup.HostArguments = new object[] { "-f foo" };
            // This throws exception
            ScriptRuntime          aRuntime = ScriptRuntime.Create(setup);
            ScriptHostBasicSubTest host     = (ScriptHostBasicSubTest)aRuntime.Host;

            // Search for 'foo' type name that is a success
            host.ResolveSourceFile(fileNameWithoutExtension);

            // Search for 'foo.py' type file fails
            host.ResolveSourceFile(fileNameWithExtension);
        }
예제 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public void Enable()
        {
            try
            {
                scriptEngineName_ = "";
                scriptFileName_   = "";

                StreamReader iniReader = new StreamReader("Config\\WwwProxyScripting.ini");
                while (!iniReader.EndOfStream)
                {
                    string l = iniReader.ReadLine().Trim().ToLower();
                    if (l.StartsWith("#"))
                    {
                        continue;
                    }

                    string[] nameValue = l.Split('=');
                    if (nameValue.Length != 2)
                    {
                        continue;
                    }

                    string name  = nameValue[0];
                    string value = nameValue[1];

                    if (name == "debug")
                    {
                        if (value == "true")
                        {
                            debugLog_.Start();
                        }
                    }
                    else if (name == "engine")
                    {
                        scriptEngineName_ = value;
                    }
                    else if (name == "file")
                    {
                        scriptFileName_ = value;
                    }
                }
                iniReader.Close();

                if ((scriptEngineName_ == "") || (scriptFileName_ == ""))
                {
                    return;
                }

                scriptEngine_ = ScriptRuntime.Create().GetEngine(scriptEngineName_);
                scriptScope_  = scriptEngine_.CreateScope();

                scriptSource_ = scriptEngine_.CreateScriptSourceFromFile(scriptFileName_);
                scriptSource_.Execute(scriptScope_);

                object wwwProxyFilterClass = scriptScope_.GetVariable <object>("WwwProxyFilter");
                wwwProxyFilterInstance_ = scriptEngine_.Operations.Call(wwwProxyFilterClass);

                WwwProxy.WwwProxy.Instance.PreRequest   += new WwwProxyRequestEvent(WwwProxy_PreRequest);
                WwwProxy.WwwProxy.Instance.PostRequest  += new WwwProxyRequestEvent(WwwProxy_PostRequest);
                WwwProxy.WwwProxy.Instance.PreResponse  += new WwwProxyResponseEvent(WwwProxy_PreResponse);
                WwwProxy.WwwProxy.Instance.PostResponse += new WwwProxyResponseEvent(WwwProxy_PostResponse);
            }
            catch (Exception e)
            {
                scriptEngineName_ = "";
                scriptFileName_   = "";

                debugLog_.Write("WwwProxyScripting.Enable()", e.ToString());
            }
        }