Пример #1
0
        private Jurassic.ScriptEngine PrepareScriptEngine(Statements.DataFieldExtension extension)
        {
            var engine = new Jurassic.ScriptEngine();

            //注册方法列表
            this._invoker.GetMethods().ToList().ForEach(o =>
                                                        engine.SetGlobalFunction(o.Key
                                                                                 , new Func <object, object, object, object
                                                                                             //, object, object, object, object, object
                                                                                             , string>(
                                                                                     (v1, v2, v3, v4) =>
                                                                                     //, v5, v6, v7, v8, v9) =>
                                                                                     this.Invoke(o.Key, v1, v2, v3, v4))));
            //, v5, v6, v7, v8, v9))));

            //注册内置方法 会覆盖上述方法
            engine.SetGlobalFunction("updateDataField", new Action <string, string>((k, v) => extension.Set(k, v)));
            engine.SetGlobalFunction("split"
                                     , new Func <string, string, Jurassic.Library.ArrayInstance>((s, i) =>
                                                                                                 engine.Array.Call((i ?? "").Split(new string[] { s }, StringSplitOptions.RemoveEmptyEntries))));

            //注册依赖上下文的内置方法 会覆盖上述方法
            engine.SetGlobalFunction("getSuperior", new Func <string>(() => this._userHelper.GetSuperior(extension.Originator)));

            //注册流程变量
            foreach (var pair in extension.DataFields)
            {
                engine.SetGlobalValue(pair.Key, pair.Value ?? "");
            }

            //注册内置上下文变量 会覆盖上述流程变量
            engine.SetGlobalValue(WorkflowBuilder.Variable_Originator, extension.Originator);

            return(engine);
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("PublishingCache", new PublishingCacheConstructor(engine));
            engine.SetGlobalValue("PublishingWeb", new PublishingWebConstructor(engine));

            return(Null.Value);
        }
Пример #3
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();
        }
Пример #4
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("PerformanceCounter", new PerformanceCounterConstructor(engine));
            engine.SetGlobalValue("PerformanceCounterCategory", new PerformanceCounterCategoryConstructor(engine));

            return(Undefined.Value);
        }
Пример #5
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("ExcelDocument", new ExcelDocumentConstructor(engine));
            engine.SetGlobalValue("ZipFile", new ZipFileConstructor(engine));
            engine.SetGlobalValue("PdfAttachment", new PdfAttachmentConstructor(engine));

            return(new DocumentInstance(engine));
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("IndexQuery", new IndexQueryConstructor(engine));
            engine.SetGlobalValue("IndexDefinition", new IndexDefinitionConstructor(engine));

            engine.SetGlobalValue("DocumentStore", new DocumentStoreConstructor(engine));

            return(Null.Value);
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("SearchArguments", new SearchArgumentsConstructor(engine));
            engine.SetGlobalValue("JsonDocument", new JsonDocumentConstructor(engine));

            var hostUrl   = BaristaContext.Current.Request.Url;
            var searchUrl = hostUrl.Scheme + "://" + hostUrl.Host + ":" + hostUrl.Port + "/Barista/v1/Search.svc";

            return(new SearchServiceInstance(engine.Object.InstancePrototype, new BaristaSearchWebClient(searchUrl)));
        }
Пример #8
0
        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);
        }
        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);
        }
        protected override void InnerSetVariableValue(string variableName, object value)
        {
            object processedValue = MapToJurassicType(value);

            try
            {
                _jsEngine.SetGlobalValue(variableName, processedValue);
            }
            catch (OriginalJsException e)
            {
                throw ConvertJavascriptExceptionToJsRuntimeException(e);
            }
        }
Пример #11
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]);
        }
Пример #12
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]);
        }
        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));
        }
        protected override void InnerSetVariableValue(string variableName, object value)
        {
            object processedValue = MapToScriptType(value);

            lock (_executionSynchronizer)
            {
                try
                {
                    _jsEngine.SetGlobalValue(variableName, processedValue);
                }
                catch (OriginalJavaScriptException e)
                {
                    throw WrapJavaScriptException(e);
                }
            }
        }
Пример #15
0
        //用于执行完成规则
        bool IScriptParser.EvaluateFinishRule(WorkItem workItem
                                              , List <DefaultHumanFinishRuleAsserter.Execution> allOtherExecutions
                                              , IDictionary <string, string> inputs
                                              , string action
                                              , string script)
        {
            var setting = workItem.GetReferredSetting();
            //断言
            var asserter = new DefaultHumanFinishRuleAsserter(setting.IsUsingSlot ? setting.SlotCount : new int?()
                                                              , new DefaultHumanFinishRuleAsserter.Execution(action, WorkItemStatus.Executed)
                                                              , allOtherExecutions);

            //初始化脚本引擎
            var engine = new Jurassic.ScriptEngine();

            //设置表达式
            engine.SetGlobalFunction("all", new Func <string, bool>(asserter.All));
            engine.SetGlobalFunction("atLeaseOf", new Func <int, string, bool>(asserter.AtLeaseOf));
            engine.SetGlobalFunction("atMostOf", new Func <int, string, bool>(asserter.AtMostOf));
            engine.SetGlobalFunction("noneOf", new Func <string, bool>(asserter.NoneOf));
            //填充变量
            foreach (var pair in inputs)
            {
                engine.SetGlobalValue(pair.Key, pair.Value ?? "");
            }

            return(this.Evaluate <bool>(engine, script));
        }
Пример #16
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.Execute(Properties.Resources.chance);
            engine.Execute(Equiv);

            engine.SetGlobalValue("assert", new AssertInstance(engine.Object.InstancePrototype));

            return(Null.Value);
        }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("Repository", new SPRepositoryConstructor(engine));

            var factory    = new BaristaRepositoryFactory();
            var repository = Repository.GetRepository(factory, new SPDocumentStore());

            return(new RepositoryInstance(engine, repository));
        }
Пример #18
0
        public CVG Process(CVG inputdata, object otherdata = null)
        {
            try
            {
                //HACK: this feels wrong
                if (!String.IsNullOrEmpty(CurrentState.Settings.Functions))
                {
                    _jsengine.Execute(CurrentState.Settings.Functions);
                }
                // Debug.WriteLine("Process();");
                //INPUT HACKS
                //  _jsengine.SetGlobalValue("gate_input", inputdata.Gate);
                // _jsengine.SetGlobalValue("cv_input", inputdata.CV);
                //  _jsengine.SetGlobalValue("parameters_input", inputdata.Parameters);
                // _jsengine.Execute("var cvg_input = {}; cvg_input['Gate'] = gate_input;cvg_input['CV'] = cv_input;cvg_input['Parameters'] = parameters_input;");
                //HACK: i hate this
                if (otherdata != null)
                {
                    _jsengine.SetGlobalValue("otherdata_raw", Newtonsoft.Json.JsonConvert.SerializeObject(otherdata));
                    _jsengine.Execute("var otherdata = JSON.parse(otherdata_raw)");
                }

                _jsengine.SetGlobalValue("cvg_input_raw", Newtonsoft.Json.JsonConvert.SerializeObject(inputdata));
                _jsengine.Execute("var cvg_input = JSON.parse(cvg_input_raw)");


                //TODO: this seems log winded
                _jsengine.Execute("var cvg_result = Process(cvg_input) ");

                //OUTPUT HACKS
                _jsengine.Execute("; if (cvg_result === undefined){ cvg_result = cvg_input}; var cvg_result_raw = JSON.stringify(cvg_result);   ");
                //   _jsengine.Execute(" var gate_result = cvg_result['Gate'] ;var cv_result = cvg_result['CV'] ;var parameters_result = cvg_result['Parameters'] ;");
                //var gate_result = (Dictionary<string, List<bool>>)_jsengine.GetGlobalValue("gate_input");
                //var cv_result = (Dictionary<string, List<short>>)_jsengine.GetGlobalValue("cv_result");
                //var parameters_result = (Dictionary<string, List<short>>)_jsengine.GetGlobalValue("parameters_result");
                //HACK: i hate this
                return(Newtonsoft.Json.JsonConvert.DeserializeObject <CVG>(_jsengine.GetGlobalValue <string>("cvg_result_raw")));
                //return new CVG(gate_result, cv_result, parameters_result);
            }catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            return(inputdata);
        }
Пример #19
0
 protected static void InitializeJurassic()
 {
     if (jurassicScriptEngine == null)
     {
         jurassicScriptEngine = new Jurassic.ScriptEngine();
         testingContext       = new TestingContext(jurassicScriptEngine);
         jurassicScriptEngine.SetGlobalValue("testingContext", testingContext);
     }
     testingContext.Clear();
 }
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            var factory  = new BaristaRepositoryFactory();
            var rootPath = Path.Combine(HttpContext.Current.Request.MapPath("~"), "DocumentStore");

            engine.SetGlobalValue("Repository", new WebRepositoryConstructor(engine));
            var repository = Repository.GetRepository(factory, new FSDocumentStore(rootPath));

            return(new RepositoryInstance(engine, repository));
        }
Пример #21
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());
                //}
            }
        }
Пример #22
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());
                //}
            }
        }
Пример #23
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);
        }
Пример #24
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);
        }
Пример #25
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);
        }
Пример #26
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);
        }
Пример #27
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));
        }
Пример #28
0
        public object InstallBundle(Jurassic.ScriptEngine engine)
        {
            engine.SetGlobalValue("ExcelDocument", new SPExcelDocumentConstructor(engine));
            engine.SetGlobalValue("ZipFile", new ZipFileConstructor(engine));
            engine.SetGlobalValue("PdfAttachment", new PdfAttachmentConstructor(engine));

            string pdfConverterLicenseKey = null;

            if (SPBaristaContext.HasCurrentContext && SPBaristaContext.Current.Web != null && SPBaristaContext.Current.Web.Properties.ContainsKey("Winnovative_HtmlToPdfConverter"))
            {
                pdfConverterLicenseKey = Convert.ToString(SPBaristaContext.Current.Web.Properties["Winnovative_HtmlToPdfConverter"]);
            }

            if (String.IsNullOrEmpty(pdfConverterLicenseKey))
            {
                pdfConverterLicenseKey = Barista.SharePoint.Utilities.GetFarmKeyValue("Winnovative_HtmlToPdfConverter");
            }

            return(new DocumentInstance(engine)
            {
                WinnovativeHtmlToPdfConverterLicenseKey = pdfConverterLicenseKey
            });
        }
Пример #29
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);
        }
Пример #30
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));
        }
Пример #31
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));
        }
Пример #32
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));
        }
Пример #33
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;
        }
Пример #34
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;
        }
Пример #35
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();
        }
Пример #36
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;
 }
Пример #37
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;
 }
Пример #38
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;
        }
Пример #39
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();
        }