Example #1
0
        //<IOC>
        //    <Add Key=""  InterfaceName=""  FullClassName="" Assembly="" />
        //    ...
        //</IOC>
        //读取所有Add节点,返回List<IocProvider>
        public List <IocProvider> GetIocProviderList(XElement iOC, IOCConfigEntity.IOC ioc)
        {
            List <IocProvider> list = new List <IocProvider>();

            IEnumerable <XElement> addElements = iOC.Elements("Add");

            foreach (XElement addElement in addElements)
            {
                IocProvider iocProvider = new IocProvider();

                iocProvider.Key           = (String)addElement.Attribute("Key");
                iocProvider.InterfaceName = (String)addElement.Attribute("InterfaceName");
                iocProvider.FullClassName = (String)addElement.Attribute("FullClassName");
                iocProvider.Assembly      = (String)addElement.Attribute("Assembly");
                iocProvider.CurrentIOC    = ioc;
                list.Add(iocProvider);
            }

            return(list);
        }
Example #2
0
        public IOCConfigEntity GetIOCConfigEntity(String configFileName)
        {
            XElement        xml             = XElement.Load(configFileName);
            IOCConfigEntity iOCConfigEntity = new IOCConfigEntity();

            iOCConfigEntity.GroupConfig     = new List <IOCConfigEntity.Group>();
            iOCConfigEntity.SystemInterface = new List <IOCConfigEntity.InterfaceRecord>();
            iOCConfigEntity.GroupSet        = new List <IOCConfigEntity.IOC>();

            //<GroupConfig>
            //    <Group ID="1" ParentID="0" Name="MB" >MB分组描述</Group>
            //    ...
            //</GroupConfig>
            XElement groupConfig = xml.Element("GroupConfig");
            IEnumerable <XElement> groupElements = groupConfig.Elements("Group");

            foreach (XElement groupElement in groupElements)
            {
                IOCConfigEntity.Group group = new IOCConfigEntity.Group();

                group.ID       = (String)groupElement.Attribute("ID");
                group.ParentID = (String)groupElement.Attribute("ParentID");
                group.Name     = (String)groupElement.Attribute("Name");
                group.Value    = (String)groupElement.Value;

                iOCConfigEntity.GroupConfig.Add(group);
            }

            //<SystemInterface>
            //  <Add Name="" Interface="" Assembly=""/>
            //  ...
            //</SystemInterface>
            XElement systemInterface = xml.Element("SystemInterface");
            IEnumerable <XElement> interfaceRecordsElements = systemInterface.Elements("Add");

            foreach (XElement interfaceRecordsElement in interfaceRecordsElements)
            {
                IOCConfigEntity.InterfaceRecord interfaceRecord = new IOCConfigEntity.InterfaceRecord();

                interfaceRecord.Name = (String)interfaceRecordsElement.Attribute("Name");
                interfaceRecord.InterfaceFullName = (String)interfaceRecordsElement.Attribute("Interface");
                interfaceRecord.Assmebly          = (String)interfaceRecordsElement.Attribute("Assembly");

                iOCConfigEntity.SystemInterface.Add(interfaceRecord);
            }

            //<GroupSet>
            //     <IOC Name="MB">
            //     </IOC>
            //      ...
            //</GroupSet>
            XElement groupSet = xml.Element("GroupSet");                   //读取GroupSet节
            IEnumerable <XElement> iOCElements = groupSet.Elements("IOC"); //所有IOC节点

            foreach (XElement iOCElement in iOCElements)                   //遍历所有Add节点,生成InterfaceRecord对象
            {
                IOCConfigEntity.IOC iOC = new IOCConfigEntity.IOC();

                iOC.Name            = (String)iOCElement.Attribute("Name");
                iOC.IocProviderList = this.GetIocProviderList(iOCElement, iOC);

                iOCConfigEntity.GroupSet.Add(iOC);
            }


            return(iOCConfigEntity);
        }