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; } } } }
public ActionResult UpdateToken() { CacheHelper.Clear(); var cookies = CacheHelper.GetCache("token", () => XmlSetting.GetNodes(ConfigEntity.NodeName)); return(PartialView("pviewTokenContent", cookies)); }
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; } } }
public void Set(string name, string value) { var existing = SettingsList.FirstOrDefault(x => x.Key == name); if (existing == null) { existing = new XmlSetting { Key = name }; SettingsList.Add(existing); } if (existing.Value == value) { return; } existing.Value = value; HasChanged = true; }
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) { //base.OnAuthorization(filterContext); var dt = DateTime.Today; var cookie = filterContext.HttpContext.Request.Cookies[ConfigEntity.NodeName]; var cookies = CacheHelper.GetCache("token", () => XmlSetting.GetNodesByDate(ConfigEntity.NodeName, dt)); bool isCheck = false; if (!cookies.IsNullOrEmpty() && cookie != null) { isCheck = cookies.Exists(d => d.Token == cookie.Value); } if (!isCheck) { filterContext.Result = new RedirectResult("/Temptoken/Login"); } }
public ActionResult Login([Bind(Include = "Token")] TempToken tokenObj) { //TODO ModelState.Remove("Email"); if (ModelState.IsValid) { var dt = DateTime.Today; var cookies = XmlSetting.GetNodesByDate(ConfigEntity.NodeName, dt).ConvertAll(d => d?.Token); var aa = tokenObj.Token.ToSalt(ConfigEntity.tknSalt); if (!cookies.IsNullOrEmpty() && cookies.Contains(tokenObj?.Token.ToSalt(ConfigEntity.tknSalt))) { Response.Cookies[ConfigEntity.NodeName].Value = tokenObj.Token.ToSalt(ConfigEntity.tknSalt); //return RedirectToAction("Index", "Alarmnotes", new {date = Today}); return(RedirectToAction("Index", "Alarmnotes")); } ModelState.AddModelError("token", "Error Token"); } return(View()); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var dt = DateTime.Today; var cookies = XmlSetting.GetNodesByDate(nodeName, dt).ConvertAll(d => d.Token.ToSalt(tknSalt)); var cuttentCookie = filterContext.HttpContext.Request.Cookies[nodeName]; bool isCheck = false; if (!cookies.IsNullOrEmpty() && cuttentCookie != null) { var ck = cuttentCookie.Value.ToSalt(tknSalt); if (cookies.Contains(ck)) { isCheck = true; } } if (isCheck) { filterContext.Result = new RedirectResult(string.Format(redirectToAction, DateTime.Today.ToYYYYMMDD())); } }
static void ReadIni(List<KeyValuePair<IPSeg, string>> corporationIPSeg, XmlSetting[] entries) { if (null == entries) return; foreach (XmlSetting driver in entries) { string from = driver.ReadSetting("@from", null); string to = driver.ReadSetting("@to", null); string value = driver.ReadSetting("@value", null); IPSeg seg = null; try { seg = new IPSeg(from, to); corporationIPSeg.Add(new KeyValuePair<IPSeg,string>(seg, value)); logger.InfoFormat("{0}={1}", seg, value); } catch { } } }
static void Main(string[] args) { XmlNode n = new XmlNode(); n.Id = "ID属性"; n.InnerText = "テキスト"; n.Test = "テスト属性"; XmlSetting s1 = new XmlSetting(); s1.Add(n.Id, n); s1.WriteXml(); XmlSetting s2 = new XmlSetting(); s2.ReadXml(); System.Console.WriteLine("ID='{0}'", s2[n.Id].Id); System.Console.WriteLine("InnerText='{0}'", s2[n.Id].InnerText); System.Console.WriteLine("Test='{0}'", s2[n.Id].Test); System.Console.ReadLine(); }
public void FromXml(string xml) { XmlDocument doc = new XmlDocument(); try { TaskSettingsList.Clear(); doc.LoadXml(xml); XmlElement XmlTask = doc[this.TaskXmlName]; foreach (XmlElement XmlSetting in XmlTask) { TaskSettingItem SettingItem = new TaskSettingItem(XmlSetting.GetAttribute("Group"), XmlSetting.GetAttribute("Setting"), XmlSetting.GetAttribute("Value")); TaskSettingsList.Add(SettingItem); } } catch (XmlException) { } catch (Exception) { } }
public static string ToXml(this DataTable dataTable, XmlSetting xmlSetting) { if (dataTable.Columns.Count < 1) { return (string.Format("<{0}></{0}>", xmlSetting.RootTitle)); } var strAttr = ""; var strData = ""; var strBuff = ""; // build attributes if (xmlSetting.ShowAttribute) { strAttr += string.Format("<{0}>", xmlSetting.AttributesTitle); foreach (DataColumn column in dataTable.Columns) { strBuff += string.Format("<{0}>", xmlSetting.DataWrapperTitle); var cpi = column.GetType().GetProperties(); strBuff = cpi.Where(info => info.GetValue(column) != null && info.GetValue(column) != new object() && !ReferenceEquals(info.GetValue(column), "")) .Aggregate(strBuff, (current, info) => current + string.Format("<{0}>{1}</{0}>", info.Name, info.GetValue(column))); strBuff += string.Format("</{0}>", xmlSetting.DataWrapperTitle); } strAttr += string.Format("{0}</{1}>", strBuff, xmlSetting.AttributesTitle); } // build data strData += string.Format("<{0}>", xmlSetting.DataTitle); for (var i = 0; i < dataTable.Rows.Count; i++) { if (dataTable.Rows.Count != 1 || xmlSetting.ShowWrapperOnSingleRow) { strData += string.Format("<{0}>", xmlSetting.DataWrapperTitle); } strBuff = ""; for (var j = 0; j < dataTable.Columns.Count; j++) { strBuff += @"<{{columnName}}>{{columnData}}</{{columnName}}>" .BindData(new Dictionary <string, object> { { "{{columnName}}", dataTable.Columns[j].ColumnName }, { "{{columnData}}", dataTable.Rows[i][j] } }); } strData += strBuff; if (dataTable.Rows.Count != 1 || xmlSetting.ShowWrapperOnSingleRow) { strData += string.Format("</{0}>", xmlSetting.DataWrapperTitle); } } strData += string.Format("</{0}>", xmlSetting.DataTitle); return(string.Format("<{0}>{1}{2}</{0}>", xmlSetting.RootTitle, strAttr, strData)); }
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); } }
static void Main(string[] args) { try { _basePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); foreach (string l in args) { if (l.StartsWith("--PATH=", StringComparison.InvariantCultureIgnoreCase)) { _basePath = GetBasePath(_basePath, l.Substring(7)); } else if (l.StartsWith("--PrefixId=", StringComparison.InvariantCultureIgnoreCase)) { _prefixId = l.Substring(11); } } _isDebugging = File.Exists(Path.Combine(Path.GetDirectoryName(_basePath), "meijing.debuger.Running")); XmlSetting xmlSetting = new XmlSetting(new StreamReader(Path.Combine(_basePath, "nanrui.performance.config"))); XmlSetting defaultSetting = XmlSetting.ReadFromFile(Path.Combine(_basePath, "../nanrui.default.config")); _prefixId = defaultSetting.ReadSetting("/configuration/Locale/PrefixId/@value", _prefixId); _corporation = defaultSetting.ReadSetting("/configuration/Locale/Corporation/@value", ""); log4net.Config.XmlConfigurator.Configure(xmlSetting.SelectOne("/configuration/log4net").AsXmlNode() as System.Xml.XmlElement); _logger = LogManager.GetLogger("Betanetworks.Performance"); try { _logger.Info("程序启动,开始读配置"); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入操作系统类型!", null); ReadMap(_osTypes, xmlSetting.Select("/configuration/OSTypes/*")); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入设备类型!", null); ReadMap(_deviceTypes, xmlSetting.Select("/configuration/DeviceTypes/*")); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入服务类型!", null); ReadMap(_serverTypes, xmlSetting.Select("/configuration/ServiceTypes/*")); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入设备指标映射!", null); DispatchImpl.ReadDispatch(xmlSetting.SelectOne("/configuration/Maps/Device"), _deviceDispatcher, _logger); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入服务指标映射!", null); DispatchImpl.ReadDispatch(xmlSetting.SelectOne("/configuration/Maps/Service"), _serviceDispatcher, _logger); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入端口指标映射!", null); ReadMap(_performanceMapForPorts, xmlSetting.Select("/configuration/PerformanceKeyMaps/Port/*")); _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Trace, "载入线路指标映射!", null); ReadMap(_performanceMapForLinks, xmlSetting.Select("/configuration/PerformanceKeyMaps/Link/*")); List<PerformanceData> dataList = GetAllReadyRecords(); _logger.InfoFormat("读队列表中的数据成功,共{0}条!", dataList.Count); Dictionary<PerformanceKey, PerformanceData> dataMap = GetAllRecordFromMap(); _logger.InfoFormat("读MAP表中的数据成功,共{0}条!", dataMap.Count); MoveToMAP(dataList, dataMap); _logger.Info("更校报MAP表完成!"); long now = ToInt64(DateTime.Now); List<PerformanceBase> recordForSend = new List<PerformanceBase>(); foreach (PerformanceBase perf in GetSendRecordFromMap(dataList.Count > 0, now)) { recordForSend.Add(perf); } if (0 == recordForSend.Count) { _logger.InfoFormat("取得需要发送的消息{0}条,没有需要发送的数据,退出程序!", recordForSend.Count); return; } _logger.InfoFormat("取得需要发送的消息{0}条,开始登录MQ!", recordForSend.Count); int count = 0; try { _encoding = System.Text.Encoding.GetEncoding(defaultSetting.ReadSetting("/configuration/Locale/Encoding/@value", "utf-8")); using (Session session = NMSSupport.Create(defaultSetting)) { //IDestination destination = Apache.NMS.Util.SessionUtil.GetDestination(session, xmlSetting.ReadSetting("/configuration/MQ/DestinationName/@value")); //using (IMessageProducer producer = session.CreateProducer(destination)) { _logger.InfoFormat("登录MQ成功开始发送消息!"); string nowTimestamp = DateTime.Now.ToString(); foreach (PerformanceBase data in recordForSend.ToArray()) { string logPath = Path.Combine(Path.Combine(_basePath, "log"), data.MOType); if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath); string logFile = Path.Combine(logPath, string.Concat(data.MOType, "-", data.MOId, "-", encodeFile(data.StatusX), "-", data.StoreId, ".txt")); string historyFile = Path.Combine(logPath, string.Concat(data.MOType, "-", data.MOId, "-", encodeFile(data.StatusX), "-", data.StoreId, ".history")); using (StreamWriter writer = new StreamWriter(logFile)) { MapMessage message = createMapMessage(session, data, writer); if (null != message) { session.Send(Destination.PERFORMANCE, message); Session.Error[] errors = session.GetLastErrors(); foreach (Session.Error err in errors) { writer.Write("//MQError:channel="); writer.Write(err.Name); writer.Write("="); writer.WriteLine(err.exception.Message); } count++; recordForSend.Remove(data); if (_isDebugging) { File.AppendAllText(historyFile, nowTimestamp + " success\r\n"); } } else if (_isDebugging && File.Exists(historyFile)) { File.AppendAllText(historyFile, nowTimestamp + " error\r\n"); } } } } } _logger.InfoFormat("本次消息发送完成,共{0}条,开始更新发送时间!", count); _logger.InfoFormat("更新发送时间完成,退出程序!"); return; } catch (Exception e) { _logger.Fatal(e); } try { if (_isDebugging) { string nowTimestamp = DateTime.Now.ToString(); foreach (PerformanceBase data in recordForSend.ToArray()) { string logPath = Path.Combine(Path.Combine(_basePath, "log"), data.MOType); string historyFile = Path.Combine(logPath, string.Concat(data.MOType, "-", data.MOId, "-", encodeFile(data.StatusX), "-", data.StoreId, ".history")); if (File.Exists(historyFile)) { File.AppendAllText(historyFile, nowTimestamp + " mq error\r\n"); } } } } catch (Exception exx) { _logger.Fatal("记录调试数据时发生错误", exx); } } catch (Exception ex) { _logger.Fatal(ex); } } catch (Exception ex) { Console.WriteLine(ex); } }
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); } }
public static void SetXmlSetting(XmlSetting xmlSetting, string settingContent) { xmlSetting.SettingContent = settingContent; }
static void ReadMap(Dictionary<string, string> map, XmlSetting[] entries) { if (null == entries) return; foreach (XmlSetting driver in entries) { string key = driver.ReadSetting("@key", null); string value = driver.ReadSetting("@value", null); if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value)) continue; map[key] = value; logger.InfoFormat("{0}={1}", key, value); } }
static void ReadMap(Dictionary<int, string> map, XmlSetting[] entries) { if (null == entries) return; foreach (XmlSetting driver in entries) { string key = driver.ReadSetting("@key", null); string value = driver.ReadSetting("@value", null); int intKey = 0; if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value) || !int.TryParse(key, out intKey)) continue; map[intKey] = value; _logger.Logger.Log(typeof(Dispatcher), log4net.Core.Level.Verbose, string.Format("{0}={1}", intKey, value), null); } }