Пример #1
0
        public IXmlSetting InitFromXmlFile(string xmlType, string xmlFilePath, string userId)
        {
            CXmlSettingImp neoXmlSetting = new CXmlSettingImp();

            neoXmlSetting.file_type   = xmlType;
            neoXmlSetting.update_time = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
            neoXmlSetting.updated_by  = userId;
            //neoXmlSetting.GetChildRelation(xmlFilePath);
            //neoXmlSetting.GetParentRelation(xmlFilePath);

            XmlDocument NodeSettingDoc = new XmlDocument();

            try
            {
                NodeSettingDoc.Load(xmlFilePath);
                XmlNode     root     = NodeSettingDoc.DocumentElement;
                XmlNodeList listNode = root.SelectNodes("//*");

                List <string> lstDisctinctNodeNames = (from XmlNode tempNode in listNode select tempNode.Name).Distinct().ToList();
                foreach (string strNodeName in lstDisctinctNodeNames)
                {
                    CXmlSettingNodeImp neoNode = new CXmlSettingNodeImp();
                    neoNode.name         = strNodeName;
                    neoNode.compare_flag = true;

                    List <string> lstDisctinctAttributeNames = new List <string>();
                    List <XmlAttributeCollection> lstAttrSet = (from XmlNode tmpXmlNode in listNode
                                                                where tmpXmlNode.Name == strNodeName
                                                                select tmpXmlNode.Attributes).ToList();
                    foreach (XmlAttributeCollection tempAttrSet in lstAttrSet)
                    {
                        foreach (XmlNode tempAttr in tempAttrSet)
                        {
                            lstDisctinctAttributeNames.Add(tempAttr.Name);
                        }
                    }
                    lstDisctinctAttributeNames = lstDisctinctAttributeNames.Distinct().ToList();


                    foreach (string strAttrName in lstDisctinctAttributeNames)
                    {
                        CXmlSettingAttrImp neoAttr = new CXmlSettingAttrImp();
                        neoAttr.name            = strAttrName;
                        neoAttr.identifier_flag = false;
                        neoAttr.compare_flag    = true;
                        neoNode.AppendAttribute(neoAttr);
                    }
                    neoXmlSetting.AppendNode(neoNode);
                }
                neoXmlSetting.GetParentRelation(xmlFilePath);
                neoXmlSetting.GetChildRelation(xmlFilePath);
                return(neoXmlSetting);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Пример #2
0
        public void AppendNode(IXmlSettingNode node)
        {
            CXmlSettingNodeImp value = (CXmlSettingNodeImp)node;

            if (m_Nodes.Exists(m => m.name == value.name))
            {
                throw new Exception("duplicate node name[" + value.name + "] exist in setting, append failed");
            }
            else
            {
                m_Nodes.Add(value);
            }
        }
Пример #3
0
        public void RemoveNode(IXmlSettingNode node)
        {
            CXmlSettingNodeImp value = (CXmlSettingNodeImp)node;

            m_Nodes.Remove(value);
        }