Exemplo n.º 1
0
        public void loadJs(JsEngine js)
        {
            if (require.isEmpty() == false) {
                foreach (SdNode n1 in require.items()) {
                    //1.如果本地可以加载并且没有出错
                    if (String.IsNullOrEmpty(n1.lib) == false) {
                        if (loadLib(js, n1.lib))
                            continue;
                    }

                    //2.尝试网络加载
                    Log.v("SdJscript", n1.url);

                    if (n1.cache == 0) {
                        n1.cache = 1;
                    }

                    HttpMessage msg = new HttpMessage(n1, n1.url);
                    msg.callback = (code, sender, text, url302) => {
                        if (code == 1) {
                            js.loadJs(text);
                        }
                    };

                    Util.http(s, false, msg);
                }
            }

            if (String.IsNullOrEmpty(code) == false) {
                js.loadJs(code);
            }
        }
Exemplo n.º 2
0
Arquivo: SdApi.cs Projeto: noear/SiteD
        public static void tryInit(SdNodeFactory factory, SdLogListener listener)
        {
            if (_js == null)
                _js = new JsEngine(null);//先让引擎进入工作状态

            if (_factory == null)
                _factory = factory;

            if (_listener == null)
                _listener = listener;
        }
Exemplo n.º 3
0
        public void loadJs(JsEngine js) {
            if (require.isEmpty() == false) {
                foreach (SdNode n1 in require.items()) {
                    Debug.WriteLine(n1.url, "SdJscript");

                    n1.cache = 1;
                    Util.http(s, false, n1.url, null, n1, (code, text) =>
                    {
                        if (code == 1) {
                            js.loadJs(s, text);
                        }
                    });
                }
            }

            if (String.IsNullOrEmpty(code) == false) {
                js.loadJs(s, code);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 解析
        /// </summary>
        /// <param name="xml"></param>
        public SdSource(String xml) {
            Util.tryInitCache();

            main = new SdNodeSet(this);

            var root =  XDocument.Parse(xml).Root;
            
            ver = int.Parse(root.Attribute("ver").Value.Trim());
            sds = root.Attribute("sds")?.Value;
            isDebug = "1".Equals(root.Attribute("debug")?.Value);
            isPrivate = "1".Equals(root.Attribute("private")?.Value);

            expr = root.Element("expr").Value.Trim();
            url = root.Element("url").Value.Trim();
            url_md5 = Util.md5(url);


            title = root.Element("title").Value.Trim();
            intro = root.Element("intro").Value.Trim();
            alert = root.Element("alert")?.Value.Trim();

            logo = root.Element("logo").Value.Trim();
            encode = root.Element("encode").Value.Trim();
            _ua = root.Element("ua").Value.Trim();
            
            jscript = new SdJscript(this, root.Element("jscript"));

            XElement xMain = root.Element("main");
            dtype = int.Parse(xMain.Attribute("dtype").Value);
            main.loadByElement(xMain);

            js = new JsEngine();
            jscript.loadJs(js);
        }
Exemplo n.º 5
0
        static bool tryLoadLibItem(String name, JsEngine js)
        {
            try {
                //Uri fileUri = new Uri("ms-appx:///raw/" + uri);
                //StorageFile file = StorageFile.GetFileFromApplicationUriAsync(fileUri).GetResults();
                //String code =  FileIO.ReadTextAsync(file).GetResults();

                Assembly asset = Assembly.Load(new AssemblyName("sited"));
                Stream stream = asset.GetManifestResourceStream("org.noear.sited.raw." + name);

                string code = new StreamReader(stream, Encoding.UTF8).ReadToEnd();

                js.loadJs(code);

                return true;
            }
            catch (Exception) {
                return false;
            }
        }
Exemplo n.º 6
0
        bool loadLib(JsEngine js, String lib)
        {
            //for debug
            switch (lib) {
                case "md5":
                    return  tryLoadLibItem("md5.js", js);

                case "sha1":
                    return  tryLoadLibItem("sha1.js", js);

                case "base64":
                    return  tryLoadLibItem("base64.js", js);

                case "cheerio":
                    return  tryLoadLibItem("cheerio.js", js);

                default:
                    return false;
            }
        }