コード例 #1
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        static XmlContainer processRT(Device dev, IDictionary <string, XmlContainer> dict)
        {
            XmlContainer xmlContainer = createXml(GetAddress(System.Net.IPAddress.Parse(dev.Address), dev.Address), dict);
            XmlElement   rt           = AppendChild(createXmlElement("Router", xmlContainer), "Router");
            string       originalKey  = generateOriginalKey(dev);

            AppendChild(rt, "OriginalKey", originalKey);
            //AppendChild(rt, "OriginalKey", string.Concat(profix, "Router-", dev.DeviceId));
            AppendChild(rt, "Name", dev.Name);
            AppendChild(rt, "Description", dev.Description);
            AppendChild(rt, "DevLevel", dev.CustomLevel);
            AppendChild(rt, "Manufacturer", Helper.GetManufacturer(dev.Manufacturer.ToString()));
            AppendChild(rt, "Architecture", Helper.GetDeviceCatalog(dev.Catalog));
            AppendChild(rt, "ROMVersion", dev.Oid);
            AppendChild(rt, "OSInfo", Helper.GetDeviceCatalog(dev.Catalog));

            string model = Helper.GetDeviceType(dev.Oid.Trim(new char[] { '.' }));

            if (!string.IsNullOrEmpty(model))
            {
                AppendChild(rt, "Model", model);
            }

            AppendChild(rt, "PrimaryMACAddress", dev.GetPrimaryMAC());
            AppendChild(rt, "UsingIPAddress", dev.Address);

            XmlElement containsInstance = FindAndAppendChild(rt, "ContainsInstance");

            processPorts(dev, true, containsInstance);
            processCPU(dev, rt.Name, containsInstance, originalKey);
            return(xmlContainer);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        static void clearXml(XmlContainer xmlContainer, IDictionary <string, XmlContainer> dict)
        {
            if (null == xmlContainer)
            {
                return;
            }


            XmlNode node = xmlContainer.Doc.SelectSingleNode("/IMSDATA/datas[@classname=\"RelationShip\"]");

            if (null != node)
            {
                XmlNode parentNode = node.ParentNode;
                parentNode.RemoveChild(node);
                parentNode.AppendChild(node);
            }

            string txt = xmlContainer.Doc.OuterXml;

            if (txt.Length < maxSize)
            {
                return;
            }


            logger.InfoFormat("数据长度大于{0},发送消息!", maxSize);

            Send(xmlContainer.Doc, txt);

            logger.Info("发送消息成功,清除数据!");

            dict.Remove(xmlContainer.Corporation);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        //static string generateOriginalKey(BusinessSystem businessSystem)
        //{
        //    return string.Concat(profix, "BusinessSystem-", businessSystem.Id);
        //}

        //static string generateOriginalKey(ServiceStaticPropertiesData service)
        //{
        //    return string.Concat(profix, "SERVER-", service.Id);
        //}

        //static XmlContainer processService( BTSystem btSystem
        //    , ServiceStaticPropertiesData service
        //    , IDictionary<string, XmlContainer> xmlNodes)
        //{

        //    if (null == service.Device)
        //    {
        //        logger.DebugFormat("跳过{0}服务[{1}:{2}] - 找不到所依赖的设备{3}"
        //            , service.TypeName, service.Id, service.CustomName, service.DeviceId);
        //        return null;
        //    }

        //    switch (service.Type)
        //    {
        //        case 1://IIS-WEB
        //            logger.InfoFormat("开始处理IIS-WEB-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForIISWEB(btSystem, service, xmlNodes);
        //        case 2://IIS-FTP
        //            logger.InfoFormat("开始处理IIS-FTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForIISFTP(btSystem, service, xmlNodes);
        //        case 3://Oracle
        //            logger.InfoFormat("开始处理Oracle-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForOracle(btSystem, service, xmlNodes);
        //        case 4://Apache-WEB
        //            logger.InfoFormat("开始处理Apache-WEB-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForApache(btSystem, service, xmlNodes);
        //        case 5://TELNET
        //            logger.InfoFormat("开始处理TELNET-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForTELNET(btSystem, service, xmlNodes);
        //        case 6://SQLServer
        //            logger.InfoFormat("开始处理SQLServer-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSQLServer(btSystem, service, xmlNodes);
        //        case 7://SMTP
        //            logger.InfoFormat("开始处理SMTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSMTP(btSystem, service, xmlNodes);
        //        case 8://POP3
        //            logger.InfoFormat("开始处理POP3-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForPOP3(btSystem, service, xmlNodes);
        //        case 9://WEBLogic
        //            logger.InfoFormat("开始处理WEBLogic-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForWEBLogic(btSystem, service, xmlNodes);
        //        case 10://WebSphere
        //            logger.InfoFormat("开始处理WebSphere-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForWebSphere(btSystem, service, xmlNodes);
        //        case 11://Domino
        //            logger.InfoFormat("开始处理Domino-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDomino(btSystem, service, xmlNodes);
        //        case 12://Sybase
        //            logger.InfoFormat("开始处理Sybase-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSybase(btSystem, service, xmlNodes);
        //        case 13://Sap
        //            logger.InfoFormat("开始处理Sap-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSap(btSystem, service, xmlNodes);
        //        case 14://HTTP
        //            logger.InfoFormat("开始处理HTTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForHTTP(btSystem, service, xmlNodes);
        //        case 15://DNS
        //            logger.InfoFormat("开始处理DNS-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDNS(btSystem, service, xmlNodes);
        //        case 16://Windows-FTP
        //            logger.InfoFormat("开始处理Windows-FTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForWindowsFTP(btSystem, service, xmlNodes);
        //        case 17://DHCP
        //            logger.InfoFormat("开始处理DHCP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDHCP(btSystem, service, xmlNodes);
        //        case 18://LDAP
        //            logger.InfoFormat("开始处理LDAP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForLDAP(btSystem, service, xmlNodes);
        //        case 19://MySql
        //            logger.InfoFormat("开始处理MySql-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForMySql(btSystem, service, xmlNodes);
        //        case 20://Tuxedo
        //            logger.InfoFormat("开始处理Tuxedo-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForTuxedo(btSystem, service, xmlNodes);
        //        case 21://Informix
        //            logger.InfoFormat("开始处理Informix-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForInformix(btSystem, service, xmlNodes);
        //        case 22://DB2
        //            logger.InfoFormat("开始处理DB2-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDB2(btSystem, service, xmlNodes);
        //        case 23://EAServer
        //            logger.InfoFormat("开始处理EAServer-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForEAServer(btSystem, service, xmlNodes);
        //        case 24://MQ
        //            logger.InfoFormat("开始处理MQ-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForMQ(btSystem, service, xmlNodes);
        //        case 25://SybaseIQ
        //            logger.InfoFormat("开始处理SybaseIQ-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSybaseIQ(btSystem, service, xmlNodes);
        //        case 26://Cognos
        //            logger.InfoFormat("开始处理Cognos-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForCognos(btSystem, service, xmlNodes);
        //        case 27://Informatica
        //            logger.InfoFormat("开始处理Informatica-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForInformatica(btSystem, service, xmlNodes);
        //        case 28://Oracle_RAC
        //            logger.InfoFormat("开始处理Oracle_RAC-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForOracle_RAC(btSystem, service, xmlNodes);
        //        default:
        //            return null;
        //    }
        //}

        static XmlElement createXmlElement(string nodeName, XmlContainer xmlContainer)
        {
            XmlElement instances = null;

            if (xmlContainer.xmlNodes.TryGetValue(nodeName, out instances))
            {
                return(instances);
            }

            instances = AppendChild(xmlContainer.imsData, "datas");
            instances.SetAttribute("classname", nodeName);
            xmlContainer.xmlNodes[nodeName] = instances;
            return(instances);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        static XmlContainer createXml(string co, IDictionary <string, XmlContainer> dict)
        {
            if (null == co)
            {
                co = corporation;
            }
            co = co.Trim();
            if (0 == co.Length)
            {
                co = corporation;
            }

            XmlContainer xmlContainer = null;

            if (dict.TryGetValue(co, out xmlContainer))
            {
                return(xmlContainer);
            }


            logger.InfoFormat("创建源为{0}的xml文件!", co);

            xmlContainer             = new XmlContainer();
            xmlContainer.Corporation = co;
            xmlContainer.Doc         = new System.Xml.XmlDocument();

            string xmlText = "<?xml version=\"1.0\" encoding=\"GB2312\"?>"
                             + "<!DOCTYPE NARI_IMS_IMPORT_DATA PUBLIC \"-//nari_ims_import_data DTD 3.0//EN\" \"nari_ims_import_data.dtd\">"
                             + "<IMSDATA>"
                             + "<datasource name=\"NARI Company IMS System's Import Data\" createtime=\"" + DateTime.Now.ToShortDateString() + "\" vendorname=\"Betasoft\" productname=\"" + Producer + "\" corporation=\"" + co + "\">"
                             + "</datasource>"
                             + "<datainfo OUTPUTIP=\"" + addresses[0].ToString() + "|\" BEGINTIME=\"" + DateTime.Now.ToShortDateString() + "\">"
                             + "</datainfo>"
                             + "</IMSDATA>";

            xmlContainer.Doc.LoadXml(xmlText);

            xmlContainer.imsData = xmlContainer.Doc.SelectSingleNode("IMSDATA") as XmlElement;

            dict[co] = xmlContainer;
            return(xmlContainer);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        static XmlContainer processSW(Device dev, Dictionary <string, XmlContainer> dict)
        {
            XmlContainer xmlContainer = createXml(GetAddress(System.Net.IPAddress.Parse(dev.Address), dev.Address), dict);
            XmlElement   sw           = AppendChild(createXmlElement("Switch", xmlContainer), "Switch");
            //logger.InfoFormat("添加节点 {0}, 父节点{1}已有{2}个子节点", string.Concat(profix, "Device-", dev.DeviceId), sw.ParentNode.Name, sw.ParentNode.ChildNodes.Count);
            //AppendChild(sw, "OriginalKey", string.Concat(profix, "Switch-", dev.DeviceId));
            string originalKey = generateOriginalKey(dev);

            AppendChild(sw, "OriginalKey", originalKey);
            AppendChild(sw, "Name", dev.Name);
            AppendChild(sw, "Description", dev.Description);
            AppendChild(sw, "DevLevel", dev.CustomLevel);
            AppendChild(sw, "Manufacturer", Helper.GetManufacturer(dev.Manufacturer.ToString()));

            AppendChild(sw, "Architecture", Helper.GetDeviceCatalog(dev.Catalog));
            AppendChild(sw, "ROMVersion", dev.Oid);
            AppendChild(sw, "OSInfo", Helper.GetDeviceCatalog(dev.Catalog));

            string model = Helper.GetDeviceType(dev.Oid.Trim(new char[] { '.' }));

            if (!string.IsNullOrEmpty(model))
            {
                AppendChild(sw, "Model", model);
            }

            AppendChild(sw, "PrimaryMACAddress", dev.GetPrimaryMAC());
            AppendChild(sw, "UsingIPAddress", dev.Address);



            XmlElement containsInstance = FindAndAppendChild(sw, "ContainsInstance");

            processPorts(dev, false, containsInstance);
            processCPU(dev, sw.Name, containsInstance, originalKey);
            return(xmlContainer);
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: Redi0/meijing-ui
        //static string generateOriginalKey(BusinessSystem businessSystem)
        //{
        //    return string.Concat(profix, "BusinessSystem-", businessSystem.Id);
        //}
        
        //static string generateOriginalKey(ServiceStaticPropertiesData service)
        //{
        //    return string.Concat(profix, "SERVER-", service.Id);
        //}

        //static XmlContainer processService( BTSystem btSystem
        //    , ServiceStaticPropertiesData service
        //    , IDictionary<string, XmlContainer> xmlNodes)
        //{

        //    if (null == service.Device)
        //    {
        //        logger.DebugFormat("跳过{0}服务[{1}:{2}] - 找不到所依赖的设备{3}"
        //            , service.TypeName, service.Id, service.CustomName, service.DeviceId);
        //        return null;
        //    }

        //    switch (service.Type)
        //    {
        //        case 1://IIS-WEB
        //            logger.InfoFormat("开始处理IIS-WEB-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForIISWEB(btSystem, service, xmlNodes);
        //        case 2://IIS-FTP
        //            logger.InfoFormat("开始处理IIS-FTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForIISFTP(btSystem, service, xmlNodes);
        //        case 3://Oracle
        //            logger.InfoFormat("开始处理Oracle-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForOracle(btSystem, service, xmlNodes);
        //        case 4://Apache-WEB
        //            logger.InfoFormat("开始处理Apache-WEB-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForApache(btSystem, service, xmlNodes);
        //        case 5://TELNET
        //            logger.InfoFormat("开始处理TELNET-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForTELNET(btSystem, service, xmlNodes);
        //        case 6://SQLServer
        //            logger.InfoFormat("开始处理SQLServer-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSQLServer(btSystem, service, xmlNodes);
        //        case 7://SMTP
        //            logger.InfoFormat("开始处理SMTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSMTP(btSystem, service, xmlNodes);
        //        case 8://POP3
        //            logger.InfoFormat("开始处理POP3-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForPOP3(btSystem, service, xmlNodes);
        //        case 9://WEBLogic
        //            logger.InfoFormat("开始处理WEBLogic-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForWEBLogic(btSystem, service, xmlNodes);
        //        case 10://WebSphere
        //            logger.InfoFormat("开始处理WebSphere-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForWebSphere(btSystem, service, xmlNodes);
        //        case 11://Domino
        //            logger.InfoFormat("开始处理Domino-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDomino(btSystem, service, xmlNodes);
        //        case 12://Sybase
        //            logger.InfoFormat("开始处理Sybase-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSybase(btSystem, service, xmlNodes);
        //        case 13://Sap
        //            logger.InfoFormat("开始处理Sap-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSap(btSystem, service, xmlNodes);
        //        case 14://HTTP
        //            logger.InfoFormat("开始处理HTTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForHTTP(btSystem, service, xmlNodes);
        //        case 15://DNS
        //            logger.InfoFormat("开始处理DNS-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDNS(btSystem, service, xmlNodes);
        //        case 16://Windows-FTP
        //            logger.InfoFormat("开始处理Windows-FTP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForWindowsFTP(btSystem, service, xmlNodes);
        //        case 17://DHCP
        //            logger.InfoFormat("开始处理DHCP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDHCP(btSystem, service, xmlNodes);
        //        case 18://LDAP
        //            logger.InfoFormat("开始处理LDAP-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForLDAP(btSystem, service, xmlNodes);
        //        case 19://MySql
        //            logger.InfoFormat("开始处理MySql-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForMySql(btSystem, service, xmlNodes);
        //        case 20://Tuxedo
        //            logger.InfoFormat("开始处理Tuxedo-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForTuxedo(btSystem, service, xmlNodes);
        //        case 21://Informix
        //            logger.InfoFormat("开始处理Informix-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForInformix(btSystem, service, xmlNodes);
        //        case 22://DB2
        //            logger.InfoFormat("开始处理DB2-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForDB2(btSystem, service, xmlNodes);
        //        case 23://EAServer
        //            logger.InfoFormat("开始处理EAServer-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForEAServer(btSystem, service, xmlNodes);
        //        case 24://MQ
        //            logger.InfoFormat("开始处理MQ-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForMQ(btSystem, service, xmlNodes);
        //        case 25://SybaseIQ
        //            logger.InfoFormat("开始处理SybaseIQ-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForSybaseIQ(btSystem, service, xmlNodes);
        //        case 26://Cognos
        //            logger.InfoFormat("开始处理Cognos-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForCognos(btSystem, service, xmlNodes);
        //        case 27://Informatica
        //            logger.InfoFormat("开始处理Informatica-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForInformatica(btSystem, service, xmlNodes);
        //        case 28://Oracle_RAC
        //            logger.InfoFormat("开始处理Oracle_RAC-{0}-{1}:{2}!", service.TypeName, service.Id, service.CustomName);
        //            return processServiceForOracle_RAC(btSystem, service, xmlNodes);       
        //        default:
        //            return null;
        //    }
        //}

        static XmlElement createXmlElement(string nodeName, XmlContainer xmlContainer)
        {
            XmlElement instances = null;
            if (xmlContainer.xmlNodes.TryGetValue(nodeName, out instances))
                return instances;

            instances = AppendChild(xmlContainer.imsData, "datas");
            instances.SetAttribute("classname", nodeName);
            xmlContainer.xmlNodes[nodeName] = instances;
            return instances;
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: Redi0/meijing-ui
        static void clearXml(XmlContainer xmlContainer, IDictionary<string, XmlContainer> dict)
        {
            if (null == xmlContainer)
                return;


            XmlNode node = xmlContainer.Doc.SelectSingleNode("/IMSDATA/datas[@classname=\"RelationShip\"]");
            if (null != node)
            {
                XmlNode parentNode = node.ParentNode;
                parentNode.RemoveChild(node);
                parentNode.AppendChild(node);
            }

            string txt = xmlContainer.Doc.OuterXml;
            if (txt.Length < maxSize)
                return;


            logger.InfoFormat("数据长度大于{0},发送消息!", maxSize);

            Send(xmlContainer.Doc, txt);

            logger.Info("发送消息成功,清除数据!");

            dict.Remove(xmlContainer.Corporation);
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: Redi0/meijing-ui
        static XmlContainer createXml(string co, IDictionary<string, XmlContainer> dict)
        {
            if (null == co)
                co = corporation;
            co = co.Trim();
            if (0 == co.Length)
                co = corporation;

            XmlContainer xmlContainer = null;
            if (dict.TryGetValue(co, out xmlContainer))
                return xmlContainer;


            logger.InfoFormat("创建源为{0}的xml文件!", co);

            xmlContainer = new XmlContainer();
            xmlContainer.Corporation = co;
            xmlContainer.Doc = new System.Xml.XmlDocument();

            string xmlText = "<?xml version=\"1.0\" encoding=\"GB2312\"?>"
                        + "<!DOCTYPE NARI_IMS_IMPORT_DATA PUBLIC \"-//nari_ims_import_data DTD 3.0//EN\" \"nari_ims_import_data.dtd\">"
                        + "<IMSDATA>"
                        + "<datasource name=\"NARI Company IMS System's Import Data\" createtime=\"" + DateTime.Now.ToShortDateString() + "\" vendorname=\"Betasoft\" productname=\"" + Producer + "\" corporation=\"" + co + "\">"
                        + "</datasource>"
                        + "<datainfo OUTPUTIP=\"" + addresses[0].ToString() + "|\" BEGINTIME=\"" + DateTime.Now.ToShortDateString() + "\">"
                        + "</datainfo>"
                        + "</IMSDATA>";

            xmlContainer.Doc.LoadXml(xmlText);

            xmlContainer.imsData = xmlContainer.Doc.SelectSingleNode("IMSDATA") as XmlElement;

            dict[co] = xmlContainer;
            return xmlContainer;
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        static XmlContainer processLink(Link link, Dictionary <string, XmlContainer> dict)
        {
            Device dev1 = null;

            _deviceByIds.TryGetValue(link.Device1Id, out dev1);

            Device dev2 = null;

            _deviceByIds.TryGetValue(link.Device2Id, out dev2);
            if (null == dev1 || null == dev2)
            {
                logger.InfoFormat("线路[{0}:{1}]其中一端的设备没有,跳过!", link.Id, link.Name);
                return(null);
            }


            Interface port1 = Interface.GetDevicePort(link.Device1Id, link.IfIndex1);
            Interface port2 = Interface.GetDevicePort(link.Device2Id, link.IfIndex2);

            if (null == port1)
            {
                if (null != linkLogger)
                {
                    linkLogger.WriteLine(string.Concat("线路 - ", link.Id
                                                       , "-", (null == dev1) ? link.Device1Id.ToString() : dev1.Name
                                                       , "-", (null == dev2) ? link.Device2Id.ToString() : dev2.Name
                                                       , " ---- ", link.Name));
                }

                if (!uploadForBadLink)
                {
                    logger.InfoFormat("线路[{0}:{1}]其中一端的端口没有,跳过!", link.Id, link.Name);
                    return(null);
                }
            }

            if (null == port2)
            {
                if (null != linkLogger)
                {
                    linkLogger.WriteLine(string.Concat("线路 - ", link.Id
                                                       , "-", (null == dev1) ? link.Device1Id.ToString() : dev1.Name
                                                       , "-", (null == dev2) ? link.Device2Id.ToString() : dev2.Name
                                                       , " ---- ", link.Name));
                }

                if (!uploadForBadLink)
                {
                    logger.InfoFormat("线路[{0}:{1}]其中一端的端口没有,跳过!", link.Id, link.Name);
                    return(null);
                }
            }


            //string dev1FieldName = "Port1ID";
            //string dev2FieldName = "Port2ID";
            string port1FieldName = "Dev1ID";
            string port2FieldName = "Dev2ID";

            string className = "L2Link";
            //if (link.IsVirtual)
            //{
            //    className = "LogicalLink";

            //    dev1FieldName = "Dev1ID";
            //    dev2FieldName = "Dev2ID";
            //    port1FieldName = "Port1ID";
            //    port2FieldName = "Port2ID";
            //}

            XmlContainer xmlContainer = createXml(GetAddress(System.Net.IPAddress.Parse(dev1.Address), dev1.Address), dict);
            XmlElement   linkNode     = AppendChild(createXmlElement(className, xmlContainer), className);


            //- <!--   原系统ID 必须填写 -->
            //  <OriginalKey>640000701</OriginalKey>
            AppendChild(linkNode, "OriginalKey", string.Concat(profix, "L2Link-", link.Id));
            //- <!--  链路名称 选填 -->
            //  <Name>主干链路</Name>
            AppendChild(linkNode, "Name", link.Name);
            AppendChild(linkNode, "Description", string.IsNullOrEmpty(link.Description) ? "" : link.Description);

            //- <!--  链路类型 选填 -->
            //  <Type>3</Type>
            //AppendChild(linkNode, "Type", link.TypeName);

            //- <!--  网络接口1ID 必须填写 -->
            //  <Dev1ID>6000203</Dev1ID>
            //AppendChild(linkNode, "Dev1ID", string.Concat(profix, "Device-", link.DevId1));

            //- <!--  网络接口2ID 必须填写 -->
            //  <Dev2ID>670202</Dev2ID>
            //AppendChild(linkNode, "Dev2ID", string.Concat(profix, "Device-", link.DevId2));


            // Port1ID与Dev1ID这两个字段意思是反的,这是南瑞制定的格式,我没有办法.
            // linkNode.AppendChild(linkNode.OwnerDocument.CreateComment("Port1ID与Dev1ID这两个字段意思是反的,但这是南瑞制定的格式,我没有办法."));


            //if ("virtual" == link.TypeName)
            //{
            //    AppendChild(linkNode, dev1FieldName, generateOriginalKey(dev1));
            //    AppendChild(linkNode, dev2FieldName, generateOriginalKey(dev2));
            //}

            if (null != port1)
            {
                AppendChild(linkNode, port1FieldName, string.Concat(profix, "IpInterface-", port1.Id));
            }

            if (null != port2)
            {
                AppendChild(linkNode, port2FieldName, string.Concat(profix, "IpInterface-", port2.Id));
            }

            //- <!--  链路带宽 必须填写 -->
            //  <BandWidth>10</BandWidth>
            AppendChild(linkNode, "BandWidth", Math.Max(link.CustomSpeedUp, link.CustomSpeedDown) / 1000000);

            AppendChild(linkNode, "UpSpeed", link.CustomSpeedUp / 1000000);

            AppendChild(linkNode, "DownSpeed", link.CustomSpeedDown / 1000000);
            //AppendChild(linkNode, "LinkLevel", link.Level);
            return(xmlContainer);
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: ioxuy/meijing-ui
        static void Main(string[] args)
        {
            try
            {
                basePath  = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                addresses = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());

                string url  = "/Btnm/LocalPlatform";
                string addr = "tcp://127.0.0.1:7070";


                foreach (string ss in args)
                {
                    if (ss.StartsWith("--Url=", StringComparison.InvariantCultureIgnoreCase))
                    {
                        url = ss.Substring("--Url=".Length);
                    }
                    else if (ss.StartsWith("--Address=", StringComparison.InvariantCultureIgnoreCase))
                    {
                        addr = ss.Substring(10);
                    }
                    else if (ss.StartsWith("--MaxSize=", StringComparison.InvariantCultureIgnoreCase))
                    {
                        maxSize = int.Parse(ss.Substring(10));
                    }
                }


                XmlSetting xmlSetting = new XmlSetting(new StreamReader(Path.Combine(basePath, "nanrui.modul.config")));
                defaultSetting = XmlSetting.ReadFromFile(Path.Combine(basePath, "../nanrui.default.config"));

                log4net.Config.XmlConfigurator.Configure(xmlSetting.SelectOne("/configuration/log4net").AsXmlNode() as System.Xml.XmlElement);
                logger = log4net.LogManager.GetLogger("Betanetworks");

                try
                {
                    cachePath        = Path.Combine(basePath, "cache");
                    profix           = defaultSetting.ReadSetting("/configuration/Locale/PrefixId/@value", profix);
                    corporation      = defaultSetting.ReadSetting("/configuration/Locale/Corporation/@value", corporation);
                    uploadForPCAgent = "true" == xmlSetting.ReadSetting("/configuration/Locale/UploadForPCAgent/@value", "false");
                    uploadForBadLink = "true" == xmlSetting.ReadSetting("/configuration/Locale/UploadForBadLink/@value", "false");
                    supportMultCPU   = "true" == xmlSetting.ReadSetting("/configuration/Locale/SupportMultCPU/@value", "false");
                    logger.InfoFormat("配置发送程序启动,缺省前缀 '{0}',缺省公司 '{1}'", profix, corporation);

                    logger.Info("载入设备指标映射!");
                    DispatchImpl.ReadDispatch(xmlSetting.SelectOne("/configuration/Maps/Device"), _deviceDispatcher, logger);

                    logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入要发送的设备备注列表!", null);
                    ReadMap(_deviceFields, xmlSetting.Select("/configuration/Locale/DeviceFields/*"));

                    logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入設備的公司列表!", null);
                    ReadIni(_corporationIPSeg, xmlSetting.Select("/configuration/Locale/Corporations/*"));

                    //<Corporations>
                    //  <IPAddress from="" to="" value="" />
                    //</Corporations>



                    Dictionary <string, XmlContainer> dict = new Dictionary <string, XmlContainer>();

                    logger.Info("开始读设备表!");

                    IList <Device> devices = Device.FindBy <Device>(null);

                    logger.Info("读设备表完成,开始处理!");


                    foreach (Device dev in devices)
                    {
                        XmlContainer xmlContainer = null;
                        switch (dev.Catalog)
                        {
                        case 1:         //交换机
                            logger.InfoFormat("开始处理交换机{0}:{1}:{2}!", dev.Id, dev.Address, dev);
                            xmlContainer = processSW(dev, dict);
                            break;

                        case 2:        //路由器
                            logger.InfoFormat("开始处理路由器{0}:{1}:{2}!", dev.Id, dev.Address, dev);
                            xmlContainer = processRT(dev, dict);
                            break;

                        case 3:        //交换路由器
                            logger.InfoFormat("开始处理交换路由器{0}:{1}:{2}!", dev.Id, dev.Address, dev);
                            xmlContainer = processSW(dev, dict);
                            break;

                        default:
                            logger.InfoFormat("跳过未知设备{0}:{1}:{2}!", dev.Id, dev.Address, dev);
                            break;
                        }

                        if (null != xmlContainer)
                        {
                            _deviceByIds[dev.Id] = dev;
                            clearXml(xmlContainer, dict);
                        }
                    }

                    logger.Info("处理设备表完成,开始读线路表!");

                    using (linkLogger = new StreamWriter(Path.Combine(basePath, string.Concat("nanrui.modul.link.txt"))))
                    {
                        IList <Link> links = Link.FindBy <Link>(null);
                        logger.Info("读线路表完成,开始处理!");

                        foreach (Link link in links)
                        {
                            logger.InfoFormat("开始处理线路{0}:{1}!", link.Id, link);

                            XmlContainer xmlContainer = processLink(link, dict);

                            clearXml(xmlContainer, dict);


                            if (null != xmlContainer)
                            {
                                _linkByIds[link.Id] = link;
                                clearXml(xmlContainer, dict);
                            }
                        }
                    }
                    linkLogger = null;

                    logger.Info("处理线路表完成, 开始发送数据!");

                    foreach (XmlContainer xmlContainer in dict.Values)
                    {
                        XmlNode node = xmlContainer.Doc.SelectSingleNode("/IMSDATA/datas[@classname=\"RelationShip\"]");
                        if (null != node)
                        {
                            XmlNode parentNode = node.ParentNode;
                            parentNode.RemoveChild(node);
                            parentNode.AppendChild(node);
                        }

                        Send(xmlContainer.Doc, xmlContainer.Doc.OuterXml);
                    }

                    logger.Info("数据处理完成,配置发送程序退出!");
                }
                catch (Exception e)
                {
                    logger.Fatal("发生异常!", e);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }