而下面这一个类则是用于对异常发布器用到的三个文件进行读写的: ///
/// LogAccess 的摘要说明。 /// public class LogAccess { ///
/// 写入异常处理日志 /// ///
public static void WriteLogFile(ExceptionLogData ds) { ds.WriteXml(ExceptionSetting.FilePath +"ExceptionLog.XML"); } ///
/// 读出异常处理日志 /// ///
public static ExceptionLogData ReadLogFile() { ExceptionLogData ds = new ExceptionLogData(); if ( !File.Exists(ExceptionSetting.FilePath +"ExceptionLog.XML")) { ds.WriteXml(ExceptionSetting.FilePath +"ExceptionLog.XML"); } ds.Clear(); ds.ReadXml(ExceptionSetting.FilePath +"ExceptionLog.XML"); return ds; } ///
/// 读出自定义通用信息 /// ///
public static CustomOutMessageData GetCustomOutMessage() { CustomOutMessageData ds = new CustomOutMessageData(); if ( !File.Exists(ExceptionSetting.FilePath +"CustomOutMessage.XML")) { ds.WriteXml(ExceptionSetting.FilePath +"CustomOutMessage.XML"); } ds.Clear(); ds.ReadXml(ExceptionSetting.FilePath +"CustomOutMessage.XML"); return ds; } ///
/// 写入自定义通用信息 /// ///
public static void SaveCustomOutMessage(CustomOutMessageData ds) { ds.WriteXml(ExceptionSetting.FilePath +"CustomOutMessage.XML"); } ///
/// 获取异常处理定义信息 /// ///
读取到的异常处理定义信息 public static ExceptionDetailData GetExceptionDetail() { ExceptionDetailData exceptionDetailDS = new ExceptionDetailData(); if ( !File.Exists(ExceptionSetting.FilePath +"ExceptionList.xml")) { exceptionDetailDS.WriteXml(ExceptionSetting.FilePath +"ExceptionList.xml"); FileStream fs = new FileStream(ExceptionSetting.FilePath +"ExceptionList.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter w = new StreamWriter(fs); w.BaseStream.Seek(0, SeekOrigin.End); w.Write("nn<!--nType:异常的类型,系统依据此值和下面的InMessage一起判定异常的处理方式,此值与异常类型的完全限定名严格相等,不区分大小写;nInMessage:异常信息中的关键字,系统依据此关键字和上面的异常类型一起判定异常的处理方式,关键字最多可以有四个,不区分大小写,有层次关系;nHelpLink:自定义的有关异常的帮助文件路径;nOutMessage:自定义的向
用户显示的友好信息。n-->"); w.Flush(); w.Close(); } exceptionDetailDS.Clear(); exceptionDetailDS.ReadXml(ExceptionSetting.FilePath +"ExceptionList.xml"); return exceptionDetailDS; } ///
/// 保存异常处理定义信息 /// ///
要保存的异常处理定义信息 public static void SaveExceptionDetail(ExceptionDetailData exceptionDetailDS) { exceptionDetailDS.WriteXml(ExceptionSetting.FilePath +"ExceptionList.xml"); FileStream fs = new FileStream(ExceptionSetting.FilePath +"ExceptionList.xml", FileMode.OpenOrCreate, FileAccess.ReadWrite); StreamWriter w = new StreamWriter(fs); w.BaseStream.Seek(0, SeekOrigin.End); w.Write("nn<!--nType:异常的类型,系统依据此值和下面的InMessage一起判定异常的处理方式,此值与异常类型的完全限定名严格相等,不区分大小写;nInMessage:异常信息中的关键字,系统依据此关键字和上面的异常类型一起判定异常的处理方式,关键字最多可以有四个,不区分大小写,有层次关系;nHelpLink:自定义的有关异常的帮助文件路径;nOutMessage:自定义的向用户显示的友好信息。n-->"); w.Flush(); w.Close(); }
}
(未完待续)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10794571/viewspace-974809/,如需转载,请注明出处,否则将追究法律责任。