Ejemplo n.º 1
0
        public static void Initialize( XmlSetting config )
        {
            sqlList[(int)SQLDialect.SELECT_QUEUE] = "select * from BHistoryReadySend order by BCreatedTime";
            sqlList[(int)SQLDialect.DELETE_QUEUE_BY_TIME] = "delete from BHistoryReadySend where BID <= {0}";
            sqlList[(int)SQLDialect.COUNT_QUEUE] = "select count(*) from BHistoryReadySend";
            sqlList[(int)SQLDialect.DELETE_QUEUE] = "delete from BHistoryReadySend";

            sqlList[(int)SQLDialect.SELECT_MAP] = "select * from BHistorySendMap";
            sqlList[(int)SQLDialect.DELETE_MAP_TIMEOUT] = "delete from BHistorySendMap where ( {0} - BCreatedTime ) > 3000 ";
            sqlList[(int)SQLDialect.SELECT_MAP_SEND_TIMEOUT] = "select * from BHistorySendMap where ( {0} - BSendTime ) > 300 ";
            sqlList[(int)SQLDialect.UPDATE_MAP_SEND_TIME] = "update BHistorySendMap set BSendTime={0} where ( {0} - BSendTime ) > 300 ";
            sqlList[(int)SQLDialect.UPDATE_MAP] = "update BHistorySendMap set BCreatedTime=@1,BValue=@2 where BStatus=@3 and BStoreId=@4";
            sqlList[(int)SQLDialect.INSERT_MAP] = "insert into BHistorySendMap(BCreatedTime,BValue,BStatus,BStoreId,BMOId,BMOtype,BSendTime) values(@21,@22,@23,@24,@25,@26,0)";

            sqlList[(int)SQLDialect.DELETE_MAP_NOT_IN_HISTORY] = "delete from BHistorySendMap where BStoreId not in ( select BStoreId from BHistoryTarget )";
            sqlList[(int)SQLDialect.SELECT_DEVICE] = "select BOwnerId,BIP,BName,BDevType from DeviceStaticProperties";
            sqlList[(int)SQLDialect.SELECT_PORT] = "select BId,BDeviceId,BIfIndex, BIfMAC from PortStaticProperties";
            sqlList[(int)SQLDialect.SELECT_LINK] = "select BOwnerId,BDevice1,BPort1,BDevice2,BPort2,BName from LinkStaticProperties";
            sqlList[(int)SQLDialect.SELECT_DEVICEIP] = "select BOwnerId,BIP,BifIndex from DeviceIP";

            if (null != config)
            {
                foreach (int i in Enum.GetValues(typeof(SQLDialect)))
                {
                    string sql = config.ReadSetting(Enum.GetName(typeof(SQLDialect), i) + "/text()", null);
                    if (!string.IsNullOrEmpty(sql))
                        sqlList[i] = sql;
                }
            }
        }
Ejemplo n.º 2
0
        public static void Initialize(XmlSetting config)
        {
            sqlList[(int)SQLDialect.SELECT_QUEUE]         = "select * from BHistoryReadySend order by BCreatedTime";
            sqlList[(int)SQLDialect.DELETE_QUEUE_BY_TIME] = "delete from BHistoryReadySend where BID <= {0}";
            sqlList[(int)SQLDialect.COUNT_QUEUE]          = "select count(*) from BHistoryReadySend";
            sqlList[(int)SQLDialect.DELETE_QUEUE]         = "delete from BHistoryReadySend";

            sqlList[(int)SQLDialect.SELECT_MAP]              = "select * from BHistorySendMap";
            sqlList[(int)SQLDialect.DELETE_MAP_TIMEOUT]      = "delete from BHistorySendMap where ( {0} - BCreatedTime ) > 3000 ";
            sqlList[(int)SQLDialect.SELECT_MAP_SEND_TIMEOUT] = "select * from BHistorySendMap where ( {0} - BSendTime ) > 300 ";
            sqlList[(int)SQLDialect.UPDATE_MAP_SEND_TIME]    = "update BHistorySendMap set BSendTime={0} where ( {0} - BSendTime ) > 300 ";
            sqlList[(int)SQLDialect.UPDATE_MAP]              = "update BHistorySendMap set BCreatedTime=@1,BValue=@2 where BStatus=@3 and BStoreId=@4";
            sqlList[(int)SQLDialect.INSERT_MAP]              = "insert into BHistorySendMap(BCreatedTime,BValue,BStatus,BStoreId,BMOId,BMOtype,BSendTime) values(@21,@22,@23,@24,@25,@26,0)";

            sqlList[(int)SQLDialect.DELETE_MAP_NOT_IN_HISTORY] = "delete from BHistorySendMap where BStoreId not in ( select BStoreId from BHistoryTarget )";
            sqlList[(int)SQLDialect.SELECT_DEVICE]             = "select BOwnerId,BIP,BName,BDevType from DeviceStaticProperties";
            sqlList[(int)SQLDialect.SELECT_PORT]     = "select BId,BDeviceId,BIfIndex, BIfMAC from PortStaticProperties";
            sqlList[(int)SQLDialect.SELECT_LINK]     = "select BOwnerId,BDevice1,BPort1,BDevice2,BPort2,BName from LinkStaticProperties";
            sqlList[(int)SQLDialect.SELECT_DEVICEIP] = "select BOwnerId,BIP,BifIndex from DeviceIP";

            if (null != config)
            {
                foreach (int i in Enum.GetValues(typeof(SQLDialect)))
                {
                    string sql = config.ReadSetting(Enum.GetName(typeof(SQLDialect), i) + "/text()", null);
                    if (!string.IsNullOrEmpty(sql))
                    {
                        sqlList[i] = sql;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }