Inheritance: ISdNode
Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        internal SdNodeSet buildForNode(XElement element)
        {
            if (element == null)
            {
                return(this);
            }

            name = element.Name.LocalName;

            _items.Clear();
            attrs.clear();

            {
                foreach (var p in element.Attributes())
                {
                    attrs.set(p.Name.LocalName, p.Value);
                }

                foreach (var p in element.Elements())
                {
                    if (p.HasAttributes == false)
                    {
                        if (new List <XNode>(p.Nodes()).Count == 1)
                        {
                            var p2 = p.FirstNode;
                            if (p2 != null && p2.NodeType == System.Xml.XmlNodeType.Text)
                            {
                                attrs.set(p.Name.LocalName, p.Value);
                            }
                        }
                    }
                }
            }

            _dtype = attrs.getInt("dtype");

            foreach (XElement e1 in element.Elements())
            {
                if (e1.HasAttributes)
                {
                    SdNode temp = Util.createNode(source).buildForNode(e1);
                    this.add(temp);
                }
                else if (e1.HasElements)
                {
                    SdNodeSet temp = Util.createNodeSet(source).buildForNode(e1);
                    this.add(temp);
                }
            }

            OnDidInit();

            return(this);
        }
Ejemplo n.º 3
0
        //
        //---------------------------------------
        //
        public void getNodeViewModel(ISdViewModel viewModel, SdNodeSet nodeSet, bool isUpdate, SdSourceCallback callback)
        {
            __AsyncTag tag = new __AsyncTag();

            foreach (ISdNode node in nodeSet.nodes())
            {
                SdNode n = (SdNode)node;
                doGetNodeViewModel(viewModel, isUpdate, tag, n.url, null, n, callback);
            }

            if (tag.total == 0)
            {
                callback(1);
            }
        }
Ejemplo n.º 4
0
        internal void loadByElement(XElement element) {
            if (element == null)
                return;

            _items.Clear();

            foreach (XElement e1 in element.Elements()) {
                if (e1.HasAttributes) {
                    SdNode temp = new SdNode(_source, e1);
                    this.add(e1.Name.LocalName, temp);
                }
                else {
                    SdNodeSet temp = new SdNodeSet(_source, e1);
                    this.add(e1.Name.LocalName, temp);
                }
            }
        }
Ejemplo n.º 5
0
        public void DoLoad()
        {
            xmlHeadName   = attrs.getString("head", xmlHeadName);
            xmlBodyName   = attrs.getString("body", xmlBodyName);
            xmlScriptName = attrs.getString("script", xmlScriptName);

            head = Util.createNodeSet(this);
            head.buildForNode(root.Element(xmlHeadName));

            body = Util.createNodeSet(this);
            body.buildForNode(root.Element(xmlBodyName));

            if (schema == 0)
            {
                head.attrs = this.attrs;
            }
            else
            {
                head.attrs.addAll(this.attrs);
            }

            title   = head.attrs.getString("title");
            expr    = head.attrs.getString("expr");
            url     = head.attrs.getString("url");
            url_md5 = Util.md5(url);

            _encode = head.attrs.getString("encode");
            _ua     = head.attrs.getString("ua");

            //----------
            //放后面
            //
            js      = new JsEngine(this);
            jscript = new SdJscript(this, root.Element(xmlScriptName));
            jscript.loadJs(js);

            root = null;
        }
Ejemplo n.º 6
0
        //
        //---------------------------------------
        //
        public void getNodeViewModel(ISdViewModel viewModel, SdNodeSet nodeSet, bool isUpdate, SdSourceCallback callback) {
            __AsyncTag tag = new __AsyncTag();

            foreach (ISdNode node in nodeSet.nodes()) {
                SdNode n = (SdNode)node;
                doGetNodeViewModel(viewModel, isUpdate, tag, n.url, null, n, callback);
            }

            if (tag.total == 0) {
                callback(1);
            }
        }