/// <summary> /// 指定されたXMLストリームの読み込みを行う。 /// </summary> /// <param name="stream">XMLストリーム</param> /// <param name="handleStartElement">開始タグの処理</param> /// <param name="handleEndElement">終了タグの処理</param> /// <param name="handleText">タグ間テキスト処理</param> public static void Load(Stream stream, HandleNode handleStartElement = null, HandleNode handleEndElement = null, HandleNode handleText = null) { using (XmlTextReader reader = new XmlTextReader(stream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (handleStartElement != null) { handleStartElement(reader); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (handleEndElement != null) { handleEndElement(reader); } } else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.SignificantWhitespace) { if (handleText != null) { handleText(reader); } } } } }
/// <summary> /// 处理错误 /// </summary> /// <param name="condition">条件</param> /// <param name="config">配置</param> /// <param name="LastTime">上一次运行时间</param> public void HandleError(Enums.EnumHandleCondition condition, ConfigNode config, DateTime?LastTime) { Enums.EnumHandleCondition cond = condition; HandleNode handleNode = null; if (config.Handles != null) { foreach (HandleNode node in config.Handles) { if (node.Condition == (int)cond) { handleNode = node; break; } } if (handleNode == null) { Log.Info("未找到处理方案,不处理这种情况"); } switch ((Enums.EnumHandlePlan)handleNode.Plan) { case Enums.EnumHandlePlan.停止服务或者进程: CloseNode(config); break; case Enums.EnumHandlePlan.重启服务或者进程: RebootNode(config); break; case Enums.EnumHandlePlan.等待Count满之后重启: if (Count >= handleNode.Count) { Log.Info("开始重启"); RebootNode(config); ResetState(); } else { Log.Info("重复次数" + Count++ + "未达到处理条件,不做处理"); } break; } } }
/// <summary> /// 指定されたXMLストリームの読み込みを行う。 /// </summary> /// <param name="stream">XMLストリーム</param> /// <param name="handleStartElement">開始タグの処理</param> /// <param name="handleEndElement">終了タグの処理</param> /// <param name="handleText">タグ間テキスト処理</param> public static void Load(Stream stream, HandleNode handleStartElement = null, HandleNode handleEndElement = null, HandleNode handleText = null) { using (XmlTextReader reader = new XmlTextReader(stream)) { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (handleStartElement != null) { handleStartElement(reader); } } else if (reader.NodeType == XmlNodeType.EndElement) { if (handleEndElement != null) { handleEndElement(reader); } } else if (reader.NodeType == XmlNodeType.Text || reader.NodeType == XmlNodeType.Whitespace || reader.NodeType == XmlNodeType.SignificantWhitespace) { if (handleText != null) { handleText(reader); } } } } }