Esempio n. 1
1
        static void OriginalMain()
        {
            var done = false;
            var sw = new Stopwatch();

            sw.Start();
            for (var i = 0; i < N; i++)
            {
                var jintEngine = new Jint.Engine();
                jintEngine.Execute(currentScript);
                done = jintEngine.GetValue("done").AsBoolean();
            }
            sw.Stop();
            Console.WriteLine("jint: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var ironjsEngine = new IronJS.Hosting.CSharp.Context();
                ironjsEngine.Execute(currentScript);
                done = ironjsEngine.GetGlobalAs<bool>("done");
            }
            sw.Stop();
            Console.WriteLine("ironjs: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                using (var jsNetEngine = new Noesis.Javascript.JavascriptContext())
                {
                    jsNetEngine.Run(currentScript);
                    done = (bool)jsNetEngine.GetParameter("done");
                }
            }
            sw.Stop();
            Console.WriteLine("js.net: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var jurassicEngine = new Jurassic.ScriptEngine();
                jurassicEngine.Execute(currentScript);
                done = jurassicEngine.GetGlobalValue<bool>("done");
            }
            sw.Stop();
            Console.WriteLine("jurassic: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                using (var clearscriptV8 = new Microsoft.ClearScript.V8.V8ScriptEngine())
                {
                    clearscriptV8.Execute(currentScript);
                    done = clearscriptV8.Script.done;
                }
            }
            sw.Stop();
            Console.WriteLine("clearscriptV8: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            using (var clearscriptV8 = new Microsoft.ClearScript.V8.V8Runtime())
            {
                var compiled = clearscriptV8.Compile(currentScript);
                for (var i = 0; i < N; i++)
                {
                    using (var engine = clearscriptV8.CreateScriptEngine())
                    {
                        engine.Evaluate(compiled);
                        done = engine.Script.done;
                    }
                }
            }
            sw.Stop();
            Console.WriteLine("clearscriptV8 compiled: " + sw.ElapsedMilliseconds / N + " - " + done);

            done = false;
            sw.Restart();
            for (var i = 0; i < N; i++)
            {
                var nilcontext = new NiL.JS.Core.Context();
                nilcontext.Eval(currentScript);
                done = (bool)nilcontext.GetVariable("done");
            }
            sw.Stop();
            Console.WriteLine("niljs: " + sw.ElapsedMilliseconds / N + " - " + done);

            Console.Read();
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("By", new ByConstructor(engine));
            engine.SetGlobalValue("Cookie", new CookieConstructor(engine));


            engine.SetGlobalValue("PhantomJSDriver", new PhantomJSDriverConstructor(engine));

            return(Null.Value);
        }
Esempio n. 3
0
        public void PreevaluateStaticMethod()
        {
            var expression = Expression(model => GetText());
            var script     = Translate(expression);

            var engine = new Jurassic.ScriptEngine();
            var result = engine.Evaluate($"({script})()");

            Assert.AreEqual("Text", result);
        }
Esempio n. 4
0
        public void Reset()
        {
            string name      = this.Name;
            string script    = this.Script;
            var    oldengine = _jsengine;

            _jsengine   = new Jurassic.ScriptEngine();
            this.Name   = name;
            this.Script = script;
        }
Esempio n. 5
0
 protected static void InitializeJurassic()
 {
     if (jurassicScriptEngine == null)
     {
         jurassicScriptEngine = new Jurassic.ScriptEngine();
         testingContext       = new TestingContext(jurassicScriptEngine);
         jurassicScriptEngine.SetGlobalValue("testingContext", testingContext);
     }
     testingContext.Clear();
 }
Esempio n. 6
0
        private static void InitializeJurassic()
        {
            if (jurassicScriptEngine == null)
            {
                jurassicScriptEngine = new Jurassic.ScriptEngine();
#if DEBUG
                jurassicScriptEngine.EnableDebugging = true;
#endif
            }
        }
 public override void Dispose()
 {
     if (_disposedFlag.Set())
     {
         lock (_executionSynchronizer)
         {
             _jsEngine = null;
         }
     }
 }
Esempio n. 8
0
 public void push()
 {
     var engine = new Jurassic.ScriptEngine();
     var array = engine.Array.New();
     TestUtils.Benchmark(() =>
     {
         for (int i = 0; i < 1024 * 100; i++)
             Jurassic.Library.ArrayInstance.Push(array, i);
     });
 }
Esempio n. 9
0
        public static string GetHash(string no, string ptwebqq)
        {
            var scriptEngine = new Jurassic.ScriptEngine();

            scriptEngine.EnableDebugging = true;
            scriptEngine.SetGlobalValue("window", new WindowObject(scriptEngine));
            scriptEngine.ExecuteFile(System.AppDomain.CurrentDomain.BaseDirectory + "hash.js");
            var ret = scriptEngine.CallGlobalFunction <string>("friendsHash", no, ptwebqq, 0);

            return(ret);
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            var eng = new Jurassic.ScriptEngine();

            eng.Evaluate("function text(){return JSON.stringify( {'a':10,'b':20});}");
            var rs = eng.CallGlobalFunction <string>("text");

            //var model = Util.SerializerJsonOrEntity.GetObject<model>(rs);
            //Console.WriteLine(model.a);
            Console.Read();
        }
Esempio n. 11
0
        public override object InstallBundle(Jurassic.ScriptEngine engine)
        {
            var adInstance = (ActiveDirectoryInstance)base.InstallBundle(engine);

            //Set the current login name based on the current user associated with the context.
            adInstance.CurrentUserLoginNameFactory = () => SPBaristaContext.Current.Web.CurrentUser == null
          ? String.Empty
          : SPBaristaContext.Current.Web.CurrentUser.LoginName;

            return(adInstance);
        }
Esempio n. 12
0
        private static string GetTranslate_GoogleTK(string str)
        {
            var scriptEngine = new Jurassic.ScriptEngine();

            scriptEngine.EnableDebugging = true;
            scriptEngine.SetGlobalValue("window", new WindowObject(scriptEngine));
            scriptEngine.ExecuteFile(System.AppDomain.CurrentDomain.BaseDirectory + "GoogleTK.js");
            var TK = scriptEngine.CallGlobalFunction <string>("VL", str);

            return(TK);
        }
 public HandlebarsCompiler()
 {
     Engine = new Jurassic.ScriptEngine();
     var ass = typeof(HandlebarsCompiler).Assembly;
     Engine.Execute("var exports = {};");
     Engine.Execute("var module = {};");
     Engine.Execute(GetEmbeddedResource("HandlebarsHelper.Scripts.handlebars-v2.0.0.js", ass));
     Engine.Execute(GetEmbeddedResource("HandlebarsHelper.Scripts.ember-template-compiler.js", ass));
     Engine.Execute("var precompile = exports.precompile;");
     Compressor = new JavaScriptCompressor();
 }
Esempio n. 14
0
        public void Execute(string script, params object[] parameters)
        {
            var engine = new Jurassic.ScriptEngine();
            int i      = 0;

            foreach (var p in parameters)
            {
                engine.SetGlobalValue("parameter" + i, p);
                i++;
            }
            engine.Execute(script);
        }
Esempio n. 15
0
        public T Evaluate <T>(string script, params object[] parameters)
        {
            var engine = new Jurassic.ScriptEngine();
            int i      = 0;

            foreach (var p in parameters)
            {
                engine.SetGlobalValue("parameter" + i, p);
                i++;
            }
            return(engine.Evaluate <T>(script));
        }
Esempio n. 16
0
 private T Evaluate <T>(Jurassic.ScriptEngine engine, string script)
 {
     try
     {
         return(engine.Evaluate <T>(script));
     }
     catch (Exception e)
     {
         this._log.Error("脚本解析异常", e);
         throw new Exception("脚本解析异常:" + e.Message);
     }
 }
Esempio n. 17
0
        public HandlebarsCompiler()
        {
            Engine = new Jurassic.ScriptEngine();
            var ass = typeof(HandlebarsCompiler).Assembly;

            Engine.Execute("var exports = {};");
            Engine.Execute("var module = {};");
            Engine.Execute(GetEmbeddedResource("HandlebarsHelper.Scripts.handlebars-v2.0.0.js", ass));
            Engine.Execute(GetEmbeddedResource("HandlebarsHelper.Scripts.ember-template-compiler.js", ass));
            Engine.Execute("var precompile = exports.precompile;");
            Compressor = new JavaScriptCompressor();
        }
Esempio n. 18
0
        public void push()
        {
            var engine = new Jurassic.ScriptEngine();
            var array  = engine.Array.New();

            TestUtils.Benchmark(() =>
            {
                for (int i = 0; i < 1024 * 100; i++)
                {
                    Jurassic.Library.ArrayInstance.Push(array, i);
                }
            });
        }
Esempio n. 19
0
 public void unshift()
 {
     TestUtils.Benchmark(() =>
     {
         // 2,080,000 inner loops/s
         var engine = new Jurassic.ScriptEngine();
         var array  = engine.Array.New();
         for (int i = 0; i < 1000; i++)
         {
             Jurassic.Library.ArrayInstance.Unshift(array, i);
         }
     });
 }
Esempio n. 20
0
 public void sum()
 {
     var engine = new Jurassic.ScriptEngine();
     var array = engine.Array.New();
     for (int i = 0; i < 1024 * 100; i++)
         Jurassic.Library.ArrayInstance.Push(array, i);
     TestUtils.Benchmark(() =>
     {
         int sum = 0;
         for (uint i = 0; i < 1024 * 100; i++)
             sum += (int)array[i];
     });
 }
Esempio n. 21
0
        private void Init()
        {
            if (BaseLocation == null)
            {
                BaseLocation = Extensibility.Instance.GetBaseLocation(this) ?? new Uri(System.Environment.CurrentDirectory);
            }

            _ctx = new Jurassic.ScriptEngine();
            _ctx.SetGlobalFunction("getContents", (Func <string, string>)GetContents);
            _ctx.SetGlobalFunction("getFullFilename", (Func <string, string>)GetFullFilename);
            Run(Zippy.Chirp.Properties.Resources.env);
            OnInit();
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("SearchArguments", new SearchArgumentsConstructor(engine));
            engine.SetGlobalValue("JsonDocument", new JsonDocumentConstructor(engine));

            var searchServiceInstance = new SearchServiceInstance(engine.Object.InstancePrototype,
                                                                  new SPBaristaSearchServiceProxy())
            {
                GetIndexDefinitionFromName = indexName => BaristaHelper.GetBaristaIndexDefinitionFromIndexName(indexName)
            };

            return(searchServiceInstance);
        }
Esempio n. 23
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            //Add the Various types required.
            engine.SetGlobalValue("SPExportObject", new SPExportObjectConstructor(engine));
            engine.SetGlobalValue("SPExportObjectCollection", new SPExportObjectCollectionConstructor(engine));

            engine.SetGlobalValue("SPExportSettings", new SPExportSettingsConstructor(engine));
            engine.SetGlobalValue("SPExport", new SPExportConstructor(engine));

            engine.SetGlobalValue("SPImportSettings", new SPImportSettingsConstructor(engine));
            engine.SetGlobalValue("SPImport", new SPImportConstructor(engine));

            return(new SPMigrationInstance(engine.Object.InstancePrototype));
        }
Esempio n. 24
0
        public void EngineTest()
        {
            var engine = new Jurassic.ScriptEngine();
            engine.SetGlobalValue("i", 1);
            engine.SetGlobalValue("i", 2);
            Assert.AreEqual(2, engine.GetGlobalValue("i"));

            engine.SetGlobalFunction("test", new Func<object, object, object, object, string>(Test));

            Trace.WriteLine(engine.Evaluate<string>("test(1)"));
            Trace.WriteLine(engine.CallGlobalFunction<string>("test", new object[] { 1 }));

            Trace.WriteLine(engine.Array.Call(1, 2, 3).ElementValues.ToList()[2]);
        }
Esempio n. 25
0
        public Jurassic.ScriptEngine Debug()
        {
            Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();

            foreach (string item in Directory.GetFiles(TemplateFolder, "*.js"))
            {
                engine.Evaluate(new Jurassic.FileScriptSource(item));
            }

            DatabaseJson = Newtonsoft.Json.JsonConvert.SerializeObject(Database, Newtonsoft.Json.Formatting.Indented, new Newtonsoft.Json.Converters.StringEnumConverter());
            SettingJson  = Newtonsoft.Json.JsonConvert.SerializeObject(Settings, Newtonsoft.Json.Formatting.Indented);

            return(engine);
        }
Esempio n. 26
0
        public virtual object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("iCalendar", new iCalendarConstructor(engine));
            engine.SetGlobalValue("iCalDateTime", new iCalDateTimeConstructor(engine));
            engine.SetGlobalValue("iEvent", new EventConstructor(engine));
            engine.SetGlobalValue("iTodo", new TodoConstructor(engine));
            engine.SetGlobalValue("iCalendarProperty", new CalendarPropertyConstructor(engine));
            engine.SetGlobalValue("iOrganizer", new OrganizerConstructor(engine));
            engine.SetGlobalValue("iTimeZone", new TimeZoneConstructor(engine));

            var iCalInstance = new iCalInstance(engine);

            return(iCalInstance);
        }
        private void Init()
        {
            try
            {
                var YandexEncoderResource = File.ReadAllText(_ResourceFilePath);
                var YandexAuthResource    = File.ReadAllText(_AccountsFilePath);

                bool IsHashCorrect = false;

                using (SHA256 sha256Hash = SHA256.Create())
                {
                    IsHashCorrect = Helper.VerifyHash(sha256Hash, YandexEncoderResource, _EncoderHash);
                    IsHashCorrect = IsHashCorrect && Helper.VerifyHash(sha256Hash, YandexAuthResource, _AuthHash);
                }

                if (!IsHashCorrect)
                {
                    return;
                }

                string YandexEncoderResourceDecrypted = StringCipher.Decrypt(YandexEncoderResource, _Password);
                string YandexEncoderJS = Helper.Base64Decode(YandexEncoderResourceDecrypted);

                _YandexEncoderEngine = new Jurassic.ScriptEngine();
                _YandexEncoderEngine.Evaluate(YandexEncoderJS);


                string yandexAuthResourceDecrypted = StringCipher.Decrypt(YandexAuthResource, _Password);
                string yandexAuthJson = Helper.Base64Decode(yandexAuthResourceDecrypted);

                var yandexAccs = JsonConvert.DeserializeObject <List <YandexAuthContainer> >(yandexAuthJson);

                List <YandexSession> sessions = new List <YandexSession>();
                foreach (var acc in yandexAccs)
                {
                    sessions.Add(new YandexSession(acc, _Logger));
                }

                _YandexSessions = sessions.Shuffle();

                _IsAvaliable = true;
            }
            catch (Exception e)
            {
                _Logger?.WriteLog(e.ToString());
                _IsAvaliable = false;
                return;
            }
        }
Esempio n. 28
0
        public void EngineTest()
        {
            var engine = new Jurassic.ScriptEngine();

            engine.SetGlobalValue("i", 1);
            engine.SetGlobalValue("i", 2);
            Assert.AreEqual(2, engine.GetGlobalValue("i"));

            engine.SetGlobalFunction("test", new Func <object, object, object, object, string>(Test));

            Trace.WriteLine(engine.Evaluate <string>("test(1)"));
            Trace.WriteLine(engine.CallGlobalFunction <string>("test", new object[] { 1 }));

            Trace.WriteLine(engine.Array.Call(1, 2, 3).ElementValues.ToList()[2]);
        }
Esempio n. 29
0
        public bool Jurassic(Parameter parameter)
        {
            Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();

            List <int> results = new List <int>(parameter.Statements.Length);

            foreach (string statement in parameter.Statements)
            {
                int result = engine.Evaluate <int>(statement);

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            //engine.SetGlobalValue("SearchServiceApplication", new SearchServiceApplicationConstructor(engine));
            engine.SetGlobalValue("SearchServiceApplicationProxy", new SearchServiceApplicationProxyConstructor(engine));
            engine.SetGlobalValue("KeywordQuery", new KeywordQueryConstructor(engine));
            engine.SetGlobalValue("FullTextSqlQuery", new FullTextSqlQueryConstructor(engine));
            engine.SetGlobalValue("RemoteScopes", new RemoteScopesConstructor(engine));

            var context        = SPServiceContext.GetContext(SPBaristaContext.Current.Site);
            var proxy          = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy));
            var searchAppProxy = proxy as SearchServiceApplicationProxy;

            return(searchAppProxy == null
                ? null
                : new SearchServiceApplicationProxyInstance(engine, searchAppProxy));
        }
Esempio n. 31
0
        public string UseJurassic(List <string> Parameters)
        {
            int a;
            int b;

            int.TryParse(Parameters[0], out a);
            int.TryParse(Parameters[1], out b);

            var engine = new Jurassic.ScriptEngine();

            engine.Evaluate("function test(a, b) { return a + b }");
            var ret = engine.CallGlobalFunction <int>("test", a, b);


            return(ret.ToString());
        }
Esempio n. 32
0
        public MainPage()
        {
            InitializeComponent();

            // Initialize the script engine.
            this.engine = new Jurassic.ScriptEngine();

            // Initialize silverlight console.
            this.console = new SilverlightConsoleOutput(this.HistoryTextBox);
            this.console.BeforeLog += new EventHandler(Console_BeforeLog);
            this.console.AfterLog += new EventHandler(Console_AfterLog);

            // Register the firebug console object.
            var consoleObject = new Jurassic.Library.FirebugConsole(engine);
            consoleObject.Output = this.console;
            engine.Global["console"] = consoleObject;
        }
Esempio n. 33
0
        public bool Jurassic(Parameter parameter)
        {
            Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();
            //engine.EnableExposedClrTypes = true;
            engine.SetGlobalValue("n", engine.Array.New(parameter.Numbers.Cast <object>().ToArray()));

            List <int> results = new List <int>(parameter.Numbers.Length);

            foreach (int number in parameter.Numbers)
            {
                int result = engine.Evaluate <int>(parameter.Statements[number]);

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
Esempio n. 34
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("SPWorkflowManager", new SPWorkflowManagerConstructor(engine));

            engine.SetGlobalValue("SPWorkflow", new SPWorkflowConstructor(engine));
            engine.SetGlobalValue("SPWorkflowCollection", new SPWorkflowCollectionConstructor(engine));
            engine.SetGlobalValue("SPWorkflowFilter", new SPWorkflowFilterConstructor(engine));
            engine.SetGlobalValue("SPWorkflowAssociation", new SPWorkflowAssociationConstructor(engine));
            engine.SetGlobalValue("SPWorkflowAssociationCollection", new SPWorkflowAssociationCollectionConstructor(engine));

            engine.SetGlobalValue("SPWorkflowTask", new SPWorkflowTaskConstructor(engine));
            engine.SetGlobalValue("SPWorkflowTaskCollection", new SPWorkflowTaskCollectionConstructor(engine));
            engine.SetGlobalValue("SPWorkflowTemplate", new SPWorkflowTemplateConstructor(engine));

            //TODO: finish this.
            return(Undefined.Value);
        }
Esempio n. 35
0
        public bool Jurassic(Parameter parameter)
        {
            Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();

            List <int> results = new List <int>(parameter.Numbers.Length);

            foreach (int number in parameter.Numbers)
            {
                engine.SetGlobalValue("n", number);

                int result = engine.Evaluate <int>(EXPRESSION);

                results.Add(result);
            }

            return(Assert(results, parameter.Sum));
        }
Esempio n. 36
0
        private void list()
        {
            try
            {
                txtPageNow.Text = pageNow.ToString();

                string start = pageNow > 1 ? ((pageNow - 1) * interval).ToString() : "0";
                string url   = getUrl(curcol, start);

                string s;
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    Byte[] pageData = wc.DownloadData(url);

                    s = System.Text.Encoding.GetEncoding("GBK").GetString(pageData);
                    //Stream stream = new System.IO.MemoryStream(Encoding.Convert(Encoding.GetEncoding("GBK"), Encoding.UTF8, pageData));
                    //s = System.Text.Encoding.UTF8.GetString(pageData);去除中文乱码

                    s += @"
    function getstring(){
        var s=serv_loadColumnNews();
        return  JSON.stringify(s);
    }
";
                    var eng = new Jurassic.ScriptEngine();
                    eng.Evaluate(s);
                    var b = eng.CallGlobalFunction <string>(@"getstring");

                    m = JsonConvert.DeserializeObject <oainfo>(b);
                }
                pagesAll        = m.total / interval + (m.total % interval == 0 ? 0 : 1);
                labPageAll.Text = pagesAll.ToString();

                listDoc.Items.Clear();
                foreach (var v in m.informations)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi = listDoc.Items.Add(v.id);
                    lvi.SubItems.Add(v.bt);
                    lvi.SubItems.Add(v.time);
                    lvi.SubItems.Add(v.mc);
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Esempio n. 37
0
        public void Process(Page page)
        {
            if (_language == Language.Javascript)
            {
                //engine.eval(defines + "\n" + script, context);
                //                        NativeObject o = (NativeObject) engine.get("result");
                //                        if (o != null) {
                //                            for (Object o1 : o.getIds()) {
                //                                string key = string.valueOf(o1);
                //                                page.getResultItems().put(key, NativeObject.getProperty(o, key));
                //                            }
                //                        }
                string realScript = _defines + Environment.NewLine + _script;

                Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();
                engine.EnableExposedClrTypes = true;
                engine.SetGlobalValue("page", page);
                engine.SetGlobalValue("config", Site);
                engine.Execute(realScript);
            }
            else if (_language == Language.Python)
            {
                //RubyHash oRuby = (RubyHash)engine.eval(defines + "\n" + script, context);
                //Iterator itruby = oRuby.entrySet().iterator();
                //while (itruby.hasNext())
                //{
                //	Map.Entry pairs = (Map.Entry)itruby.next();
                //	page.getResultItems().put(pairs.getKey().toString(), pairs.getValue());
                //}
            }
            else if (_language == Language.Ruby)
            {
                //engine.eval(defines + "\n" + script, context);
                //PyDictionary oJython = (PyDictionary)engine.get("result");
                //Iterator it = oJython.entrySet().iterator();
                //while (it.hasNext())
                //{
                //	Map.Entry pairs = (Map.Entry)it.next();
                //	page.getResultItems().put(pairs.getKey().toString(), pairs.getValue());
                //}
            }
        }
Esempio n. 38
0
        static void Main(string[] args)
        {
            var timer = System.Diagnostics.Stopwatch.StartNew();
            var engine = new Jurassic.ScriptEngine();
            Console.WriteLine("Start-up time: {0}ms", timer.ElapsedMilliseconds);
            using (var testSuite = new TestSuite(Path.Combine ("..", "..", "..", "Test Suite Files")))
            {
                //testSuite.RunInSandbox = true;
                //testSuite.IncludedTests.Add("12.7-1");
                //testSuite.IncludedTests.Add("15.2.3.14-5-13");

                testSuite.TestFinished += OnTestFinished;
                testSuite.Start();

                Console.WriteLine();
                Console.WriteLine("Finished in {0} minutes, {1} seconds!", (int)timer.Elapsed.TotalMinutes, timer.Elapsed.Seconds);
                Console.WriteLine("Succeeded: {0} ({1:P1})", testSuite.SuccessfulTestCount, testSuite.SuccessfulPercentage);
                Console.WriteLine("Failed: {0} ({1:P1})", testSuite.FailedTestCount, testSuite.FailedPercentage);
                Console.WriteLine("Skipped: {0} ({1:P1})", testSuite.SkippedTestCount, testSuite.SkippedPercentage);
                Console.WriteLine("Total: {0}", testSuite.ExecutedTestCount);
            }
        }
Esempio n. 39
0
        static object EvalJScript(string jScript, params string[] dependencies)
        {
            var engine = new Jurassic.ScriptEngine();

            var scriptWithDependencies = string.Join("\r\n\r\n", dependencies) + "\r\n" + jScript;
            object result = null;
            try
            {
                var evalJScript = engine.Evaluate(scriptWithDependencies);
                if (evalJScript is Jurassic.Library.UserDefinedFunction)
                {
                    engine.Execute(scriptWithDependencies);
                    return engine.Evaluate("out()");
                }
                return evalJScript;
            }
            catch (Exception ex)
            {
                throw new InvalidJavascriptException(jScript, ex);
            }

            return result;
        }        
Esempio n. 40
0
        static void Main(string[] args)
        {
            const int iterations = 1000;
            const bool reuseEngine = false;

            var watch = new Stopwatch();

            var jint = new Jint.JintEngine();

            watch.Restart();
            for (var i = 0; i < iterations; i++)
            {
                if (!reuseEngine)
                {
                    jint = new Jint.JintEngine();
                }

                jint.Run(script);
            }

            Console.WriteLine("Jint: {0} iterations in {1} ms", iterations, watch.ElapsedMilliseconds);

            var jurassic = new Jurassic.ScriptEngine();

            watch.Restart();
            for (var i = 0; i < iterations; i++)
            {
                if (!reuseEngine)
                {
                    jurassic = new Jurassic.ScriptEngine();
                }

                jurassic.Execute(script);
            }

            Console.WriteLine("Jurassic: {0} iterations in {1} ms", iterations, watch.ElapsedMilliseconds);
        }
Esempio n. 41
0
        // 输出 RML 格式的表格
        // 本函数负责写入 <table> 元素
        // parameters:
        //      nTopLines   顶部预留多少行
        void OutputRmlTable(
            DbDataReader data_reader,
            XmlTextWriter writer,
            int nMaxLines = -1)
        {
            // StringBuilder strResult = new StringBuilder(4096);
            int i, j;

#if NO
            if (nMaxLines == -1)
                nMaxLines = table.Count;
#endif

            writer.WriteStartElement("table");
            WriteAttributeString(writer, "class", "table");

            writer.WriteStartElement("thead");
            writer.WriteStartElement("tr");

            int nEvalCount = 0; // 具有 eval 的栏目个数
            for (j = 0; j < this.Columns.Count; j++)
            {
                PrintColumn000 column = this.Columns[j];
                if (column.Colspan == 0)
                    continue;

                if (string.IsNullOrEmpty(column.Eval) == false)
                    nEvalCount++;

                writer.WriteStartElement("th");
                if (string.IsNullOrEmpty(column.CssClass) == false)
                    WriteAttributeString(writer, "class", column.CssClass);
                if (column.Colspan > 1)
                    WriteAttributeString(writer, "colspan", column.Colspan.ToString());

                WriteString(writer, column.Title);
                writer.WriteEndElement();   // </th>
            }

            writer.WriteEndElement();   // </tr>
            writer.WriteEndElement();   // </thead>

            // 合计数组
            object[] sums = null;   // 2008/12/1 new changed

            if (this.SumLine)
            {
                sums = new object[this.Columns.Count];
                for (i = 0; i < sums.Length; i++)
                {
                    sums[i] = null;
                }
            }

            NumberFormatInfo nfi = new CultureInfo("zh-CN", false).NumberFormat;
            nfi.NumberDecimalDigits = 2;

            writer.WriteStartElement("tbody");

            // Jurassic.ScriptEngine engine = null;
            if (nEvalCount > 0 && engine == null)
            {
                engine = new Jurassic.ScriptEngine();
                engine.EnableExposedClrTypes = true;
            }

            int nLineCount = 0;

            // 内容行循环
            for (i = 0; ; i++)  // i < Math.Min(nMaxLines, table.Count)
            {
                if (data_reader.Read() == false)
                {
                    if (data_reader.NextResult() == false)
                        break;

                    if (data_reader.Read() == false)
                        break;
                }

                nLineCount++;
#if NO
                if (table.HasRows == false)
                    break;
#endif
                // Line line = table[i];

                if (engine != null)
                {
                    engine.SetGlobalValue("line", data_reader);
                }

                string strLineCssClass = "content";
#if NO
                if (report.OutputLine != null)
                {
                    OutputLineEventArgs e = new OutputLineEventArgs();
                    e.Line = line;
                    e.Index = i;
                    e.LineCssClass = strLineCssClass;
                    report.OutputLine(this, e);
                    if (e.Output == false)
                        continue;

                    strLineCssClass = e.LineCssClass;
                }
#endif

                // strResult.Append("<tr class='" + strLineCssClass + "'>\r\n");
                writer.WriteStartElement("tr");
                WriteAttributeString(writer, "class", strLineCssClass);

                // 列循环
                for (j = 0; j < this.Columns.Count; j++)
                {
                    PrintColumn000 column = this.Columns[j];

                    if (column.ColumnNumber < -1)
                    {
                        throw (new Exception("PrintColumn对象ColumnNumber列尚未初始化,位置" + Convert.ToString(j)));
                    }

                    string strText = "";
                    if (column.ColumnNumber != -1)
                    {
                        // Debug.Assert(column.ColumnNumber < data_reader.FieldCount, "");

                        if (string.IsNullOrEmpty(column.Eval) == false)
                        {
                            // engine.SetGlobalValue("cell", line.GetObject(column.ColumnNumber));
                            engine.SetGlobalValue("rowNumber", nLineCount.ToString());
                            engine.SetGlobalValue("currency", new PriceUtil());
                            strText = engine.Evaluate(column.Eval).ToString();
                        }
                        else if (column.DataType == ColumnDataType.PriceDouble)
                        {
                            if (data_reader.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                double v = data_reader.GetDouble(column.ColumnNumber);
                                /*
                                NumberFormatInfo provider = new NumberFormatInfo();
                                provider.NumberDecimalDigits = 2;
                                provider.NumberGroupSeparator = ".";
                                provider.NumberGroupSizes = new int[] { 3 };
                                strText = Convert.ToString(v, provider);
                                 * */
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == ColumnDataType.PriceDecimal)
                        {
                            if (data_reader.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                decimal v = data_reader.GetDecimal(column.ColumnNumber);
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == ColumnDataType.PriceDecimal)
                        {
                            if (data_reader.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                decimal v = data_reader.GetDecimal(column.ColumnNumber);
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == ColumnDataType.Price)
                        {
                            // Debug.Assert(false, "");
                            if (data_reader.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;	// 2005/5/26
                            else
                                strText = data_reader.GetString(column.ColumnNumber);    // 
                        }
                        else if (column.DataType == ColumnDataType.String)
                        {
                            // strText = data_reader.GetString(column.ColumnNumber/*, column.DefaultValue*/);
                            // 2014/8/28
                            object o = data_reader.GetValue(column.ColumnNumber);
                            if (o != null)
                                strText = o.ToString();
                            else
                                strText = "";
                        }
                        else
                        {
                            object o = data_reader.GetValue(column.ColumnNumber);
                            if (o != null)
                                strText = o.ToString();
                            else
                                strText = "";
                        }
                    }
                    else
                    {
                        strText = data_reader.GetString(0);   // line.Entry;
                    }

                    writer.WriteStartElement(j == 0 ? "th" : "td");
                    if (string.IsNullOrEmpty(column.CssClass) == false)
                        WriteAttributeString(writer, "class", column.CssClass);
                    WriteString(writer, strText);
                    writer.WriteEndElement();   // </td>

                    if (this.SumLine == true
                        && column.Sum == true
                        && column.ColumnNumber != -1)
                    {
                        try
                        {
                            // if (column.DataType != DataType.Currency)
                            {
                                object v = null;

                                if (column.ColumnNumber < data_reader.FieldCount)
                                    v = data_reader.GetValue(column.ColumnNumber);
#if NO
                                if (report.SumCell != null)
                                {
                                    SumCellEventArgs e = new SumCellEventArgs();
                                    e.DataType = column.DataType;
                                    e.ColumnNumber = column.ColumnNumber;
                                    e.LineIndex = i;
                                    e.Line = line;
                                    e.Value = v;
                                    report.SumCell(this, e);
                                    if (e.Value == null)
                                        continue;

                                    v = e.Value;
                                }
#endif

                                if (sums[j] == null)
                                    sums[j] = v;
                                else
                                {
                                    sums[j] = AddValue(column.DataType,
            sums[j],
            v);
                                    // sums[j] = ((decimal)sums[j]) + v;
                                }
                            }
                        }
                        catch (Exception ex)	// 俘获可能因字符串转换为整数抛出的异常
                        {
                            throw new Exception("在累加 行 " + i.ToString() + " 列 " + column.ColumnNumber.ToString() + " 值的时候,出现异常: " + ExceptionUtil.GetAutoText(ex));
                        }
                    }
                }

                // strResult.Append("</tr>\r\n");
                writer.WriteEndElement();   // </tr>
            }

            writer.WriteEndElement();   // </tbody>

            if (this.SumLine == true)
            {
                SumLineReader sum_line = null;
                if (engine != null)
                {
                    // 准备 Line 对象
                    sum_line = new SumLineReader();
                    sum_line.FieldValues = sums;
                    sum_line.Read();
#if NO
                    for (j = 1; j < this.Columns.Count; j++)
                    {
                        PrintColumn000 column = this.Columns[j];
                        if (column.Sum == true
                            && sums[j] != null)
                        {
                            sum_line.SetValue(j - 1, sums[j]);
                        }
                    }
#endif
                    engine.SetGlobalValue("line", sum_line);
                    engine.SetGlobalValue("rowNumber", "");
                }

                // strResult.Append("<tr class='sum'>\r\n");
                writer.WriteStartElement("tfoot");
                writer.WriteStartElement("tr");
                WriteAttributeString(writer, "class", "sum");

                for (j = 0; j < this.Columns.Count; j++)
                {
                    PrintColumn000 column = this.Columns[j];
                    string strText = "";

                    if (j == 0)
                        strText = "合计(" + nLineCount.ToString() + "行)";
                    else if (column.Sum == true)
                    {
                        if (string.IsNullOrEmpty(column.Eval) == false)
                        {
                            engine.SetGlobalValue("currency", new PriceUtil());
                            strText = engine.Evaluate(column.Eval).ToString();
                        }
                        else if (column.Sum == true
                            && sums[j] != null)
                        {
                            if (column.DataType == ColumnDataType.PriceDouble)
                                strText = ((double)sums[j]).ToString("N", nfi);
                            else if (column.DataType == ColumnDataType.PriceDecimal)
                                strText = ((decimal)sums[j]).ToString("N", nfi);
                            else if (column.DataType == ColumnDataType.Price)
                            {
                                strText = StatisUtil.Int64ToPrice((Int64)sums[j]);
                            }
                            else
                                strText = Convert.ToString(sums[j]);

                            if (column.DataType == ColumnDataType.Currency)
                            {
                                string strSomPrice = "";
                                string strError = "";
                                // 汇总价格
                                int nRet = PriceUtil.SumPrices(strText,
                out strSomPrice,
                out strError);
                                if (nRet == -1)
                                    strText = strError;
                                else
                                    strText = strSomPrice;
                            }
                        }
                        else
                            strText = column.DefaultValue;  //  "&nbsp;";

                    }

#if NO
                    doc.WriteExcelCell(
    _lineIndex,
    j,
    strText,
    true);
#endif
                    writer.WriteStartElement(j == 0 ? "th" : "td");
                    if (string.IsNullOrEmpty(column.CssClass) == false)
                        WriteAttributeString(writer, "class", column.CssClass);
                    WriteString(writer, strText);
                    writer.WriteEndElement();   // </td>
                }

                // strResult.Append("</tr>\r\n");
                writer.WriteEndElement();   // </tr>
                writer.WriteEndElement();   // </tfoot>
            }

            writer.WriteEndElement();   // </table>
        }
Esempio n. 42
0
 private static void ExecuteWithJurrasic(Test test)
 {
     Execute("jurassic", test, () =>
     {
         var jurassicEngine = new Jurassic.ScriptEngine();
         jurassicEngine.Execute(test.Content);
     });
 }
Esempio n. 43
0
		/// <summary>
		/// Turn the encrypted s parameter into a valid signature
		/// </summary>
		/// <param name="s">s Parameter value of the URL parameters</param>
		/// <returns></returns>
		string DecryptSignature(string javascriptUrl, string s)
        {
			if (string.IsNullOrEmpty(s)) return string.Empty;

			// try decryption by executing the Javascript from Youtube
			if (!string.IsNullOrEmpty(javascriptUrl))
			{
				try
				{
					if (javascriptUrl.StartsWith("//"))
						javascriptUrl = "http:" + javascriptUrl;
                    /*
                    var match = Regex.Match(javascriptUrl, @".*?-(?<id>[a-zA-Z0-9_-]+)(?:/watch_as3|/html5player)?\.(?<ext>[a-z]+)$");
                    if (!match.Success)
                        throw new Exception(string.Format("Cannot identify player {0}", javascriptUrl));
                    var player_type = match.Groups["ext"];
                    var player_id = match.Groups["id"];
                    */
					string jsContent = WebCache.Instance.GetWebData(javascriptUrl);

					string signatureMethodName = Regex.Match(jsContent, @"\.sig\|\|([a-zA-Z0-9$]+)\(").Groups[1].Value;
                    
                    Jurassic.ScriptEngine engine;
                    if (!cachedJavascript.TryGetValue(jsContent, out engine))
                    {
                        engine = new Jurassic.ScriptEngine();
                        
                        // define globals that are used in the script
                        engine.Global["window"] = engine.Global;
                        engine.Global["document"] = engine.Global;
                        engine.Global["navigator"] = engine.Global;
                        
                        // this regexp is not valid for .net but js : https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/RegExp
                        var fixedJs = jsContent.Replace("[^]", ".");

                        // cut out the global function(){...} surrounding everything, so our method is defined global in Jurassic
                        fixedJs = fixedJs.Substring(fixedJs.IndexOf('{') + 1);
                        fixedJs = fixedJs.Substring(0, fixedJs.LastIndexOf('}'));
                        
                        // due to js nature - all methods called in our target function must be defined before, so for performance cut off where our function ends
                        var method = Regex.Match(fixedJs, "(function\\s+" + signatureMethodName + @".*?)function [a-zA-Z]+\(\)").Groups[1];
                        fixedJs = fixedJs.Substring(0, method.Index + method.Length);

                        engine.Execute(fixedJs);
                        cachedJavascript.Add(jsContent, engine);
                    }
					string decrypted = engine.CallGlobalFunction(signatureMethodName, s).ToString();
                    if (!string.IsNullOrEmpty(decrypted))
                        return decrypted;
                    else
                        Log.Info("Javascript decryption function returned nothing!");
				}
				catch (Exception ex)
				{
					Log.Info("Signature decryption by executing the Javascript failed: {0}", ex.Message);
				}
			}
            else
            {
                Log.Info("No Javascript url for decrpyting signature!");
            }
            return string.Empty;
		}
Esempio n. 44
0
        int BuildTextTableLine(PrintOption option,
            List<ListViewItem> items,
            int nIndex,
            StreamWriter sw,
            // ref ExcelDocument doc,
            IXLWorksheet sheet,
            bool bCutText)
        {
            string strError = "";
            int nRet = 0;

            if (nIndex >= items.Count)
            {
                strError = "error: nIndex(" + nIndex.ToString() + ") >= items.Count(" + items.Count.ToString() + ")";
                goto ERROR1;
            }

            ListViewItem item = items[nIndex];
            string strMARC = "";
            string strOutMarcSyntax = "";

            if (this.MarcFilter != null
                || option.HasEvalue() == true)
            {

                // TODO: 有错误要明显报出来,否则容易在打印出来后才发现,就晚了

                // 获得MARC格式书目记录
                string strBiblioRecPath = ListViewUtil.GetItemText(item, COLUMN_BIBLIORECPATH);
                nRet = GetMarc(strBiblioRecPath,
                    out strMARC,
                    out strOutMarcSyntax,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (this.MarcFilter != null)
                {
                    this.ColumnTable.Clear();   // 清除上一记录处理时残余的内容
                    this.MarcFilter.Host.UiItem = item; // 当前正在处理的 ListViewItem

                    // 触发filter中的Record相关动作
                    nRet = this.MarcFilter.DoRecord(
                        null,
                        strMARC,
                        strOutMarcSyntax,
                        nIndex,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }
            }

            // 栏目内容
            string strLineContent = "";

            // bool bBiblioSumLine = false;    // 是否为种的最后一行(汇总行)
            List<CellData> cells = new List<CellData>();
            int nColIndex = 0;

            for (int i = 0; i < option.Columns.Count; i++)
            {
                Column column = option.Columns[i];
                bool bNumber = false;

                // int nIndex = nPage * option.LinesPerPage + nLine;

                /*
                if (nIndex >= items.Count)
                    break;

                ListViewItem item = items[nIndex];
                 * */
                string strContent = "";
                if (string.IsNullOrEmpty(column.Evalue) == false)
                {
                    Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();
                    engine.EnableExposedClrTypes = true;
                    engine.SetGlobalValue("syntax", strOutMarcSyntax);
                    engine.SetGlobalValue("biblio", new MarcRecord(strMARC));
                    strContent = engine.Evaluate(column.Evalue).ToString();

                }
                else
                {
                    strContent = GetColumnContent(item,
                        column.Name);

                    if (strContent == "!!!#")
                    {
                        // strContent = ((nPage * option.LinesPerPage) + nLine + 1).ToString();
                        strContent = (nIndex + 1).ToString();
                        bNumber = true;
                    }

                    if (strContent == "!!!biblioPrice")
                    {
                        // 看看自己是不是处在切换边沿
                        string strCurLineBiblioRecPath = GetColumnContent(item, "biblioRecpath");

                        string strNextLineBiblioRecPath = "";

                        if (nIndex < items.Count - 1)
                        {
                            ListViewItem next_item = items[nIndex + 1];
                            strNextLineBiblioRecPath = GetColumnContent(next_item, "biblioRecpath");
                        }

                        if (strCurLineBiblioRecPath != strNextLineBiblioRecPath)
                        {
                            // 处在切换边沿

                            // 汇总前面的册价格
                            strContent = ComputeBiblioPrice(items, nIndex).ToString();
                            // bBiblioSumLine = true;
                        }
                        else
                        {
                            // 其他普通行
                            strContent = "";    //  "&nbsp;";
                        }

                    }
                }

                if (bCutText == true)
                {
                    // 截断字符串
                    if (column.MaxChars != -1)
                    {
                        if (strContent.Length > column.MaxChars)
                        {
                            strContent = strContent.Substring(0, column.MaxChars);
                            strContent += "...";
                        }
                    }
                }

                if (String.IsNullOrEmpty(strContent) == true)
                    strContent = "";    //  "&nbsp;";

                // string strClass = Global.GetLeft(column.Name);

                if (i != 0)
                    strLineContent += "\t";

                strLineContent += strContent;

                if (sheet != null)
                {
#if NO
                    CellData cell = new CellData(nColIndex++, strContent,
            !bNumber,
            5);
                    cells.Add(cell);
#endif
                    IXLCell cell = sheet.Cell(nIndex + _nTopIndex + 1, nColIndex + 1);
                    if (bNumber == true)
                        cell.Value = strContent;
                    else
                        cell.SetValue(strContent);
                    cell.Style.Alignment.WrapText = true;
                    cell.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;

                    nColIndex++;
                }
            }

            /*
            if (bBiblioSumLine == false)
            {
                StreamUtil.WriteText(strFileName,
        "<tr class='content'>");
            }
            else
            {
                StreamUtil.WriteText(strFileName,
        "<tr class='content_biblio_sum'>");
            }*/
            if (sw != null)
                sw.WriteLine(strLineContent);

#if NO
            if (doc != null)
                doc.WriteExcelLine(nIndex + _nTopIndex,
                    cells,
                    WriteExcelLineStyle.AutoString);  // WriteExcelLineStyle.None
#endif

            return 0;
        ERROR1:
            if (sw != null)
                sw.WriteLine(strError);
        if (sheet != null)
        {
#if NO
            List<CellData> temp_cells = new List<CellData>();
            temp_cells.Add(new CellData(0, strError));
            doc.WriteExcelLine(nIndex + _nTopIndex, temp_cells);
#endif
            IXLCell cell = sheet.Cell(nIndex + _nTopIndex + 1, 1);
            cell.Value = strError;

        }
            return -1;
        }
Esempio n. 45
0
        int BuildWordXmlTableLine(PrintOption option,
            List<ListViewItem> items,
            int nIndex,
            XmlTextWriter writer,
            bool bCutText)
        {
            string strError = "";
            int nRet = 0;

            if (nIndex >= items.Count)
            {
                strError = "error: nIndex(" + nIndex.ToString() + ") >= items.Count(" + items.Count.ToString() + ")";
                goto ERROR1;
            }

            ListViewItem item = items[nIndex];
            string strMARC = "";
            string strOutMarcSyntax = "";

            if (this.MarcFilter != null
                || option.HasEvalue() == true)
            {

                // TODO: 有错误要明显报出来,否则容易在打印出来后才发现,就晚了

                // 获得MARC格式书目记录
                string strBiblioRecPath = ListViewUtil.GetItemText(item, COLUMN_BIBLIORECPATH);
                nRet = GetMarc(strBiblioRecPath,
                    out strMARC,
                    out strOutMarcSyntax,
                    out strError);
                if (nRet == -1)
                    goto ERROR1;

                if (this.MarcFilter != null)
                {
                    this.ColumnTable.Clear();   // 清除上一记录处理时残余的内容
                    this.MarcFilter.Host.UiItem = item; // 当前正在处理的 ListViewItem

                    // 触发filter中的Record相关动作
                    nRet = this.MarcFilter.DoRecord(
                        null,
                        strMARC,
                        strOutMarcSyntax,
                        nIndex,
                        out strError);
                    if (nRet == -1)
                        goto ERROR1;
                }
            }

            // <w:tr>
            writer.WriteStartElement("w", "tr", m_strWordMlNsUri);

            for (int i = 0; i < option.Columns.Count; i++)
            {
                Column column = option.Columns[i];

                // int nIndex = nPage * option.LinesPerPage + nLine;

                /*
                if (nIndex >= items.Count)
                    break;

                ListViewItem item = items[nIndex];
                 * */

                string strContent = "";
                if (string.IsNullOrEmpty(column.Evalue) == false)
                {
                    Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();
                    engine.EnableExposedClrTypes = true;
                    engine.SetGlobalValue("syntax", strOutMarcSyntax);
                    engine.SetGlobalValue("biblio", new MarcRecord(strMARC));
                    strContent = engine.Evaluate(column.Evalue).ToString();
                }
                else
                {
                    strContent = GetColumnContent(item,
                        column.Name);

                    if (strContent == "!!!#")
                    {
                        // strContent = ((nPage * option.LinesPerPage) + nLine + 1).ToString();
                        strContent = (nIndex + 1).ToString();
                    }

                    if (strContent == "!!!biblioPrice")
                    {
                        // 看看自己是不是处在切换边沿
                        string strCurLineBiblioRecPath = GetColumnContent(item, "biblioRecpath");

                        string strNextLineBiblioRecPath = "";

                        if (nIndex < items.Count - 1)
                        {
                            ListViewItem next_item = items[nIndex + 1];
                            strNextLineBiblioRecPath = GetColumnContent(next_item, "biblioRecpath");
                        }

                        if (strCurLineBiblioRecPath != strNextLineBiblioRecPath)
                        {
                            // 处在切换边沿

                            // 汇总前面的册价格
                            strContent = ComputeBiblioPrice(items, nIndex).ToString();
                            // bBiblioSumLine = true;
                        }
                        else
                        {
                            // 其他普通行
                            strContent = "";    //  "&nbsp;";
                        }
                    }
                }

                if (bCutText == true)
                {
                    // 截断字符串
                    if (column.MaxChars != -1)
                    {
                        if (strContent.Length > column.MaxChars)
                        {
                            strContent = strContent.Substring(0, column.MaxChars);
                            strContent += "...";
                        }
                    }
                }

                if (String.IsNullOrEmpty(strContent) == true)
                    strContent = "";    //  "&nbsp;";

                // string strClass = Global.GetLeft(column.Name);

                // <w:tc>
                writer.WriteStartElement("w", "tc", m_strWordMlNsUri);

                WriteParagraph(writer, strContent);

                // <w:tc>
                writer.WriteEndElement();
            }

            /*
            if (bBiblioSumLine == false)
            {
                StreamUtil.WriteText(strFileName,
        "<tr class='content'>");
            }
            else
            {
                StreamUtil.WriteText(strFileName,
        "<tr class='content_biblio_sum'>");
            }*/

            // <w:tr>
            writer.WriteEndElement();
            // sw.WriteLine(strLineContent);
            return 0;
        ERROR1:
            // <w:tr>
            writer.WriteStartElement("w", "tr", m_strWordMlNsUri);

            // <w:tc>
            writer.WriteStartElement("w", "tc", m_strWordMlNsUri);

            WriteParagraph(writer, strError);

            // <w:tc>
            writer.WriteEndElement();

            // <w:tr>
            writer.WriteEndElement();

            return -1;
        }
Esempio n. 46
0
        int BuildHtmlTableLine(PrintOption option,
            List<ListViewItem> items,
            string strFileName,
            int nPage,
            int nLine)
        {
            // 栏目内容
            string strLineContent = "";
            int nRet = 0;

            bool bBiblioSumLine = false;    // 是否为种的最后一行(汇总行)

            int nIndex = nPage * option.LinesPerPage + nLine;

            if (nIndex >= items.Count)
                goto END1;

            ListViewItem item = items[nIndex];

            string strMARC = "";
            string strOutMarcSyntax = "";

            if (this.MarcFilter != null
                || option.HasEvalue() == true)
            {
                string strError = "";

                // TODO: 有错误要明显报出来,否则容易在打印出来后才发现,就晚了

                // 获得MARC格式书目记录
                string strBiblioRecPath = ListViewUtil.GetItemText(item, COLUMN_BIBLIORECPATH);

                // TODO: 可以 cache,提高速度
                nRet = GetMarc(strBiblioRecPath,
                    out strMARC,
                    out strOutMarcSyntax,
                    out strError);
                if (nRet == -1)
                {
                    strLineContent = strError;
                    goto END1;
                }

                if (this.MarcFilter != null)
                {
                    this.ColumnTable.Clear();   // 清除上一记录处理时残余的内容
                    this.MarcFilter.Host.UiItem = item; // 当前正在处理的 ListViewItem

                    // 触发filter中的Record相关动作
                    nRet = this.MarcFilter.DoRecord(
                        null,
                        strMARC,
                        strOutMarcSyntax,
                        nIndex,
                        out strError);
                    if (nRet == -1)
                    {
                        strLineContent = strError;
                        goto END1;
                    }
                }
            }

            for (int i = 0; i < option.Columns.Count; i++)
            {
                Column column = option.Columns[i];

                /*
                int nIndex = nPage * option.LinesPerPage + nLine;

                if (nIndex >= items.Count)
                    break;

                ListViewItem item = items[nIndex];
                 * */

                string strContent = "";

                if (string.IsNullOrEmpty(column.Evalue) == false)
                {
                    Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine();
                    engine.EnableExposedClrTypes = true;
                    engine.SetGlobalValue("syntax", strOutMarcSyntax);
                    engine.SetGlobalValue("biblio", new MarcRecord(strMARC));
                    strContent = engine.Evaluate(column.Evalue).ToString();

                }
                else
                {

                    strContent = GetColumnContent(item,
                        column.Name);

                    if (strContent == "!!!#")
                        strContent = ((nPage * option.LinesPerPage) + nLine + 1).ToString();

                    if (strContent == "!!!biblioPrice")
                    {
                        // 看看自己是不是处在切换边沿
                        string strCurLineBiblioRecPath = GetColumnContent(item, "biblioRecpath");

                        string strNextLineBiblioRecPath = "";

                        if (nIndex < items.Count - 1)
                        {
                            ListViewItem next_item = items[nIndex + 1];
                            strNextLineBiblioRecPath = GetColumnContent(next_item, "biblioRecpath");
                        }

                        if (strCurLineBiblioRecPath != strNextLineBiblioRecPath)
                        {
                            // 处在切换边沿

                            // 汇总前面的册价格
                            strContent = ComputeBiblioPrice(items, nIndex).ToString();
                            bBiblioSumLine = true;
                        }
                        else
                        {
                            // 其他普通行
                            strContent = "&nbsp;";
                        }
                    }

                }

                // 截断字符串
                if (column.MaxChars != -1)
                {
                    if (strContent.Length > column.MaxChars)
                    {
                        strContent = strContent.Substring(0, column.MaxChars);
                        strContent += "...";
                    }
                }

                if (String.IsNullOrEmpty(strContent) == true)
                    strContent = "&nbsp;";

                string strClass = StringUtil.GetLeft(column.Name);
                if (strClass.Length > 0 && strClass[0] == '@')
                {
                    strClass = "ext_" + strClass.Substring(1);
                }

                strLineContent +=
                    IndentString(4) + "<td class='" + strClass + "'>" + strContent + "</td>\r\n";
            }

        END1:

            string strOdd = "";
            if (((nLine + 1) % 2) != 0) // 用每页内的行号来计算奇数
                strOdd = " odd";

            string strBiblioSum = "";
            if (bBiblioSumLine == true)
                strBiblioSum = " biblio_sum";

            // 2009/10/10 changed
            StreamUtil.WriteText(strFileName,
                IndentString(3) + "<tr class='content" + strBiblioSum + strOdd + "'><!-- 内容行"
                + (bBiblioSumLine == true ? "(书目汇总)" : "")
                + (nIndex + 1).ToString() + " -->\r\n");

            StreamUtil.WriteText(strFileName,
                strLineContent);

            StreamUtil.WriteText(strFileName,
                IndentString(3) + "</tr>\r\n");

            return 0;
        }
Esempio n. 47
0
 public static void Benchmark(string code, double previousResult = 0)
 {
     // Run the javascript code.
     var engine = new Jurassic.ScriptEngine();
     Benchmark(() => engine.Execute(new Jurassic.StringScriptSource(code)), previousResult);
 }
Esempio n. 48
0
 public static string GetHash(string no, string ptwebqq)
 {
     var scriptEngine = new Jurassic.ScriptEngine();
     scriptEngine.EnableDebugging = true;
     scriptEngine.SetGlobalValue("window", new WindowObject(scriptEngine));
     scriptEngine.ExecuteFile(System.AppDomain.CurrentDomain.BaseDirectory + "hash.js");
     var ret = scriptEngine.CallGlobalFunction<string>("friendsHash", no, ptwebqq, 0);
     return ret;
 }
Esempio n. 49
0
        protected override void Initialize()
        {
            timers = new TimerManager();

            js = new Jurassic.ScriptEngine();
            js.SetGlobalFunction("setTimeout", new Action<Jurassic.Library.FunctionInstance, int>(setTimeout));
            js.SetGlobalFunction("setInterval", new Action<Jurassic.Library.FunctionInstance, int>(setInterval));
            js.SetGlobalFunction("clearTimeout", new Action<int>(clearTimeout));
            js.SetGlobalFunction("clearInterval", new Action<int>(clearInterval));

            js.SetGlobalValue("window", js.Global);
            js.SetGlobalValue("console", new JSConsole(js));
            js.SetGlobalValue("Canvas", new JSCanvasConstructor(js));
            js.SetGlobalValue("Image", new JSImageConstructor(js));

            #if !XBOX
            if (GenerateAndExit != null)
            {
                GenerateAssemblyAndExit(GenerateAndExit);
                return;
            }

            #endif

            #if XBOX || RELEASE
            // On the XBOX or RELEASE config, run the compiled JavaScript from the Assembly
            js.LoadFromAssembly("ImpactGame");
            Generated.Main(js, js.CreateGlobalScope(), js.Global);
            #else
            // In Windows/DEBUG, run JavaScript directly from source
            js.EnableDebugging = true;
            js.Evaluate(new Jurassic.FileScriptSource("Game/index.js"));
            #endif
            base.Initialize();
        }
Esempio n. 50
0
 internal static string EncodePassword(string password, string token, string bits)
 {
     var scriptEngine = new Jurassic.ScriptEngine();
     scriptEngine.EnableDebugging = true;
     scriptEngine.SetGlobalValue("window", new WindowObject(scriptEngine));
     scriptEngine.ExecuteFile(System.AppDomain.CurrentDomain.BaseDirectory + "encode.js");
     var ret = scriptEngine.CallGlobalFunction<string>("getEncryption", password, token, bits, 0);
     return ret;
 }
Esempio n. 51
0
        private void Init()
        {
            if (BaseLocation == null)
                BaseLocation = Extensibility.Instance.GetBaseLocation(this) ?? new Uri(System.Environment.CurrentDirectory);

            _ctx = new Jurassic.ScriptEngine();
            _ctx.SetGlobalFunction("getContents", (Func<string, string>)GetContents);
            _ctx.SetGlobalFunction("getFullFilename", (Func<string, string>)GetFullFilename);
            Run(Zippy.Chirp.Properties.Resources.env);
            OnInit();
        }
Esempio n. 52
0
 public void unshift()
 {
     TestUtils.Benchmark(() =>
     {
         // 2,080,000 inner loops/s
         var engine = new Jurassic.ScriptEngine();
         var array = engine.Array.New();
         for (int i = 0; i < 1000; i++)
             Jurassic.Library.ArrayInstance.Unshift(array, i);
     });
 }
Esempio n. 53
0
        private static void StartSpider(Options param)
        {
            ScriptProcessor pageProcessor = ScriptProcessorBuilder.Custom().Language(param.Lang).ScriptFromFile(param.File).Thread(param.Thread).Build();
            pageProcessor.Site.SleepTime = param.Sleep;
            pageProcessor.Site.RetryTimes = 3;
            pageProcessor.Site.AcceptStatCode=new HashSet<int> { 200, 404, 403, 500, 502 };
            Core.Spider spider = Core.Spider.Create(pageProcessor).SetThreadNum(param.Thread);
            spider.ClearPipeline();

            StringBuilder builder = new StringBuilder();
            using (StreamReader sr = new StreamReader(typeof(ScriptConsole).Assembly.GetManifestResourceStream("Java2Dotnet.Spider.Scripts.Resource.js.define.js")))
            {
                string line;

                while ((line = sr.ReadLine()) != null)
                {
                    builder.AppendLine(line);
                }
            }

            string script = builder + Environment.NewLine + File.ReadAllText(param.File);

            Jurassic.ScriptEngine engine = new Jurassic.ScriptEngine { EnableExposedClrTypes = true };
            //engine.SetGlobalValue("page", new Page());
            engine.SetGlobalValue("config", new Site());

            engine.Evaluate(script);

            foreach (string url in param.Urls)
            {
                spider.AddUrl(url);
            }
            spider.Run();
        }
Esempio n. 54
0
        static void Main()
        {
            const bool runIronJs = true;
            const bool runJint = true;
            const bool runJurassic = true;

            const int iterations = 1000;
            const bool reuseEngine = false;

            var watch = new Stopwatch();


            if (runIronJs)
            {
                IronJS.Hosting.CSharp.Context ironjs;
                ironjs = new IronJS.Hosting.CSharp.Context();
                ironjs.Execute(Script);
                watch.Restart();
                for (var i = 0; i < iterations; i++)
                {
                    if (!reuseEngine)
                    {
                        ironjs = new IronJS.Hosting.CSharp.Context();
                    }

                    ironjs.Execute(Script);
                }

                Console.WriteLine("IronJs: {0} iterations in {1} ms", iterations, watch.ElapsedMilliseconds);
            }

            if (runJint)
            {
                Engine jint;
                jint = new Engine();
                jint.Execute(Script);

                watch.Restart();
                for (var i = 0; i < iterations; i++)
                {
                    if (!reuseEngine)
                    {
                        jint = new Jint.Engine();
                    }

                    jint.Execute(Script);
                }

                Console.WriteLine("Jint: {0} iterations in {1} ms", iterations, watch.ElapsedMilliseconds);
            }

            if (runJurassic)
            {
                Jurassic.ScriptEngine jurassic;
                jurassic = new Jurassic.ScriptEngine();
                jurassic.Execute(Script);

                watch.Restart();
                for (var i = 0; i < iterations; i++)
                {
                    if (!reuseEngine)
                    {
                        jurassic = new Jurassic.ScriptEngine();
                    }

                    jurassic.Execute(Script);
                }

                Console.WriteLine("Jurassic: {0} iterations in {1} ms", iterations, watch.ElapsedMilliseconds);
            }
        }
        protected void ProcessRequest(HttpListenerContext context)
        {
            Debug.WriteLine(context.Request.RawUrl);

            // build response data
            HttpListenerResponse response = context.Response;
            string responseString = "";

            response.StatusCode = 200;
            response.Headers.Add("Content-Type: text/html");

            // crossdomain.xml
            if (context.Request.RawUrl == "/crossdomain.xml")
            {
                responseString = "<?xml version=\"1.0\"?>"
                    + "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">"
                    + "<cross-domain-policy>"
                    + "<allow-access-from domain=\"*\" />"
                    + "</cross-domain-policy>";

            } else if( context.Request.RawUrl == "/jdcheck.js" )
            {
                responseString = "jdownloader=true; var version='18507';";

            }
            else if (context.Request.RawUrl.StartsWith("/flash"))
            {
                if (context.Request.RawUrl.Contains("addcrypted2"))
                {
                    System.IO.Stream body = context.Request.InputStream;
                    System.IO.StreamReader reader = new System.IO.StreamReader(body, context.Request.ContentEncoding);

                    String requestBody = System.Web.HttpUtility.UrlDecode(reader.ReadToEnd());

                    // get encrypted data
                    Regex rgxData = new Regex("crypted=(.*?)(&|$)");
                    String data = rgxData.Match(requestBody).Groups[1].ToString();

                    // get encrypted pass
                    Regex rgxPass = new Regex("jk=(.*?){(.*?)}(&|$)");
                    String pass = rgxPass.Match(requestBody).Groups[2].ToString();

                    var jsEngine = new Jurassic.ScriptEngine();
                    pass = jsEngine.Evaluate("(function (){" + pass + "})()").ToString();

                    // show decrypted links
                    Dispatcher.BeginInvoke(
                        new Action<Object>((sender) => { showDecryptedLinks(pass,data); })
                    ,   new object[] { this }
                    );

                    responseString = "success\r\n";
                }
                else
                {
                    responseString = "JDownloader";
                }
            }
            else
            {
                response.StatusCode = 400;
            }

            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
            response.ContentLength64 = buffer.Length;

            // output response
            System.IO.Stream output = response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            output.Close();
        }
Esempio n. 56
0
        private void list()
        {
            try
            {
                txtPageNow.Text = pageNow.ToString();

                string start = pageNow > 1 ? ((pageNow - 1) * interval).ToString() : "0";
                string url = getUrl(curcol, start);

                string s;
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    Byte[] pageData = wc.DownloadData(url);

                    s = System.Text.Encoding.GetEncoding("GBK").GetString(pageData);
                    //Stream stream = new System.IO.MemoryStream(Encoding.Convert(Encoding.GetEncoding("GBK"), Encoding.UTF8, pageData));
                    //s = System.Text.Encoding.UTF8.GetString(pageData);去除中文乱码

                    s += @"
            function getstring(){
            var s=serv_loadColumnNews();
            return  JSON.stringify(s);
            }
            ";
                    var eng = new Jurassic.ScriptEngine();
                    eng.Evaluate(s);
                    var b = eng.CallGlobalFunction<string>(@"getstring");

                    m = JsonConvert.DeserializeObject<oainfo>(b);
                }
                pagesAll = m.total / interval + (m.total % interval == 0 ? 0 : 1);
                labPageAll.Text = pagesAll.ToString();

                listDoc.Items.Clear();
                foreach (var v in m.informations)
                {
                    ListViewItem lvi = new ListViewItem();
                    lvi = listDoc.Items.Add(v.id);
                    lvi.SubItems.Add(v.bt);
                    lvi.SubItems.Add(v.time);
                    lvi.SubItems.Add(v.mc);
                }

            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Esempio n. 57
0
 private ResultPerPage InnerUserList(string token, int pageSize, int pageIndex)
 {
     var dic = new Dictionary<string, object>
     {
         {"t", "user/index"},
         {"pagesize", pageSize},
         {"pageidx", pageIndex},
         {"type", "0"},
         {"groupid", GroupId},
         {"token", token},
         {"lang", Language},
     };
     //var s = HttpHelper.GetString(DefaultUserListUrl, dic, _cc, null);
     var stream = HttpHelper.Get(DefaultUserListUrl, dic, _cc, null);
     var doc = new HtmlDocument();
     doc.Load(stream, Encoding);
     var ss = doc.DocumentNode.SelectNodes("//script");
     var se = new Jurassic.ScriptEngine();
     foreach (var s in ss.Where(e => e.GetAttributeValue("src", string.Empty).Equals(string.Empty)))
     {
         try
         {
             se.Execute(s.InnerText);
         }
         catch
         {
         }
     }
     var temp = se.GetGlobalValue("cgiData") as Jurassic.Library.ObjectInstance;
     var r = ResultPerPage.FromObjectInstance(temp);
     return r;
 }
Esempio n. 58
0
        // 输出 RML 格式的表格
        // 本函数负责写入 <table> 元素
        // parameters:
        //      nTopLines   顶部预留多少行
        public void OutputRmlTable(
            Report report,
            SQLiteDataReader table,
            XmlTextWriter writer,
            int nMaxLines = -1)
        {
            // StringBuilder strResult = new StringBuilder(4096);
            int i, j;

#if NO
            if (nMaxLines == -1)
                nMaxLines = table.Count;
#endif

            writer.WriteStartElement("table");
            writer.WriteAttributeString("class", "table");

            writer.WriteStartElement("thead");
            writer.WriteStartElement("tr");

            int nEvalCount = 0; // 具有 eval 的栏目个数
            for (j = 0; j < report.Count; j++)
            {
                PrintColumn column = (PrintColumn)report[j];
                if (column.Colspan == 0)
                    continue;

                if (string.IsNullOrEmpty(column.Eval) == false)
                    nEvalCount++;

                writer.WriteStartElement("th");
                if (string.IsNullOrEmpty(column.CssClass) == false)
                    writer.WriteAttributeString("class", column.CssClass);
                if (column.Colspan > 1)
                    writer.WriteAttributeString("colspan", column.Colspan.ToString());

                writer.WriteString(column.Title);
                writer.WriteEndElement();   // </th>
            }

            writer.WriteEndElement();   // </tr>
            writer.WriteEndElement();   // </thead>


            // 合计数组
            object[] sums = null;   // 2008/12/1 new changed

            if (report.SumLine)
            {
                sums = new object[report.Count];
                for (i = 0; i < sums.Length; i++)
                {
                    sums[i] = null;
                }
            }

            NumberFormatInfo nfi = new CultureInfo("zh-CN", false).NumberFormat;
            nfi.NumberDecimalDigits = 2;

            writer.WriteStartElement("tbody");

            // Jurassic.ScriptEngine engine = null;
            if (nEvalCount > 0 && engine == null)
            {
                engine = new Jurassic.ScriptEngine();
                engine.EnableExposedClrTypes = true;
            }

            // 内容行循环
            for (i = 0; ; i++)  // i < Math.Min(nMaxLines, table.Count)
            {
                if (table.HasRows == false)
                    break;
                // Line line = table[i];

                if (engine != null)
                    engine.SetGlobalValue("reader", table);

                string strLineCssClass = "content";
#if NO
                if (report.OutputLine != null)
                {
                    OutputLineEventArgs e = new OutputLineEventArgs();
                    e.Line = line;
                    e.Index = i;
                    e.LineCssClass = strLineCssClass;
                    report.OutputLine(this, e);
                    if (e.Output == false)
                        continue;

                    strLineCssClass = e.LineCssClass;
                }
#endif

                // strResult.Append("<tr class='" + strLineCssClass + "'>\r\n");
                writer.WriteStartElement("tr");
                writer.WriteAttributeString("class", strLineCssClass);

                // 列循环
                for (j = 0; j < report.Count; j++)
                {
                    PrintColumn column = (PrintColumn)report[j];

                    if (column.ColumnNumber < -1)
                    {
                        throw (new Exception("PrintColumn对象ColumnNumber列尚未初始化,位置" + Convert.ToString(j)));
                    }

                    string strText = "";
                    if (column.ColumnNumber != -1)
                    {
                        if (string.IsNullOrEmpty(column.Eval) == false)
                        {
                            // engine.SetGlobalValue("cell", line.GetObject(column.ColumnNumber));
                            strText = engine.Evaluate(column.Eval).ToString();
                        }
                        else if (column.DataType == DataType.PriceDouble)
                        {
                            if (table.IsDBNull(column.ColumnNumber /**/) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                double v = table.GetDouble(column.ColumnNumber);
                                /*
                                NumberFormatInfo provider = new NumberFormatInfo();
                                provider.NumberDecimalDigits = 2;
                                provider.NumberGroupSeparator = ".";
                                provider.NumberGroupSizes = new int[] { 3 };
                                strText = Convert.ToString(v, provider);
                                 * */
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == DataType.PriceDecimal)
                        {
                            if (table.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                decimal v = table.GetDecimal(column.ColumnNumber);
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == DataType.PriceDecimal)
                        {
                            if (table.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;
                            else
                            {
                                decimal v = table.GetDecimal(column.ColumnNumber);
                                strText = v.ToString("N", nfi);
                            }
                        }
                        else if (column.DataType == DataType.Price)
                        {
                            // Debug.Assert(false, "");
                            if (table.IsDBNull(column.ColumnNumber) == true)
                                strText = column.DefaultValue;	// 2005/5/26
                            else
                                strText = table.GetString(column.ColumnNumber);    // 
                        }
                        else
                            strText = table.GetString(column.ColumnNumber/*, column.DefaultValue*/);
                    }
                    else
                    {
                        strText = table.GetString(0);   // line.Entry;
                    }

                    writer.WriteStartElement(j == 0 ? "th" : "td");
                    if (string.IsNullOrEmpty(column.CssClass) == false)
                        writer.WriteAttributeString("class", column.CssClass);
                    writer.WriteString(strText);
                    writer.WriteEndElement();   // </td>

                    if (report.SumLine == true
                        && column.Sum == true
                        && column.ColumnNumber != -1)
                    {
                        try
                        {
                            // if (column.DataType != DataType.Currency)
                            {
                                object v = table.GetValue(column.ColumnNumber);
#if NO
                                if (report.SumCell != null)
                                {
                                    SumCellEventArgs e = new SumCellEventArgs();
                                    e.DataType = column.DataType;
                                    e.ColumnNumber = column.ColumnNumber;
                                    e.LineIndex = i;
                                    e.Line = line;
                                    e.Value = v;
                                    report.SumCell(this, e);
                                    if (e.Value == null)
                                        continue;

                                    v = e.Value;
                                }
#endif

                                if (sums[j] == null)
                                    sums[j] = v;
                                else
                                {
                                    sums[j] = AddValue(column.DataType,
            sums[j],
            v);
                                    // sums[j] = ((decimal)sums[j]) + v;
                                }
                            }
                        }
                        catch (Exception ex)	// 俘获可能因字符串转换为整数抛出的异常
                        {
                            throw new Exception("在累加 行 " + i.ToString() + " 列 " + column.ColumnNumber.ToString() + " 值的时候,抛出异常: " + ex.Message);
                        }
                    }
                }

                // strResult.Append("</tr>\r\n");
                writer.WriteEndElement();   // </tr>
            }
Esempio n. 59
0
 public void Dispose()
 {
     // if (_ctx != null) _ctx.Dispose();
     _ctx = null;
 }
Esempio n. 60
0
 public void stringify3()
 {
     // 166 inner loops/sec
     var engine = new Jurassic.ScriptEngine();
     var jsonObject = Jurassic.Library.JSONObject.Parse(engine, jsonString3);
     TestUtils.Benchmark(() =>
     {
         string str = Jurassic.Library.JSONObject.Stringify(engine, jsonObject);
     });
 }