《吐血整理》C#一些常用的帮助类

常用类总结

简介:此文章总结了很多的帮助类,求推荐

1.简化Excel操作帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 using System.Data;
  5 using System.Configuration;
  6 using System.Data.OleDb;
  7 using System.IO;
  8 using NPOI.SS.UserModel;
  9 using NPOI.XSSF.UserModel;
 10 using NPOI.HSSF.UserModel;
 11 
 12 namespace Utilities
 13 {
 14     /// <summary>
 15     /// 简化Excel操作
 16     /// </summary>
 17     public class ExcelHelper
 18     {
 19         /// <summary>
 20         /// 从指定的Excell文件中获取数据,要求必须是规范的二维表数据且excel文件的首行为字段名
 21         /// </summary>
 22         /// <param name="fileUrl">服务器上的文件路径</param>
 23         /// <param name="head">获取哪些字段的值(例如:编号,姓名,入学时间),不提供时返回所有列</param>
 24         /// <returns>承载数据的DataSet(内存数据库)</returns>
 25         public static DataSet ImportDataFromExcell(string fileUrl, string head = "")
 26         {
 27             //string connExcel = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileUrl + ";Extended Properties=Excel 8.0";//07之前版本使用
 28             string connExcel = "Provider=Microsoft.Ace.OleDb.12.0;" + "data source=" + fileUrl + ";Extended Properties='Excel 12.0; HDR=Yes; IMEX=1'"; //此连接可以操作.xls与.xlsx文件 (支持Excel2003 和 Excel2007 的连接字符串)
 29             using (OleDbConnection oleDbConnection = new OleDbConnection(connExcel))
 30             {
 31                 oleDbConnection.Open();
 32                 //获得Excel的每页上的信息
 33                 DataTable dataTable = oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
 34                 //获得Excel中的页数
 35                 int pages = dataTable.Rows.Count;
 36                 string tableName = "";
 37                 string query = "";
 38                 DataSet ds = new DataSet();
 39                 OleDbDataAdapter oleAdapter = null;
 40                 for (int i = 0; i < pages; i++)
 41                 {
 42                     //获得每一页的名称
 43                     tableName = dataTable.Rows[i][2].ToString().Trim();
 44                     string tn = tableName.Remove(tableName.Length - 1);
 45                     tableName = "[" + tableName.Replace("'", "") + "]";
 46                     if (string.IsNullOrEmpty(head))
 47                         query = "SELECT * FROM " + tableName;
 48                     else
 49                         query = "SELECT " + head + " FROM " + tableName;
 50                     oleAdapter = new OleDbDataAdapter(query, connExcel);
 51                     //表示每页上的内容
 52                     DataTable dt = new DataTable(tn);
 53                     oleAdapter.Fill(dt);
 54                     ds.Tables.Add(dt);
 55                 }
 56                 return ds;
 57             }
 58         }
 59         /// <summary>
 60         /// 从Excel中读取数据
 61         /// </summary>
 62         /// <param name="fileName"></param>
 63         /// <param name="sheetName"></param>
 64         /// <param name="isFirstRowColumn"></param>
 65         /// <returns></returns>
 66         public DataTable GetDataToExcel(string fileName, string sheetName, bool isFirstRowColumn)
 67         {
 68             IWorkbook workbook = null;
 69             ISheet sheet = null;
 70             FileStream fs = null;
 71             DataTable dt = new DataTable();
 72             int startRow = 0;
 73             try
 74             {
 75                 fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
 76                 if (fileName.IndexOf(".xlsx") > 0)
 77                 {
 78                     workbook = new XSSFWorkbook(fs);
 79                 }
 80                 else if (fileName.IndexOf(".xls") > 0)
 81                 {
 82                     workbook = new HSSFWorkbook(fs);
 83                 }
 84 
 85                 if (sheetName != null)
 86                 {
 87                     sheet = workbook.GetSheet(sheetName);
 88                     if (sheet == null)
 89                     {
 90                         sheet = workbook.GetSheetAt(0);
 91                     }
 92                 }
 93                 else
 94                 {
 95                     sheet = workbook.GetSheetAt(0);
 96                 }
 97 
 98                 if (sheet != null)
 99                 {
100                     IRow firstRow = sheet.GetRow(sheet.FirstRowNum);
101                     int cellCount = firstRow.LastCellNum;
102                     if (isFirstRowColumn)
103                     {
104                         for (int i = firstRow.FirstCellNum; i < cellCount; i++)
105                         {
106                             ICell cell = firstRow.GetCell(i);
107                             if (cell != null)
108                             {
109                                 string cellValue = cell.StringCellValue;
110                                 if (cellValue != null)
111                                 {
112                                     DataColumn column = new DataColumn(cellValue);
113                                     dt.Columns.Add(column);
114                                 }
115                             }
116                         }
117                         startRow = sheet.FirstRowNum + 1;
118                     }
119                     else
120                     {
121                         startRow = sheet.FirstRowNum;
122                     }
123                     //取行
124                     int rowCount = sheet.LastRowNum;
125                     for (int i = startRow; i <= rowCount; i++)
126                     {
127                         IRow row = sheet.GetRow(i);
128                         if (row == null)
129                         {
130                             continue;
131                         }
132                         DataRow dr = dt.NewRow();
133                         int r = 0;
134                         for (int j = row.FirstCellNum; j < cellCount; j++)
135                         {
136                             dr[r++] = row.GetCell(j).ToString();
137                         }
138                         dt.Rows.Add(dr);
139                     }
140                 }
141                 return dt;
142             }
143             catch (Exception)
144             {
145                 return null;
146             }
147         }
148         /// <summary>
149         /// 将数据从DataTable中导入到Excel
150         /// </summary>
151         /// <param name="fileName">文件路径</param>
152         /// <param name="data">要导入的数据</param>
153         /// <param name="sheetName">sheet名称</param>
154         /// <param name="isColumnWritten">是否将表格的列名写入</param>
155         /// <returns></returns>
156         public int DataTableToExcel(string fileName, DataTable data, string sheetName, bool isColumnWritten) 
157         {
158             int count = 0;//最终写入的记录条数
159             IWorkbook workbook = null;
160             ISheet sheet = null;
161             FileStream fs = null;
162 
163             try
164             {
165                 fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
166                 if (fileName.IndexOf(".xlsx") > 0)
167                 {
168                     workbook = new XSSFWorkbook();
169                 }
170                 else if (fileName.IndexOf(".xls") > 0)
171                 {
172                     workbook = new HSSFWorkbook();
173                 }
174 
175                 //将列名写入第一行
176                 if (workbook != null)
177                 {
178                     sheet = workbook.CreateSheet(sheetName);
179                 }
180                 else
181                 {
182                     return -1;
183                 }
184 
185                 if (isColumnWritten)
186                 {//写入DataTable的列名
187                     IRow row = sheet.CreateRow(0);
188                     for (int j = 0; j < data.Columns.Count; j++)
189                     {
190                         row.CreateCell(j).SetCellValue(data.Columns[j].ColumnName);
191                     }
192                     count = 1;
193                 }
194                 else
195                 {
196                     count = 0;
197                 }
198 
199                 for (int i = 0; i < data.Rows.Count; i++)
200                 {
201                     IRow row = sheet.CreateRow(count);
202                     for (int j = 0; j < data.Columns.Count; j++)
203                     {
204                         row.CreateCell(j).SetCellValue(data.Rows[i][j].ToString());
205                     }
206                     count++;
207                 }
208 
209                 workbook.Write(fs);//将内容写入到对应的文件
210                 return count;
211             }
212             catch (Exception)
213             {
214                 return -1;
215             }
216         }
217     }
218 }
简化Excel操作帮助类
复制代码

2.扩展代码之用帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Data;
  6 using System.Runtime.Serialization.Json;
  7 using Newtonsoft.Json;
  8 
  9 namespace Utilities
 10 {
 11     /// <summary>
 12     /// 扩展代码之用
 13     /// </summary>
 14     public static class Extensions
 15     {
 16         /// <summary>
 17         /// 将2-1 中的“DataTable 对象转字符串”封装到 Extensions 中。
 18         /// </summary>
 19         /// <param name="dt"></param>
 20         /// <returns></returns>
 21         public static string ToHtml(this DataTable dt)
 22         {
 23             StringBuilder sb = new StringBuilder("<table><thead>");
 24             foreach (DataColumn c in dt.Columns)
 25             {
 26                 sb.AppendFormat($"<th>{c.ColumnName}</th>");
 27             }
 28             sb.Append("</thead><tbody>");
 29             foreach (DataRow r in dt.Rows)
 30             {
 31                 sb.Append("<tr>");
 32                 for (int i = 0; i < dt.Columns.Count; i++)
 33                 {
 34                     sb.AppendFormat($"<td>{r[i]}</td>");
 35                 }
 36                 sb.Append("</tr>");
 37             }
 38             sb.Append("</tbody></table>");
 39             return sb.ToString();
 40         }
 41         /// <summary>
 42         /// 为List集合扩展1个获取json字符串的方法,此方法可用于LayUI的数据表格组件
 43         /// </summary>
 44         /// <typeparam name="T">集合的类型</typeparam>
 45         /// <param name="list">数据集合</param>
 46         /// <param name="count">满足条件的数据的条数</param>
 47         /// <param name="dateTimeFormat">统一的日期时间格式</param>
 48         /// <returns>layui数据表格组件可用的json格式字符串</returns>
 49         public static String ToJsonForLayUITable<T>(this IList<T> list, int count, String dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
 50         {
 51             StringBuilder strJson = new StringBuilder();
 52             JsonSerializerSettings settings = new JsonSerializerSettings();
 53             settings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
 54             settings.DateFormatString = dateTimeFormat;
 55             settings.MaxDepth = 1; //设置序列化的最大层数  
 56             settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
 57             settings.NullValueHandling = NullValueHandling.Ignore;
 58             foreach (var item in list)
 59             {
 60                 strJson.Append(JsonConvert.SerializeObject(item, settings) + ",");
 61             }
 62             return "{\"code\":0,\"msg\":\"\",\"count\":" + count + ",\"data\":[" + strJson.ToString().TrimEnd(',') + "]}";
 63         }
 64         /// <summary>
 65         /// 系统中统一禁用DataSet自己的WriteXml,使用下边定义的格式,在客户端便于解析
 66         /// </summary>
 67         /// <param name="ds"></param>
 68         /// <returns></returns>
 69         public static string ToXml(this DataSet ds)
 70         {
 71             StringBuilder sb = new StringBuilder("<DataSet>  <Tables>");
 72             foreach (DataTable dt in ds.Tables)
 73                 sb.Append(dt.ToXml());
 74             sb.Append("</Tables></DataSet>");
 75             return sb.ToString();
 76         }
 77         /// <summary>
 78         /// 系统中统一禁用DataTable自己的WriteXml,使用下边定义的格式,在客户端便于解析。
 79         /// </summary>
 80         /// <param name="dt"></param>
 81         /// <returns></returns>
 82         public static string ToXml(this DataTable dt)
 83         {
 84             StringBuilder sb = new StringBuilder(String.Format("<DataTable Name='{0}'>  <Columns>", dt.TableName));
 85             int colCount = dt.Columns.Count, rowCount = dt.Rows.Count;
 86             for (int i = 0; i < colCount; i++)
 87             {
 88                 sb.Append("<").Append(dt.Columns[i].ColumnName).Append(" DataType='").Append(dt.Columns[i].DataType).Append("'/>");
 89             }
 90             sb.Append("  </Columns> <Rows>");
 91 
 92             for (int j = 0; j < rowCount; j++)
 93             {
 94                 sb.Append("<Row ");
 95                 for (int i = 0; i < colCount; i++)
 96                     sb.Append(dt.Columns[i].ColumnName + "='").Append(dt.Rows[j][i].ToString() + "' ");
 97                 sb.Append("/>");
 98             }
 99             sb.Append(" </Rows> </DataTable>");
100             return sb.ToString();
101         }
102 
103         static string GetJsonStr(string obj, DataContractJsonSerializer ser, System.IO.MemoryStream ms)
104         {
105             ms.Flush();
106             ser.WriteObject(ms, obj);
107             return System.Text.Encoding.UTF8.GetString(ms.ToArray());
108         }
109         /// <summary>
110         /// 将DataTable转为字符串
111         /// </summary>
112         /// <param name="dt"></param>
113         /// <returns></returns>
114         public static string ToJson(this DataTable dt)
115         {
116             StringBuilder sb = new StringBuilder("[");
117             int colCount = dt.Columns.Count, rowCount = dt.Rows.Count;
118             for (int j = 0; j < rowCount; j++)
119             {
120                 if (j == 0)
121                     sb.Append("{");
122                 else
123                     sb.Append(",{");
124 
125                 for (int i = 0; i < colCount; i++)
126                 {
127                     if (i == 0)
128                         sb.Append(string.Format(@"""{0}"":{1}", dt.Columns[i].ColumnName, IoHelper.SerializeJson(dt.Rows[j][i].ToString())));
129                     else
130                         sb.Append(string.Format(@",""{0}"":{1}", dt.Columns[i].ColumnName, IoHelper.SerializeJson(dt.Rows[j][i].ToString())));
131                 }
132                 sb.Append("}");
133             }
134             sb.Append("]");
135             return sb.ToString();
136         }
137         /// <summary>
138         /// 返回可以直接用于EasyUI的分页数据
139         /// </summary>
140         /// <param name="dt">DataTable 对象</param>
141         /// <param name="rowCount">本次分页查询条件符合记录的总数</param>
142         /// <returns></returns>
143         public static string ToJsonForEasyUI(this DataTable dt, int rowCount)
144         {
145             return "{" + string.Format(@"""total"":{0},""rows"":{1}", rowCount, dt.ToJson()) + "}";
146         }
147 
148 
149         /// <summary>
150         /// 将字符串转换为字节数组
151         /// </summary>
152         /// <remarks>
153         /// 在WebService服务端客户端的数据传输过程中,调用加密方法或者字符串中含有特殊符号,可能造成数据传输或解析错误
154         /// 调用此法使用字节数组传输,避免此类问题。
155         /// </remarks>
156         /// <param name="str">源字符串</param>
157         /// <returns>字节数组</returns>
158         public static byte[] ToPDSBytes(this string str)
159         {
160             System.Text.UTF8Encoding u = new System.Text.UTF8Encoding();
161             return u.GetBytes(str);
162         }
163         /// <summary>
164         /// 转换为字符串
165         /// </summary>
166         /// <remarks>
167         /// 这是ToPDSBytes方法的反向方法
168         /// </remarks>
169         /// <seealso cref="ToPDSBytes()"/>
170         /// <param name="bs">源字节数组</param>
171         /// <returns>字符串</returns>
172         public static string ToPDSString(this byte[] bs)
173         {
174             System.Text.UTF8Encoding u = new System.Text.UTF8Encoding();
175             return u.GetString(bs);
176         }
177 
178     }
179 }
扩展代码之用帮助类
复制代码

3.对图片的所有处理操作帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Drawing;
  4 using System.Drawing.Imaging;
  5 using System.IO;
  6 using System.Linq;
  7 using System.Runtime.InteropServices;
  8 using System.Text;
  9 
 10 namespace Utilities
 11 {
 12     /// <summary>
 13     /// 对图片的所有处理操作
 14     /// </summary>
 15     public static class ImageHelper
 16     {
 17         /// <summary>
 18         /// 生成网页验证码数据
 19         /// </summary>
 20         /// <param name="randomCode">验证码上显示的内容</param>
 21         /// <param name="imgWdith">宽度</param>
 22         /// <param name="imgHeight">高度</param>
 23         /// <returns></returns>
 24         public static byte[] CreateImage(string randomCode, int imgWdith = 70, int imgHeight = 28)
 25         {
 26             Bitmap map = new Bitmap(imgWdith, imgHeight);//创建图片背景  
 27             Graphics graph = Graphics.FromImage(map);
 28             graph.Clear(Color.AliceBlue);//清除画面,填充背景 
 29             Random rand = new Random();
 30             //背景噪点生成
 31             Brush blackPen = new SolidBrush(Color.LightGray);
 32             for (int i = 0; i < 50; i++)
 33             {
 34                 int x = rand.Next(0, map.Width);
 35                 int y = rand.Next(0, map.Height);
 36                 graph.FillRectangle(blackPen, x, y, 2, 2);
 37             }
 38             var chars = randomCode.ToCharArray();
 39             Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };
 40             string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };
 41             float[] fontSize = { 10f, 12f, 14f, 16f };
 42             var offset = 5f;
 43             var sf = new StringFormat { LineAlignment = StringAlignment.Center };
 44             foreach (var t in chars)
 45             {
 46                 var cindex = rand.Next(7);
 47                 var findex = rand.Next(5);
 48                 var f = new Font(font[findex], fontSize[rand.Next(0, 4)], FontStyle.Bold);
 49                 Brush b = new SolidBrush(c[cindex]);
 50                 var s = t.ToString();
 51                 graph.DrawString(s, f, b, new RectangleF(offset, 0, map.Width, map.Height), sf);
 52                 offset += graph.MeasureString(s, f).Width;
 53 
 54                 b.Dispose();
 55                 f.Dispose();
 56             }
 57             sf.Dispose();
 58             var ms = new MemoryStream();
 59             map.Save(ms, ImageFormat.Jpeg);
 60             var buffer = ms.ToArray();
 61 
 62             ms.Dispose();
 63             graph.Dispose();
 64             map.Dispose();
 65 
 66             return buffer;
 67         }
 68 
 69         /// <summary>
 70         /// 获取指定路径的位图对象
 71         /// </summary>
 72         /// <param name="path"></param>
 73         /// <returns></returns>
 74         public static Bitmap GetImage(string path)
 75         {
 76             byte[] bs = GetImageData(path);
 77             return bs.ToImage();
 78         }
 79         /// <summary>
 80         /// 获取指定字节数组的位图
 81         /// </summary>
 82         /// <param name="bs"></param>
 83         /// <returns></returns>
 84         public static Bitmap ToImage(this byte[] bs)
 85         {
 86             if (bs != null && bs.Length > 50)
 87             {
 88                 MemoryStream ms = new MemoryStream(bs);
 89                 return new Bitmap(ms);
 90             }
 91             else
 92                 return null;
 93         }
 94         /// <summary>
 95         /// 
 96         /// </summary>
 97         /// <param name="fileName"></param>
 98         /// <returns></returns>
 99         public static byte[] GetImageData(string fileName)
100         {
101             FileStream fs = null;
102             try
103             {
104                 if (File.Exists(fileName))
105                 {
106                     fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
107                     byte[] bs = new byte[fs.Length];
108                     fs.Read(bs, 0, bs.Length);
109                     return bs;
110                 }
111                 return null;
112             }
113             catch (Exception ex)
114             {
115                 Console.WriteLine("读取【{0}】时出错:{1}", fileName, ex.Message);
116                 return new byte[1];
117             }
118             finally
119             {
120                 if (fs != null)
121                     fs.Close();
122             }
123         }
124         /// <summary>
125         /// 将Image图像保存为png格式的文件
126         /// </summary>
127         /// <param name="img"></param>
128         /// <param name="path"></param>
129         public static void SavePng(Image img, string path)
130         {
131             img.Save(path, ImageFormat.Png);
132         }
133         /// <summary>
134         /// 将Image图像保存为bmp格式的文件
135         /// </summary>
136         /// <param name="img"></param>
137         /// <param name="path"></param>
138         public static void SaveBmp(Image img, string path)
139         {
140             img.Save(path, ImageFormat.Bmp);
141         }
142         /// <summary>
143         /// 将Image图像保存为jpg格式的文件
144         /// </summary>
145         /// <param name="img">Image对象</param>
146         /// <param name="path">要保存的图片路径</param>
147         /// <param name="quality">质量(0~100)</param>
148         public static void SaveJpg(Image img, string path, long quality = 75)
149         {
150             using (EncoderParameters paras = new EncoderParameters(1))
151             {
152                 paras.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
153                 img.Save(path, GetEncoderInfo("image/jpeg"), paras);
154             }
155         }
156         /// <summary>
157         /// 获取ImageCodecInfo信息
158         /// </summary>
159         /// <param name="mimeType"></param>
160         /// <returns></returns>
161         private static ImageCodecInfo GetEncoderInfo(String mimeType)
162         {
163             int j;
164             ImageCodecInfo[] encoders;
165             encoders = ImageCodecInfo.GetImageEncoders();
166             for (j = 0; j < encoders.Length; ++j)
167             {
168                 if (encoders[j].MimeType == mimeType)
169                     return encoders[j];
170             }
171             return null;
172         }
173         /// <summary>
174         /// 正方型裁剪
175         /// 以图片中心为轴心,截取正方型,然后等比缩放(常用于web开发中的头像截取)
176         /// </summary>
177         /// <param name="fromFile">原图Stream对象</param>
178         /// <param name="fileSaveUrl">缩略图存放地址</param>
179         /// <param name="side">指定的边长(正方型)</param>
180         /// <param name="quality">质量(范围0-100)</param>
181         public static void CutForSquare(System.IO.Stream fromFile, string fileSaveUrl, int side, int quality)
182         {
183             //创建目录
184             string dir = Path.GetDirectoryName(fileSaveUrl);
185             if (!Directory.Exists(dir))
186                 Directory.CreateDirectory(dir);
187             //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
188             System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true);
189             //原图宽高均小于模版,不作处理,直接保存
190             if (initImage.Width <= side && initImage.Height <= side)
191                 initImage.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
192             else
193             {
194                 //原始图片的宽、高
195                 int initWidth = initImage.Width;
196                 int initHeight = initImage.Height;
197                 //非正方型先裁剪为正方型
198                 if (initWidth != initHeight)
199                 {
200                     //截图对象
201                     System.Drawing.Image pickedImage = null;
202                     System.Drawing.Graphics pickedG = null;
203                     //宽大于高的横图
204                     if (initWidth > initHeight)
205                     {
206                         //对象实例化
207                         pickedImage = new System.Drawing.Bitmap(initHeight, initHeight);
208                         pickedG = System.Drawing.Graphics.FromImage(pickedImage);
209                         //设置质量
210                         pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
211                         pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
212                         //定位
213                         Rectangle fromR = new Rectangle((initWidth - initHeight) / 2, 0, initHeight, initHeight);
214                         Rectangle toR = new Rectangle(0, 0, initHeight, initHeight);
215                         //画图
216                         pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
217                         //重置宽
218                         initWidth = initHeight;
219                     }
220                     else//高大于宽的竖图
221                     {
222                         //对象实例化
223                         pickedImage = new System.Drawing.Bitmap(initWidth, initWidth);
224                         pickedG = System.Drawing.Graphics.FromImage(pickedImage);
225                         //设置质量
226                         pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
227                         pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
228                         //定位
229                         Rectangle fromR = new Rectangle(0, (initHeight - initWidth) / 2, initWidth, initWidth);
230                         Rectangle toR = new Rectangle(0, 0, initWidth, initWidth);
231                         //画图
232                         pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
233                         //重置高
234                         initHeight = initWidth;
235                     }
236                     //将截图对象赋给原图
237                     initImage = (System.Drawing.Image)pickedImage.Clone();
238                     //释放截图资源
239                     pickedG.Dispose();
240                     pickedImage.Dispose();
241                 }
242                 //缩略图对象
243                 using (System.Drawing.Image resultImage = new System.Drawing.Bitmap(side, side))
244                 {
245                     using (System.Drawing.Graphics resultG = System.Drawing.Graphics.FromImage(resultImage))
246                     {
247                         //设置质量
248                         resultG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
249                         resultG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
250                         //用指定背景色清空画布
251                         resultG.Clear(Color.White);
252                         //绘制缩略图
253                         resultG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, side, side), new System.Drawing.Rectangle(0, 0, initWidth, initHeight), System.Drawing.GraphicsUnit.Pixel);
254                         //关键质量控制
255                         //获取系统编码类型数组,包含了jpeg,bmp,png,gif,tiff
256                         ImageCodecInfo[] icis = ImageCodecInfo.GetImageEncoders();
257                         ImageCodecInfo ici = null;
258                         foreach (ImageCodecInfo i in icis)
259                         {
260                             if (i.MimeType == "image/jpeg" || i.MimeType == "image/bmp" || i.MimeType == "image/png" || i.MimeType == "image/gif")
261                             {
262                                 ici = i;
263                             }
264                         }
265                         using (EncoderParameters ep = new EncoderParameters(1))
266                         {
267                             ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
268                             //保存缩略图
269                             resultImage.Save(fileSaveUrl, ici, ep);
270                             //释放关键质量控制所用资源
271                             ep.Dispose();
272                         }
273                         //释放缩略图资源
274                         resultG.Dispose();
275                     }
276                     resultImage.Dispose();
277                 }
278                 //释放原始图片资源
279                 initImage.Dispose();
280             }
281         }
282         /// <summary>
283         /// 指定长宽裁剪(按模版比例最大范围的裁剪图片并缩放至模版尺寸)
284         /// </summary>
285         /// <param name="fromFile">原图Stream对象</param>
286         /// <param name="fileSaveUrl">保存路径</param>
287         /// <param name="maxWidth">最大宽(单位:px)</param>
288         /// <param name="maxHeight">最大高(单位:px)</param>
289         /// <param name="quality">质量(范围0-100)</param>
290         public static void CutForCustom(System.IO.Stream fromFile, string fileSaveUrl, int maxWidth, int maxHeight, int quality)
291         {
292             //从文件获取原始图片,并使用流中嵌入的颜色管理信息
293             using (System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true))
294             {
295                 CutForCustom(initImage, fileSaveUrl, maxWidth, maxHeight, quality);
296             }
297         }
298 
299         /// <summary>
300         /// 按模版比例最大范围的裁剪图片并缩放至模版尺寸
301         /// </summary>
302         /// <param name="initImage">原始图片</param>
303         /// <param name="fileSaveUrl">要保存的路径</param>
304         /// <param name="maxWidth">最大宽度px</param>
305         /// <param name="maxHeight">最大高度px</param>
306         /// <param name="quality">图片质量(范围0-100)</param>
307         public static void CutForCustom(System.Drawing.Image initImage, string fileSaveUrl, int maxWidth, int maxHeight, int quality, float dpi = 96)
308         {
309             //原图宽高均小于模版,不作处理,直接保存
310             if (initImage.Width <= maxWidth && initImage.Height <= maxHeight)
311                 initImage.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
312             else
313             {
314                 //模版的宽高比例
315                 double templateRate = (double)maxWidth / maxHeight;
316                 //原图片的宽高比例
317                 double initRate = (double)initImage.Width / initImage.Height;
318                 Bitmap templateImage = new System.Drawing.Bitmap(maxWidth, maxHeight); //按模版大小生成最终图片
319                 templateImage.SetResolution(dpi, dpi);
320                 //原图与模版比例相等,直接缩放
321                 if (templateRate == initRate)
322                 {
323                     System.Drawing.Graphics templateG = System.Drawing.Graphics.FromImage(templateImage);
324                     templateG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
325                     templateG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
326                     templateG.Clear(Color.White);
327                     templateG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, maxWidth, maxHeight), new System.Drawing.Rectangle(0, 0, initImage.Width, initImage.Height), System.Drawing.GraphicsUnit.Pixel);
328                     templateImage.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
329                 }
330                 //原图与模版比例不等,裁剪后缩放
331                 else
332                 {
333                     //裁剪对象
334                     System.Drawing.Image pickedImage = null;
335                     System.Drawing.Graphics pickedG = null;
336                     //定位
337                     Rectangle fromR = new Rectangle(0, 0, 0, 0);//原图裁剪定位
338                     Rectangle toR = new Rectangle(0, 0, 0, 0);//目标定位
339                                                               //宽为标准进行裁剪
340                     if (templateRate > initRate)
341                     {
342                         //裁剪对象实例化
343                         pickedImage = new System.Drawing.Bitmap(initImage.Width, (int)System.Math.Floor(initImage.Width / templateRate));
344                         pickedG = System.Drawing.Graphics.FromImage(pickedImage);
345                         //裁剪源定位
346                         fromR.X = 0;
347                         fromR.Y = (int)System.Math.Floor((initImage.Height - initImage.Width / templateRate) / 2);
348                         fromR.Width = initImage.Width;
349                         fromR.Height = (int)System.Math.Floor(initImage.Width / templateRate);
350                         //裁剪目标定位
351                         toR.X = 0;
352                         toR.Y = 0;
353                         toR.Width = initImage.Width;
354                         toR.Height = (int)System.Math.Floor(initImage.Width / templateRate);
355                     }
356                     //高为标准进行裁剪
357                     else
358                     {
359                         pickedImage = new System.Drawing.Bitmap((int)System.Math.Floor(initImage.Height * templateRate), initImage.Height);
360                         pickedG = System.Drawing.Graphics.FromImage(pickedImage);
361                         fromR.X = (int)System.Math.Floor((initImage.Width - initImage.Height * templateRate) / 2);
362                         fromR.Y = 0;
363                         fromR.Width = (int)System.Math.Floor(initImage.Height * templateRate);
364                         fromR.Height = initImage.Height;
365                         toR.X = 0;
366                         toR.Y = 0;
367                         toR.Width = (int)System.Math.Floor(initImage.Height * templateRate);
368                         toR.Height = initImage.Height;
369                     }
370 
371                     //设置质量
372                     pickedG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
373                     pickedG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
374                     //裁剪
375                     pickedG.DrawImage(initImage, toR, fromR, System.Drawing.GraphicsUnit.Pixel);
376 
377                     System.Drawing.Graphics templateG = System.Drawing.Graphics.FromImage(templateImage);
378                     templateG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
379                     templateG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
380                     templateG.Clear(Color.White);
381                     templateG.DrawImage(pickedImage, new System.Drawing.Rectangle(0, 0, maxWidth, maxHeight), new System.Drawing.Rectangle(0, 0, pickedImage.Width, pickedImage.Height), System.Drawing.GraphicsUnit.Pixel);
382                     ////保存缩略图
383                     //templateImage.Save(fileSaveUrl, ici, ep);
384                     EncoderParameters paras = new EncoderParameters(1);
385                     paras.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);
386                     templateImage.Save(fileSaveUrl, GetEncoderInfo("image/jpeg"), paras);
387                     //释放资源
388                     templateG.Dispose();
389                     templateImage.Dispose();
390                     pickedG.Dispose();
391                     pickedImage.Dispose();
392                 }
393             }
394         }
395         /// <summary>
396         /// 图片等比缩放并设置水印
397         /// <param name="fromFile">原图Stream对象</param>
398         /// <param name="savePath">缩略图存放地址</param>
399         /// <param name="targetWidth">指定的最大宽度</param>
400         /// <param name="targetHeight">指定的最大高度</param>
401         /// <param name="watermarkText">水印文字(为""表示不使用水印)</param>
402         /// <param name="watermarkImage">水印图片路径(为""表示不使用水印)</param>
403         ///  </summary>
404         public static void ZoomAuto(System.IO.Stream fromFile, string savePath, System.Double targetWidth, System.Double targetHeight, string watermarkText, string watermarkImage)
405         {
406             //创建目录
407             string dir = Path.GetDirectoryName(savePath);
408             if (!Directory.Exists(dir))
409                 Directory.CreateDirectory(dir);
410             //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息)
411             System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true);
412 
413             //原图宽高均小于模版,不作处理,直接保存
414             if (initImage.Width <= targetWidth && initImage.Height <= targetHeight)
415             {
416                 //文字水印
417                 if (watermarkText != "")
418                 {
419                     using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(initImage))
420                     {
421                         System.Drawing.Font fontWater = new Font("黑体", 10);
422                         System.Drawing.Brush brushWater = new SolidBrush(Color.White);
423                         gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10);
424                         gWater.Dispose();
425                     }
426                 }
427                 //透明图片水印
428                 if (watermarkImage != "")
429                 {
430                     if (File.Exists(watermarkImage))
431                     {
432                         //获取水印图片
433                         using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage))
434                         {
435                             //水印绘制条件:原始图片宽高均大于或等于水印图片
436                             if (initImage.Width >= wrImage.Width && initImage.Height >= wrImage.Height)
437                             {
438                                 Graphics gWater = Graphics.FromImage(initImage);
439 
440                                 //透明属性
441                                 ImageAttributes imgAttributes = new ImageAttributes();
442                                 ColorMap colorMap = new ColorMap();
443                                 colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
444                                 colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
445                                 ColorMap[] remapTable = { colorMap };
446                                 imgAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
447 
448                                 float[][] colorMatrixElements = {
449                             new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
450                             new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
451                             new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
452                             new float[] {0.0f,  0.0f,  0.0f,  0.5f, 0.0f},//透明度:0.5
453                             new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
454                         };
455 
456                                 ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
457                                 imgAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
458                                 gWater.DrawImage(wrImage, new Rectangle(initImage.Width - wrImage.Width, initImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, GraphicsUnit.Pixel, imgAttributes);
459 
460                                 gWater.Dispose();
461                             }
462                             wrImage.Dispose();
463                         }
464                     }
465                 }
466 
467                 //保存
468                 initImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
469             }
470             else
471             {
472                 //缩略图宽、高计算
473                 double newWidth = initImage.Width;
474                 double newHeight = initImage.Height;
475                 //宽大于高或宽等于高(横图或正方)
476                 if (initImage.Width > initImage.Height || initImage.Width == initImage.Height)
477                 {
478                     //如果宽大于模版
479                     if (initImage.Width > targetWidth)
480                     {
481                         //宽按模版,高按比例缩放
482                         newWidth = targetWidth;
483                         newHeight = initImage.Height * (targetWidth / initImage.Width);
484                     }
485                 }
486                 //高大于宽(竖图)
487                 else
488                 {
489                     //如果高大于模版
490                     if (initImage.Height > targetHeight)
491                     {
492                         //高按模版,宽按比例缩放
493                         newHeight = targetHeight;
494                         newWidth = initImage.Width * (targetHeight / initImage.Height);
495                     }
496                 }
497                 //生成新图
498                 //新建一个bmp图片
499                 System.Drawing.Image newImage = new System.Drawing.Bitmap((int)newWidth, (int)newHeight);
500                 //新建一个画板
501                 System.Drawing.Graphics newG = System.Drawing.Graphics.FromImage(newImage);
502                 //设置质量
503                 newG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
504                 newG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
505                 //置背景色
506                 newG.Clear(Color.White);
507                 //画图
508                 newG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, newImage.Width, newImage.Height), new System.Drawing.Rectangle(0, 0, initImage.Width, initImage.Height), System.Drawing.GraphicsUnit.Pixel);
509 
510                 //文字水印
511                 if (watermarkText != "")
512                 {
513                     using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(newImage))
514                     {
515                         System.Drawing.Font fontWater = new Font("宋体", 10);
516                         System.Drawing.Brush brushWater = new SolidBrush(Color.White);
517                         gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10);
518                         gWater.Dispose();
519                     }
520                 }
521 
522                 //透明图片水印
523                 if (watermarkImage != "")
524                 {
525                     if (File.Exists(watermarkImage))
526                     {
527                         //获取水印图片
528                         using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage))
529                         {
530                             //水印绘制条件:原始图片宽高均大于或等于水印图片
531                             if (newImage.Width >= wrImage.Width && newImage.Height >= wrImage.Height)
532                             {
533                                 Graphics gWater = Graphics.FromImage(newImage);
534 
535                                 //透明属性
536                                 ImageAttributes imgAttributes = new ImageAttributes();
537                                 ColorMap colorMap = new ColorMap();
538                                 colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
539                                 colorMap.NewColor = Color.FromArgb(0, 0, 0, 0);
540                                 ColorMap[] remapTable = { colorMap };
541                                 imgAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap);
542 
543                                 float[][] colorMatrixElements = {
544                             new float[] {1.0f,  0.0f,  0.0f,  0.0f, 0.0f},
545                             new float[] {0.0f,  1.0f,  0.0f,  0.0f, 0.0f},
546                             new float[] {0.0f,  0.0f,  1.0f,  0.0f, 0.0f},
547                             new float[] {0.0f,  0.0f,  0.0f,  0.5f, 0.0f},//透明度:0.5
548                             new float[] {0.0f,  0.0f,  0.0f,  0.0f, 1.0f}
549                         };
550 
551                                 ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
552                                 imgAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
553                                 gWater.DrawImage(wrImage, new Rectangle(newImage.Width - wrImage.Width, newImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, GraphicsUnit.Pixel, imgAttributes);
554                                 gWater.Dispose();
555                             }
556                             wrImage.Dispose();
557                         }
558                     }
559                 }
560                 //保存缩略图
561                 newImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
562                 //释放资源
563                 newG.Dispose();
564                 newImage.Dispose();
565                 initImage.Dispose();
566             }
567         }
568         /// <summary>
569         /// 截取源图中指定部分区域的图片,并存储为指定的文件。
570         /// </summary>
571         /// <param name="sourceFileName">源图地址</param>
572         /// <param name="saveFilePath">区域图的地址</param>
573         /// <param name="width">截取图片的宽度</param>
574         /// <param name="height">截取图片的高度</param>
575         /// <param name="offsetX">开始截取图片的X坐标</param>
576         /// <param name="offsetY">开始截取图片的Y坐标</param>
577         /// <param name="qu">保存质量</param>
578         /// <param name="xdpi">横向dpi值</param>
579         /// <param name="ydpi">纵向dpi值</param>
580         public static void SavePartOfImageRec(string sourceFileName, string saveFilePath, int width, int height, int offsetX, int offsetY, int qu = 100, int xdpi = 96, int ydpi = 96)
581         {
582             using (Bitmap sourceBitmap = new Bitmap(sourceFileName))
583             {
584                 using (Bitmap resultBitmap = new Bitmap(width, height))
585                 {
586                     resultBitmap.SetResolution(xdpi, ydpi);
587                     using (Graphics g = Graphics.FromImage(resultBitmap))
588                     {
589                         Rectangle resultRectangle = new Rectangle(0, 0, width, height);
590                         Rectangle sourceRectangle = new Rectangle(0 + offsetX, 0 + offsetY, sourceBitmap.Width, sourceBitmap.Height);
591                         g.DrawImage(sourceBitmap, resultRectangle, sourceRectangle, GraphicsUnit.Pixel);
592                     }
593                     EncoderParameters paras = new EncoderParameters(1);
594                     paras.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)qu);
595                     resultBitmap.Save(saveFilePath, GetEncoderInfo("image/jpeg"), paras);
596                 }
597             }
598         }
599         /// <summary>
600         /// 获取一张图片的指定部分,在一个指定位置画一个要截取的图像       
601         /// </summary>
602         /// <param name="sourceFileName">原始图片路径名称</param>
603         /// <param name="width">截取图片的宽度</param>
604         /// <param name="height">截取图片的高度</param>
605         /// <param name="offsetX">开始截取图片的X坐标</param>
606         /// <param name="offsetY">开始截取图片的Y坐标</param>
607         /// <returns>指定部分转换成的字节数组</returns>
608         /// <param name="qu">保存质量</param>
609         /// <param name="xdpi">横向dpi值</param>
610         /// <param name="ydpi">纵向dpi值</param>
611         public static byte[] GetPartOfImageRec(string sourceFileName, int width, int height, int offsetX, int offsetY, int qu = 100, int xdpi = 96, int ydpi = 96)
612         {
613             MemoryStream ms = new MemoryStream();
614             using (Bitmap sourceBitmap = new Bitmap(sourceFileName))
615             {
616                 using (Bitmap resultBitmap = new Bitmap(width, height))
617                 {
618                     resultBitmap.SetResolution(xdpi, ydpi);
619                     using (Graphics g = Graphics.FromImage(resultBitmap))
620                     {
621                         Rectangle resultRectangle = new Rectangle(0, 0, width, height);
622                         Rectangle sourceRectangle = new Rectangle(0 + offsetX, 0 + offsetY, sourceBitmap.Width, sourceBitmap.Height);
623                         g.DrawImage(sourceBitmap, resultRectangle, sourceRectangle, GraphicsUnit.Pixel);
624                     }
625                     EncoderParameters paras = new EncoderParameters(1);
626                     paras.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)qu);
627                     resultBitmap.Save(ms, GetEncoderInfo("image/jpeg"), paras);
628                 }
629             }
630             return ms.ToArray();
631         }
632 
633         /// <summary>
634         /// 设置图形颜色  边缘的色彩更换成新的颜色
635         /// </summary>
636         /// <param name="p_Image">图片</param>
637         /// <param name="p_OldColor">老的边缘色彩</param>
638         /// <param name="p_NewColor">新的边缘色彩</param>
639         /// <param name="p_Float">溶差</param>
640         /// <returns>清理后的图形</returns>
641         public static Image SetImageColorBrim(Image p_Image, Color p_OldColor, Color p_NewColor, int p_Float)
642         {
643             int _Width = p_Image.Width;
644             int _Height = p_Image.Height;
645 
646             Bitmap _NewBmp = new Bitmap(_Width, _Height, PixelFormat.Format32bppArgb);
647             Graphics _Graphics = Graphics.FromImage(_NewBmp);
648             _Graphics.DrawImage(p_Image, new Rectangle(0, 0, _Width, _Height));
649             _Graphics.Dispose();
650 
651             BitmapData _Data = _NewBmp.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
652             _Data.PixelFormat = PixelFormat.Format32bppArgb;
653             int _ByteSize = _Data.Stride * _Height;
654             byte[] _DataBytes = new byte[_ByteSize];
655             Marshal.Copy(_Data.Scan0, _DataBytes, 0, _ByteSize);
656 
657             int _Index = 0;
658             #region659             for (int z = 0; z != _Height; z++)
660             {
661                 _Index = z * _Data.Stride;
662                 for (int i = 0; i != _Width; i++)
663                 {
664                     Color _Color = Color.FromArgb(_DataBytes[_Index + 3], _DataBytes[_Index + 2], _DataBytes[_Index + 1], _DataBytes[_Index]);
665 
666                     if (ScanColor(_Color, p_OldColor, p_Float))
667                     {
668                         _DataBytes[_Index + 3] = (byte)p_NewColor.A;
669                         _DataBytes[_Index + 2] = (byte)p_NewColor.R;
670                         _DataBytes[_Index + 1] = (byte)p_NewColor.G;
671                         _DataBytes[_Index] = (byte)p_NewColor.B;
672                         _Index += 4;
673                     }
674                     else
675                     {
676                         break;
677                     }
678                 }
679                 _Index = (z + 1) * _Data.Stride;
680                 for (int i = 0; i != _Width; i++)
681                 {
682                     Color _Color = Color.FromArgb(_DataBytes[_Index - 1], _DataBytes[_Index - 2], _DataBytes[_Index - 3], _DataBytes[_Index - 4]);
683 
684                     if (ScanColor(_Color, p_OldColor, p_Float))
685                     {
686                         _DataBytes[_Index - 1] = (byte)p_NewColor.A;
687                         _DataBytes[_Index - 2] = (byte)p_NewColor.R;
688                         _DataBytes[_Index - 3] = (byte)p_NewColor.G;
689                         _DataBytes[_Index - 4] = (byte)p_NewColor.B;
690                         _Index -= 4;
691                     }
692                     else
693                     {
694                         break;
695                     }
696                 }
697             }
698             #endregion
699 
700             #region701 
702             for (int i = 0; i != _Width; i++)
703             {
704                 _Index = i * 4;
705                 for (int z = 0; z != _Height; z++)
706                 {
707                     Color _Color = Color.FromArgb(_DataBytes[_Index + 3], _DataBytes[_Index + 2], _DataBytes[_Index + 1], _DataBytes[_Index]);
708                     if (ScanColor(_Color, p_OldColor, p_Float))
709                     {
710                         _DataBytes[_Index + 3] = (byte)p_NewColor.A;
711                         _DataBytes[_Index + 2] = (byte)p_NewColor.R;
712                         _DataBytes[_Index + 1] = (byte)p_NewColor.G;
713                         _DataBytes[_Index] = (byte)p_NewColor.B;
714                         _Index += _Data.Stride;
715                     }
716                     else
717                     {
718                         break;
719                     }
720                 }
721                 _Index = (i * 4) + ((_Height - 1) * _Data.Stride);
722                 for (int z = 0; z != _Height; z++)
723                 {
724                     Color _Color = Color.FromArgb(_DataBytes[_Index + 3], _DataBytes[_Index + 2], _DataBytes[_Index + 1], _DataBytes[_Index]);
725                     if (ScanColor(_Color, p_OldColor, p_Float))
726                     {
727                         _DataBytes[_Index + 3] = (byte)p_NewColor.A;
728                         _DataBytes[_Index + 2] = (byte)p_NewColor.R;
729                         _DataBytes[_Index + 1] = (byte)p_NewColor.G;
730                         _DataBytes[_Index] = (byte)p_NewColor.B;
731                         _Index -= _Data.Stride;
732                     }
733                     else
734                     {
735                         break;
736                     }
737                 }
738             }
739 
740 
741             #endregion
742             Marshal.Copy(_DataBytes, 0, _Data.Scan0, _ByteSize);
743             _NewBmp.UnlockBits(_Data);
744             return _NewBmp;
745         }
746         /// <summary>
747         /// 设置图形颜色  所有的色彩更换成新的颜色
748         /// </summary>
749         /// <param name="p_Image">图片</param>
750         /// <param name="p_OdlColor">老的颜色</param>
751         /// <param name="p_NewColor">新的颜色</param>
752         /// <param name="p_Float">溶差</param>
753         /// <returns>清理后的图形</returns>
754         public static Image SetImageColorAll(Image p_Image, Color p_OdlColor, Color p_NewColor, int p_Float)
755         {
756             int _Width = p_Image.Width;
757             int _Height = p_Image.Height;
758 
759             Bitmap _NewBmp = new Bitmap(_Width, _Height, PixelFormat.Format32bppArgb);
760             Graphics _Graphics = Graphics.FromImage(_NewBmp);
761             _Graphics.DrawImage(p_Image, new Rectangle(0, 0, _Width, _Height));
762             _Graphics.Dispose();
763 
764             BitmapData _Data = _NewBmp.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
765             _Data.PixelFormat = PixelFormat.Format32bppArgb;
766             int _ByteSize = _Data.Stride * _Height;
767             byte[] _DataBytes = new byte[_ByteSize];
768             Marshal.Copy(_Data.Scan0, _DataBytes, 0, _ByteSize);
769 
770             int _WhileCount = _Width * _Height;
771             int _Index = 0;
772             for (int i = 0; i != _WhileCount; i++)
773             {
774                 Color _Color = Color.FromArgb(_DataBytes[_Index + 3], _DataBytes[_Index + 2], _DataBytes[_Index + 1], _DataBytes[_Index]);
775                 if (ScanColor(_Color, p_OdlColor, p_Float))
776                 {
777                     _DataBytes[_Index + 3] = (byte)p_NewColor.A;
778                     _DataBytes[_Index + 2] = (byte)p_NewColor.R;
779                     _DataBytes[_Index + 1] = (byte)p_NewColor.G;
780                     _DataBytes[_Index] = (byte)p_NewColor.B;
781                 }
782                 _Index += 4;
783             }
784             Marshal.Copy(_DataBytes, 0, _Data.Scan0, _ByteSize);
785             _NewBmp.UnlockBits(_Data);
786             return _NewBmp;
787         }
788         /// <summary>
789         /// 设置图形颜色  坐标的颜色更换成新的色彩 (漏斗)
790         /// </summary>
791         /// <param name="p_Image">新图形</param>
792         /// <param name="p_Point">位置</param>
793         /// <param name="p_NewColor">新的色彩</param>
794         /// <param name="p_Float">溶差</param>
795         /// <returns>清理后的图形</returns>
796         public static Image SetImageColorPoint(Image p_Image, Point p_Point, Color p_NewColor, int p_Float)
797         {
798             int _Width = p_Image.Width;
799             int _Height = p_Image.Height;
800 
801             if (p_Point.X > _Width - 1) return p_Image;
802             if (p_Point.Y > _Height - 1) return p_Image;
803 
804             Bitmap _SS = (Bitmap)p_Image;
805             Color _Scolor = _SS.GetPixel(p_Point.X, p_Point.Y);//获取指定坐标的颜色
806                                                                //创建一个空位图,将源图绘制到此位图中
807             Bitmap _NewBmp = new Bitmap(_Width, _Height, PixelFormat.Format32bppArgb);
808             Graphics _Graphics = Graphics.FromImage(_NewBmp);
809             _Graphics.DrawImage(p_Image, new Rectangle(0, 0, _Width, _Height));
810             _Graphics.Dispose();
811 
812             BitmapData _Data = _NewBmp.LockBits(new Rectangle(0, 0, _Width, _Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
813             _Data.PixelFormat = PixelFormat.Format32bppArgb;
814             int _ByteSize = _Data.Stride * _Height;
815             byte[] _DataBytes = new byte[_ByteSize];
816             Marshal.Copy(_Data.Scan0, _DataBytes, 0, _ByteSize);
817 
818 
819             int _Index = (p_Point.Y * _Data.Stride) + (p_Point.X * 4);
820 
821             Color _OldColor = Color.FromArgb(_DataBytes[_Index + 3], _DataBytes[_Index + 2], _DataBytes[_Index + 1], _DataBytes[_Index]);
822 
823             if (_OldColor.Equals(p_NewColor)) return p_Image;
824             Stack<Point> _ColorStack = new Stack<Point>(1000);
825             _ColorStack.Push(p_Point);
826 
827             _DataBytes[_Index + 3] = (byte)p_NewColor.A;
828             _DataBytes[_Index + 2] = (byte)p_NewColor.R;
829             _DataBytes[_Index + 1] = (byte)p_NewColor.G;
830             _DataBytes[_Index] = (byte)p_NewColor.B;
831 
832             do
833             {
834                 Point _NewPoint = (Point)_ColorStack.Pop();
835 
836                 if (_NewPoint.X > 0) SetImageColorPoint(_DataBytes, _Data.Stride, _ColorStack, _NewPoint.X - 1, _NewPoint.Y, _OldColor, p_NewColor, p_Float);
837                 if (_NewPoint.Y > 0) SetImageColorPoint(_DataBytes, _Data.Stride, _ColorStack, _NewPoint.X, _NewPoint.Y - 1, _OldColor, p_NewColor, p_Float);
838 
839                 if (_NewPoint.X < _Width - 1) SetImageColorPoint(_DataBytes, _Data.Stride, _ColorStack, _NewPoint.X + 1, _NewPoint.Y, _OldColor, p_NewColor, p_Float);
840                 if (_NewPoint.Y < _Height - 1) SetImageColorPoint(_DataBytes, _Data.Stride, _ColorStack, _NewPoint.X, _NewPoint.Y + 1, _OldColor, p_NewColor, p_Float);
841 
842             }
843             while (_ColorStack.Count > 0);
844 
845             Marshal.Copy(_DataBytes, 0, _Data.Scan0, _ByteSize);
846             _NewBmp.UnlockBits(_Data);
847             return _NewBmp;
848         }
849         /// <summary>
850         /// SetImageColorPoint 循环调用 检查新的坐标是否符合条件 符合条件会写入栈p_ColorStack 并更改颜色
851         /// </summary>
852         /// <param name="p_DataBytes">数据区</param>
853         /// <param name="p_Stride">行扫描字节数</param>
854         /// <param name="p_ColorStack">需要检查的位置栈</param>
855         /// <param name="p_X">位置X</param>
856         /// <param name="p_Y">位置Y</param>
857         /// <param name="p_OldColor">老色彩</param>
858         /// <param name="p_NewColor">新色彩</param>
859         /// <param name="p_Float">溶差</param>
860         private static void SetImageColorPoint(byte[] p_DataBytes, int p_Stride, Stack<Point> p_ColorStack, int p_X, int p_Y, Color p_OldColor, Color p_NewColor, int p_Float)
861         {
862 
863             int _Index = (p_Y * p_Stride) + (p_X * 4);
864             Color _OldColor = Color.FromArgb(p_DataBytes[_Index + 3], p_DataBytes[_Index + 2], p_DataBytes[_Index + 1], p_DataBytes[_Index]);
865 
866             if (ScanColor(_OldColor, p_OldColor, p_Float))
867             {
868                 p_ColorStack.Push(new Point(p_X, p_Y));
869 
870                 p_DataBytes[_Index + 3] = (byte)p_NewColor.A;
871                 p_DataBytes[_Index + 2] = (byte)p_NewColor.R;
872                 p_DataBytes[_Index + 1] = (byte)p_NewColor.G;
873                 p_DataBytes[_Index] = (byte)p_NewColor.B;
874             }
875         }
876 
877         /// <summary>
878         /// 检查色彩(可以根据这个更改比较方式
879         /// </summary>
880         /// <param name="p_CurrentlyColor">当前色彩</param>
881         /// <param name="p_CompareColor">比较色彩</param>
882         /// <param name="p_Float">溶差</param>
883         /// <returns></returns>
884         private static bool ScanColor(Color p_CurrentlyColor, Color p_CompareColor, int p_Float)
885         {
886             int _R = p_CurrentlyColor.R;
887             int _G = p_CurrentlyColor.G;
888             int _B = p_CurrentlyColor.B;
889             return (_R <= p_CompareColor.R + p_Float && _R >= p_CompareColor.R - p_Float) && (_G <= p_CompareColor.G + p_Float && _G >= p_CompareColor.G - p_Float) && (_B <= p_CompareColor.B + p_Float && _B >= p_CompareColor.B - p_Float);
890         }
891     }
892 }
对图片的所有处理操作帮助类
复制代码

4.序列化工具类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Drawing.Imaging;
  4 using System.IO;
  5 using System.Linq;
  6 using System.Runtime.Serialization.Formatters.Binary;
  7 using System.Runtime.Serialization.Json;
  8 using System.Text;
  9 using System.Threading.Tasks;
 10 using System.Web;
 11 using System.Xml.Serialization;
 12 
 13 namespace Utilities
 14 {
 15     /// <summary>
 16     /// 序列化工具类
 17     /// </summary>
 18     public static class IoHelper
 19     {
 20         //是否已经加载了JPEG编码解码器
 21         private static bool _isloadjpegcodec = false;
 22         //当前系统安装的JPEG编码解码器
 23         private static ImageCodecInfo _jpegcodec = null;
 24 
 25         /// <summary>
 26         /// 获得文件物理路径
 27         /// </summary>
 28         /// <returns></returns>
 29         public static string GetMapPath(string path)
 30         {
 31             if (HttpContext.Current != null)
 32             {
 33                 return HttpContext.Current.Server.MapPath(path);
 34             }
 35             return System.Web.Hosting.HostingEnvironment.MapPath(path);
 36         }
 37 
 38         #region Xml部分
 39         /// <summary>
 40         /// 序列化任意对象(XML)
 41         /// </summary>
 42         /// <param name="obj">要序列化的对象</param>
 43         /// <returns>序列化后的 XML 字符串</returns>
 44         public static string SerializeXml(object obj)
 45         {
 46             XmlSerializer xml = new XmlSerializer(obj.GetType());
 47             MemoryStream ms = new MemoryStream();
 48             xml.Serialize(ms, obj);
 49             byte[] tmpBytes = ms.ToArray();
 50             ms.Close();
 51             return System.Text.Encoding.UTF8.GetString(tmpBytes);
 52         }
 53         /// <summary>
 54         /// 反序列化任意对象(XML)
 55         /// </summary>
 56         /// <param name="xmlString">XML字符串</param>
 57         /// <returns>反序列化后的对象</returns>
 58         public static T DeSerializeXml<T>(string xmlString)
 59         {
 60             byte[] tmpBytes = System.Text.Encoding.Default.GetBytes(xmlString);
 61             MemoryStream ms = new MemoryStream(tmpBytes);
 62             ms.Position = 0;
 63             XmlSerializer xml = new XmlSerializer(typeof(T));
 64             T obj = (T)xml.Deserialize(ms);
 65             ms.Close();
 66             return obj;
 67         }
 68         #endregion
 69 
 70         #region Json部分
 71         /// <summary>
 72         /// 将obj对象序列化成JSON字符串
 73         /// </summary>
 74         /// <param name="obj">对象</param>
 75         /// <returns>JSON字符串</returns>
 76         public static string SerializeJson(Object obj)
 77         {
 78             string json = "";
 79             DataContractJsonSerializer ser = new DataContractJsonSerializer(obj.GetType());
 80             using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
 81             {
 82                 ser.WriteObject(ms, obj);
 83                 json = System.Text.Encoding.UTF8.GetString(ms.ToArray());
 84             }
 85             return json;
 86         }
 87         /// <summary>
 88         /// 将JSON字符串序反列化为指定T型的对象
 89         /// </summary>
 90         /// <typeparam name="T">目标类型</typeparam>
 91         /// <param name="json">json字符串</param>
 92         /// <returns>T类型的对象</returns>
 93         public static T DeSerializeJson<T>(string json)
 94         {
 95             System.Text.UTF8Encoding utf = new System.Text.UTF8Encoding();
 96 
 97             DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
 98             using (System.IO.MemoryStream s = new System.IO.MemoryStream(utf.GetBytes(json)))
 99             {
100                 return (T)ser.ReadObject(s);
101             }
102         }
103         #endregion
104 
105         #region IO部分
106         /// <summary>
107         /// 将指定对象obj序列化到文件fn中
108         /// </summary>
109         /// <param name="fn">文件路径</param>
110         /// <param name="obj">对象</param>
111         public static void Serialize(string fn, object obj)
112         {
113             BinaryFormatter bf = new BinaryFormatter();
114             using (FileStream fs = new FileStream(fn, FileMode.OpenOrCreate, FileAccess.Write))
115             {
116                 bf.Serialize(fs, obj);
117             }
118         }
119         /// <summary>
120         /// 从文件fn中反序列出类型为T的对象
121         /// </summary>
122         /// <typeparam name="T">返回的对象类型</typeparam>
123         /// <param name="fn">文件名称</param>
124         /// <returns>对象</returns>
125         public static T DeSerialize<T>(string fn)
126         {
127             BinaryFormatter bf = new BinaryFormatter();
128             using (FileStream fs = new FileStream(fn, FileMode.OpenOrCreate, FileAccess.Read))
129             {
130                 return (T)bf.Deserialize(fs);
131             }
132         }
133         /// <summary>
134         /// 获取指定对象的深度克隆对象
135         /// </summary>
136         /// <typeparam name="T">被克隆者类型</typeparam>
137         /// <param name="obj">被克隆者</param>
138         /// <returns>克隆出来的对象</returns>
139         public static T Clone<T>(T obj)
140         {
141             BinaryFormatter bf = new BinaryFormatter();
142             using (MemoryStream ms = new MemoryStream())
143             {
144                 bf.Serialize(ms, obj);
145                 ms.Position = 0;
146                 return (T)bf.Deserialize(ms);
147             }
148         }
149         #endregion
150     }
151 }
序列化工具类
复制代码

5.封装NLog组件进行日志管理类

复制代码
  1 using NLog;
  2 using System;
  3 using System.Collections.Generic;
  4 using System.Linq;
  5 using System.Text;
  6 
  7 namespace Utilities
  8 {
  9     /// <summary>
 10     /// 封装NLog组件进行日志管理
 11     /// </summary>
 12     public class LogHelper
 13     {
 14         NLog.Logger logger;
 15         /// <summary>
 16         /// 私有构造方法,只给当前类的其他构造方法调用
 17         /// </summary>
 18         /// <param name="logger"></param>
 19         private LogHelper(NLog.Logger logger)
 20         {
 21             this.logger = logger;
 22         }
 23         /// <summary>
 24         /// 通过指定的名称来创建日志对象
 25         /// </summary>
 26         /// <param name="name"></param>
 27         public LogHelper(string name): this(NLog.LogManager.GetLogger(name)){ }
 28         /// <summary>
 29         /// 提供1个默认的静态使用方式,例如:LogHelper.Default.Info("info");
 30         /// </summary>
 31         public static LogHelper Default { get; private set; }
 32         /// <summary>
 33         /// 私有的静态构造方法,初始化Default对象
 34         /// </summary>
 35         static LogHelper()
 36         {
 37             Default = new LogHelper(NLog.LogManager.GetCurrentClassLogger());
 38         }
 39         /// <summary>
 40         /// Trace等级写日志
 41         /// </summary>
 42         /// <param name="msg">日志信息</param>
 43         /// <param name="args">其他参数</param>
 44         public void Trace(string msg, params object[] args)
 45         {
 46             logger.Trace(msg, args);
 47         }
 48         /// <summary>
 49         /// Trace等级写日志
 50         /// </summary>
 51         /// <param name="msg">日志信息</param>
 52         /// <param name="err">需要记录的异常信息</param>
 53         public void Trace(string msg, Exception err)
 54         {
 55             logger.Trace(err, msg);
 56         }
 57         /// <summary>
 58         /// Debug等级写日志
 59         /// </summary>
 60         /// <param name="msg">日志信息</param>
 61         /// <param name="args">其他参数</param>
 62         public void Debug(string msg, params object[] args)
 63         {
 64             logger.Debug(msg, args);
 65         }
 66         /// <summary>
 67         /// Debug等级写日志
 68         /// </summary>
 69         /// <param name="msg">日志信息</param>
 70         /// <param name="err">需要记录的异常信息</param>
 71         public void Debug(string msg, Exception err)
 72         {
 73             logger.Debug( err, msg);
 74         }
 75         /// <summary>
 76         /// Info等级写日志
 77         /// </summary>
 78         /// <param name="msg">日志信息</param>
 79         /// <param name="args">其他参数</param>
 80         public void Info(string msg, params object[] args)
 81         {
 82             logger.Info(msg, args);
 83         }
 84         /// <summary>
 85         /// Info等级写日志
 86         /// </summary>
 87         /// <param name="msg">日志信息</param>
 88         /// <param name="err">需要记录的异常信息</param>
 89         public void Info(string msg, Exception err)
 90         {
 91             logger.Info(err, msg);
 92         }
 93         /// <summary>
 94         /// Warn等级写日志
 95         /// </summary>
 96         /// <param name="msg">日志信息</param>
 97         /// <param name="args">其他参数</param>
 98         public void Warn(string msg, params object[] args)
 99         {
100             logger.Warn(msg, args);
101         }
102         /// <summary>
103         /// Warn等级写日志
104         /// </summary>
105         /// <param name="msg">日志信息</param>
106         /// <param name="err">需要记录的异常信息</param>
107         public void Warn(string msg, Exception err)
108         {
109             logger.Warn(err, msg);
110         }
111         /// <summary>
112         /// Error等级写日志
113         /// </summary>
114         /// <param name="msg">日志信息</param>
115         /// <param name="args">其他参数</param>
116         public void Error(string msg, params object[] args)
117         {
118             logger.Error(msg, args);
119         }
120         /// <summary>
121         /// Error等级写日志
122         /// </summary>
123         /// <param name="msg">日志信息</param>
124         /// <param name="err">需要记录的异常信息</param>
125         public void Error(string msg, Exception err)
126         {
127             logger.Error(err, msg);
128         }
129         /// <summary>
130         /// Fatal等级写日志
131         /// </summary>
132         /// <param name="msg">日志信息</param>
133         /// <param name="args">其他参数</param>
134         public void Fatal(string msg, params object[] args)
135         {
136             logger.Fatal(msg, args);
137         }
138         /// <summary>
139         /// Fatal等级写日志
140         /// </summary>
141         /// <param name="msg">日志信息</param>
142         /// <param name="err">需要记录的异常信息</param>
143         public void Fatal(string msg, Exception err)
144         {
145             logger.Fatal(err, msg);
146         }
147     }
148 }
封装NLog组件进行日志管理帮助类
复制代码
复制代码
 1 <?xml version="1.0" encoding="utf-8" ?>
 2 <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
 3       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4       xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
 5       autoReload="true"
 6       throwExceptions="false"
 7       internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
 8 
 9   <!-- optional, add some variables
10   https://github.com/nlog/NLog/wiki/Configuration-file#variables
11   -->
12   <variable name="myvar" value="myvalue"/>
13 
14   <!--
15   See https://github.com/nlog/nlog/wiki/Configuration-file
16   for information on customizing logging rules and outputs.
17    -->
18   <targets>
19     <!--
20     add your targets here
21     See https://github.com/nlog/NLog/wiki/Targets for possible targets.
22     See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
23     -->
24     <!--
25     Write events to a file with the date in the filename. -->
26     <target name="debugger" xsi:type="Debugger" layout="${date:format=HH\:mm\:ss.fff}: ${message}" />
27     <target name="error_file" xsi:type="File" fileName="${basedir}/logs/${shortdate}.log"
28             layout="时间:${longdate} 级别:${uppercase:${level}} 信息:${message} 异常:${exception}" 
29             encoding="UTF-8"/>
30     <target name="f" xsi:type="File" fileName="${basedir}/logs/${shortdate}.txt"
31             layout="时间:${longdate} 级别:${uppercase:${level}} 信息:${message} 异常:${exception}" 
32             encoding="UTF-8" />
33   </targets>
34   <rules>
35     <!-- add your logging rules here -->    
36     <!--Write all events with minimal level of Debug (So Debug, Info, Warn, 
37         Error and Fatal, but not Trace)  to "f"-->
38     <logger name="logAll" writeTo="f" minlevel="Debug" />
39     <logger name="*" writeTo="debugger" />
40     <logger name="*" minlevel="Error" writeTo="error_file" />
41   </rules>
42 </nlog>
nlog.config
复制代码
复制代码
   1 <?xml version="1.0" encoding="utf-8"?>
   2 <xs:schema id="NLog" targetNamespace="http://www.nlog-project.org/schemas/NLog.xsd" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.nlog-project.org/schemas/NLog.xsd">
   3   <xs:element name="nlog" type="NLogConfiguration" />
   4   <xs:complexType name="NLogConfiguration">
   5     <xs:choice minOccurs="0" maxOccurs="unbounded">
   6       <xs:element name="extensions" type="NLogExtensions" />
   7       <xs:element name="include" type="NLogInclude" />
   8       <xs:element name="variable" type="NLogVariable" />
   9       <xs:element name="targets" type="NLogTargets" />
  10       <xs:element name="rules" type="NLogRules" />
  11       <xs:element name="time" type="TimeSource" />
  12     </xs:choice>
  13     <xs:attribute name="autoReload" type="xs:boolean">
  14       <xs:annotation>
  15         <xs:documentation>Watch config file for changes and reload automatically.</xs:documentation>
  16       </xs:annotation>
  17     </xs:attribute>
  18     <xs:attribute name="internalLogToConsole" type="xs:boolean">
  19       <xs:annotation>
  20         <xs:documentation>Print internal NLog messages to the console. Default value is: false</xs:documentation>
  21       </xs:annotation>
  22     </xs:attribute>
  23     <xs:attribute name="internalLogToConsoleError" type="xs:boolean">
  24       <xs:annotation>
  25         <xs:documentation>Print internal NLog messages to the console error output. Default value is: false</xs:documentation>
  26       </xs:annotation>
  27     </xs:attribute>
  28     <xs:attribute name="internalLogFile" type="xs:string">
  29       <xs:annotation>
  30         <xs:documentation>Write internal NLog messages to the specified file.</xs:documentation>
  31       </xs:annotation>
  32     </xs:attribute>
  33     <xs:attribute name="internalLogLevel" type="NLogLevel">
  34       <xs:annotation>
  35         <xs:documentation>Log level threshold for internal log messages. Default value is: Info.</xs:documentation>
  36       </xs:annotation>
  37     </xs:attribute>
  38     <xs:attribute name="globalThreshold" type="NLogLevel">
  39       <xs:annotation>
  40         <xs:documentation>Global log level threshold for application log messages. Messages below this level won't be logged..</xs:documentation>
  41       </xs:annotation>
  42     </xs:attribute>
  43     <xs:attribute name="throwExceptions" type="xs:boolean">
  44       <xs:annotation>
  45         <xs:documentation>Throw an exception when there is an internal error. Default value is: false.</xs:documentation>
  46       </xs:annotation>
  47     </xs:attribute>
  48     <xs:attribute name="throwConfigExceptions" type="xs:boolean">
  49       <xs:annotation>
  50         <xs:documentation>Throw an exception when there is a configuration error. If not set, determined by throwExceptions.</xs:documentation>
  51       </xs:annotation>
  52     </xs:attribute>
  53     <xs:attribute name="keepVariablesOnReload" type="xs:boolean">
  54       <xs:annotation>
  55         <xs:documentation>Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false.</xs:documentation>
  56       </xs:annotation>
  57     </xs:attribute>
  58     <xs:attribute name="internalLogToTrace" type="xs:boolean">
  59       <xs:annotation>
  60         <xs:documentation>Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false.</xs:documentation>
  61       </xs:annotation>
  62     </xs:attribute>
  63     <xs:attribute name="internalLogIncludeTimestamp" type="xs:boolean">
  64       <xs:annotation>
  65         <xs:documentation>Write timestamps for internal NLog messages. Default value is: true.</xs:documentation>
  66       </xs:annotation>
  67     </xs:attribute>
  68     <xs:attribute name="useInvariantCulture" type="xs:boolean">
  69       <xs:annotation>
  70         <xs:documentation>Use InvariantCulture as default culture instead of CurrentCulture.  Default value is: false.</xs:documentation>
  71       </xs:annotation>
  72     </xs:attribute>
  73     <xs:attribute name="parseMessageTemplates" type="xs:boolean">
  74       <xs:annotation>
  75         <xs:documentation>Perform mesage template parsing and formatting of LogEvent messages (true = Always, false = Never, empty = Auto Detect). Default value is: empty.</xs:documentation>
  76       </xs:annotation>
  77     </xs:attribute>
  78   </xs:complexType>
  79   <xs:complexType name="NLogTargets">
  80     <xs:choice minOccurs="0" maxOccurs="unbounded">
  81       <xs:element name="default-wrapper" type="WrapperTargetBase" />
  82       <xs:element name="default-target-parameters" type="Target" />
  83       <xs:element name="target" type="Target" />
  84       <xs:element name="wrapper-target" type="WrapperTargetBase" />
  85       <xs:element name="compound-target" type="CompoundTargetBase" />
  86     </xs:choice>
  87     <xs:attribute name="async" type="xs:boolean">
  88       <xs:annotation>
  89         <xs:documentation>Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes).</xs:documentation>
  90       </xs:annotation>
  91     </xs:attribute>
  92   </xs:complexType>
  93   <xs:complexType name="NLogRules">
  94     <xs:sequence minOccurs="0" maxOccurs="unbounded">
  95       <xs:element name="logger" type="NLogLoggerRule" />
  96     </xs:sequence>
  97   </xs:complexType>
  98   <xs:complexType name="NLogExtensions">
  99     <xs:choice minOccurs="0" maxOccurs="unbounded">
 100       <xs:element name="add" type="NLogExtensionsAdd" />
 101     </xs:choice>
 102   </xs:complexType>
 103   <xs:complexType name="NLogExtensionsAdd">
 104     <xs:attribute name="prefix" type="xs:string">
 105       <xs:annotation>
 106         <xs:documentation>Prefix for targets/layout renderers/filters/conditions loaded from this assembly.</xs:documentation>
 107       </xs:annotation>
 108     </xs:attribute>
 109     <xs:attribute name="assemblyFile" type="xs:string">
 110       <xs:annotation>
 111         <xs:documentation>Load NLog extensions from the specified file (*.dll)</xs:documentation>
 112       </xs:annotation>
 113     </xs:attribute>
 114     <xs:attribute name="assembly" type="xs:string">
 115       <xs:annotation>
 116         <xs:documentation>Load NLog extensions from the specified assembly. Assembly name should be fully qualified.</xs:documentation>
 117       </xs:annotation>
 118     </xs:attribute>
 119   </xs:complexType>
 120   <xs:complexType name="NLogLoggerRule">
 121     <xs:choice minOccurs="0" maxOccurs="unbounded">
 122       <xs:element name="filters" type="NLogFilters" />
 123     </xs:choice>
 124     <xs:attribute name="name" use="optional">
 125       <xs:annotation>
 126         <xs:documentation>Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name*</xs:documentation>
 127       </xs:annotation>
 128     </xs:attribute>
 129     <xs:attribute name="levels" type="NLogLevelList">
 130       <xs:annotation>
 131         <xs:documentation>Comma separated list of levels that this rule matches.</xs:documentation>
 132       </xs:annotation>
 133     </xs:attribute>
 134     <xs:attribute name="minlevel" type="NLogLevel">
 135       <xs:annotation>
 136         <xs:documentation>Minimum level that this rule matches.</xs:documentation>
 137       </xs:annotation>
 138     </xs:attribute>
 139     <xs:attribute name="maxlevel" type="NLogLevel">
 140       <xs:annotation>
 141         <xs:documentation>Maximum level that this rule matches.</xs:documentation>
 142       </xs:annotation>
 143     </xs:attribute>
 144     <xs:attribute name="level" type="NLogLevel">
 145       <xs:annotation>
 146         <xs:documentation>Level that this rule matches.</xs:documentation>
 147       </xs:annotation>
 148     </xs:attribute>
 149     <xs:attribute name="writeTo" type="NLogTargetIDList">
 150       <xs:annotation>
 151         <xs:documentation>Comma separated list of target names.</xs:documentation>
 152       </xs:annotation>
 153     </xs:attribute>
 154     <xs:attribute name="final" type="xs:boolean" default="false">
 155       <xs:annotation>
 156         <xs:documentation>Ignore further rules if this one matches.</xs:documentation>
 157       </xs:annotation>
 158     </xs:attribute>
 159     <xs:attribute name="enabled" type="xs:boolean" default="true">
 160       <xs:annotation>
 161         <xs:documentation>Enable or disable logging rule. Disabled rules are ignored.</xs:documentation>
 162       </xs:annotation>
 163     </xs:attribute>
 164   </xs:complexType>
 165   <xs:complexType name="NLogFilters">
 166     <xs:choice minOccurs="0" maxOccurs="unbounded">
 167       <xs:element name="when" type="when" />
 168       <xs:element name="whenContains" type="whenContains" />
 169       <xs:element name="whenEqual" type="whenEqual" />
 170       <xs:element name="whenNotContains" type="whenNotContains" />
 171       <xs:element name="whenNotEqual" type="whenNotEqual" />
 172       <xs:element name="whenRepeated" type="whenRepeated" />
 173     </xs:choice>
 174   </xs:complexType>
 175   <xs:simpleType name="NLogLevel">
 176     <xs:restriction base="xs:string">
 177       <xs:enumeration value="Off" />
 178       <xs:enumeration value="Trace" />
 179       <xs:enumeration value="Debug" />
 180       <xs:enumeration value="Info" />
 181       <xs:enumeration value="Warn" />
 182       <xs:enumeration value="Error" />
 183       <xs:enumeration value="Fatal" />
 184     </xs:restriction>
 185   </xs:simpleType>
 186   <xs:simpleType name="LineEndingMode">
 187     <xs:restriction base="xs:string">
 188       <xs:enumeration value="Default" />
 189       <xs:enumeration value="CRLF" />
 190       <xs:enumeration value="CR" />
 191       <xs:enumeration value="LF" />
 192       <xs:enumeration value="None" />
 193     </xs:restriction>
 194   </xs:simpleType>
 195   <xs:simpleType name="NLogLevelList">
 196     <xs:restriction base="xs:string">
 197       <xs:pattern value="(|Trace|Debug|Info|Warn|Error|Fatal)(,(Trace|Debug|Info|Warn|Error|Fatal))*" />
 198     </xs:restriction>
 199   </xs:simpleType>
 200   <xs:complexType name="NLogInclude">
 201     <xs:attribute name="file" type="SimpleLayoutAttribute" use="required">
 202       <xs:annotation>
 203         <xs:documentation>Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file.</xs:documentation>
 204       </xs:annotation>
 205     </xs:attribute>
 206     <xs:attribute name="ignoreErrors" type="xs:boolean" use="optional" default="false">
 207       <xs:annotation>
 208         <xs:documentation>Ignore any errors in the include file.</xs:documentation>
 209       </xs:annotation>
 210     </xs:attribute>
 211   </xs:complexType>
 212   <xs:complexType name="NLogVariable">
 213     <xs:attribute name="name" type="xs:string" use="required">
 214       <xs:annotation>
 215         <xs:documentation>Variable name.</xs:documentation>
 216       </xs:annotation>
 217     </xs:attribute>
 218     <xs:attribute name="value" type="SimpleLayoutAttribute" use="required">
 219       <xs:annotation>
 220         <xs:documentation>Variable value.</xs:documentation>
 221       </xs:annotation>
 222     </xs:attribute>
 223   </xs:complexType>
 224   <xs:simpleType name="NLogTargetIDList">
 225     <xs:restriction base="xs:string">
 226       <xs:pattern value="(|([a-zA-Z][a-zA-Z0-9_\-]*))(,([a-zA-Z][a-zA-Z0-9_\-]*))*" />
 227     </xs:restriction>
 228   </xs:simpleType>
 229   <xs:complexType name="Target" abstract="true"></xs:complexType>
 230   <xs:complexType name="TargetRef">
 231     <xs:attribute name="name" type="xs:string" use="required" />
 232   </xs:complexType>
 233   <xs:complexType name="WrapperTargetBase" abstract="true">
 234     <xs:complexContent>
 235       <xs:extension base="Target">
 236         <xs:choice minOccurs="0" maxOccurs="unbounded">
 237           <xs:element name="target" type="Target" minOccurs="1" maxOccurs="1" />
 238           <xs:element name="wrapper-target" type="WrapperTargetBase" minOccurs="1" maxOccurs="1" />
 239           <xs:element name="compound-target" type="CompoundTargetBase" minOccurs="1" maxOccurs="1" />
 240           <xs:element name="target-ref" type="TargetRef" minOccurs="1" maxOccurs="1" />
 241           <xs:element name="wrapper-target-ref" type="TargetRef" minOccurs="1" maxOccurs="1" />
 242           <xs:element name="compound-target-ref" type="TargetRef" minOccurs="1" maxOccurs="1" />
 243         </xs:choice>
 244       </xs:extension>
 245     </xs:complexContent>
 246   </xs:complexType>
 247   <xs:complexType name="CompoundTargetBase" abstract="true">
 248     <xs:complexContent>
 249       <xs:extension base="Target">
 250         <xs:choice minOccurs="0" maxOccurs="unbounded">
 251           <xs:element name="target" type="Target" minOccurs="1" maxOccurs="unbounded" />
 252           <xs:element name="wrapper-target" type="WrapperTargetBase" minOccurs="1" maxOccurs="1" />
 253           <xs:element name="compound-target" type="CompoundTargetBase" minOccurs="1" maxOccurs="1" />
 254           <xs:element name="target-ref" type="TargetRef" minOccurs="1" maxOccurs="1" />
 255           <xs:element name="wrapper-target-ref" type="TargetRef" minOccurs="1" maxOccurs="1" />
 256           <xs:element name="compound-target-ref" type="TargetRef" minOccurs="1" maxOccurs="1" />
 257         </xs:choice>
 258       </xs:extension>
 259     </xs:complexContent>
 260   </xs:complexType>
 261   <xs:complexType name="Filter" abstract="true"></xs:complexType>
 262   <xs:complexType name="TimeSource" abstract="true"></xs:complexType>
 263   <xs:simpleType name="SimpleLayoutAttribute">
 264     <xs:restriction base="xs:string">
 265       <xs:pattern value=".*" />
 266     </xs:restriction>
 267   </xs:simpleType>
 268   <xs:simpleType name="Condition">
 269     <xs:restriction base="xs:string">
 270       <xs:minLength value="1" />
 271     </xs:restriction>
 272   </xs:simpleType>
 273   <xs:complexType name="AsyncWrapper">
 274     <xs:complexContent>
 275       <xs:extension base="WrapperTargetBase">
 276         <xs:choice minOccurs="0" maxOccurs="unbounded">
 277           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 278           <xs:element name="batchSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
 279           <xs:element name="fullBatchSizeWriteLimit" minOccurs="0" maxOccurs="1" type="xs:integer" />
 280           <xs:element name="overflowAction" minOccurs="0" maxOccurs="1" type="NLog.Targets.Wrappers.AsyncTargetWrapperOverflowAction" />
 281           <xs:element name="queueLimit" minOccurs="0" maxOccurs="1" type="xs:integer" />
 282           <xs:element name="timeToSleepBetweenBatches" minOccurs="0" maxOccurs="1" type="xs:integer" />
 283           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 284         </xs:choice>
 285         <xs:attribute name="name" type="xs:string">
 286           <xs:annotation>
 287             <xs:documentation>Name of the target.</xs:documentation>
 288           </xs:annotation>
 289         </xs:attribute>
 290         <xs:attribute name="batchSize" type="xs:integer">
 291           <xs:annotation>
 292             <xs:documentation>Number of log events that should be processed in a batch by the lazy writer thread.</xs:documentation>
 293           </xs:annotation>
 294         </xs:attribute>
 295         <xs:attribute name="fullBatchSizeWriteLimit" type="xs:integer">
 296           <xs:annotation>
 297             <xs:documentation>Limit of full s to write before yielding into  Performance is better when writing many small batches, than writing a single large batch</xs:documentation>
 298           </xs:annotation>
 299         </xs:attribute>
 300         <xs:attribute name="overflowAction" type="NLog.Targets.Wrappers.AsyncTargetWrapperOverflowAction">
 301           <xs:annotation>
 302             <xs:documentation>Action to be taken when the lazy writer thread request queue count exceeds the set limit.</xs:documentation>
 303           </xs:annotation>
 304         </xs:attribute>
 305         <xs:attribute name="queueLimit" type="xs:integer">
 306           <xs:annotation>
 307             <xs:documentation>Limit on the number of requests in the lazy writer thread request queue.</xs:documentation>
 308           </xs:annotation>
 309         </xs:attribute>
 310         <xs:attribute name="timeToSleepBetweenBatches" type="xs:integer">
 311           <xs:annotation>
 312             <xs:documentation>Time in milliseconds to sleep between batches.</xs:documentation>
 313           </xs:annotation>
 314         </xs:attribute>
 315         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 316           <xs:annotation>
 317             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 318           </xs:annotation>
 319         </xs:attribute>
 320       </xs:extension>
 321     </xs:complexContent>
 322   </xs:complexType>
 323   <xs:simpleType name="NLog.Targets.Wrappers.AsyncTargetWrapperOverflowAction">
 324     <xs:restriction base="xs:string">
 325       <xs:enumeration value="Grow" />
 326       <xs:enumeration value="Discard" />
 327       <xs:enumeration value="Block" />
 328     </xs:restriction>
 329   </xs:simpleType>
 330   <xs:complexType name="AutoFlushWrapper">
 331     <xs:complexContent>
 332       <xs:extension base="WrapperTargetBase">
 333         <xs:choice minOccurs="0" maxOccurs="unbounded">
 334           <xs:element name="asyncFlush" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 335           <xs:element name="condition" minOccurs="0" maxOccurs="1" type="Condition" />
 336           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 337           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 338         </xs:choice>
 339         <xs:attribute name="asyncFlush" type="xs:boolean">
 340           <xs:annotation>
 341             <xs:documentation>Delay the flush until the LogEvent has been confirmed as written</xs:documentation>
 342           </xs:annotation>
 343         </xs:attribute>
 344         <xs:attribute name="condition" type="Condition">
 345           <xs:annotation>
 346             <xs:documentation>Condition expression. Log events who meet this condition will cause a flush on the wrapped target.</xs:documentation>
 347           </xs:annotation>
 348         </xs:attribute>
 349         <xs:attribute name="name" type="xs:string">
 350           <xs:annotation>
 351             <xs:documentation>Name of the target.</xs:documentation>
 352           </xs:annotation>
 353         </xs:attribute>
 354         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 355           <xs:annotation>
 356             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 357           </xs:annotation>
 358         </xs:attribute>
 359       </xs:extension>
 360     </xs:complexContent>
 361   </xs:complexType>
 362   <xs:complexType name="BufferingWrapper">
 363     <xs:complexContent>
 364       <xs:extension base="WrapperTargetBase">
 365         <xs:choice minOccurs="0" maxOccurs="unbounded">
 366           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 367           <xs:element name="bufferSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
 368           <xs:element name="flushTimeout" minOccurs="0" maxOccurs="1" type="xs:integer" />
 369           <xs:element name="overflowAction" minOccurs="0" maxOccurs="1" type="NLog.Targets.Wrappers.BufferingTargetWrapperOverflowAction" />
 370           <xs:element name="slidingTimeout" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 371           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 372         </xs:choice>
 373         <xs:attribute name="name" type="xs:string">
 374           <xs:annotation>
 375             <xs:documentation>Name of the target.</xs:documentation>
 376           </xs:annotation>
 377         </xs:attribute>
 378         <xs:attribute name="bufferSize" type="xs:integer">
 379           <xs:annotation>
 380             <xs:documentation>Number of log events to be buffered.</xs:documentation>
 381           </xs:annotation>
 382         </xs:attribute>
 383         <xs:attribute name="flushTimeout" type="xs:integer">
 384           <xs:annotation>
 385             <xs:documentation>Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes.</xs:documentation>
 386           </xs:annotation>
 387         </xs:attribute>
 388         <xs:attribute name="overflowAction" type="NLog.Targets.Wrappers.BufferingTargetWrapperOverflowAction">
 389           <xs:annotation>
 390             <xs:documentation>Action to take if the buffer overflows.</xs:documentation>
 391           </xs:annotation>
 392         </xs:attribute>
 393         <xs:attribute name="slidingTimeout" type="xs:boolean">
 394           <xs:annotation>
 395             <xs:documentation>Indicates whether to use sliding timeout.</xs:documentation>
 396           </xs:annotation>
 397         </xs:attribute>
 398         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 399           <xs:annotation>
 400             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 401           </xs:annotation>
 402         </xs:attribute>
 403       </xs:extension>
 404     </xs:complexContent>
 405   </xs:complexType>
 406   <xs:simpleType name="NLog.Targets.Wrappers.BufferingTargetWrapperOverflowAction">
 407     <xs:restriction base="xs:string">
 408       <xs:enumeration value="Flush" />
 409       <xs:enumeration value="Discard" />
 410     </xs:restriction>
 411   </xs:simpleType>
 412   <xs:complexType name="Chainsaw">
 413     <xs:complexContent>
 414       <xs:extension base="Target">
 415         <xs:choice minOccurs="0" maxOccurs="unbounded">
 416           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 417           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
 418           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
 419           <xs:element name="lineEnding" minOccurs="0" maxOccurs="1" type="LineEndingMode" />
 420           <xs:element name="maxMessageSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
 421           <xs:element name="newLine" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 422           <xs:element name="onConnectionOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.NetworkTargetConnectionsOverflowAction" />
 423           <xs:element name="maxQueueSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
 424           <xs:element name="maxConnections" minOccurs="0" maxOccurs="1" type="xs:integer" />
 425           <xs:element name="keepConnection" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 426           <xs:element name="connectionCacheSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
 427           <xs:element name="address" minOccurs="0" maxOccurs="1" type="Layout" />
 428           <xs:element name="onOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.NetworkTargetOverflowAction" />
 429           <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.NLogViewerParameterInfo" />
 430           <xs:element name="ndlcItemSeparator" minOccurs="0" maxOccurs="1" type="xs:string" />
 431           <xs:element name="ndcItemSeparator" minOccurs="0" maxOccurs="1" type="xs:string" />
 432           <xs:element name="includeNLogData" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 433           <xs:element name="includeSourceInfo" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 434           <xs:element name="includeNdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 435           <xs:element name="includeNdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 436           <xs:element name="includeMdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 437           <xs:element name="includeMdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 438           <xs:element name="includeCallSite" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 439           <xs:element name="includeAllProperties" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 440           <xs:element name="appInfo" minOccurs="0" maxOccurs="1" type="xs:string" />
 441           <xs:element name="loggerName" minOccurs="0" maxOccurs="1" type="Layout" />
 442           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 443         </xs:choice>
 444         <xs:attribute name="name" type="xs:string">
 445           <xs:annotation>
 446             <xs:documentation>Name of the target.</xs:documentation>
 447           </xs:annotation>
 448         </xs:attribute>
 449         <xs:attribute name="encoding" type="xs:string">
 450           <xs:annotation>
 451             <xs:documentation>Encoding to be used.</xs:documentation>
 452           </xs:annotation>
 453         </xs:attribute>
 454         <xs:attribute name="layout" type="SimpleLayoutAttribute">
 455           <xs:annotation>
 456             <xs:documentation>Instance of  that is used to format log messages.</xs:documentation>
 457           </xs:annotation>
 458         </xs:attribute>
 459         <xs:attribute name="lineEnding" type="LineEndingMode">
 460           <xs:annotation>
 461             <xs:documentation>End of line value if a newline is appended at the end of log message .</xs:documentation>
 462           </xs:annotation>
 463         </xs:attribute>
 464         <xs:attribute name="maxMessageSize" type="xs:integer">
 465           <xs:annotation>
 466             <xs:documentation>Maximum message size in bytes.</xs:documentation>
 467           </xs:annotation>
 468         </xs:attribute>
 469         <xs:attribute name="newLine" type="xs:boolean">
 470           <xs:annotation>
 471             <xs:documentation>Indicates whether to append newline at the end of log message.</xs:documentation>
 472           </xs:annotation>
 473         </xs:attribute>
 474         <xs:attribute name="onConnectionOverflow" type="NLog.Targets.NetworkTargetConnectionsOverflowAction">
 475           <xs:annotation>
 476             <xs:documentation>Action that should be taken if the will be more connections than .</xs:documentation>
 477           </xs:annotation>
 478         </xs:attribute>
 479         <xs:attribute name="maxQueueSize" type="xs:integer">
 480           <xs:annotation>
 481             <xs:documentation>Maximum queue size.</xs:documentation>
 482           </xs:annotation>
 483         </xs:attribute>
 484         <xs:attribute name="maxConnections" type="xs:integer">
 485           <xs:annotation>
 486             <xs:documentation>Maximum current connections. 0 = no maximum.</xs:documentation>
 487           </xs:annotation>
 488         </xs:attribute>
 489         <xs:attribute name="keepConnection" type="xs:boolean">
 490           <xs:annotation>
 491             <xs:documentation>Indicates whether to keep connection open whenever possible.</xs:documentation>
 492           </xs:annotation>
 493         </xs:attribute>
 494         <xs:attribute name="connectionCacheSize" type="xs:integer">
 495           <xs:annotation>
 496             <xs:documentation>Size of the connection cache (number of connections which are kept alive).</xs:documentation>
 497           </xs:annotation>
 498         </xs:attribute>
 499         <xs:attribute name="address" type="SimpleLayoutAttribute">
 500           <xs:annotation>
 501             <xs:documentation>Network address.</xs:documentation>
 502           </xs:annotation>
 503         </xs:attribute>
 504         <xs:attribute name="onOverflow" type="NLog.Targets.NetworkTargetOverflowAction">
 505           <xs:annotation>
 506             <xs:documentation>Action that should be taken if the message is larger than maxMessageSize.</xs:documentation>
 507           </xs:annotation>
 508         </xs:attribute>
 509         <xs:attribute name="ndlcItemSeparator" type="xs:string">
 510           <xs:annotation>
 511             <xs:documentation>NDLC item separator.</xs:documentation>
 512           </xs:annotation>
 513         </xs:attribute>
 514         <xs:attribute name="ndcItemSeparator" type="xs:string">
 515           <xs:annotation>
 516             <xs:documentation>NDC item separator.</xs:documentation>
 517           </xs:annotation>
 518         </xs:attribute>
 519         <xs:attribute name="includeNLogData" type="xs:boolean">
 520           <xs:annotation>
 521             <xs:documentation>Indicates whether to include NLog-specific extensions to log4j schema.</xs:documentation>
 522           </xs:annotation>
 523         </xs:attribute>
 524         <xs:attribute name="includeSourceInfo" type="xs:boolean">
 525           <xs:annotation>
 526             <xs:documentation>Indicates whether to include source info (file name and line number) in the information sent over the network.</xs:documentation>
 527           </xs:annotation>
 528         </xs:attribute>
 529         <xs:attribute name="includeNdlc" type="xs:boolean">
 530           <xs:annotation>
 531             <xs:documentation>Indicates whether to include contents of the  stack.</xs:documentation>
 532           </xs:annotation>
 533         </xs:attribute>
 534         <xs:attribute name="includeNdc" type="xs:boolean">
 535           <xs:annotation>
 536             <xs:documentation>Indicates whether to include  stack contents.</xs:documentation>
 537           </xs:annotation>
 538         </xs:attribute>
 539         <xs:attribute name="includeMdlc" type="xs:boolean">
 540           <xs:annotation>
 541             <xs:documentation>Indicates whether to include  dictionary contents.</xs:documentation>
 542           </xs:annotation>
 543         </xs:attribute>
 544         <xs:attribute name="includeMdc" type="xs:boolean">
 545           <xs:annotation>
 546             <xs:documentation>Indicates whether to include  dictionary contents.</xs:documentation>
 547           </xs:annotation>
 548         </xs:attribute>
 549         <xs:attribute name="includeCallSite" type="xs:boolean">
 550           <xs:annotation>
 551             <xs:documentation>Indicates whether to include call site (class and method name) in the information sent over the network.</xs:documentation>
 552           </xs:annotation>
 553         </xs:attribute>
 554         <xs:attribute name="includeAllProperties" type="xs:boolean">
 555           <xs:annotation>
 556             <xs:documentation>Option to include all properties from the log events</xs:documentation>
 557           </xs:annotation>
 558         </xs:attribute>
 559         <xs:attribute name="appInfo" type="xs:string">
 560           <xs:annotation>
 561             <xs:documentation>AppInfo field. By default it's the friendly name of the current AppDomain.</xs:documentation>
 562           </xs:annotation>
 563         </xs:attribute>
 564         <xs:attribute name="loggerName" type="SimpleLayoutAttribute">
 565           <xs:annotation>
 566             <xs:documentation>Renderer for log4j:event logger-xml-attribute (Default ${logger})</xs:documentation>
 567           </xs:annotation>
 568         </xs:attribute>
 569         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 570           <xs:annotation>
 571             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 572           </xs:annotation>
 573         </xs:attribute>
 574       </xs:extension>
 575     </xs:complexContent>
 576   </xs:complexType>
 577   <xs:simpleType name="NLog.Targets.NetworkTargetConnectionsOverflowAction">
 578     <xs:restriction base="xs:string">
 579       <xs:enumeration value="AllowNewConnnection" />
 580       <xs:enumeration value="DiscardMessage" />
 581       <xs:enumeration value="Block" />
 582     </xs:restriction>
 583   </xs:simpleType>
 584   <xs:simpleType name="NLog.Targets.NetworkTargetOverflowAction">
 585     <xs:restriction base="xs:string">
 586       <xs:enumeration value="Error" />
 587       <xs:enumeration value="Split" />
 588       <xs:enumeration value="Discard" />
 589     </xs:restriction>
 590   </xs:simpleType>
 591   <xs:complexType name="NLog.Targets.NLogViewerParameterInfo">
 592     <xs:choice minOccurs="0" maxOccurs="unbounded">
 593       <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
 594       <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 595     </xs:choice>
 596     <xs:attribute name="layout" type="SimpleLayoutAttribute">
 597       <xs:annotation>
 598         <xs:documentation>Layout that should be use to calcuate the value for the parameter.</xs:documentation>
 599       </xs:annotation>
 600     </xs:attribute>
 601     <xs:attribute name="name" type="xs:string">
 602       <xs:annotation>
 603         <xs:documentation>Viewer parameter name.</xs:documentation>
 604       </xs:annotation>
 605     </xs:attribute>
 606   </xs:complexType>
 607   <xs:complexType name="ColoredConsole">
 608     <xs:complexContent>
 609       <xs:extension base="Target">
 610         <xs:choice minOccurs="0" maxOccurs="unbounded">
 611           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 612           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
 613           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
 614           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
 615           <xs:element name="detectConsoleAvailable" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 616           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
 617           <xs:element name="errorStream" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 618           <xs:element name="useDefaultRowHighlightingRules" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 619           <xs:element name="highlight-row" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.ConsoleRowHighlightingRule" />
 620           <xs:element name="highlight-word" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.ConsoleWordHighlightingRule" />
 621           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 622         </xs:choice>
 623         <xs:attribute name="name" type="xs:string">
 624           <xs:annotation>
 625             <xs:documentation>Name of the target.</xs:documentation>
 626           </xs:annotation>
 627         </xs:attribute>
 628         <xs:attribute name="layout" type="SimpleLayoutAttribute">
 629           <xs:annotation>
 630             <xs:documentation>Text to be rendered.</xs:documentation>
 631           </xs:annotation>
 632         </xs:attribute>
 633         <xs:attribute name="header" type="SimpleLayoutAttribute">
 634           <xs:annotation>
 635             <xs:documentation>Header.</xs:documentation>
 636           </xs:annotation>
 637         </xs:attribute>
 638         <xs:attribute name="footer" type="SimpleLayoutAttribute">
 639           <xs:annotation>
 640             <xs:documentation>Footer.</xs:documentation>
 641           </xs:annotation>
 642         </xs:attribute>
 643         <xs:attribute name="detectConsoleAvailable" type="xs:boolean">
 644           <xs:annotation>
 645             <xs:documentation>Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App)</xs:documentation>
 646           </xs:annotation>
 647         </xs:attribute>
 648         <xs:attribute name="encoding" type="xs:string">
 649           <xs:annotation>
 650             <xs:documentation>The encoding for writing messages to the .</xs:documentation>
 651           </xs:annotation>
 652         </xs:attribute>
 653         <xs:attribute name="errorStream" type="xs:boolean">
 654           <xs:annotation>
 655             <xs:documentation>Indicates whether the error stream (stderr) should be used instead of the output stream (stdout).</xs:documentation>
 656           </xs:annotation>
 657         </xs:attribute>
 658         <xs:attribute name="useDefaultRowHighlightingRules" type="xs:boolean">
 659           <xs:annotation>
 660             <xs:documentation>Indicates whether to use default row highlighting rules.</xs:documentation>
 661           </xs:annotation>
 662         </xs:attribute>
 663         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 664           <xs:annotation>
 665             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 666           </xs:annotation>
 667         </xs:attribute>
 668       </xs:extension>
 669     </xs:complexContent>
 670   </xs:complexType>
 671   <xs:simpleType name="NLog.Targets.ConsoleOutputColor">
 672     <xs:restriction base="xs:string">
 673       <xs:enumeration value="Black" />
 674       <xs:enumeration value="DarkBlue" />
 675       <xs:enumeration value="DarkGreen" />
 676       <xs:enumeration value="DarkCyan" />
 677       <xs:enumeration value="DarkRed" />
 678       <xs:enumeration value="DarkMagenta" />
 679       <xs:enumeration value="DarkYellow" />
 680       <xs:enumeration value="Gray" />
 681       <xs:enumeration value="DarkGray" />
 682       <xs:enumeration value="Blue" />
 683       <xs:enumeration value="Green" />
 684       <xs:enumeration value="Cyan" />
 685       <xs:enumeration value="Red" />
 686       <xs:enumeration value="Magenta" />
 687       <xs:enumeration value="Yellow" />
 688       <xs:enumeration value="White" />
 689       <xs:enumeration value="NoChange" />
 690     </xs:restriction>
 691   </xs:simpleType>
 692   <xs:complexType name="NLog.Targets.ConsoleRowHighlightingRule">
 693     <xs:choice minOccurs="0" maxOccurs="unbounded">
 694       <xs:element name="condition" minOccurs="0" maxOccurs="1" type="Condition" />
 695       <xs:element name="backgroundColor" minOccurs="0" maxOccurs="1" type="NLog.Targets.ConsoleOutputColor" />
 696       <xs:element name="foregroundColor" minOccurs="0" maxOccurs="1" type="NLog.Targets.ConsoleOutputColor" />
 697     </xs:choice>
 698     <xs:attribute name="condition" type="Condition">
 699       <xs:annotation>
 700         <xs:documentation>Condition that must be met in order to set the specified foreground and background color.</xs:documentation>
 701       </xs:annotation>
 702     </xs:attribute>
 703     <xs:attribute name="backgroundColor" type="NLog.Targets.ConsoleOutputColor">
 704       <xs:annotation>
 705         <xs:documentation>Background color.</xs:documentation>
 706       </xs:annotation>
 707     </xs:attribute>
 708     <xs:attribute name="foregroundColor" type="NLog.Targets.ConsoleOutputColor">
 709       <xs:annotation>
 710         <xs:documentation>Foreground color.</xs:documentation>
 711       </xs:annotation>
 712     </xs:attribute>
 713   </xs:complexType>
 714   <xs:complexType name="NLog.Targets.ConsoleWordHighlightingRule">
 715     <xs:choice minOccurs="0" maxOccurs="unbounded">
 716       <xs:element name="compileRegex" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 717       <xs:element name="ignoreCase" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 718       <xs:element name="regex" minOccurs="0" maxOccurs="1" type="xs:string" />
 719       <xs:element name="text" minOccurs="0" maxOccurs="1" type="xs:string" />
 720       <xs:element name="wholeWords" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 721       <xs:element name="backgroundColor" minOccurs="0" maxOccurs="1" type="NLog.Targets.ConsoleOutputColor" />
 722       <xs:element name="foregroundColor" minOccurs="0" maxOccurs="1" type="NLog.Targets.ConsoleOutputColor" />
 723     </xs:choice>
 724     <xs:attribute name="compileRegex" type="xs:boolean">
 725       <xs:annotation>
 726         <xs:documentation>Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used.</xs:documentation>
 727       </xs:annotation>
 728     </xs:attribute>
 729     <xs:attribute name="ignoreCase" type="xs:boolean">
 730       <xs:annotation>
 731         <xs:documentation>Indicates whether to ignore case when comparing texts.</xs:documentation>
 732       </xs:annotation>
 733     </xs:attribute>
 734     <xs:attribute name="regex" type="xs:string">
 735       <xs:annotation>
 736         <xs:documentation>Regular expression to be matched. You must specify either text or regex.</xs:documentation>
 737       </xs:annotation>
 738     </xs:attribute>
 739     <xs:attribute name="text" type="xs:string">
 740       <xs:annotation>
 741         <xs:documentation>Text to be matched. You must specify either text or regex.</xs:documentation>
 742       </xs:annotation>
 743     </xs:attribute>
 744     <xs:attribute name="wholeWords" type="xs:boolean">
 745       <xs:annotation>
 746         <xs:documentation>Indicates whether to match whole words only.</xs:documentation>
 747       </xs:annotation>
 748     </xs:attribute>
 749     <xs:attribute name="backgroundColor" type="NLog.Targets.ConsoleOutputColor">
 750       <xs:annotation>
 751         <xs:documentation>Background color.</xs:documentation>
 752       </xs:annotation>
 753     </xs:attribute>
 754     <xs:attribute name="foregroundColor" type="NLog.Targets.ConsoleOutputColor">
 755       <xs:annotation>
 756         <xs:documentation>Foreground color.</xs:documentation>
 757       </xs:annotation>
 758     </xs:attribute>
 759   </xs:complexType>
 760   <xs:complexType name="Console">
 761     <xs:complexContent>
 762       <xs:extension base="Target">
 763         <xs:choice minOccurs="0" maxOccurs="unbounded">
 764           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 765           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
 766           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
 767           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
 768           <xs:element name="detectConsoleAvailable" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 769           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
 770           <xs:element name="error" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 771           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 772         </xs:choice>
 773         <xs:attribute name="name" type="xs:string">
 774           <xs:annotation>
 775             <xs:documentation>Name of the target.</xs:documentation>
 776           </xs:annotation>
 777         </xs:attribute>
 778         <xs:attribute name="layout" type="SimpleLayoutAttribute">
 779           <xs:annotation>
 780             <xs:documentation>Text to be rendered.</xs:documentation>
 781           </xs:annotation>
 782         </xs:attribute>
 783         <xs:attribute name="header" type="SimpleLayoutAttribute">
 784           <xs:annotation>
 785             <xs:documentation>Header.</xs:documentation>
 786           </xs:annotation>
 787         </xs:attribute>
 788         <xs:attribute name="footer" type="SimpleLayoutAttribute">
 789           <xs:annotation>
 790             <xs:documentation>Footer.</xs:documentation>
 791           </xs:annotation>
 792         </xs:attribute>
 793         <xs:attribute name="detectConsoleAvailable" type="xs:boolean">
 794           <xs:annotation>
 795             <xs:documentation>Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App)</xs:documentation>
 796           </xs:annotation>
 797         </xs:attribute>
 798         <xs:attribute name="encoding" type="xs:string">
 799           <xs:annotation>
 800             <xs:documentation>The encoding for writing messages to the .</xs:documentation>
 801           </xs:annotation>
 802         </xs:attribute>
 803         <xs:attribute name="error" type="xs:boolean">
 804           <xs:annotation>
 805             <xs:documentation>Indicates whether to send the log messages to the standard error instead of the standard output.</xs:documentation>
 806           </xs:annotation>
 807         </xs:attribute>
 808         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 809           <xs:annotation>
 810             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 811           </xs:annotation>
 812         </xs:attribute>
 813       </xs:extension>
 814     </xs:complexContent>
 815   </xs:complexType>
 816   <xs:complexType name="Database">
 817     <xs:complexContent>
 818       <xs:extension base="Target">
 819         <xs:choice minOccurs="0" maxOccurs="unbounded">
 820           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 821           <xs:element name="useTransactions" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 822           <xs:element name="dbUserName" minOccurs="0" maxOccurs="1" type="Layout" />
 823           <xs:element name="dbProvider" minOccurs="0" maxOccurs="1" type="xs:string" />
 824           <xs:element name="dbPassword" minOccurs="0" maxOccurs="1" type="Layout" />
 825           <xs:element name="keepConnection" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 826           <xs:element name="dbDatabase" minOccurs="0" maxOccurs="1" type="Layout" />
 827           <xs:element name="connectionStringName" minOccurs="0" maxOccurs="1" type="xs:string" />
 828           <xs:element name="connectionString" minOccurs="0" maxOccurs="1" type="Layout" />
 829           <xs:element name="dbHost" minOccurs="0" maxOccurs="1" type="Layout" />
 830           <xs:element name="installConnectionString" minOccurs="0" maxOccurs="1" type="Layout" />
 831           <xs:element name="install-command" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.DatabaseCommandInfo" />
 832           <xs:element name="uninstall-command" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.DatabaseCommandInfo" />
 833           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 834           <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.DatabaseParameterInfo" />
 835           <xs:element name="commandText" minOccurs="0" maxOccurs="1" type="Layout" />
 836           <xs:element name="commandType" minOccurs="0" maxOccurs="1" type="System.Data.CommandType" />
 837         </xs:choice>
 838         <xs:attribute name="name" type="xs:string">
 839           <xs:annotation>
 840             <xs:documentation>Name of the target.</xs:documentation>
 841           </xs:annotation>
 842         </xs:attribute>
 843         <xs:attribute name="useTransactions" type="xs:boolean">
 844           <xs:annotation>
 845             <xs:documentation>Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this.</xs:documentation>
 846           </xs:annotation>
 847         </xs:attribute>
 848         <xs:attribute name="dbUserName" type="SimpleLayoutAttribute">
 849           <xs:annotation>
 850             <xs:documentation>Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string.</xs:documentation>
 851           </xs:annotation>
 852         </xs:attribute>
 853         <xs:attribute name="dbProvider" type="xs:string">
 854           <xs:annotation>
 855             <xs:documentation>Name of the database provider.</xs:documentation>
 856           </xs:annotation>
 857         </xs:attribute>
 858         <xs:attribute name="dbPassword" type="SimpleLayoutAttribute">
 859           <xs:annotation>
 860             <xs:documentation>Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string.</xs:documentation>
 861           </xs:annotation>
 862         </xs:attribute>
 863         <xs:attribute name="keepConnection" type="xs:boolean">
 864           <xs:annotation>
 865             <xs:documentation>Indicates whether to keep the database connection open between the log events.</xs:documentation>
 866           </xs:annotation>
 867         </xs:attribute>
 868         <xs:attribute name="dbDatabase" type="SimpleLayoutAttribute">
 869           <xs:annotation>
 870             <xs:documentation>Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string.</xs:documentation>
 871           </xs:annotation>
 872         </xs:attribute>
 873         <xs:attribute name="connectionStringName" type="xs:string">
 874           <xs:annotation>
 875             <xs:documentation>Name of the connection string (as specified in &lt;connectionStrings&gt; configuration section.</xs:documentation>
 876           </xs:annotation>
 877         </xs:attribute>
 878         <xs:attribute name="connectionString" type="SimpleLayoutAttribute">
 879           <xs:annotation>
 880             <xs:documentation>Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase.</xs:documentation>
 881           </xs:annotation>
 882         </xs:attribute>
 883         <xs:attribute name="dbHost" type="SimpleLayoutAttribute">
 884           <xs:annotation>
 885             <xs:documentation>Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string.</xs:documentation>
 886           </xs:annotation>
 887         </xs:attribute>
 888         <xs:attribute name="installConnectionString" type="SimpleLayoutAttribute">
 889           <xs:annotation>
 890             <xs:documentation>Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used.</xs:documentation>
 891           </xs:annotation>
 892         </xs:attribute>
 893         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
 894           <xs:annotation>
 895             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
 896           </xs:annotation>
 897         </xs:attribute>
 898         <xs:attribute name="commandText" type="SimpleLayoutAttribute">
 899           <xs:annotation>
 900             <xs:documentation>Text of the SQL command to be run on each log level.</xs:documentation>
 901           </xs:annotation>
 902         </xs:attribute>
 903         <xs:attribute name="commandType" type="System.Data.CommandType">
 904           <xs:annotation>
 905             <xs:documentation>Type of the SQL command to be run on each log level.</xs:documentation>
 906           </xs:annotation>
 907         </xs:attribute>
 908       </xs:extension>
 909     </xs:complexContent>
 910   </xs:complexType>
 911   <xs:simpleType name="System.Data.CommandType">
 912     <xs:restriction base="xs:string">
 913       <xs:enumeration value="Text" />
 914       <xs:enumeration value="StoredProcedure" />
 915       <xs:enumeration value="TableDirect" />
 916     </xs:restriction>
 917   </xs:simpleType>
 918   <xs:complexType name="NLog.Targets.DatabaseCommandInfo">
 919     <xs:choice minOccurs="0" maxOccurs="unbounded">
 920       <xs:element name="commandType" minOccurs="0" maxOccurs="1" type="System.Data.CommandType" />
 921       <xs:element name="connectionString" minOccurs="0" maxOccurs="1" type="Layout" />
 922       <xs:element name="ignoreFailures" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 923       <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.DatabaseParameterInfo" />
 924       <xs:element name="text" minOccurs="0" maxOccurs="1" type="Layout" />
 925     </xs:choice>
 926     <xs:attribute name="commandType" type="System.Data.CommandType">
 927       <xs:annotation>
 928         <xs:documentation>Type of the command.</xs:documentation>
 929       </xs:annotation>
 930     </xs:attribute>
 931     <xs:attribute name="connectionString" type="SimpleLayoutAttribute">
 932       <xs:annotation>
 933         <xs:documentation>Connection string to run the command against. If not provided, connection string from the target is used.</xs:documentation>
 934       </xs:annotation>
 935     </xs:attribute>
 936     <xs:attribute name="ignoreFailures" type="xs:boolean">
 937       <xs:annotation>
 938         <xs:documentation>Indicates whether to ignore failures.</xs:documentation>
 939       </xs:annotation>
 940     </xs:attribute>
 941     <xs:attribute name="text" type="SimpleLayoutAttribute">
 942       <xs:annotation>
 943         <xs:documentation>Command text.</xs:documentation>
 944       </xs:annotation>
 945     </xs:attribute>
 946   </xs:complexType>
 947   <xs:complexType name="NLog.Targets.DatabaseParameterInfo">
 948     <xs:choice minOccurs="0" maxOccurs="unbounded">
 949       <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
 950       <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 951       <xs:element name="precision" minOccurs="0" maxOccurs="1" type="xs:byte" />
 952       <xs:element name="scale" minOccurs="0" maxOccurs="1" type="xs:byte" />
 953       <xs:element name="size" minOccurs="0" maxOccurs="1" type="xs:integer" />
 954     </xs:choice>
 955     <xs:attribute name="layout" type="SimpleLayoutAttribute">
 956       <xs:annotation>
 957         <xs:documentation>Layout that should be use to calcuate the value for the parameter.</xs:documentation>
 958       </xs:annotation>
 959     </xs:attribute>
 960     <xs:attribute name="name" type="xs:string">
 961       <xs:annotation>
 962         <xs:documentation>Database parameter name.</xs:documentation>
 963       </xs:annotation>
 964     </xs:attribute>
 965     <xs:attribute name="precision" type="xs:byte">
 966       <xs:annotation>
 967         <xs:documentation>Database parameter precision.</xs:documentation>
 968       </xs:annotation>
 969     </xs:attribute>
 970     <xs:attribute name="scale" type="xs:byte">
 971       <xs:annotation>
 972         <xs:documentation>Database parameter scale.</xs:documentation>
 973       </xs:annotation>
 974     </xs:attribute>
 975     <xs:attribute name="size" type="xs:integer">
 976       <xs:annotation>
 977         <xs:documentation>Database parameter size.</xs:documentation>
 978       </xs:annotation>
 979     </xs:attribute>
 980   </xs:complexType>
 981   <xs:complexType name="Debugger">
 982     <xs:complexContent>
 983       <xs:extension base="Target">
 984         <xs:choice minOccurs="0" maxOccurs="unbounded">
 985           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
 986           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
 987           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
 988           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
 989           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
 990         </xs:choice>
 991         <xs:attribute name="name" type="xs:string">
 992           <xs:annotation>
 993             <xs:documentation>Name of the target.</xs:documentation>
 994           </xs:annotation>
 995         </xs:attribute>
 996         <xs:attribute name="layout" type="SimpleLayoutAttribute">
 997           <xs:annotation>
 998             <xs:documentation>Text to be rendered.</xs:documentation>
 999           </xs:annotation>
1000         </xs:attribute>
1001         <xs:attribute name="header" type="SimpleLayoutAttribute">
1002           <xs:annotation>
1003             <xs:documentation>Header.</xs:documentation>
1004           </xs:annotation>
1005         </xs:attribute>
1006         <xs:attribute name="footer" type="SimpleLayoutAttribute">
1007           <xs:annotation>
1008             <xs:documentation>Footer.</xs:documentation>
1009           </xs:annotation>
1010         </xs:attribute>
1011         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1012           <xs:annotation>
1013             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1014           </xs:annotation>
1015         </xs:attribute>
1016       </xs:extension>
1017     </xs:complexContent>
1018   </xs:complexType>
1019   <xs:complexType name="Debug">
1020     <xs:complexContent>
1021       <xs:extension base="Target">
1022         <xs:choice minOccurs="0" maxOccurs="unbounded">
1023           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1024           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1025           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1026         </xs:choice>
1027         <xs:attribute name="name" type="xs:string">
1028           <xs:annotation>
1029             <xs:documentation>Name of the target.</xs:documentation>
1030           </xs:annotation>
1031         </xs:attribute>
1032         <xs:attribute name="layout" type="SimpleLayoutAttribute">
1033           <xs:annotation>
1034             <xs:documentation>Layout used to format log messages.</xs:documentation>
1035           </xs:annotation>
1036         </xs:attribute>
1037         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1038           <xs:annotation>
1039             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1040           </xs:annotation>
1041         </xs:attribute>
1042       </xs:extension>
1043     </xs:complexContent>
1044   </xs:complexType>
1045   <xs:complexType name="EventLog">
1046     <xs:complexContent>
1047       <xs:extension base="Target">
1048         <xs:choice minOccurs="0" maxOccurs="unbounded">
1049           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1050           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1051           <xs:element name="category" minOccurs="0" maxOccurs="1" type="Layout" />
1052           <xs:element name="entryType" minOccurs="0" maxOccurs="1" type="Layout" />
1053           <xs:element name="eventId" minOccurs="0" maxOccurs="1" type="Layout" />
1054           <xs:element name="log" minOccurs="0" maxOccurs="1" type="xs:string" />
1055           <xs:element name="machineName" minOccurs="0" maxOccurs="1" type="xs:string" />
1056           <xs:element name="maxKilobytes" minOccurs="0" maxOccurs="1" type="xs:long" />
1057           <xs:element name="maxMessageLength" minOccurs="0" maxOccurs="1" type="xs:integer" />
1058           <xs:element name="source" minOccurs="0" maxOccurs="1" type="Layout" />
1059           <xs:element name="onOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.EventLogTargetOverflowAction" />
1060           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1061         </xs:choice>
1062         <xs:attribute name="name" type="xs:string">
1063           <xs:annotation>
1064             <xs:documentation>Name of the target.</xs:documentation>
1065           </xs:annotation>
1066         </xs:attribute>
1067         <xs:attribute name="layout" type="SimpleLayoutAttribute">
1068           <xs:annotation>
1069             <xs:documentation>Layout used to format log messages.</xs:documentation>
1070           </xs:annotation>
1071         </xs:attribute>
1072         <xs:attribute name="category" type="SimpleLayoutAttribute">
1073           <xs:annotation>
1074             <xs:documentation>Layout that renders event Category.</xs:documentation>
1075           </xs:annotation>
1076         </xs:attribute>
1077         <xs:attribute name="entryType" type="SimpleLayoutAttribute">
1078           <xs:annotation>
1079             <xs:documentation>Optional entrytype. When not set, or when not convertable to  then determined by </xs:documentation>
1080           </xs:annotation>
1081         </xs:attribute>
1082         <xs:attribute name="eventId" type="SimpleLayoutAttribute">
1083           <xs:annotation>
1084             <xs:documentation>Layout that renders event ID.</xs:documentation>
1085           </xs:annotation>
1086         </xs:attribute>
1087         <xs:attribute name="log" type="xs:string">
1088           <xs:annotation>
1089             <xs:documentation>Name of the Event Log to write to. This can be System, Application or any user-defined name.</xs:documentation>
1090           </xs:annotation>
1091         </xs:attribute>
1092         <xs:attribute name="machineName" type="xs:string">
1093           <xs:annotation>
1094             <xs:documentation>Name of the machine on which Event Log service is running.</xs:documentation>
1095           </xs:annotation>
1096         </xs:attribute>
1097         <xs:attribute name="maxKilobytes" type="xs:long">
1098           <xs:annotation>
1099             <xs:documentation>Maximum Event log size in kilobytes. If null, the value won't be set. Default is 512 Kilobytes as specified by Eventlog API</xs:documentation>
1100           </xs:annotation>
1101         </xs:attribute>
1102         <xs:attribute name="maxMessageLength" type="xs:integer">
1103           <xs:annotation>
1104             <xs:documentation>Message length limit to write to the Event Log.</xs:documentation>
1105           </xs:annotation>
1106         </xs:attribute>
1107         <xs:attribute name="source" type="SimpleLayoutAttribute">
1108           <xs:annotation>
1109             <xs:documentation>Value to be used as the event Source.</xs:documentation>
1110           </xs:annotation>
1111         </xs:attribute>
1112         <xs:attribute name="onOverflow" type="NLog.Targets.EventLogTargetOverflowAction">
1113           <xs:annotation>
1114             <xs:documentation>Action to take if the message is larger than the  option.</xs:documentation>
1115           </xs:annotation>
1116         </xs:attribute>
1117         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1118           <xs:annotation>
1119             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1120           </xs:annotation>
1121         </xs:attribute>
1122       </xs:extension>
1123     </xs:complexContent>
1124   </xs:complexType>
1125   <xs:simpleType name="NLog.Targets.EventLogTargetOverflowAction">
1126     <xs:restriction base="xs:string">
1127       <xs:enumeration value="Truncate" />
1128       <xs:enumeration value="Split" />
1129       <xs:enumeration value="Discard" />
1130     </xs:restriction>
1131   </xs:simpleType>
1132   <xs:complexType name="FallbackGroup">
1133     <xs:complexContent>
1134       <xs:extension base="CompoundTargetBase">
1135         <xs:choice minOccurs="0" maxOccurs="unbounded">
1136           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1137           <xs:element name="returnToFirstOnSuccess" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1138           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1139         </xs:choice>
1140         <xs:attribute name="name" type="xs:string">
1141           <xs:annotation>
1142             <xs:documentation>Name of the target.</xs:documentation>
1143           </xs:annotation>
1144         </xs:attribute>
1145         <xs:attribute name="returnToFirstOnSuccess" type="xs:boolean">
1146           <xs:annotation>
1147             <xs:documentation>Indicates whether to return to the first target after any successful write.</xs:documentation>
1148           </xs:annotation>
1149         </xs:attribute>
1150         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1151           <xs:annotation>
1152             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1153           </xs:annotation>
1154         </xs:attribute>
1155       </xs:extension>
1156     </xs:complexContent>
1157   </xs:complexType>
1158   <xs:complexType name="File">
1159     <xs:complexContent>
1160       <xs:extension base="Target">
1161         <xs:choice minOccurs="0" maxOccurs="unbounded">
1162           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1163           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1164           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
1165           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
1166           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
1167           <xs:element name="lineEnding" minOccurs="0" maxOccurs="1" type="LineEndingMode" />
1168           <xs:element name="enableArchiveFileCompression" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1169           <xs:element name="archiveNumbering" minOccurs="0" maxOccurs="1" type="NLog.Targets.ArchiveNumberingMode" />
1170           <xs:element name="archiveFileName" minOccurs="0" maxOccurs="1" type="Layout" />
1171           <xs:element name="archiveFileKind" minOccurs="0" maxOccurs="1" type="NLog.Targets.FilePathKind" />
1172           <xs:element name="archiveEvery" minOccurs="0" maxOccurs="1" type="NLog.Targets.FileArchivePeriod" />
1173           <xs:element name="archiveAboveSize" minOccurs="0" maxOccurs="1" type="xs:long" />
1174           <xs:element name="maxArchiveFiles" minOccurs="0" maxOccurs="1" type="xs:integer" />
1175           <xs:element name="writeFooterOnArchivingOnly" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1176           <xs:element name="maxLogFilenames" minOccurs="0" maxOccurs="1" type="xs:integer" />
1177           <xs:element name="fileNameKind" minOccurs="0" maxOccurs="1" type="NLog.Targets.FilePathKind" />
1178           <xs:element name="forceManaged" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1179           <xs:element name="forceMutexConcurrentWrites" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1180           <xs:element name="replaceFileContentsOnEachWrite" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1181           <xs:element name="writeBom" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1182           <xs:element name="enableFileDelete" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1183           <xs:element name="fileName" minOccurs="0" maxOccurs="1" type="Layout" />
1184           <xs:element name="archiveDateFormat" minOccurs="0" maxOccurs="1" type="xs:string" />
1185           <xs:element name="archiveOldFileOnStartup" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1186           <xs:element name="cleanupFileName" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1187           <xs:element name="createDirs" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1188           <xs:element name="deleteOldFileOnStartup" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1189           <xs:element name="fileAttributes" minOccurs="0" maxOccurs="1" type="NLog.Targets.Win32FileAttributes" />
1190           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1191           <xs:element name="networkWrites" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1192           <xs:element name="openFileCacheTimeout" minOccurs="0" maxOccurs="1" type="xs:integer" />
1193           <xs:element name="openFileCacheSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
1194           <xs:element name="keepFileOpen" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1195           <xs:element name="discardAll" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1196           <xs:element name="concurrentWrites" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1197           <xs:element name="concurrentWriteAttempts" minOccurs="0" maxOccurs="1" type="xs:integer" />
1198           <xs:element name="concurrentWriteAttemptDelay" minOccurs="0" maxOccurs="1" type="xs:integer" />
1199           <xs:element name="bufferSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
1200           <xs:element name="openFileFlushTimeout" minOccurs="0" maxOccurs="1" type="xs:integer" />
1201           <xs:element name="autoFlush" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1202         </xs:choice>
1203         <xs:attribute name="name" type="xs:string">
1204           <xs:annotation>
1205             <xs:documentation>Name of the target.</xs:documentation>
1206           </xs:annotation>
1207         </xs:attribute>
1208         <xs:attribute name="layout" type="SimpleLayoutAttribute">
1209           <xs:annotation>
1210             <xs:documentation>Text to be rendered.</xs:documentation>
1211           </xs:annotation>
1212         </xs:attribute>
1213         <xs:attribute name="header" type="SimpleLayoutAttribute">
1214           <xs:annotation>
1215             <xs:documentation>Header.</xs:documentation>
1216           </xs:annotation>
1217         </xs:attribute>
1218         <xs:attribute name="footer" type="SimpleLayoutAttribute">
1219           <xs:annotation>
1220             <xs:documentation>Footer.</xs:documentation>
1221           </xs:annotation>
1222         </xs:attribute>
1223         <xs:attribute name="encoding" type="xs:string">
1224           <xs:annotation>
1225             <xs:documentation>File encoding.</xs:documentation>
1226           </xs:annotation>
1227         </xs:attribute>
1228         <xs:attribute name="lineEnding" type="LineEndingMode">
1229           <xs:annotation>
1230             <xs:documentation>Line ending mode.</xs:documentation>
1231           </xs:annotation>
1232         </xs:attribute>
1233         <xs:attribute name="enableArchiveFileCompression" type="xs:boolean">
1234           <xs:annotation>
1235             <xs:documentation>Indicates whether to compress archive files into the zip archive format.</xs:documentation>
1236           </xs:annotation>
1237         </xs:attribute>
1238         <xs:attribute name="archiveNumbering" type="NLog.Targets.ArchiveNumberingMode">
1239           <xs:annotation>
1240             <xs:documentation>Way file archives are numbered.</xs:documentation>
1241           </xs:annotation>
1242         </xs:attribute>
1243         <xs:attribute name="archiveFileName" type="SimpleLayoutAttribute">
1244           <xs:annotation>
1245             <xs:documentation>Name of the file to be used for an archive.</xs:documentation>
1246           </xs:annotation>
1247         </xs:attribute>
1248         <xs:attribute name="archiveFileKind" type="NLog.Targets.FilePathKind">
1249           <xs:annotation>
1250             <xs:documentation>Is the  an absolute or relative path?</xs:documentation>
1251           </xs:annotation>
1252         </xs:attribute>
1253         <xs:attribute name="archiveEvery" type="NLog.Targets.FileArchivePeriod">
1254           <xs:annotation>
1255             <xs:documentation>Indicates whether to automatically archive log files every time the specified time passes.</xs:documentation>
1256           </xs:annotation>
1257         </xs:attribute>
1258         <xs:attribute name="archiveAboveSize" type="xs:long">
1259           <xs:annotation>
1260             <xs:documentation>Size in bytes above which log files will be automatically archived. Warning: combining this with  isn't supported. We cannot create multiple archive files, if they should have the same name. Choose: </xs:documentation>
1261           </xs:annotation>
1262         </xs:attribute>
1263         <xs:attribute name="maxArchiveFiles" type="xs:integer">
1264           <xs:annotation>
1265             <xs:documentation>Maximum number of archive files that should be kept.</xs:documentation>
1266           </xs:annotation>
1267         </xs:attribute>
1268         <xs:attribute name="writeFooterOnArchivingOnly" type="xs:boolean">
1269           <xs:annotation>
1270             <xs:documentation>Indicates whether the footer should be written only when the file is archived.</xs:documentation>
1271           </xs:annotation>
1272         </xs:attribute>
1273         <xs:attribute name="maxLogFilenames" type="xs:integer">
1274           <xs:annotation>
1275             <xs:documentation>Maximum number of log filenames that should be stored as existing.</xs:documentation>
1276           </xs:annotation>
1277         </xs:attribute>
1278         <xs:attribute name="fileNameKind" type="NLog.Targets.FilePathKind">
1279           <xs:annotation>
1280             <xs:documentation>Is the  an absolute or relative path?</xs:documentation>
1281           </xs:annotation>
1282         </xs:attribute>
1283         <xs:attribute name="forceManaged" type="xs:boolean">
1284           <xs:annotation>
1285             <xs:documentation>Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation.</xs:documentation>
1286           </xs:annotation>
1287         </xs:attribute>
1288         <xs:attribute name="forceMutexConcurrentWrites" type="xs:boolean">
1289           <xs:annotation>
1290             <xs:documentation>Value indicationg whether file creation calls should be synchronized by a system global mutex.</xs:documentation>
1291           </xs:annotation>
1292         </xs:attribute>
1293         <xs:attribute name="replaceFileContentsOnEachWrite" type="xs:boolean">
1294           <xs:annotation>
1295             <xs:documentation>Indicates whether to replace file contents on each write instead of appending log message at the end.</xs:documentation>
1296           </xs:annotation>
1297         </xs:attribute>
1298         <xs:attribute name="writeBom" type="xs:boolean">
1299           <xs:annotation>
1300             <xs:documentation>Indicates whether to write BOM (byte order mark) in created files</xs:documentation>
1301           </xs:annotation>
1302         </xs:attribute>
1303         <xs:attribute name="enableFileDelete" type="xs:boolean">
1304           <xs:annotation>
1305             <xs:documentation>Indicates whether to enable log file(s) to be deleted.</xs:documentation>
1306           </xs:annotation>
1307         </xs:attribute>
1308         <xs:attribute name="fileName" type="SimpleLayoutAttribute">
1309           <xs:annotation>
1310             <xs:documentation>Name of the file to write to.</xs:documentation>
1311           </xs:annotation>
1312         </xs:attribute>
1313         <xs:attribute name="archiveDateFormat" type="xs:string">
1314           <xs:annotation>
1315             <xs:documentation>Value specifying the date format to use when archiving files.</xs:documentation>
1316           </xs:annotation>
1317         </xs:attribute>
1318         <xs:attribute name="archiveOldFileOnStartup" type="xs:boolean">
1319           <xs:annotation>
1320             <xs:documentation>Indicates whether to archive old log file on startup.</xs:documentation>
1321           </xs:annotation>
1322         </xs:attribute>
1323         <xs:attribute name="cleanupFileName" type="xs:boolean">
1324           <xs:annotation>
1325             <xs:documentation>Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong.</xs:documentation>
1326           </xs:annotation>
1327         </xs:attribute>
1328         <xs:attribute name="createDirs" type="xs:boolean">
1329           <xs:annotation>
1330             <xs:documentation>Indicates whether to create directories if they do not exist.</xs:documentation>
1331           </xs:annotation>
1332         </xs:attribute>
1333         <xs:attribute name="deleteOldFileOnStartup" type="xs:boolean">
1334           <xs:annotation>
1335             <xs:documentation>Indicates whether to delete old log file on startup.</xs:documentation>
1336           </xs:annotation>
1337         </xs:attribute>
1338         <xs:attribute name="fileAttributes" type="NLog.Targets.Win32FileAttributes">
1339           <xs:annotation>
1340             <xs:documentation>File attributes (Windows only).</xs:documentation>
1341           </xs:annotation>
1342         </xs:attribute>
1343         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1344           <xs:annotation>
1345             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1346           </xs:annotation>
1347         </xs:attribute>
1348         <xs:attribute name="networkWrites" type="xs:boolean">
1349           <xs:annotation>
1350             <xs:documentation>Indicates whether concurrent writes to the log file by multiple processes on different network hosts.</xs:documentation>
1351           </xs:annotation>
1352         </xs:attribute>
1353         <xs:attribute name="openFileCacheTimeout" type="xs:integer">
1354           <xs:annotation>
1355             <xs:documentation>Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity.</xs:documentation>
1356           </xs:annotation>
1357         </xs:attribute>
1358         <xs:attribute name="openFileCacheSize" type="xs:integer">
1359           <xs:annotation>
1360             <xs:documentation>Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger).</xs:documentation>
1361           </xs:annotation>
1362         </xs:attribute>
1363         <xs:attribute name="keepFileOpen" type="xs:boolean">
1364           <xs:annotation>
1365             <xs:documentation>Indicates whether to keep log file open instead of opening and closing it on each logging event.</xs:documentation>
1366           </xs:annotation>
1367         </xs:attribute>
1368         <xs:attribute name="discardAll" type="xs:boolean">
1369           <xs:annotation>
1370             <xs:documentation>Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write</xs:documentation>
1371           </xs:annotation>
1372         </xs:attribute>
1373         <xs:attribute name="concurrentWrites" type="xs:boolean">
1374           <xs:annotation>
1375             <xs:documentation>Indicates whether concurrent writes to the log file by multiple processes on the same host.</xs:documentation>
1376           </xs:annotation>
1377         </xs:attribute>
1378         <xs:attribute name="concurrentWriteAttempts" type="xs:integer">
1379           <xs:annotation>
1380             <xs:documentation>Number of times the write is appended on the file before NLog discards the log message.</xs:documentation>
1381           </xs:annotation>
1382         </xs:attribute>
1383         <xs:attribute name="concurrentWriteAttemptDelay" type="xs:integer">
1384           <xs:annotation>
1385             <xs:documentation>Delay in milliseconds to wait before attempting to write to the file again.</xs:documentation>
1386           </xs:annotation>
1387         </xs:attribute>
1388         <xs:attribute name="bufferSize" type="xs:integer">
1389           <xs:annotation>
1390             <xs:documentation>Log file buffer size in bytes.</xs:documentation>
1391           </xs:annotation>
1392         </xs:attribute>
1393         <xs:attribute name="openFileFlushTimeout" type="xs:integer">
1394           <xs:annotation>
1395             <xs:documentation>Maximum number of seconds before open files are flushed. If this number is negative or zero the files are not flushed by timer.</xs:documentation>
1396           </xs:annotation>
1397         </xs:attribute>
1398         <xs:attribute name="autoFlush" type="xs:boolean">
1399           <xs:annotation>
1400             <xs:documentation>Indicates whether to automatically flush the file buffers after each log message.</xs:documentation>
1401           </xs:annotation>
1402         </xs:attribute>
1403       </xs:extension>
1404     </xs:complexContent>
1405   </xs:complexType>
1406   <xs:simpleType name="NLog.Targets.ArchiveNumberingMode">
1407     <xs:restriction base="xs:string">
1408       <xs:enumeration value="Sequence" />
1409       <xs:enumeration value="Rolling" />
1410       <xs:enumeration value="Date" />
1411       <xs:enumeration value="DateAndSequence" />
1412     </xs:restriction>
1413   </xs:simpleType>
1414   <xs:simpleType name="NLog.Targets.FilePathKind">
1415     <xs:restriction base="xs:string">
1416       <xs:enumeration value="Unknown" />
1417       <xs:enumeration value="Relative" />
1418       <xs:enumeration value="Absolute" />
1419     </xs:restriction>
1420   </xs:simpleType>
1421   <xs:simpleType name="NLog.Targets.FileArchivePeriod">
1422     <xs:restriction base="xs:string">
1423       <xs:enumeration value="None" />
1424       <xs:enumeration value="Year" />
1425       <xs:enumeration value="Month" />
1426       <xs:enumeration value="Day" />
1427       <xs:enumeration value="Hour" />
1428       <xs:enumeration value="Minute" />
1429       <xs:enumeration value="Sunday" />
1430       <xs:enumeration value="Monday" />
1431       <xs:enumeration value="Tuesday" />
1432       <xs:enumeration value="Wednesday" />
1433       <xs:enumeration value="Thursday" />
1434       <xs:enumeration value="Friday" />
1435       <xs:enumeration value="Saturday" />
1436     </xs:restriction>
1437   </xs:simpleType>
1438   <xs:simpleType name="NLog.Targets.Win32FileAttributes">
1439     <xs:restriction base="xs:string">
1440       <xs:enumeration value="ReadOnly" />
1441       <xs:enumeration value="Hidden" />
1442       <xs:enumeration value="System" />
1443       <xs:enumeration value="Archive" />
1444       <xs:enumeration value="Device" />
1445       <xs:enumeration value="Normal" />
1446       <xs:enumeration value="Temporary" />
1447       <xs:enumeration value="SparseFile" />
1448       <xs:enumeration value="ReparsePoint" />
1449       <xs:enumeration value="Compressed" />
1450       <xs:enumeration value="NotContentIndexed" />
1451       <xs:enumeration value="Encrypted" />
1452       <xs:enumeration value="WriteThrough" />
1453       <xs:enumeration value="NoBuffering" />
1454       <xs:enumeration value="DeleteOnClose" />
1455       <xs:enumeration value="PosixSemantics" />
1456     </xs:restriction>
1457   </xs:simpleType>
1458   <xs:complexType name="FilteringWrapper">
1459     <xs:complexContent>
1460       <xs:extension base="WrapperTargetBase">
1461         <xs:choice minOccurs="0" maxOccurs="unbounded">
1462           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1463           <xs:element name="condition" minOccurs="0" maxOccurs="1" type="Condition" />
1464           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1465         </xs:choice>
1466         <xs:attribute name="name" type="xs:string">
1467           <xs:annotation>
1468             <xs:documentation>Name of the target.</xs:documentation>
1469           </xs:annotation>
1470         </xs:attribute>
1471         <xs:attribute name="condition" type="Condition">
1472           <xs:annotation>
1473             <xs:documentation>Condition expression. Log events who meet this condition will be forwarded to the wrapped target.</xs:documentation>
1474           </xs:annotation>
1475         </xs:attribute>
1476         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1477           <xs:annotation>
1478             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1479           </xs:annotation>
1480         </xs:attribute>
1481       </xs:extension>
1482     </xs:complexContent>
1483   </xs:complexType>
1484   <xs:complexType name="ImpersonatingWrapper">
1485     <xs:complexContent>
1486       <xs:extension base="WrapperTargetBase">
1487         <xs:choice minOccurs="0" maxOccurs="unbounded">
1488           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1489           <xs:element name="domain" minOccurs="0" maxOccurs="1" type="xs:string" />
1490           <xs:element name="impersonationLevel" minOccurs="0" maxOccurs="1" type="NLog.Targets.Wrappers.SecurityImpersonationLevel" />
1491           <xs:element name="logOnProvider" minOccurs="0" maxOccurs="1" type="NLog.Targets.Wrappers.LogOnProviderType" />
1492           <xs:element name="logOnType" minOccurs="0" maxOccurs="1" type="NLog.Targets.Wrappers.SecurityLogOnType" />
1493           <xs:element name="password" minOccurs="0" maxOccurs="1" type="xs:string" />
1494           <xs:element name="revertToSelf" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1495           <xs:element name="userName" minOccurs="0" maxOccurs="1" type="xs:string" />
1496           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1497         </xs:choice>
1498         <xs:attribute name="name" type="xs:string">
1499           <xs:annotation>
1500             <xs:documentation>Name of the target.</xs:documentation>
1501           </xs:annotation>
1502         </xs:attribute>
1503         <xs:attribute name="domain" type="xs:string">
1504           <xs:annotation>
1505             <xs:documentation>Windows domain name to change context to.</xs:documentation>
1506           </xs:annotation>
1507         </xs:attribute>
1508         <xs:attribute name="impersonationLevel" type="NLog.Targets.Wrappers.SecurityImpersonationLevel">
1509           <xs:annotation>
1510             <xs:documentation>Required impersonation level.</xs:documentation>
1511           </xs:annotation>
1512         </xs:attribute>
1513         <xs:attribute name="logOnProvider" type="NLog.Targets.Wrappers.LogOnProviderType">
1514           <xs:annotation>
1515             <xs:documentation>Type of the logon provider.</xs:documentation>
1516           </xs:annotation>
1517         </xs:attribute>
1518         <xs:attribute name="logOnType" type="NLog.Targets.Wrappers.SecurityLogOnType">
1519           <xs:annotation>
1520             <xs:documentation>Logon Type.</xs:documentation>
1521           </xs:annotation>
1522         </xs:attribute>
1523         <xs:attribute name="password" type="xs:string">
1524           <xs:annotation>
1525             <xs:documentation>User account password.</xs:documentation>
1526           </xs:annotation>
1527         </xs:attribute>
1528         <xs:attribute name="revertToSelf" type="xs:boolean">
1529           <xs:annotation>
1530             <xs:documentation>Indicates whether to revert to the credentials of the process instead of impersonating another user.</xs:documentation>
1531           </xs:annotation>
1532         </xs:attribute>
1533         <xs:attribute name="userName" type="xs:string">
1534           <xs:annotation>
1535             <xs:documentation>Username to change context to.</xs:documentation>
1536           </xs:annotation>
1537         </xs:attribute>
1538         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1539           <xs:annotation>
1540             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1541           </xs:annotation>
1542         </xs:attribute>
1543       </xs:extension>
1544     </xs:complexContent>
1545   </xs:complexType>
1546   <xs:simpleType name="NLog.Targets.Wrappers.SecurityImpersonationLevel">
1547     <xs:restriction base="xs:string">
1548       <xs:enumeration value="Anonymous" />
1549       <xs:enumeration value="Identification" />
1550       <xs:enumeration value="Impersonation" />
1551       <xs:enumeration value="Delegation" />
1552     </xs:restriction>
1553   </xs:simpleType>
1554   <xs:simpleType name="NLog.Targets.Wrappers.LogOnProviderType">
1555     <xs:restriction base="xs:string">
1556       <xs:enumeration value="Default" />
1557     </xs:restriction>
1558   </xs:simpleType>
1559   <xs:simpleType name="NLog.Targets.Wrappers.SecurityLogOnType">
1560     <xs:restriction base="xs:string">
1561       <xs:enumeration value="Interactive" />
1562       <xs:enumeration value="Network" />
1563       <xs:enumeration value="Batch" />
1564       <xs:enumeration value="Service" />
1565       <xs:enumeration value="NetworkClearText" />
1566       <xs:enumeration value="NewCredentials" />
1567     </xs:restriction>
1568   </xs:simpleType>
1569   <xs:complexType name="LimitingWrapper">
1570     <xs:complexContent>
1571       <xs:extension base="WrapperTargetBase">
1572         <xs:choice minOccurs="0" maxOccurs="unbounded">
1573           <xs:element name="interval" minOccurs="0" maxOccurs="1" type="xs:string" />
1574           <xs:element name="messageLimit" minOccurs="0" maxOccurs="1" type="xs:integer" />
1575           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1576           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1577         </xs:choice>
1578         <xs:attribute name="interval" type="xs:string">
1579           <xs:annotation>
1580             <xs:documentation>Interval in which messages will be written up to the  number of messages.</xs:documentation>
1581           </xs:annotation>
1582         </xs:attribute>
1583         <xs:attribute name="messageLimit" type="xs:integer">
1584           <xs:annotation>
1585             <xs:documentation>Maximum allowed number of messages written per .</xs:documentation>
1586           </xs:annotation>
1587         </xs:attribute>
1588         <xs:attribute name="name" type="xs:string">
1589           <xs:annotation>
1590             <xs:documentation>Name of the target.</xs:documentation>
1591           </xs:annotation>
1592         </xs:attribute>
1593         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1594           <xs:annotation>
1595             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1596           </xs:annotation>
1597         </xs:attribute>
1598       </xs:extension>
1599     </xs:complexContent>
1600   </xs:complexType>
1601   <xs:complexType name="LogReceiverService">
1602     <xs:complexContent>
1603       <xs:extension base="Target">
1604         <xs:choice minOccurs="0" maxOccurs="unbounded">
1605           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1606           <xs:element name="endpointAddress" minOccurs="0" maxOccurs="1" type="xs:string" />
1607           <xs:element name="endpointConfigurationName" minOccurs="0" maxOccurs="1" type="xs:string" />
1608           <xs:element name="useOneWayContract" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1609           <xs:element name="clientId" minOccurs="0" maxOccurs="1" type="Layout" />
1610           <xs:element name="includeEventProperties" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1611           <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.MethodCallParameter" />
1612           <xs:element name="useBinaryEncoding" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1613           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1614         </xs:choice>
1615         <xs:attribute name="name" type="xs:string">
1616           <xs:annotation>
1617             <xs:documentation>Name of the target.</xs:documentation>
1618           </xs:annotation>
1619         </xs:attribute>
1620         <xs:attribute name="endpointAddress" type="xs:string">
1621           <xs:annotation>
1622             <xs:documentation>Endpoint address.</xs:documentation>
1623           </xs:annotation>
1624         </xs:attribute>
1625         <xs:attribute name="endpointConfigurationName" type="xs:string">
1626           <xs:annotation>
1627             <xs:documentation>Name of the endpoint configuration in WCF configuration file.</xs:documentation>
1628           </xs:annotation>
1629         </xs:attribute>
1630         <xs:attribute name="useOneWayContract" type="xs:boolean">
1631           <xs:annotation>
1632             <xs:documentation>Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply)</xs:documentation>
1633           </xs:annotation>
1634         </xs:attribute>
1635         <xs:attribute name="clientId" type="SimpleLayoutAttribute">
1636           <xs:annotation>
1637             <xs:documentation>Client ID.</xs:documentation>
1638           </xs:annotation>
1639         </xs:attribute>
1640         <xs:attribute name="includeEventProperties" type="xs:boolean">
1641           <xs:annotation>
1642             <xs:documentation>Indicates whether to include per-event properties in the payload sent to the server.</xs:documentation>
1643           </xs:annotation>
1644         </xs:attribute>
1645         <xs:attribute name="useBinaryEncoding" type="xs:boolean">
1646           <xs:annotation>
1647             <xs:documentation>Indicates whether to use binary message encoding.</xs:documentation>
1648           </xs:annotation>
1649         </xs:attribute>
1650         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1651           <xs:annotation>
1652             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1653           </xs:annotation>
1654         </xs:attribute>
1655       </xs:extension>
1656     </xs:complexContent>
1657   </xs:complexType>
1658   <xs:complexType name="NLog.Targets.MethodCallParameter">
1659     <xs:choice minOccurs="0" maxOccurs="unbounded">
1660       <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1661       <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1662       <xs:element name="parameterType" minOccurs="0" maxOccurs="1" type="xs:string" />
1663       <xs:element name="type" minOccurs="0" maxOccurs="1" type="xs:string" />
1664     </xs:choice>
1665     <xs:attribute name="layout" type="SimpleLayoutAttribute">
1666       <xs:annotation>
1667         <xs:documentation>Layout that should be use to calculate the value for the parameter.</xs:documentation>
1668       </xs:annotation>
1669     </xs:attribute>
1670     <xs:attribute name="name" type="xs:string">
1671       <xs:annotation>
1672         <xs:documentation>Name of the parameter.</xs:documentation>
1673       </xs:annotation>
1674     </xs:attribute>
1675     <xs:attribute name="parameterType" type="xs:string">
1676       <xs:annotation>
1677         <xs:documentation>Type of the parameter.</xs:documentation>
1678       </xs:annotation>
1679     </xs:attribute>
1680     <xs:attribute name="type" type="xs:string">
1681       <xs:annotation>
1682         <xs:documentation>Type of the parameter. Obsolete alias for </xs:documentation>
1683       </xs:annotation>
1684     </xs:attribute>
1685   </xs:complexType>
1686   <xs:complexType name="Mail">
1687     <xs:complexContent>
1688       <xs:extension base="Target">
1689         <xs:choice minOccurs="0" maxOccurs="unbounded">
1690           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1691           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1692           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
1693           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
1694           <xs:element name="replaceNewlineWithBrTagInHtml" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1695           <xs:element name="priority" minOccurs="0" maxOccurs="1" type="Layout" />
1696           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
1697           <xs:element name="bcc" minOccurs="0" maxOccurs="1" type="Layout" />
1698           <xs:element name="cc" minOccurs="0" maxOccurs="1" type="Layout" />
1699           <xs:element name="addNewLines" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1700           <xs:element name="html" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1701           <xs:element name="from" minOccurs="0" maxOccurs="1" type="Layout" />
1702           <xs:element name="body" minOccurs="0" maxOccurs="1" type="Layout" />
1703           <xs:element name="subject" minOccurs="0" maxOccurs="1" type="Layout" />
1704           <xs:element name="to" minOccurs="0" maxOccurs="1" type="Layout" />
1705           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1706           <xs:element name="timeout" minOccurs="0" maxOccurs="1" type="xs:integer" />
1707           <xs:element name="smtpServer" minOccurs="0" maxOccurs="1" type="Layout" />
1708           <xs:element name="smtpAuthentication" minOccurs="0" maxOccurs="1" type="NLog.Targets.SmtpAuthenticationMode" />
1709           <xs:element name="smtpUserName" minOccurs="0" maxOccurs="1" type="Layout" />
1710           <xs:element name="smtpPassword" minOccurs="0" maxOccurs="1" type="Layout" />
1711           <xs:element name="enableSsl" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1712           <xs:element name="smtpPort" minOccurs="0" maxOccurs="1" type="xs:integer" />
1713           <xs:element name="useSystemNetMailSettings" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1714           <xs:element name="pickupDirectoryLocation" minOccurs="0" maxOccurs="1" type="xs:string" />
1715           <xs:element name="deliveryMethod" minOccurs="0" maxOccurs="1" type="System.Net.Mail.SmtpDeliveryMethod" />
1716         </xs:choice>
1717         <xs:attribute name="name" type="xs:string">
1718           <xs:annotation>
1719             <xs:documentation>Name of the target.</xs:documentation>
1720           </xs:annotation>
1721         </xs:attribute>
1722         <xs:attribute name="layout" type="SimpleLayoutAttribute">
1723           <xs:annotation>
1724             <xs:documentation>Text to be rendered.</xs:documentation>
1725           </xs:annotation>
1726         </xs:attribute>
1727         <xs:attribute name="header" type="SimpleLayoutAttribute">
1728           <xs:annotation>
1729             <xs:documentation>Header.</xs:documentation>
1730           </xs:annotation>
1731         </xs:attribute>
1732         <xs:attribute name="footer" type="SimpleLayoutAttribute">
1733           <xs:annotation>
1734             <xs:documentation>Footer.</xs:documentation>
1735           </xs:annotation>
1736         </xs:attribute>
1737         <xs:attribute name="replaceNewlineWithBrTagInHtml" type="xs:boolean">
1738           <xs:annotation>
1739             <xs:documentation>Indicates whether NewLine characters in the body should be replaced with  tags.</xs:documentation>
1740           </xs:annotation>
1741         </xs:attribute>
1742         <xs:attribute name="priority" type="SimpleLayoutAttribute">
1743           <xs:annotation>
1744             <xs:documentation>Priority used for sending mails.</xs:documentation>
1745           </xs:annotation>
1746         </xs:attribute>
1747         <xs:attribute name="encoding" type="xs:string">
1748           <xs:annotation>
1749             <xs:documentation>Encoding to be used for sending e-mail.</xs:documentation>
1750           </xs:annotation>
1751         </xs:attribute>
1752         <xs:attribute name="bcc" type="SimpleLayoutAttribute">
1753           <xs:annotation>
1754             <xs:documentation>BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com).</xs:documentation>
1755           </xs:annotation>
1756         </xs:attribute>
1757         <xs:attribute name="cc" type="SimpleLayoutAttribute">
1758           <xs:annotation>
1759             <xs:documentation>CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com).</xs:documentation>
1760           </xs:annotation>
1761         </xs:attribute>
1762         <xs:attribute name="addNewLines" type="xs:boolean">
1763           <xs:annotation>
1764             <xs:documentation>Indicates whether to add new lines between log entries.</xs:documentation>
1765           </xs:annotation>
1766         </xs:attribute>
1767         <xs:attribute name="html" type="xs:boolean">
1768           <xs:annotation>
1769             <xs:documentation>Indicates whether to send message as HTML instead of plain text.</xs:documentation>
1770           </xs:annotation>
1771         </xs:attribute>
1772         <xs:attribute name="from" type="SimpleLayoutAttribute">
1773           <xs:annotation>
1774             <xs:documentation>Sender's email address (e.g. joe@domain.com).</xs:documentation>
1775           </xs:annotation>
1776         </xs:attribute>
1777         <xs:attribute name="body" type="SimpleLayoutAttribute">
1778           <xs:annotation>
1779             <xs:documentation>Mail message body (repeated for each log message send in one mail).</xs:documentation>
1780           </xs:annotation>
1781         </xs:attribute>
1782         <xs:attribute name="subject" type="SimpleLayoutAttribute">
1783           <xs:annotation>
1784             <xs:documentation>Mail subject.</xs:documentation>
1785           </xs:annotation>
1786         </xs:attribute>
1787         <xs:attribute name="to" type="SimpleLayoutAttribute">
1788           <xs:annotation>
1789             <xs:documentation>Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com).</xs:documentation>
1790           </xs:annotation>
1791         </xs:attribute>
1792         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1793           <xs:annotation>
1794             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1795           </xs:annotation>
1796         </xs:attribute>
1797         <xs:attribute name="timeout" type="xs:integer">
1798           <xs:annotation>
1799             <xs:documentation>Indicates the SMTP client timeout.</xs:documentation>
1800           </xs:annotation>
1801         </xs:attribute>
1802         <xs:attribute name="smtpServer" type="SimpleLayoutAttribute">
1803           <xs:annotation>
1804             <xs:documentation>SMTP Server to be used for sending.</xs:documentation>
1805           </xs:annotation>
1806         </xs:attribute>
1807         <xs:attribute name="smtpAuthentication" type="NLog.Targets.SmtpAuthenticationMode">
1808           <xs:annotation>
1809             <xs:documentation>SMTP Authentication mode.</xs:documentation>
1810           </xs:annotation>
1811         </xs:attribute>
1812         <xs:attribute name="smtpUserName" type="SimpleLayoutAttribute">
1813           <xs:annotation>
1814             <xs:documentation>Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic").</xs:documentation>
1815           </xs:annotation>
1816         </xs:attribute>
1817         <xs:attribute name="smtpPassword" type="SimpleLayoutAttribute">
1818           <xs:annotation>
1819             <xs:documentation>Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic").</xs:documentation>
1820           </xs:annotation>
1821         </xs:attribute>
1822         <xs:attribute name="enableSsl" type="xs:boolean">
1823           <xs:annotation>
1824             <xs:documentation>Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server.</xs:documentation>
1825           </xs:annotation>
1826         </xs:attribute>
1827         <xs:attribute name="smtpPort" type="xs:integer">
1828           <xs:annotation>
1829             <xs:documentation>Port number that SMTP Server is listening on.</xs:documentation>
1830           </xs:annotation>
1831         </xs:attribute>
1832         <xs:attribute name="useSystemNetMailSettings" type="xs:boolean">
1833           <xs:annotation>
1834             <xs:documentation>Indicates whether the default Settings from System.Net.MailSettings should be used.</xs:documentation>
1835           </xs:annotation>
1836         </xs:attribute>
1837         <xs:attribute name="pickupDirectoryLocation" type="xs:string">
1838           <xs:annotation>
1839             <xs:documentation>Folder where applications save mail messages to be processed by the local SMTP server.</xs:documentation>
1840           </xs:annotation>
1841         </xs:attribute>
1842         <xs:attribute name="deliveryMethod" type="System.Net.Mail.SmtpDeliveryMethod">
1843           <xs:annotation>
1844             <xs:documentation>Specifies how outgoing email messages will be handled.</xs:documentation>
1845           </xs:annotation>
1846         </xs:attribute>
1847       </xs:extension>
1848     </xs:complexContent>
1849   </xs:complexType>
1850   <xs:simpleType name="NLog.Targets.SmtpAuthenticationMode">
1851     <xs:restriction base="xs:string">
1852       <xs:enumeration value="None" />
1853       <xs:enumeration value="Basic" />
1854       <xs:enumeration value="Ntlm" />
1855     </xs:restriction>
1856   </xs:simpleType>
1857   <xs:simpleType name="System.Net.Mail.SmtpDeliveryMethod">
1858     <xs:restriction base="xs:string">
1859       <xs:enumeration value="Network" />
1860       <xs:enumeration value="SpecifiedPickupDirectory" />
1861       <xs:enumeration value="PickupDirectoryFromIis" />
1862     </xs:restriction>
1863   </xs:simpleType>
1864   <xs:complexType name="Memory">
1865     <xs:complexContent>
1866       <xs:extension base="Target">
1867         <xs:choice minOccurs="0" maxOccurs="unbounded">
1868           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1869           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1870           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1871         </xs:choice>
1872         <xs:attribute name="name" type="xs:string">
1873           <xs:annotation>
1874             <xs:documentation>Name of the target.</xs:documentation>
1875           </xs:annotation>
1876         </xs:attribute>
1877         <xs:attribute name="layout" type="SimpleLayoutAttribute">
1878           <xs:annotation>
1879             <xs:documentation>Layout used to format log messages.</xs:documentation>
1880           </xs:annotation>
1881         </xs:attribute>
1882         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1883           <xs:annotation>
1884             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1885           </xs:annotation>
1886         </xs:attribute>
1887       </xs:extension>
1888     </xs:complexContent>
1889   </xs:complexType>
1890   <xs:complexType name="MethodCall">
1891     <xs:complexContent>
1892       <xs:extension base="Target">
1893         <xs:choice minOccurs="0" maxOccurs="unbounded">
1894           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1895           <xs:element name="className" minOccurs="0" maxOccurs="1" type="xs:string" />
1896           <xs:element name="methodName" minOccurs="0" maxOccurs="1" type="xs:string" />
1897           <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.MethodCallParameter" />
1898           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1899         </xs:choice>
1900         <xs:attribute name="name" type="xs:string">
1901           <xs:annotation>
1902             <xs:documentation>Name of the target.</xs:documentation>
1903           </xs:annotation>
1904         </xs:attribute>
1905         <xs:attribute name="className" type="xs:string">
1906           <xs:annotation>
1907             <xs:documentation>Class name.</xs:documentation>
1908           </xs:annotation>
1909         </xs:attribute>
1910         <xs:attribute name="methodName" type="xs:string">
1911           <xs:annotation>
1912             <xs:documentation>Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g.</xs:documentation>
1913           </xs:annotation>
1914         </xs:attribute>
1915         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
1916           <xs:annotation>
1917             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
1918           </xs:annotation>
1919         </xs:attribute>
1920       </xs:extension>
1921     </xs:complexContent>
1922   </xs:complexType>
1923   <xs:complexType name="Network">
1924     <xs:complexContent>
1925       <xs:extension base="Target">
1926         <xs:choice minOccurs="0" maxOccurs="unbounded">
1927           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
1928           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
1929           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
1930           <xs:element name="lineEnding" minOccurs="0" maxOccurs="1" type="LineEndingMode" />
1931           <xs:element name="maxMessageSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
1932           <xs:element name="newLine" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1933           <xs:element name="address" minOccurs="0" maxOccurs="1" type="Layout" />
1934           <xs:element name="connectionCacheSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
1935           <xs:element name="keepConnection" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1936           <xs:element name="maxConnections" minOccurs="0" maxOccurs="1" type="xs:integer" />
1937           <xs:element name="maxQueueSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
1938           <xs:element name="onConnectionOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.NetworkTargetConnectionsOverflowAction" />
1939           <xs:element name="onOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.NetworkTargetOverflowAction" />
1940           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
1941         </xs:choice>
1942         <xs:attribute name="name" type="xs:string">
1943           <xs:annotation>
1944             <xs:documentation>Name of the target.</xs:documentation>
1945           </xs:annotation>
1946         </xs:attribute>
1947         <xs:attribute name="layout" type="SimpleLayoutAttribute">
1948           <xs:annotation>
1949             <xs:documentation>Layout used to format log messages.</xs:documentation>
1950           </xs:annotation>
1951         </xs:attribute>
1952         <xs:attribute name="encoding" type="xs:string">
1953           <xs:annotation>
1954             <xs:documentation>Encoding to be used.</xs:documentation>
1955           </xs:annotation>
1956         </xs:attribute>
1957         <xs:attribute name="lineEnding" type="LineEndingMode">
1958           <xs:annotation>
1959             <xs:documentation>End of line value if a newline is appended at the end of log message .</xs:documentation>
1960           </xs:annotation>
1961         </xs:attribute>
1962         <xs:attribute name="maxMessageSize" type="xs:integer">
1963           <xs:annotation>
1964             <xs:documentation>Maximum message size in bytes.</xs:documentation>
1965           </xs:annotation>
1966         </xs:attribute>
1967         <xs:attribute name="newLine" type="xs:boolean">
1968           <xs:annotation>
1969             <xs:documentation>Indicates whether to append newline at the end of log message.</xs:documentation>
1970           </xs:annotation>
1971         </xs:attribute>
1972         <xs:attribute name="address" type="SimpleLayoutAttribute">
1973           <xs:annotation>
1974             <xs:documentation>Network address.</xs:documentation>
1975           </xs:annotation>
1976         </xs:attribute>
1977         <xs:attribute name="connectionCacheSize" type="xs:integer">
1978           <xs:annotation>
1979             <xs:documentation>Size of the connection cache (number of connections which are kept alive).</xs:documentation>
1980           </xs:annotation>
1981         </xs:attribute>
1982         <xs:attribute name="keepConnection" type="xs:boolean">
1983           <xs:annotation>
1984             <xs:documentation>Indicates whether to keep connection open whenever possible.</xs:documentation>
1985           </xs:annotation>
1986         </xs:attribute>
1987         <xs:attribute name="maxConnections" type="xs:integer">
1988           <xs:annotation>
1989             <xs:documentation>Maximum current connections. 0 = no maximum.</xs:documentation>
1990           </xs:annotation>
1991         </xs:attribute>
1992         <xs:attribute name="maxQueueSize" type="xs:integer">
1993           <xs:annotation>
1994             <xs:documentation>Maximum queue size.</xs:documentation>
1995           </xs:annotation>
1996         </xs:attribute>
1997         <xs:attribute name="onConnectionOverflow" type="NLog.Targets.NetworkTargetConnectionsOverflowAction">
1998           <xs:annotation>
1999             <xs:documentation>Action that should be taken if the will be more connections than .</xs:documentation>
2000           </xs:annotation>
2001         </xs:attribute>
2002         <xs:attribute name="onOverflow" type="NLog.Targets.NetworkTargetOverflowAction">
2003           <xs:annotation>
2004             <xs:documentation>Action that should be taken if the message is larger than maxMessageSize.</xs:documentation>
2005           </xs:annotation>
2006         </xs:attribute>
2007         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2008           <xs:annotation>
2009             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2010           </xs:annotation>
2011         </xs:attribute>
2012       </xs:extension>
2013     </xs:complexContent>
2014   </xs:complexType>
2015   <xs:complexType name="NLogViewer">
2016     <xs:complexContent>
2017       <xs:extension base="Target">
2018         <xs:choice minOccurs="0" maxOccurs="unbounded">
2019           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2020           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
2021           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2022           <xs:element name="lineEnding" minOccurs="0" maxOccurs="1" type="LineEndingMode" />
2023           <xs:element name="maxMessageSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
2024           <xs:element name="newLine" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2025           <xs:element name="onConnectionOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.NetworkTargetConnectionsOverflowAction" />
2026           <xs:element name="maxQueueSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
2027           <xs:element name="maxConnections" minOccurs="0" maxOccurs="1" type="xs:integer" />
2028           <xs:element name="keepConnection" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2029           <xs:element name="connectionCacheSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
2030           <xs:element name="address" minOccurs="0" maxOccurs="1" type="Layout" />
2031           <xs:element name="onOverflow" minOccurs="0" maxOccurs="1" type="NLog.Targets.NetworkTargetOverflowAction" />
2032           <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.NLogViewerParameterInfo" />
2033           <xs:element name="ndlcItemSeparator" minOccurs="0" maxOccurs="1" type="xs:string" />
2034           <xs:element name="ndcItemSeparator" minOccurs="0" maxOccurs="1" type="xs:string" />
2035           <xs:element name="includeNLogData" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2036           <xs:element name="includeSourceInfo" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2037           <xs:element name="includeNdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2038           <xs:element name="includeNdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2039           <xs:element name="includeMdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2040           <xs:element name="includeMdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2041           <xs:element name="includeCallSite" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2042           <xs:element name="includeAllProperties" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2043           <xs:element name="appInfo" minOccurs="0" maxOccurs="1" type="xs:string" />
2044           <xs:element name="loggerName" minOccurs="0" maxOccurs="1" type="Layout" />
2045           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2046         </xs:choice>
2047         <xs:attribute name="name" type="xs:string">
2048           <xs:annotation>
2049             <xs:documentation>Name of the target.</xs:documentation>
2050           </xs:annotation>
2051         </xs:attribute>
2052         <xs:attribute name="encoding" type="xs:string">
2053           <xs:annotation>
2054             <xs:documentation>Encoding to be used.</xs:documentation>
2055           </xs:annotation>
2056         </xs:attribute>
2057         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2058           <xs:annotation>
2059             <xs:documentation>Instance of  that is used to format log messages.</xs:documentation>
2060           </xs:annotation>
2061         </xs:attribute>
2062         <xs:attribute name="lineEnding" type="LineEndingMode">
2063           <xs:annotation>
2064             <xs:documentation>End of line value if a newline is appended at the end of log message .</xs:documentation>
2065           </xs:annotation>
2066         </xs:attribute>
2067         <xs:attribute name="maxMessageSize" type="xs:integer">
2068           <xs:annotation>
2069             <xs:documentation>Maximum message size in bytes.</xs:documentation>
2070           </xs:annotation>
2071         </xs:attribute>
2072         <xs:attribute name="newLine" type="xs:boolean">
2073           <xs:annotation>
2074             <xs:documentation>Indicates whether to append newline at the end of log message.</xs:documentation>
2075           </xs:annotation>
2076         </xs:attribute>
2077         <xs:attribute name="onConnectionOverflow" type="NLog.Targets.NetworkTargetConnectionsOverflowAction">
2078           <xs:annotation>
2079             <xs:documentation>Action that should be taken if the will be more connections than .</xs:documentation>
2080           </xs:annotation>
2081         </xs:attribute>
2082         <xs:attribute name="maxQueueSize" type="xs:integer">
2083           <xs:annotation>
2084             <xs:documentation>Maximum queue size.</xs:documentation>
2085           </xs:annotation>
2086         </xs:attribute>
2087         <xs:attribute name="maxConnections" type="xs:integer">
2088           <xs:annotation>
2089             <xs:documentation>Maximum current connections. 0 = no maximum.</xs:documentation>
2090           </xs:annotation>
2091         </xs:attribute>
2092         <xs:attribute name="keepConnection" type="xs:boolean">
2093           <xs:annotation>
2094             <xs:documentation>Indicates whether to keep connection open whenever possible.</xs:documentation>
2095           </xs:annotation>
2096         </xs:attribute>
2097         <xs:attribute name="connectionCacheSize" type="xs:integer">
2098           <xs:annotation>
2099             <xs:documentation>Size of the connection cache (number of connections which are kept alive).</xs:documentation>
2100           </xs:annotation>
2101         </xs:attribute>
2102         <xs:attribute name="address" type="SimpleLayoutAttribute">
2103           <xs:annotation>
2104             <xs:documentation>Network address.</xs:documentation>
2105           </xs:annotation>
2106         </xs:attribute>
2107         <xs:attribute name="onOverflow" type="NLog.Targets.NetworkTargetOverflowAction">
2108           <xs:annotation>
2109             <xs:documentation>Action that should be taken if the message is larger than maxMessageSize.</xs:documentation>
2110           </xs:annotation>
2111         </xs:attribute>
2112         <xs:attribute name="ndlcItemSeparator" type="xs:string">
2113           <xs:annotation>
2114             <xs:documentation>NDLC item separator.</xs:documentation>
2115           </xs:annotation>
2116         </xs:attribute>
2117         <xs:attribute name="ndcItemSeparator" type="xs:string">
2118           <xs:annotation>
2119             <xs:documentation>NDC item separator.</xs:documentation>
2120           </xs:annotation>
2121         </xs:attribute>
2122         <xs:attribute name="includeNLogData" type="xs:boolean">
2123           <xs:annotation>
2124             <xs:documentation>Indicates whether to include NLog-specific extensions to log4j schema.</xs:documentation>
2125           </xs:annotation>
2126         </xs:attribute>
2127         <xs:attribute name="includeSourceInfo" type="xs:boolean">
2128           <xs:annotation>
2129             <xs:documentation>Indicates whether to include source info (file name and line number) in the information sent over the network.</xs:documentation>
2130           </xs:annotation>
2131         </xs:attribute>
2132         <xs:attribute name="includeNdlc" type="xs:boolean">
2133           <xs:annotation>
2134             <xs:documentation>Indicates whether to include contents of the  stack.</xs:documentation>
2135           </xs:annotation>
2136         </xs:attribute>
2137         <xs:attribute name="includeNdc" type="xs:boolean">
2138           <xs:annotation>
2139             <xs:documentation>Indicates whether to include  stack contents.</xs:documentation>
2140           </xs:annotation>
2141         </xs:attribute>
2142         <xs:attribute name="includeMdlc" type="xs:boolean">
2143           <xs:annotation>
2144             <xs:documentation>Indicates whether to include  dictionary contents.</xs:documentation>
2145           </xs:annotation>
2146         </xs:attribute>
2147         <xs:attribute name="includeMdc" type="xs:boolean">
2148           <xs:annotation>
2149             <xs:documentation>Indicates whether to include  dictionary contents.</xs:documentation>
2150           </xs:annotation>
2151         </xs:attribute>
2152         <xs:attribute name="includeCallSite" type="xs:boolean">
2153           <xs:annotation>
2154             <xs:documentation>Indicates whether to include call site (class and method name) in the information sent over the network.</xs:documentation>
2155           </xs:annotation>
2156         </xs:attribute>
2157         <xs:attribute name="includeAllProperties" type="xs:boolean">
2158           <xs:annotation>
2159             <xs:documentation>Option to include all properties from the log events</xs:documentation>
2160           </xs:annotation>
2161         </xs:attribute>
2162         <xs:attribute name="appInfo" type="xs:string">
2163           <xs:annotation>
2164             <xs:documentation>AppInfo field. By default it's the friendly name of the current AppDomain.</xs:documentation>
2165           </xs:annotation>
2166         </xs:attribute>
2167         <xs:attribute name="loggerName" type="SimpleLayoutAttribute">
2168           <xs:annotation>
2169             <xs:documentation>Renderer for log4j:event logger-xml-attribute (Default ${logger})</xs:documentation>
2170           </xs:annotation>
2171         </xs:attribute>
2172         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2173           <xs:annotation>
2174             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2175           </xs:annotation>
2176         </xs:attribute>
2177       </xs:extension>
2178     </xs:complexContent>
2179   </xs:complexType>
2180   <xs:complexType name="Null">
2181     <xs:complexContent>
2182       <xs:extension base="Target">
2183         <xs:choice minOccurs="0" maxOccurs="unbounded">
2184           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2185           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2186           <xs:element name="formatMessage" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2187           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2188         </xs:choice>
2189         <xs:attribute name="name" type="xs:string">
2190           <xs:annotation>
2191             <xs:documentation>Name of the target.</xs:documentation>
2192           </xs:annotation>
2193         </xs:attribute>
2194         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2195           <xs:annotation>
2196             <xs:documentation>Layout used to format log messages.</xs:documentation>
2197           </xs:annotation>
2198         </xs:attribute>
2199         <xs:attribute name="formatMessage" type="xs:boolean">
2200           <xs:annotation>
2201             <xs:documentation>Indicates whether to perform layout calculation.</xs:documentation>
2202           </xs:annotation>
2203         </xs:attribute>
2204         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2205           <xs:annotation>
2206             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2207           </xs:annotation>
2208         </xs:attribute>
2209       </xs:extension>
2210     </xs:complexContent>
2211   </xs:complexType>
2212   <xs:complexType name="OutputDebugString">
2213     <xs:complexContent>
2214       <xs:extension base="Target">
2215         <xs:choice minOccurs="0" maxOccurs="unbounded">
2216           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2217           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2218           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2219         </xs:choice>
2220         <xs:attribute name="name" type="xs:string">
2221           <xs:annotation>
2222             <xs:documentation>Name of the target.</xs:documentation>
2223           </xs:annotation>
2224         </xs:attribute>
2225         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2226           <xs:annotation>
2227             <xs:documentation>Layout used to format log messages.</xs:documentation>
2228           </xs:annotation>
2229         </xs:attribute>
2230         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2231           <xs:annotation>
2232             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2233           </xs:annotation>
2234         </xs:attribute>
2235       </xs:extension>
2236     </xs:complexContent>
2237   </xs:complexType>
2238   <xs:complexType name="PerfCounter">
2239     <xs:complexContent>
2240       <xs:extension base="Target">
2241         <xs:choice minOccurs="0" maxOccurs="unbounded">
2242           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2243           <xs:element name="autoCreate" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2244           <xs:element name="categoryName" minOccurs="0" maxOccurs="1" type="xs:string" />
2245           <xs:element name="counterHelp" minOccurs="0" maxOccurs="1" type="xs:string" />
2246           <xs:element name="counterName" minOccurs="0" maxOccurs="1" type="xs:string" />
2247           <xs:element name="counterType" minOccurs="0" maxOccurs="1" type="System.Diagnostics.PerformanceCounterType" />
2248           <xs:element name="incrementValue" minOccurs="0" maxOccurs="1" type="Layout" />
2249           <xs:element name="instanceName" minOccurs="0" maxOccurs="1" type="xs:string" />
2250           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2251         </xs:choice>
2252         <xs:attribute name="name" type="xs:string">
2253           <xs:annotation>
2254             <xs:documentation>Name of the target.</xs:documentation>
2255           </xs:annotation>
2256         </xs:attribute>
2257         <xs:attribute name="autoCreate" type="xs:boolean">
2258           <xs:annotation>
2259             <xs:documentation>Indicates whether performance counter should be automatically created.</xs:documentation>
2260           </xs:annotation>
2261         </xs:attribute>
2262         <xs:attribute name="categoryName" type="xs:string">
2263           <xs:annotation>
2264             <xs:documentation>Name of the performance counter category.</xs:documentation>
2265           </xs:annotation>
2266         </xs:attribute>
2267         <xs:attribute name="counterHelp" type="xs:string">
2268           <xs:annotation>
2269             <xs:documentation>Counter help text.</xs:documentation>
2270           </xs:annotation>
2271         </xs:attribute>
2272         <xs:attribute name="counterName" type="xs:string">
2273           <xs:annotation>
2274             <xs:documentation>Name of the performance counter.</xs:documentation>
2275           </xs:annotation>
2276         </xs:attribute>
2277         <xs:attribute name="counterType" type="System.Diagnostics.PerformanceCounterType">
2278           <xs:annotation>
2279             <xs:documentation>Performance counter type.</xs:documentation>
2280           </xs:annotation>
2281         </xs:attribute>
2282         <xs:attribute name="incrementValue" type="SimpleLayoutAttribute">
2283           <xs:annotation>
2284             <xs:documentation>The value by which to increment the counter.</xs:documentation>
2285           </xs:annotation>
2286         </xs:attribute>
2287         <xs:attribute name="instanceName" type="xs:string">
2288           <xs:annotation>
2289             <xs:documentation>Performance counter instance name.</xs:documentation>
2290           </xs:annotation>
2291         </xs:attribute>
2292         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2293           <xs:annotation>
2294             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2295           </xs:annotation>
2296         </xs:attribute>
2297       </xs:extension>
2298     </xs:complexContent>
2299   </xs:complexType>
2300   <xs:simpleType name="System.Diagnostics.PerformanceCounterType">
2301     <xs:restriction base="xs:string">
2302       <xs:enumeration value="NumberOfItems32" />
2303       <xs:enumeration value="NumberOfItems64" />
2304       <xs:enumeration value="NumberOfItemsHEX32" />
2305       <xs:enumeration value="NumberOfItemsHEX64" />
2306       <xs:enumeration value="RateOfCountsPerSecond32" />
2307       <xs:enumeration value="RateOfCountsPerSecond64" />
2308       <xs:enumeration value="CountPerTimeInterval32" />
2309       <xs:enumeration value="CountPerTimeInterval64" />
2310       <xs:enumeration value="RawFraction" />
2311       <xs:enumeration value="RawBase" />
2312       <xs:enumeration value="AverageTimer32" />
2313       <xs:enumeration value="AverageBase" />
2314       <xs:enumeration value="AverageCount64" />
2315       <xs:enumeration value="SampleFraction" />
2316       <xs:enumeration value="SampleCounter" />
2317       <xs:enumeration value="SampleBase" />
2318       <xs:enumeration value="CounterTimer" />
2319       <xs:enumeration value="CounterTimerInverse" />
2320       <xs:enumeration value="Timer100Ns" />
2321       <xs:enumeration value="Timer100NsInverse" />
2322       <xs:enumeration value="ElapsedTime" />
2323       <xs:enumeration value="CounterMultiTimer" />
2324       <xs:enumeration value="CounterMultiTimerInverse" />
2325       <xs:enumeration value="CounterMultiTimer100Ns" />
2326       <xs:enumeration value="CounterMultiTimer100NsInverse" />
2327       <xs:enumeration value="CounterMultiBase" />
2328       <xs:enumeration value="CounterDelta32" />
2329       <xs:enumeration value="CounterDelta64" />
2330     </xs:restriction>
2331   </xs:simpleType>
2332   <xs:complexType name="PostFilteringWrapper">
2333     <xs:complexContent>
2334       <xs:extension base="WrapperTargetBase">
2335         <xs:choice minOccurs="0" maxOccurs="unbounded">
2336           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2337           <xs:element name="defaultFilter" minOccurs="0" maxOccurs="1" type="Condition" />
2338           <xs:element name="when" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.Wrappers.FilteringRule" />
2339           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2340         </xs:choice>
2341         <xs:attribute name="name" type="xs:string">
2342           <xs:annotation>
2343             <xs:documentation>Name of the target.</xs:documentation>
2344           </xs:annotation>
2345         </xs:attribute>
2346         <xs:attribute name="defaultFilter" type="Condition">
2347           <xs:annotation>
2348             <xs:documentation>Default filter to be applied when no specific rule matches.</xs:documentation>
2349           </xs:annotation>
2350         </xs:attribute>
2351         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2352           <xs:annotation>
2353             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2354           </xs:annotation>
2355         </xs:attribute>
2356       </xs:extension>
2357     </xs:complexContent>
2358   </xs:complexType>
2359   <xs:complexType name="NLog.Targets.Wrappers.FilteringRule">
2360     <xs:choice minOccurs="0" maxOccurs="unbounded">
2361       <xs:element name="exists" minOccurs="0" maxOccurs="1" type="Condition" />
2362       <xs:element name="filter" minOccurs="0" maxOccurs="1" type="Condition" />
2363     </xs:choice>
2364     <xs:attribute name="exists" type="Condition">
2365       <xs:annotation>
2366         <xs:documentation>Condition to be tested.</xs:documentation>
2367       </xs:annotation>
2368     </xs:attribute>
2369     <xs:attribute name="filter" type="Condition">
2370       <xs:annotation>
2371         <xs:documentation>Resulting filter to be applied when the condition matches.</xs:documentation>
2372       </xs:annotation>
2373     </xs:attribute>
2374   </xs:complexType>
2375   <xs:complexType name="RandomizeGroup">
2376     <xs:complexContent>
2377       <xs:extension base="CompoundTargetBase">
2378         <xs:choice minOccurs="0" maxOccurs="unbounded">
2379           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2380           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2381         </xs:choice>
2382         <xs:attribute name="name" type="xs:string">
2383           <xs:annotation>
2384             <xs:documentation>Name of the target.</xs:documentation>
2385           </xs:annotation>
2386         </xs:attribute>
2387         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2388           <xs:annotation>
2389             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2390           </xs:annotation>
2391         </xs:attribute>
2392       </xs:extension>
2393     </xs:complexContent>
2394   </xs:complexType>
2395   <xs:complexType name="RepeatingWrapper">
2396     <xs:complexContent>
2397       <xs:extension base="WrapperTargetBase">
2398         <xs:choice minOccurs="0" maxOccurs="unbounded">
2399           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2400           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2401           <xs:element name="repeatCount" minOccurs="0" maxOccurs="1" type="xs:integer" />
2402         </xs:choice>
2403         <xs:attribute name="name" type="xs:string">
2404           <xs:annotation>
2405             <xs:documentation>Name of the target.</xs:documentation>
2406           </xs:annotation>
2407         </xs:attribute>
2408         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2409           <xs:annotation>
2410             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2411           </xs:annotation>
2412         </xs:attribute>
2413         <xs:attribute name="repeatCount" type="xs:integer">
2414           <xs:annotation>
2415             <xs:documentation>Number of times to repeat each log message.</xs:documentation>
2416           </xs:annotation>
2417         </xs:attribute>
2418       </xs:extension>
2419     </xs:complexContent>
2420   </xs:complexType>
2421   <xs:complexType name="RetryingWrapper">
2422     <xs:complexContent>
2423       <xs:extension base="WrapperTargetBase">
2424         <xs:choice minOccurs="0" maxOccurs="unbounded">
2425           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2426           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2427           <xs:element name="retryCount" minOccurs="0" maxOccurs="1" type="xs:integer" />
2428           <xs:element name="retryDelayMilliseconds" minOccurs="0" maxOccurs="1" type="xs:integer" />
2429         </xs:choice>
2430         <xs:attribute name="name" type="xs:string">
2431           <xs:annotation>
2432             <xs:documentation>Name of the target.</xs:documentation>
2433           </xs:annotation>
2434         </xs:attribute>
2435         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2436           <xs:annotation>
2437             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2438           </xs:annotation>
2439         </xs:attribute>
2440         <xs:attribute name="retryCount" type="xs:integer">
2441           <xs:annotation>
2442             <xs:documentation>Number of retries that should be attempted on the wrapped target in case of a failure.</xs:documentation>
2443           </xs:annotation>
2444         </xs:attribute>
2445         <xs:attribute name="retryDelayMilliseconds" type="xs:integer">
2446           <xs:annotation>
2447             <xs:documentation>Time to wait between retries in milliseconds.</xs:documentation>
2448           </xs:annotation>
2449         </xs:attribute>
2450       </xs:extension>
2451     </xs:complexContent>
2452   </xs:complexType>
2453   <xs:complexType name="RoundRobinGroup">
2454     <xs:complexContent>
2455       <xs:extension base="CompoundTargetBase">
2456         <xs:choice minOccurs="0" maxOccurs="unbounded">
2457           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2458           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2459         </xs:choice>
2460         <xs:attribute name="name" type="xs:string">
2461           <xs:annotation>
2462             <xs:documentation>Name of the target.</xs:documentation>
2463           </xs:annotation>
2464         </xs:attribute>
2465         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2466           <xs:annotation>
2467             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2468           </xs:annotation>
2469         </xs:attribute>
2470       </xs:extension>
2471     </xs:complexContent>
2472   </xs:complexType>
2473   <xs:complexType name="SplitGroup">
2474     <xs:complexContent>
2475       <xs:extension base="CompoundTargetBase">
2476         <xs:choice minOccurs="0" maxOccurs="unbounded">
2477           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2478           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2479         </xs:choice>
2480         <xs:attribute name="name" type="xs:string">
2481           <xs:annotation>
2482             <xs:documentation>Name of the target.</xs:documentation>
2483           </xs:annotation>
2484         </xs:attribute>
2485         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2486           <xs:annotation>
2487             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2488           </xs:annotation>
2489         </xs:attribute>
2490       </xs:extension>
2491     </xs:complexContent>
2492   </xs:complexType>
2493   <xs:complexType name="Trace">
2494     <xs:complexContent>
2495       <xs:extension base="Target">
2496         <xs:choice minOccurs="0" maxOccurs="unbounded">
2497           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2498           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2499           <xs:element name="rawWrite" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2500           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2501         </xs:choice>
2502         <xs:attribute name="name" type="xs:string">
2503           <xs:annotation>
2504             <xs:documentation>Name of the target.</xs:documentation>
2505           </xs:annotation>
2506         </xs:attribute>
2507         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2508           <xs:annotation>
2509             <xs:documentation>Layout used to format log messages.</xs:documentation>
2510           </xs:annotation>
2511         </xs:attribute>
2512         <xs:attribute name="rawWrite" type="xs:boolean">
2513           <xs:annotation>
2514             <xs:documentation>Always use  independent of </xs:documentation>
2515           </xs:annotation>
2516         </xs:attribute>
2517         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2518           <xs:annotation>
2519             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2520           </xs:annotation>
2521         </xs:attribute>
2522       </xs:extension>
2523     </xs:complexContent>
2524   </xs:complexType>
2525   <xs:complexType name="WebService">
2526     <xs:complexContent>
2527       <xs:extension base="Target">
2528         <xs:choice minOccurs="0" maxOccurs="unbounded">
2529           <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2530           <xs:element name="parameter" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.MethodCallParameter" />
2531           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2532           <xs:element name="includeBOM" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2533           <xs:element name="methodName" minOccurs="0" maxOccurs="1" type="xs:string" />
2534           <xs:element name="namespace" minOccurs="0" maxOccurs="1" type="xs:string" />
2535           <xs:element name="protocol" minOccurs="0" maxOccurs="1" type="NLog.Targets.WebServiceProtocol" />
2536           <xs:element name="proxyAddress" minOccurs="0" maxOccurs="1" type="xs:string" />
2537           <xs:element name="encoding" minOccurs="0" maxOccurs="1" type="xs:string" />
2538           <xs:element name="url" minOccurs="0" maxOccurs="1" type="xs:anyURI" />
2539           <xs:element name="escapeDataNLogLegacy" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2540           <xs:element name="escapeDataRfc3986" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2541           <xs:element name="preAuthenticate" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2542           <xs:element name="xmlRoot" minOccurs="0" maxOccurs="1" type="xs:string" />
2543           <xs:element name="xmlRootNamespace" minOccurs="0" maxOccurs="1" type="xs:string" />
2544           <xs:element name="header" minOccurs="0" maxOccurs="unbounded" type="NLog.Targets.MethodCallParameter" />
2545           <xs:element name="proxyType" minOccurs="0" maxOccurs="1" type="NLog.Targets.WebServiceProxyType" />
2546         </xs:choice>
2547         <xs:attribute name="name" type="xs:string">
2548           <xs:annotation>
2549             <xs:documentation>Name of the target.</xs:documentation>
2550           </xs:annotation>
2551         </xs:attribute>
2552         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
2553           <xs:annotation>
2554             <xs:documentation>Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit</xs:documentation>
2555           </xs:annotation>
2556         </xs:attribute>
2557         <xs:attribute name="includeBOM" type="xs:boolean">
2558           <xs:annotation>
2559             <xs:documentation>Should we include the BOM (Byte-order-mark) for UTF? Influences the  property. This will only work for UTF-8.</xs:documentation>
2560           </xs:annotation>
2561         </xs:attribute>
2562         <xs:attribute name="methodName" type="xs:string">
2563           <xs:annotation>
2564             <xs:documentation>Web service method name. Only used with Soap.</xs:documentation>
2565           </xs:annotation>
2566         </xs:attribute>
2567         <xs:attribute name="namespace" type="xs:string">
2568           <xs:annotation>
2569             <xs:documentation>Web service namespace. Only used with Soap.</xs:documentation>
2570           </xs:annotation>
2571         </xs:attribute>
2572         <xs:attribute name="protocol" type="NLog.Targets.WebServiceProtocol">
2573           <xs:annotation>
2574             <xs:documentation>Protocol to be used when calling web service.</xs:documentation>
2575           </xs:annotation>
2576         </xs:attribute>
2577         <xs:attribute name="proxyAddress" type="xs:string">
2578           <xs:annotation>
2579             <xs:documentation>Custom proxy address, include port separated by a colon</xs:documentation>
2580           </xs:annotation>
2581         </xs:attribute>
2582         <xs:attribute name="encoding" type="xs:string">
2583           <xs:annotation>
2584             <xs:documentation>Encoding.</xs:documentation>
2585           </xs:annotation>
2586         </xs:attribute>
2587         <xs:attribute name="url" type="xs:anyURI">
2588           <xs:annotation>
2589             <xs:documentation>Web service URL.</xs:documentation>
2590           </xs:annotation>
2591         </xs:attribute>
2592         <xs:attribute name="escapeDataNLogLegacy" type="xs:boolean">
2593           <xs:annotation>
2594             <xs:documentation>Value whether escaping be done according to the old NLog style (Very non-standard)</xs:documentation>
2595           </xs:annotation>
2596         </xs:attribute>
2597         <xs:attribute name="escapeDataRfc3986" type="xs:boolean">
2598           <xs:annotation>
2599             <xs:documentation>Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs)</xs:documentation>
2600           </xs:annotation>
2601         </xs:attribute>
2602         <xs:attribute name="preAuthenticate" type="xs:boolean">
2603           <xs:annotation>
2604             <xs:documentation>Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in  parameters)</xs:documentation>
2605           </xs:annotation>
2606         </xs:attribute>
2607         <xs:attribute name="xmlRoot" type="xs:string">
2608           <xs:annotation>
2609             <xs:documentation>Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see  and ).</xs:documentation>
2610           </xs:annotation>
2611         </xs:attribute>
2612         <xs:attribute name="xmlRootNamespace" type="xs:string">
2613           <xs:annotation>
2614             <xs:documentation>(optional) root namespace of the XML document, if POST of XML document chosen. (see  and ).</xs:documentation>
2615           </xs:annotation>
2616         </xs:attribute>
2617         <xs:attribute name="proxyType" type="NLog.Targets.WebServiceProxyType">
2618           <xs:annotation>
2619             <xs:documentation>Proxy configuration when calling web service</xs:documentation>
2620           </xs:annotation>
2621         </xs:attribute>
2622       </xs:extension>
2623     </xs:complexContent>
2624   </xs:complexType>
2625   <xs:simpleType name="NLog.Targets.WebServiceProtocol">
2626     <xs:restriction base="xs:string">
2627       <xs:enumeration value="Soap11" />
2628       <xs:enumeration value="Soap12" />
2629       <xs:enumeration value="HttpPost" />
2630       <xs:enumeration value="HttpGet" />
2631       <xs:enumeration value="JsonPost" />
2632       <xs:enumeration value="XmlPost" />
2633     </xs:restriction>
2634   </xs:simpleType>
2635   <xs:simpleType name="NLog.Targets.WebServiceProxyType">
2636     <xs:restriction base="xs:string">
2637       <xs:enumeration value="DefaultWebProxy" />
2638       <xs:enumeration value="AutoProxy" />
2639       <xs:enumeration value="NoProxy" />
2640       <xs:enumeration value="ProxyAddress" />
2641     </xs:restriction>
2642   </xs:simpleType>
2643   <xs:complexType name="CompoundLayout">
2644     <xs:complexContent>
2645       <xs:extension base="Layout">
2646         <xs:choice minOccurs="0" maxOccurs="unbounded">
2647           <xs:element name="layout" minOccurs="0" maxOccurs="unbounded" type="Layout" />
2648         </xs:choice>
2649       </xs:extension>
2650     </xs:complexContent>
2651   </xs:complexType>
2652   <xs:complexType name="Layout">
2653     <xs:choice minOccurs="0" maxOccurs="unbounded" />
2654   </xs:complexType>
2655   <xs:complexType name="CsvLayout">
2656     <xs:complexContent>
2657       <xs:extension base="Layout">
2658         <xs:choice minOccurs="0" maxOccurs="unbounded">
2659           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
2660           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
2661           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2662           <xs:element name="column" minOccurs="0" maxOccurs="unbounded" type="NLog.Layouts.CsvColumn" />
2663           <xs:element name="customColumnDelimiter" minOccurs="0" maxOccurs="1" type="xs:string" />
2664           <xs:element name="delimiter" minOccurs="0" maxOccurs="1" type="NLog.Layouts.CsvColumnDelimiterMode" />
2665           <xs:element name="quoteChar" minOccurs="0" maxOccurs="1" type="xs:string" />
2666           <xs:element name="quoting" minOccurs="0" maxOccurs="1" type="NLog.Layouts.CsvQuotingMode" />
2667           <xs:element name="withHeader" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2668         </xs:choice>
2669         <xs:attribute name="footer" type="SimpleLayoutAttribute">
2670           <xs:annotation>
2671             <xs:documentation>Footer layout.</xs:documentation>
2672           </xs:annotation>
2673         </xs:attribute>
2674         <xs:attribute name="header" type="SimpleLayoutAttribute">
2675           <xs:annotation>
2676             <xs:documentation>Header layout.</xs:documentation>
2677           </xs:annotation>
2678         </xs:attribute>
2679         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2680           <xs:annotation>
2681             <xs:documentation>Body layout (can be repeated multiple times).</xs:documentation>
2682           </xs:annotation>
2683         </xs:attribute>
2684         <xs:attribute name="customColumnDelimiter" type="xs:string">
2685           <xs:annotation>
2686             <xs:documentation>Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom').</xs:documentation>
2687           </xs:annotation>
2688         </xs:attribute>
2689         <xs:attribute name="delimiter" type="NLog.Layouts.CsvColumnDelimiterMode">
2690           <xs:annotation>
2691             <xs:documentation>Column delimiter.</xs:documentation>
2692           </xs:annotation>
2693         </xs:attribute>
2694         <xs:attribute name="quoteChar" type="xs:string">
2695           <xs:annotation>
2696             <xs:documentation>Quote Character.</xs:documentation>
2697           </xs:annotation>
2698         </xs:attribute>
2699         <xs:attribute name="quoting" type="NLog.Layouts.CsvQuotingMode">
2700           <xs:annotation>
2701             <xs:documentation>Quoting mode.</xs:documentation>
2702           </xs:annotation>
2703         </xs:attribute>
2704         <xs:attribute name="withHeader" type="xs:boolean">
2705           <xs:annotation>
2706             <xs:documentation>Indicates whether CVS should include header.</xs:documentation>
2707           </xs:annotation>
2708         </xs:attribute>
2709       </xs:extension>
2710     </xs:complexContent>
2711   </xs:complexType>
2712   <xs:simpleType name="NLog.Layouts.CsvColumnDelimiterMode">
2713     <xs:restriction base="xs:string">
2714       <xs:enumeration value="Auto" />
2715       <xs:enumeration value="Comma" />
2716       <xs:enumeration value="Semicolon" />
2717       <xs:enumeration value="Tab" />
2718       <xs:enumeration value="Pipe" />
2719       <xs:enumeration value="Space" />
2720       <xs:enumeration value="Custom" />
2721     </xs:restriction>
2722   </xs:simpleType>
2723   <xs:simpleType name="NLog.Layouts.CsvQuotingMode">
2724     <xs:restriction base="xs:string">
2725       <xs:enumeration value="All" />
2726       <xs:enumeration value="Nothing" />
2727       <xs:enumeration value="Auto" />
2728     </xs:restriction>
2729   </xs:simpleType>
2730   <xs:complexType name="NLog.Layouts.CsvColumn">
2731     <xs:choice minOccurs="0" maxOccurs="unbounded">
2732       <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2733       <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2734     </xs:choice>
2735     <xs:attribute name="layout" type="SimpleLayoutAttribute">
2736       <xs:annotation>
2737         <xs:documentation>Layout of the column.</xs:documentation>
2738       </xs:annotation>
2739     </xs:attribute>
2740     <xs:attribute name="name" type="xs:string">
2741       <xs:annotation>
2742         <xs:documentation>Name of the column.</xs:documentation>
2743       </xs:annotation>
2744     </xs:attribute>
2745   </xs:complexType>
2746   <xs:complexType name="JsonLayout">
2747     <xs:complexContent>
2748       <xs:extension base="Layout">
2749         <xs:choice minOccurs="0" maxOccurs="unbounded">
2750           <xs:element name="attribute" minOccurs="0" maxOccurs="unbounded" type="NLog.Layouts.JsonAttribute" />
2751           <xs:element name="excludeProperties" minOccurs="0" maxOccurs="1" type="xs:string" />
2752           <xs:element name="includeAllProperties" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2753           <xs:element name="includeMdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2754           <xs:element name="includeMdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2755           <xs:element name="renderEmptyObject" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2756           <xs:element name="suppressSpaces" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2757           <xs:element name="maxRecursionLimit" minOccurs="0" maxOccurs="1" type="xs:integer" />
2758         </xs:choice>
2759         <xs:attribute name="excludeProperties" type="xs:string">
2760           <xs:annotation>
2761             <xs:documentation>List of property names to exclude when  is true</xs:documentation>
2762           </xs:annotation>
2763         </xs:attribute>
2764         <xs:attribute name="includeAllProperties" type="xs:boolean">
2765           <xs:annotation>
2766             <xs:documentation>Option to include all properties from the log event (as JSON)</xs:documentation>
2767           </xs:annotation>
2768         </xs:attribute>
2769         <xs:attribute name="includeMdc" type="xs:boolean">
2770           <xs:annotation>
2771             <xs:documentation>Indicates whether to include contents of the  dictionary.</xs:documentation>
2772           </xs:annotation>
2773         </xs:attribute>
2774         <xs:attribute name="includeMdlc" type="xs:boolean">
2775           <xs:annotation>
2776             <xs:documentation>Indicates whether to include contents of the  dictionary.</xs:documentation>
2777           </xs:annotation>
2778         </xs:attribute>
2779         <xs:attribute name="renderEmptyObject" type="xs:boolean">
2780           <xs:annotation>
2781             <xs:documentation>Option to render the empty object value {}</xs:documentation>
2782           </xs:annotation>
2783         </xs:attribute>
2784         <xs:attribute name="suppressSpaces" type="xs:boolean">
2785           <xs:annotation>
2786             <xs:documentation>Option to suppress the extra spaces in the output json</xs:documentation>
2787           </xs:annotation>
2788         </xs:attribute>
2789         <xs:attribute name="maxRecursionLimit" type="xs:integer">
2790           <xs:annotation>
2791             <xs:documentation>How far should the JSON serializer follow object references before backing off</xs:documentation>
2792           </xs:annotation>
2793         </xs:attribute>
2794       </xs:extension>
2795     </xs:complexContent>
2796   </xs:complexType>
2797   <xs:complexType name="NLog.Layouts.JsonAttribute">
2798     <xs:choice minOccurs="0" maxOccurs="unbounded">
2799       <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2800       <xs:element name="name" minOccurs="0" maxOccurs="1" type="xs:string" />
2801       <xs:element name="encode" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2802       <xs:element name="escapeUnicode" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2803       <xs:element name="includeEmptyValue" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2804     </xs:choice>
2805     <xs:attribute name="layout" type="SimpleLayoutAttribute">
2806       <xs:annotation>
2807         <xs:documentation>Layout that will be rendered as the attribute's value.</xs:documentation>
2808       </xs:annotation>
2809     </xs:attribute>
2810     <xs:attribute name="name" type="xs:string">
2811       <xs:annotation>
2812         <xs:documentation>Name of the attribute.</xs:documentation>
2813       </xs:annotation>
2814     </xs:attribute>
2815     <xs:attribute name="encode" type="xs:boolean">
2816       <xs:annotation>
2817         <xs:documentation>Determines wether or not this attribute will be Json encoded.</xs:documentation>
2818       </xs:annotation>
2819     </xs:attribute>
2820     <xs:attribute name="escapeUnicode" type="xs:boolean">
2821       <xs:annotation>
2822         <xs:documentation>Indicates whether to escape non-ascii characters</xs:documentation>
2823       </xs:annotation>
2824     </xs:attribute>
2825     <xs:attribute name="includeEmptyValue" type="xs:boolean">
2826       <xs:annotation>
2827         <xs:documentation>Whether an attribute with empty value should be included in the output</xs:documentation>
2828       </xs:annotation>
2829     </xs:attribute>
2830   </xs:complexType>
2831   <xs:complexType name="LayoutWithHeaderAndFooter">
2832     <xs:complexContent>
2833       <xs:extension base="Layout">
2834         <xs:choice minOccurs="0" maxOccurs="unbounded">
2835           <xs:element name="footer" minOccurs="0" maxOccurs="1" type="Layout" />
2836           <xs:element name="header" minOccurs="0" maxOccurs="1" type="Layout" />
2837           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2838         </xs:choice>
2839         <xs:attribute name="footer" type="SimpleLayoutAttribute">
2840           <xs:annotation>
2841             <xs:documentation>Footer layout.</xs:documentation>
2842           </xs:annotation>
2843         </xs:attribute>
2844         <xs:attribute name="header" type="SimpleLayoutAttribute">
2845           <xs:annotation>
2846             <xs:documentation>Header layout.</xs:documentation>
2847           </xs:annotation>
2848         </xs:attribute>
2849         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2850           <xs:annotation>
2851             <xs:documentation>Body layout (can be repeated multiple times).</xs:documentation>
2852           </xs:annotation>
2853         </xs:attribute>
2854       </xs:extension>
2855     </xs:complexContent>
2856   </xs:complexType>
2857   <xs:complexType name="Log4JXmlEventLayout">
2858     <xs:complexContent>
2859       <xs:extension base="Layout">
2860         <xs:choice minOccurs="0" maxOccurs="unbounded">
2861           <xs:element name="includeAllProperties" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2862           <xs:element name="includeMdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2863           <xs:element name="includeMdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2864           <xs:element name="includeNdc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2865           <xs:element name="includeNdlc" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2866         </xs:choice>
2867         <xs:attribute name="includeAllProperties" type="xs:boolean">
2868           <xs:annotation>
2869             <xs:documentation>Option to include all properties from the log events</xs:documentation>
2870           </xs:annotation>
2871         </xs:attribute>
2872         <xs:attribute name="includeMdc" type="xs:boolean">
2873           <xs:annotation>
2874             <xs:documentation>Indicates whether to include contents of the  dictionary.</xs:documentation>
2875           </xs:annotation>
2876         </xs:attribute>
2877         <xs:attribute name="includeMdlc" type="xs:boolean">
2878           <xs:annotation>
2879             <xs:documentation>Indicates whether to include contents of the  dictionary.</xs:documentation>
2880           </xs:annotation>
2881         </xs:attribute>
2882         <xs:attribute name="includeNdc" type="xs:boolean">
2883           <xs:annotation>
2884             <xs:documentation>Indicates whether to include contents of the  stack.</xs:documentation>
2885           </xs:annotation>
2886         </xs:attribute>
2887         <xs:attribute name="includeNdlc" type="xs:boolean">
2888           <xs:annotation>
2889             <xs:documentation>Indicates whether to include contents of the  stack.</xs:documentation>
2890           </xs:annotation>
2891         </xs:attribute>
2892       </xs:extension>
2893     </xs:complexContent>
2894   </xs:complexType>
2895   <xs:complexType name="SimpleLayout">
2896     <xs:complexContent>
2897       <xs:extension base="Layout">
2898         <xs:choice minOccurs="0" maxOccurs="unbounded">
2899           <xs:element name="text" minOccurs="0" maxOccurs="1" type="xs:string" />
2900         </xs:choice>
2901         <xs:attribute name="text" type="xs:string">
2902           <xs:annotation>
2903             <xs:documentation>Layout text.</xs:documentation>
2904           </xs:annotation>
2905         </xs:attribute>
2906       </xs:extension>
2907     </xs:complexContent>
2908   </xs:complexType>
2909   <xs:complexType name="when">
2910     <xs:complexContent>
2911       <xs:extension base="Filter">
2912         <xs:choice minOccurs="0" maxOccurs="unbounded">
2913           <xs:element name="action" minOccurs="0" maxOccurs="1" type="FilterResult" />
2914           <xs:element name="condition" minOccurs="0" maxOccurs="1" type="Condition" />
2915         </xs:choice>
2916         <xs:attribute name="action" type="FilterResult">
2917           <xs:annotation>
2918             <xs:documentation>Action to be taken when filter matches.</xs:documentation>
2919           </xs:annotation>
2920         </xs:attribute>
2921         <xs:attribute name="condition" type="Condition">
2922           <xs:annotation>
2923             <xs:documentation>Condition expression.</xs:documentation>
2924           </xs:annotation>
2925         </xs:attribute>
2926       </xs:extension>
2927     </xs:complexContent>
2928   </xs:complexType>
2929   <xs:simpleType name="FilterResult">
2930     <xs:restriction base="xs:string">
2931       <xs:enumeration value="Neutral" />
2932       <xs:enumeration value="Log" />
2933       <xs:enumeration value="Ignore" />
2934       <xs:enumeration value="LogFinal" />
2935       <xs:enumeration value="IgnoreFinal" />
2936     </xs:restriction>
2937   </xs:simpleType>
2938   <xs:complexType name="whenContains">
2939     <xs:complexContent>
2940       <xs:extension base="Filter">
2941         <xs:choice minOccurs="0" maxOccurs="unbounded">
2942           <xs:element name="action" minOccurs="0" maxOccurs="1" type="FilterResult" />
2943           <xs:element name="ignoreCase" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2944           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2945           <xs:element name="substring" minOccurs="0" maxOccurs="1" type="xs:string" />
2946         </xs:choice>
2947         <xs:attribute name="action" type="FilterResult">
2948           <xs:annotation>
2949             <xs:documentation>Action to be taken when filter matches.</xs:documentation>
2950           </xs:annotation>
2951         </xs:attribute>
2952         <xs:attribute name="ignoreCase" type="xs:boolean">
2953           <xs:annotation>
2954             <xs:documentation>Indicates whether to ignore case when comparing strings.</xs:documentation>
2955           </xs:annotation>
2956         </xs:attribute>
2957         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2958           <xs:annotation>
2959             <xs:documentation>Layout to be used to filter log messages.</xs:documentation>
2960           </xs:annotation>
2961         </xs:attribute>
2962         <xs:attribute name="substring" type="xs:string">
2963           <xs:annotation>
2964             <xs:documentation>Substring to be matched.</xs:documentation>
2965           </xs:annotation>
2966         </xs:attribute>
2967       </xs:extension>
2968     </xs:complexContent>
2969   </xs:complexType>
2970   <xs:complexType name="whenEqual">
2971     <xs:complexContent>
2972       <xs:extension base="Filter">
2973         <xs:choice minOccurs="0" maxOccurs="unbounded">
2974           <xs:element name="action" minOccurs="0" maxOccurs="1" type="FilterResult" />
2975           <xs:element name="compareTo" minOccurs="0" maxOccurs="1" type="xs:string" />
2976           <xs:element name="ignoreCase" minOccurs="0" maxOccurs="1" type="xs:boolean" />
2977           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
2978         </xs:choice>
2979         <xs:attribute name="action" type="FilterResult">
2980           <xs:annotation>
2981             <xs:documentation>Action to be taken when filter matches.</xs:documentation>
2982           </xs:annotation>
2983         </xs:attribute>
2984         <xs:attribute name="compareTo" type="xs:string">
2985           <xs:annotation>
2986             <xs:documentation>String to compare the layout to.</xs:documentation>
2987           </xs:annotation>
2988         </xs:attribute>
2989         <xs:attribute name="ignoreCase" type="xs:boolean">
2990           <xs:annotation>
2991             <xs:documentation>Indicates whether to ignore case when comparing strings.</xs:documentation>
2992           </xs:annotation>
2993         </xs:attribute>
2994         <xs:attribute name="layout" type="SimpleLayoutAttribute">
2995           <xs:annotation>
2996             <xs:documentation>Layout to be used to filter log messages.</xs:documentation>
2997           </xs:annotation>
2998         </xs:attribute>
2999       </xs:extension>
3000     </xs:complexContent>
3001   </xs:complexType>
3002   <xs:complexType name="whenNotContains">
3003     <xs:complexContent>
3004       <xs:extension base="Filter">
3005         <xs:choice minOccurs="0" maxOccurs="unbounded">
3006           <xs:element name="action" minOccurs="0" maxOccurs="1" type="FilterResult" />
3007           <xs:element name="ignoreCase" minOccurs="0" maxOccurs="1" type="xs:boolean" />
3008           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
3009           <xs:element name="substring" minOccurs="0" maxOccurs="1" type="xs:string" />
3010         </xs:choice>
3011         <xs:attribute name="action" type="FilterResult">
3012           <xs:annotation>
3013             <xs:documentation>Action to be taken when filter matches.</xs:documentation>
3014           </xs:annotation>
3015         </xs:attribute>
3016         <xs:attribute name="ignoreCase" type="xs:boolean">
3017           <xs:annotation>
3018             <xs:documentation>Indicates whether to ignore case when comparing strings.</xs:documentation>
3019           </xs:annotation>
3020         </xs:attribute>
3021         <xs:attribute name="layout" type="SimpleLayoutAttribute">
3022           <xs:annotation>
3023             <xs:documentation>Layout to be used to filter log messages.</xs:documentation>
3024           </xs:annotation>
3025         </xs:attribute>
3026         <xs:attribute name="substring" type="xs:string">
3027           <xs:annotation>
3028             <xs:documentation>Substring to be matched.</xs:documentation>
3029           </xs:annotation>
3030         </xs:attribute>
3031       </xs:extension>
3032     </xs:complexContent>
3033   </xs:complexType>
3034   <xs:complexType name="whenNotEqual">
3035     <xs:complexContent>
3036       <xs:extension base="Filter">
3037         <xs:choice minOccurs="0" maxOccurs="unbounded">
3038           <xs:element name="action" minOccurs="0" maxOccurs="1" type="FilterResult" />
3039           <xs:element name="compareTo" minOccurs="0" maxOccurs="1" type="xs:string" />
3040           <xs:element name="ignoreCase" minOccurs="0" maxOccurs="1" type="xs:boolean" />
3041           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
3042         </xs:choice>
3043         <xs:attribute name="action" type="FilterResult">
3044           <xs:annotation>
3045             <xs:documentation>Action to be taken when filter matches.</xs:documentation>
3046           </xs:annotation>
3047         </xs:attribute>
3048         <xs:attribute name="compareTo" type="xs:string">
3049           <xs:annotation>
3050             <xs:documentation>String to compare the layout to.</xs:documentation>
3051           </xs:annotation>
3052         </xs:attribute>
3053         <xs:attribute name="ignoreCase" type="xs:boolean">
3054           <xs:annotation>
3055             <xs:documentation>Indicates whether to ignore case when comparing strings.</xs:documentation>
3056           </xs:annotation>
3057         </xs:attribute>
3058         <xs:attribute name="layout" type="SimpleLayoutAttribute">
3059           <xs:annotation>
3060             <xs:documentation>Layout to be used to filter log messages.</xs:documentation>
3061           </xs:annotation>
3062         </xs:attribute>
3063       </xs:extension>
3064     </xs:complexContent>
3065   </xs:complexType>
3066   <xs:complexType name="whenRepeated">
3067     <xs:complexContent>
3068       <xs:extension base="Filter">
3069         <xs:choice minOccurs="0" maxOccurs="unbounded">
3070           <xs:element name="action" minOccurs="0" maxOccurs="1" type="FilterResult" />
3071           <xs:element name="defaultFilterCacheSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
3072           <xs:element name="includeFirst" minOccurs="0" maxOccurs="1" type="xs:boolean" />
3073           <xs:element name="layout" minOccurs="0" maxOccurs="1" type="Layout" />
3074           <xs:element name="maxFilterCacheSize" minOccurs="0" maxOccurs="1" type="xs:integer" />
3075           <xs:element name="maxLength" minOccurs="0" maxOccurs="1" type="xs:integer" />
3076           <xs:element name="timeoutSeconds" minOccurs="0" maxOccurs="1" type="xs:integer" />
3077           <xs:element name="optimizeBufferDefaultLength" minOccurs="0" maxOccurs="1" type="xs:integer" />
3078           <xs:element name="optimizeBufferReuse" minOccurs="0" maxOccurs="1" type="xs:boolean" />
3079           <xs:element name="filterCountMessageAppendFormat" minOccurs="0" maxOccurs="1" type="xs:string" />
3080           <xs:element name="filterCountPropertyName" minOccurs="0" maxOccurs="1" type="xs:string" />
3081         </xs:choice>
3082         <xs:attribute name="action" type="FilterResult">
3083           <xs:annotation>
3084             <xs:documentation>Action to be taken when filter matches.</xs:documentation>
3085           </xs:annotation>
3086         </xs:attribute>
3087         <xs:attribute name="defaultFilterCacheSize" type="xs:integer">
3088           <xs:annotation>
3089             <xs:documentation>Default number of unique filter values to expect, will automatically increase if needed</xs:documentation>
3090           </xs:annotation>
3091         </xs:attribute>
3092         <xs:attribute name="includeFirst" type="xs:boolean">
3093           <xs:annotation>
3094             <xs:documentation>Applies the configured action to the initial logevent that starts the timeout period. Used to configure that it should ignore all events until timeout.</xs:documentation>
3095           </xs:annotation>
3096         </xs:attribute>
3097         <xs:attribute name="layout" type="SimpleLayoutAttribute">
3098           <xs:annotation>
3099             <xs:documentation>Layout to be used to filter log messages.</xs:documentation>
3100           </xs:annotation>
3101         </xs:attribute>
3102         <xs:attribute name="maxFilterCacheSize" type="xs:integer">
3103           <xs:annotation>
3104             <xs:documentation>Max number of unique filter values to expect simultaneously</xs:documentation>
3105           </xs:annotation>
3106         </xs:attribute>
3107         <xs:attribute name="maxLength" type="xs:integer">
3108           <xs:annotation>
3109             <xs:documentation>Max length of filter values, will truncate if above limit</xs:documentation>
3110           </xs:annotation>
3111         </xs:attribute>
3112         <xs:attribute name="timeoutSeconds" type="xs:integer">
3113           <xs:annotation>
3114             <xs:documentation>How long before a filter expires, and logging is accepted again</xs:documentation>
3115           </xs:annotation>
3116         </xs:attribute>
3117         <xs:attribute name="optimizeBufferDefaultLength" type="xs:integer">
3118           <xs:annotation>
3119             <xs:documentation>Default buffer size for the internal buffers</xs:documentation>
3120           </xs:annotation>
3121         </xs:attribute>
3122         <xs:attribute name="optimizeBufferReuse" type="xs:boolean">
3123           <xs:annotation>
3124             <xs:documentation>Reuse internal buffers, and doesn't have to constantly allocate new buffers</xs:documentation>
3125           </xs:annotation>
3126         </xs:attribute>
3127         <xs:attribute name="filterCountMessageAppendFormat" type="xs:string">
3128           <xs:annotation>
3129             <xs:documentation>Append FilterCount to the  when an event is no longer filtered</xs:documentation>
3130           </xs:annotation>
3131         </xs:attribute>
3132         <xs:attribute name="filterCountPropertyName" type="xs:string">
3133           <xs:annotation>
3134             <xs:documentation>Insert FilterCount value into  when an event is no longer filtered</xs:documentation>
3135           </xs:annotation>
3136         </xs:attribute>
3137       </xs:extension>
3138     </xs:complexContent>
3139   </xs:complexType>
3140   <xs:complexType name="AccurateLocal">
3141     <xs:complexContent>
3142       <xs:extension base="TimeSource">
3143         <xs:choice minOccurs="0" maxOccurs="unbounded" />
3144       </xs:extension>
3145     </xs:complexContent>
3146   </xs:complexType>
3147   <xs:complexType name="AccurateUTC">
3148     <xs:complexContent>
3149       <xs:extension base="TimeSource">
3150         <xs:choice minOccurs="0" maxOccurs="unbounded" />
3151       </xs:extension>
3152     </xs:complexContent>
3153   </xs:complexType>
3154   <xs:complexType name="FastLocal">
3155     <xs:complexContent>
3156       <xs:extension base="TimeSource">
3157         <xs:choice minOccurs="0" maxOccurs="unbounded" />
3158       </xs:extension>
3159     </xs:complexContent>
3160   </xs:complexType>
3161   <xs:complexType name="FastUTC">
3162     <xs:complexContent>
3163       <xs:extension base="TimeSource">
3164         <xs:choice minOccurs="0" maxOccurs="unbounded" />
3165       </xs:extension>
3166     </xs:complexContent>
3167   </xs:complexType>
3168 </xs:schema>
NLog.xsd
复制代码

6.此类实现金额的阿拉伯数字到大写汉字的转换

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 
  5 namespace Utilities
  6 {
  7     /// <summary>
  8     /// 此类实现金额的阿拉伯数字到大写汉字的转换
  9     /// </summary>
 10     public static class MoneyHelper
 11     {
 12         /// <summary>
 13         /// 转换数字金额主函数(包括小数)
 14         /// </summary>
 15         /// <param name="str"></param>
 16         /// <returns></returns>
 17         public static string ConvertSum(string str)
 18         {
 19             if (!IsPositveDecimal(str))
 20             {
 21                 return "";
 22             }
 23 
 24             if (Double.Parse(str) > 999999999999.99)
 25             {
 26                 return "数字太大,无法换算,请输入一万亿元以下的金额";
 27             }
 28 
 29             char[] ch = new char[1];
 30 
 31             //小数点
 32             ch[0] = '.';
 33 
 34             //定义按小数点分割后的字符串数组 
 35 
 36             //按小数点分割字符串 
 37             string[] splitstr = str.Split(ch[0]);
 38 
 39             //只有整数部分 
 40             if (splitstr.Length == 1)
 41             {
 42                 return ConvertData(str) + "圆整";
 43             }
 44 
 45             //转换整数部分 
 46             string rstr = ConvertData(splitstr[0]) + "";
 47 
 48             //转换小数部分 
 49             rstr += ConvertXiaoShu(splitstr[1]);
 50 
 51             //rstr = rstr.Replace("零万", "万");
 52 
 53             return rstr;
 54         }
 55         /// <summary>
 56         /// 需要转换的小数部分数字字符串
 57         /// </summary>
 58         /// <param name="str"></param>
 59         /// <returns></returns>
 60         private static string ConvertXiaoShu(string str)
 61         {
 62             int strlen = str.Length;
 63             string rstr;
 64             if (strlen == 1)
 65             {
 66                 rstr = ConvertChinese(str) + "";
 67                 return rstr;
 68             }
 69 
 70             string tmpstr = str.Substring(0, 1);
 71             rstr = ConvertChinese(tmpstr) + "";
 72             tmpstr = str.Substring(1, 1);
 73             rstr += ConvertChinese(tmpstr) + "";
 74             rstr = rstr.Replace("零分", "");
 75             rstr = rstr.Replace("零角", "");
 76 
 77             return rstr;
 78         }
 79         /// <summary>
 80         /// 判断是否是正数字字符串 
 81         /// </summary>
 82         /// <param name="str"></param>
 83         /// <returns>如果是数字,返回true,否则返回false </returns>
 84         private static bool IsPositveDecimal(string str)
 85         {
 86             Decimal d;
 87             if (Decimal.TryParse(str, out d))
 88                 return d > 0;
 89             else
 90                 return false;
 91         }
 92         /// 转换数字(整数) 
 93         /// 需要转换的整数数字字符串 
 94         /// 转换成中文大写后的字符串 
 95         private static string ConvertData(string str)
 96         {
 97             string rstr = "";
 98             int strlen = str.Length;
 99 
100             //数字长度小于四位
101             if (strlen <= 4)
102             {
103                 rstr = ConvertDigit(str);
104 
105             }
106             else
107             {
108                 string tmpstr;
109 
110                 //数字长度大于四位,小于八位 
111                 if (strlen <= 8)
112                 {
113                     //先截取最后四位数字
114                     tmpstr = str.Substring(strlen - 4, 4);
115 
116                     //转换最后四位数字
117                     rstr = ConvertDigit(tmpstr);
118 
119                     //截取其余数字 
120                     tmpstr = str.Substring(0, strlen - 4);
121 
122                     //将两次转换的数字加上万后相连接 
123                     rstr = String.Concat(ConvertDigit(tmpstr) + "", rstr);
124                     rstr = rstr.Replace("零万", "");
125                     rstr = rstr.Replace("零零", "");
126                 }
127                 else
128                 {
129                     //数字长度大于八位,小于十二位 
130                     if (strlen <= 12)
131                     {
132                         //先截取最后四位数字 
133                         tmpstr = str.Substring(strlen - 4, 4);
134 
135                         //转换最后四位数字 
136                         rstr = ConvertDigit(tmpstr);
137 
138                         //再截取四位数字 
139                         tmpstr = str.Substring(strlen - 8, 4);
140                         rstr = String.Concat(ConvertDigit(tmpstr) + "", rstr);
141                         tmpstr = str.Substring(0, strlen - 8);
142                         rstr = String.Concat(ConvertDigit(tmpstr) + "亿", rstr);
143                         rstr = rstr.Replace("零亿", "亿");
144                         rstr = rstr.Replace("零万", "");
145                         rstr = rstr.Replace("零零", "");
146                         rstr = rstr.Replace("零零", "");
147                     }
148                 }
149             }
150 
151             strlen = rstr.Length;
152             if (strlen >= 2)
153             {
154                 switch (rstr.Substring(strlen - 2, 2))
155                 {
156                     case "佰零": rstr = rstr.Substring(0, strlen - 2) + ""; break;
157                     case "仟零": rstr = rstr.Substring(0, strlen - 2) + ""; break;
158                     case "万零": rstr = rstr.Substring(0, strlen - 2) + ""; break;
159                     case "亿零": rstr = rstr.Substring(0, strlen - 2) + "亿"; break;
160                 }
161             }
162             return rstr;
163         }
164         /// <summary>
165         /// 转换的字符串(四位以内)
166         /// </summary>
167         /// <param name="str"></param>
168         /// <returns></returns>
169         private static string ConvertDigit(string str)
170         {
171             int strlen = str.Length;
172             string rstr = "";
173             switch (strlen)
174             {
175                 case 1: rstr = ConvertChinese(str); break;
176                 case 2: rstr = Convert2Digit(str); break;
177                 case 3: rstr = Convert3Digit(str); break;
178                 case 4: rstr = Convert4Digit(str); break;
179             }
180             rstr = rstr.Replace("拾零", "");
181             return rstr;
182         }
183         /// <summary>
184         /// 转换四位数字
185         /// </summary>
186         /// <param name="str"></param>
187         /// <returns></returns>
188         private static string Convert4Digit(string str)
189         {
190             string str1 = str.Substring(0, 1);
191             string str2 = str.Substring(1, 1);
192             string str3 = str.Substring(2, 1);
193             string str4 = str.Substring(3, 1);
194             string rstring = "";
195             rstring += ConvertChinese(str1) + "";
196             rstring += ConvertChinese(str2) + "";
197             rstring += ConvertChinese(str3) + "";
198             rstring += ConvertChinese(str4);
199             rstring = rstring.Replace("零仟", "");
200             rstring = rstring.Replace("零佰", "");
201             rstring = rstring.Replace("零拾", "");
202             rstring = rstring.Replace("零零", "");
203             rstring = rstring.Replace("零零", "");
204             rstring = rstring.Replace("零零", "");
205             return rstring;
206         }
207         /// <summary>
208         /// 转换三位数字
209         /// </summary>
210         /// <param name="str"></param>
211         /// <returns></returns>
212         private static string Convert3Digit(string str)
213         {
214             string str1 = str.Substring(0, 1);
215             string str2 = str.Substring(1, 1);
216             string str3 = str.Substring(2, 1);
217             string rstring = "";
218             rstring += ConvertChinese(str1) + "";
219             rstring += ConvertChinese(str2) + "";
220             rstring += ConvertChinese(str3);
221             rstring = rstring.Replace("零佰", "");
222             rstring = rstring.Replace("零拾", "");
223             rstring = rstring.Replace("零零", "");
224             rstring = rstring.Replace("零零", "");
225             return rstring;
226         }
227         /// <summary>
228         /// 转换二位数字
229         /// </summary>
230         /// <param name="str"></param>
231         /// <returns></returns>
232         private static string Convert2Digit(string str)
233         {
234             string str1 = str.Substring(0, 1);
235             string str2 = str.Substring(1, 1);
236             string rstring = "";
237             rstring += ConvertChinese(str1) + "";
238             rstring += ConvertChinese(str2);
239             rstring = rstring.Replace("零拾", "");
240             rstring = rstring.Replace("零零", "");
241             return rstring;
242         }
243         /// <summary>
244         /// 将一位数字转换成中文大写数字 
245         /// </summary>
246         /// <param name="str"></param>
247         /// <returns></returns>
248         private static string ConvertChinese(string str)
249         {
250             //"零壹贰叁肆伍陆柒捌玖拾佰仟万亿圆整角分" 
251             string cstr = "";
252             switch (str)
253             {
254                 case "0":
255                     cstr = "";
256                     break;
257                 case "1":
258                     cstr = "";
259                     break;
260                 case "2":
261                     cstr = "";
262                     break;
263                 case "3":
264                     cstr = "";
265                     break;
266                 case "4":
267                     cstr = "";
268                     break;
269                 case "5":
270                     cstr = "";
271                     break;
272                 case "6":
273                     cstr = "";
274                     break;
275                 case "7":
276                     cstr = "";
277                     break;
278                 case "8":
279                     cstr = "";
280                     break;
281                 case "9":
282                     cstr = "";
283                     break;
284             }
285 
286             return (cstr);
287         }
288     }
289 }
此类实现金额的阿拉伯数字到大写汉字的转换
复制代码

7.邮件发送的帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.IO;
  4 using System.Linq;
  5 using System.Net;
  6 using System.Net.Mail;
  7 using System.Text;
  8 
  9 namespace Utilities
 10 {
 11     /// <summary>
 12     /// 邮件发送的帮助类
 13     /// </summary>
 14     public class NetHelper
 15     {      
 16 
 17         #region 下载公开网页资源
 18         /// <summary>
 19         /// 下载指定路径的网页内容
 20         /// </summary>
 21         /// <param name="url">网页路径,可以是html、css、js等</param>
 22         /// <returns></returns>
 23         public static string DownContent(string url)
 24         {
 25             try
 26             {
 27                 WebClient client = new WebClient();
 28                 Stream strm = client.OpenRead(url);
 29                 using (StreamReader sr = new StreamReader(strm))
 30                 {
 31                     return sr.ReadToEnd();
 32                 }
 33             }
 34             catch (Exception exp)
 35             {
 36                 LogHelper.Default.Error("{ time:'" + DateTime.Now + "',msg:'" + exp.Message + exp.StackTrace + "'}");
 37             }
 38             return "";
 39         }
 40         #endregion
 41 
 42         #region 发送电子邮件
 43 
 44         /// <summary> 
 45         /// 发送邮件程序 
 46         /// </summary> 
 47         /// <param name="from">发送人邮件地址</param> 
 48         /// <param name="fromName">发送人显示名称</param> 
 49         /// <param name="to">发送给谁(邮件地址)</param> 
 50         /// <param name="subject">标题</param> 
 51         /// <param name="body">内容</param> 
 52         /// <param name="username">邮件登录名</param> 
 53         /// <param name="password">邮件密码</param> 
 54         /// <param name="server">邮件服务器,例如:smtp.126.com </param> 
 55         /// <param name="fujian">附件,例如: C:\\a.txt;D:\\b.rar</param> 
 56         /// <param name="port">端口,例如:25</param> 
 57         /// <returns>是否发送成功</returns> 
 58         public static bool SendEMail(string from, string fromName, string to, string subject, string body,
 59             string username, string password, string server, string fujian, int port = 25)
 60         {
 61             try
 62             {
 63                 MailMessage mail = new MailMessage(); //创建邮件信息对象                
 64                 mail.From = new MailAddress(from, fromName); //是谁发送的邮件 
 65                 mail.To.Add(to);//发送给谁
 66                 mail.Subject = subject;//标题               
 67                 mail.BodyEncoding = Encoding.UTF8;//内容编码
 68                 mail.Priority = MailPriority.High;//发送优先级
 69                 mail.Body = body;//邮件内容 
 70                 mail.IsBodyHtml = false;//是否HTML形式发送 
 71                 //附件 
 72                 string[] fjs = fujian.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
 73                 if(fjs !=null && fjs.Length > 0)
 74                 {
 75                     for (int i = 0; i < fjs.Length; i++)
 76                         mail.Attachments.Add(new Attachment(fjs[i]));
 77                 }
 78                 SmtpClient smtp = new SmtpClient(server, port); //smtp邮件服务器和端口                
 79                 smtp.UseDefaultCredentials = true;
 80                 smtp.DeliveryMethod = SmtpDeliveryMethod.Network;//指定发送方式 
 81                 smtp.Credentials = new System.Net.NetworkCredential(username, password);//指定登录名和密码 
 82                 smtp.Timeout = 10000;//超时时间 
 83                 smtp.Send(mail);
 84                 return true;
 85             }
 86             catch (SmtpException exp)
 87             {
 88                 LogHelper.Default.Error("{ time:'" + DateTime.Now + "',msg:'" + exp.Message + exp.StackTrace + "'}");
 89                 return false;
 90             }
 91             catch (Exception exp)
 92             {
 93                 LogHelper.Default.Error("{ time:'"+ DateTime.Now+"',msg:'" + exp.Message+exp.StackTrace+"'}");
 94                 return false;
 95             }
 96         }
 97 
 98         #endregion
 99     }
100 }
邮件发送的帮助类
复制代码

8.在Silverlight中,微软并没有提供DataSet,DataTable对象,但当进行非常灵活的设计时,又是非常必要的
这里提供一个简易型的PDataSet对象,作为在客户端使用还是非常方便的。

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 using System.Data;
  5 using System.Linq;
  6 using System.Xml.Linq;
  7 
  8 namespace Utilities
  9 {
 10 
 11     /// <summary>
 12     /// 在Silverlight中,微软并没有提供DataSet,DataTable对象,但当进行非常灵活的设计时,又是非常必要的
 13     /// 这里提供一个简易型的PDataSet对象,作为在客户端使用还是非常方便的。
 14     /// <example>
 15     /// PDataSet pds = new PDataSet(res);
 16     /// ObservableCollection<DetailModel> list = new ObservableCollection<DetailModel>();
 17     /// foreach (PDataRow v in pds.Tables[0].Rows)
 18     /// {
 19     ///     DetailModel dm = new DetailModel { FileName = v["FileName"], Path = _siteUrl + "/" + v["FilePath"], Size = Convert.ToInt64(v["FileSize"]) };
 20     ///     list.Add(dm);
 21     /// }
 22     /// this.fileView.ItemSource = list;   
 23     /// </example>
 24     /// </summary>
 25     public class PDataSet
 26     {
 27         /// <summary>
 28         /// 从指定格式的xml字符串中,生成自定义的PDataSet对象
 29         /// </summary>
 30         /// <seealso cref="TransferConvert.ToXml(this DataSet ds)"/>
 31         /// <param name="xml">由TransferConvert.ToXml方法生成的xml字符串</param>
 32         public PDataSet(string xml)
 33         {
 34             var xDoc = XDocument.Parse(xml);
 35             var root = xDoc.Root.Element("Tables").Elements();
 36             var index = 0;
 37             this.Result = xml;
 38             this.Tables = new List<PDataTable>(root.Count());
 39 
 40             foreach (XElement elem in root)
 41             {
 42                 var columns = elem.Element("Columns").Nodes();
 43                 var rows = elem.Element("Rows").Nodes();
 44                 this.Tables.Add(new PDataTable(columns.Count()));
 45                 this.Tables[index].Name = elem.Attribute("Name").Value;
 46                 //初始化列
 47                 foreach (XElement firstNode in columns)
 48                     this.Tables[index].Columns.Add(new PDataColumn { Name = firstNode.Name.LocalName, DataType = firstNode.Attribute("DataType").Value });
 49                 //填充行数据
 50                 foreach (XElement lastNode in rows)
 51                 {
 52                     var atts = lastNode.Attributes();
 53                     PDataRow row = this.Tables[index].NewRow();
 54                     this.Tables[index].Rows.Add(row);
 55                     int i = 0;
 56                     foreach (XAttribute att in atts)
 57                         row[i++] = att.Value;
 58                 }
 59                 index++;
 60             }
 61         }
 62 
 63         /// <summary>
 64         /// 获取数据集中的所有表
 65         /// </summary>
 66         public List<PDataTable> Tables { get; private set; }
 67         /// <summary>
 68         /// 获取指定名称的数据表
 69         /// </summary>
 70         /// <param name="tableName"></param>
 71         /// <returns></returns>
 72         public PDataTable GetTable(string tableName)
 73         {
 74             foreach (PDataTable dt in Tables)
 75             {
 76                 if (dt.Name == tableName.ToLower())
 77                     return dt;
 78             }
 79             return null;
 80         }
 81         /// <summary>
 82         /// 获取原始的构造字符串
 83         /// </summary>
 84         public string Result { get; private set; }
 85     }
 86     /// <summary>
 87     /// PDataSet中表的定义
 88     /// </summary>
 89     public class PDataTable
 90     {
 91         /// <summary>
 92         /// 创建表对象
 93         /// </summary>
 94         public PDataTable() { }
 95         /// <summary>
 96         /// 创建指定列数的表对象
 97         /// </summary>
 98         /// <param name="columnCount"></param>
 99         public PDataTable(int columnCount)
100         {
101             this.Columns = new List<PDataColumn>(columnCount);
102             this.Rows = new List<PDataRow>();
103         }
104         /// <summary>
105         /// 获取或设置表名称
106         /// </summary>
107         public string Name { get; set; }
108         /// <summary>
109         /// 获取或设置列集合
110         /// </summary>
111         public List<PDataColumn> Columns { get; set; }
112         /// <summary>
113         /// 获取此表的数据行
114         /// </summary>
115         public List<PDataRow> Rows { get; private set; }
116 
117         /// <summary>
118         /// 创建一个新数据行
119         /// </summary>
120         public PDataRow NewRow()
121         {
122             return new PDataRow(this, Columns.Count);
123         }
124         /// <summary>
125         /// 向表中添加列
126         /// </summary>
127         /// <param name="columnName">列名</param>
128         public void NewColumn(string columnName)
129         {
130             NewColumn(columnName, "");
131         }
132         /// <summary>
133         /// 向表中添加列
134         /// </summary>
135         /// <param name="columnName">列名</param>
136         /// <param name="defValue">该列的默认值</param>
137         /// <returns>true:添加成功 false:已经存在同名列</returns>
138         public void NewColumn(string columnName, string defValue)
139         {
140             NewColumn(columnName, defValue, "System.String");
141         }
142         /// <summary>
143         /// 向表中添加列
144         /// </summary>
145         /// <param name="columnName">列名</param>
146         /// <param name="defValue">默认值</param>
147         /// <param name="columnType">列类型</param>
148         public void NewColumn(string columnName, string defValue, string columnType)
149         {
150             if (this.Columns.Where(p => p.Name.ToLower() == columnName.ToLower()).Count() > 0)
151                 throw new Exception("不能添加同名的列(注意:列名不区分大小写)");
152             else
153             {
154                 this.Columns.Add(new PDataColumn { Name = columnName, DataType = columnType });
155                 foreach (var r in this.Rows)
156                     r._values.Add(defValue);
157             }
158         }
159 
160         //public override string ToString()
161         //{
162         //    StringBuilder sb = new StringBuilder();
163         //    int colNum = this.Columns.Count;
164         //    for (int j = 0; j < colNum; ++j)
165         //    {
166         //        if (j == 0)
167         //            sb.Append(this.Columns[j].Name);
168         //        else
169         //            sb.Append("#" + this.Columns[j].Name);
170         //    }
171         //    sb.Append("\r\n");
172         //    //加载展示数据
173         //    int i = 0;
174         //    foreach (var c in this.Rows)
175         //    {
176         //        for (i = 0; i < colNum; i++)
177         //        {
178         //            if (i == 0)
179         //                sb.Append(c[i]);
180         //            else
181         //                sb.Append("#" + c[i]);
182         //        }
183         //        sb.Append("\r\n");
184         //    }
185         //    return sb.ToString();
186         //}
187     }
188 
189     /// <summary>
190     /// PDataSet中行的定义
191     /// </summary>
192     public class PDataRow
193     {
194         public PDataRow(PDataTable parentTable, int columnCount)
195         {
196             this._table = parentTable;
197             this._values = new List<string>(columnCount);
198             for (int i = 0; i < columnCount; i++)
199                 this._values.Add("");
200         }
201         /// <summary>
202         /// 为进行Id比较专门留的一个构造方法
203         /// </summary>
204         /// <example>
205         /// pds.Tables[0].Rows.BinarySearch(new PDataRow("3"), new IdComparer())//IdComparer是一个实现了IComparer<PDataRow>接口的类        /// 
206         /// </example>
207         /// <param name="id"></param>
208         public PDataRow(string id)
209         {
210             this._values = new List<string>(1);
211             this._values.Add(id);
212         }
213         public PDataTable _table;
214         internal List<string> _values;
215         /// <summary>
216         /// 获取隶属表的列名
217         /// </summary>
218         internal List<string> _columnNames
219         {
220             get
221             {
222                 return _table.Columns.Select(p => p.Name).ToList<string>();
223             }
224         }
225 
226         public string this[int index]
227         {
228             get
229             {
230                 if (index < 0 || index >= _values.Capacity)
231                     throw new IndexOutOfRangeException("超出了取值范围");
232                 else
233                     return _values[index];
234             }
235             set
236             {
237                 if (index < 0 || index > _values.Capacity)
238                     throw new IndexOutOfRangeException();
239                 else
240                 {
241                     _values[index] = value;
242                 }
243             }
244         }
245 
246         public string this[string key]
247         {
248             get
249             {
250                 int i = 0;
251                 foreach (string str in _columnNames)
252                 {
253                     if (str.ToLower() == key.ToLower())
254                         return _values[i];
255                     i++;
256                 }
257                 throw new Exception("您提供的列名不存在");
258             }
259             set
260             {
261                 for (int i = 0; i < _columnNames.Count; i++)
262                 {
263                     if (_columnNames[i] == key)
264                     {
265                         _values[i] = value;
266                         return;
267                     }
268                 }
269             }
270         }
271     }
272 
273     /// <summary>
274     /// PDataSet中列的定义
275     /// </summary>
276     public class PDataColumn
277     {
278         /// <summary>
279         /// 列名
280         /// </summary>
281         public string Name { get; set; }
282         /// <summary>
283         /// 类型名称
284         /// </summary>
285         public string DataType { get; set; }
286     }
287 }
PDataSet
复制代码

9.需要使用nuget获取itextsharp

 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Text;
 6 using iTextSharp.text;
 7 using iTextSharp.text.pdf;
 8 using iTextSharp.tool.xml;
 9 
10 
11 namespace Utilities
12 {
13     /// <summary>
14     /// 需要使用nuget获取itextsharp
15     /// </summary>
16     public class PdfHelper
17     {
18         /// <summary>
19         /// 注意事项
20         /// 1:html标签必须闭合,符合规范
21         /// 2:目前暂不支持link样式导入,只能写style
22         /// 使用示例:
23         /// WebClient wc = new WebClient();
24         /// 从网址下载Html字串
25         /// string htmlText = wc.DownloadString("http://localhost:6953/test.html");
26         /// byte[] pdfFile = PdfHelper.ConvertHtmlTextToPdf(htmlText);
27         /// return File(pdfFile, "application/pdf", "测试.pdf");
28         /// </summary>
29         /// <param name="htmlText">html格式的字符串</param>
30         /// <returns></returns>
31         public static byte[] ConvertHtmlTextToPdf(string htmlText)
32         {
33             if (string.IsNullOrEmpty(htmlText))
34             {
35                 return null;
36             }
37             //避免当htmlText无任何html tag标签的纯文字时,转PDF时会挂掉,所以一律加上<p>标签
38             htmlText = "<p>" + htmlText + "</p>";
39 
40             MemoryStream outputStream = new MemoryStream();//要把PDF写到哪个串流
41             byte[] data = Encoding.UTF8.GetBytes(htmlText);//字串转成byte[]
42             MemoryStream msInput = new MemoryStream(data);
43             Document doc = new Document();//要写PDF的文件,建构子没填的话预设直式A4
44             PdfWriter writer = PdfWriter.GetInstance(doc, outputStream);
45             //指定文件预设开档时的缩放为100%
46             PdfDestination pdfDest = new PdfDestination(PdfDestination.XYZ, 0, doc.PageSize.Height, 1f);
47             //开启Document文件 
48             doc.Open();
49             
50             //使用XMLWorkerHelper把Html parse到PDF档里
51             XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, msInput, null, Encoding.UTF8, new UnicodeFontFactory());
52             //将pdfDest设定的资料写到PDF档
53             PdfAction action = PdfAction.GotoLocalPage(1, pdfDest, writer);
54             writer.SetOpenAction(action);
55             doc.Close();
56             msInput.Close();
57             outputStream.Close();
58             //回传PDF档案 
59             return outputStream.ToArray();
60         }
61     }
62     /// <summary>
63     /// 字体工厂类
64     /// </summary>
65     public class UnicodeFontFactory : FontFactoryImp
66     {
67         /// <summary>
68         /// 定义一个pdf使用的字体,这里选择的是微软雅黑
69         /// </summary>
70         private static readonly string yh = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),
71           "msyh.ttc,0");
72         /// <summary>
73         /// 定义一个pdf使用的字体,这里选择的是楷体
74         /// </summary>
75         private static readonly string 标楷体Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),
76           "simkai.ttf"); 
77 
78         /// <summary>
79         /// 
80         /// </summary>
81         /// <param name="fontname"></param>
82         /// <param name="encoding"></param>
83         /// <param name="embedded"></param>
84         /// <param name="size"></param>
85         /// <param name="style"></param>
86         /// <param name="color"></param>
87         /// <param name="cached"></param>
88         /// <returns></returns>
89         public override Font GetFont(string fontname, string encoding, bool embedded, float size, int style, BaseColor color,
90           bool cached)
91         {
92             //可用雅黑字体或标楷体,自己选一个
93             BaseFont baseFont = BaseFont.CreateFont(yh, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
94             return new Font(baseFont, size, style, color);
95         }
96     }
97 }

需要使用nuget获取itextsharp

10.汉字拼音转换类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 
  6 namespace Utilities
  7 {
  8     /// <summary>
  9     /// 汉字拼音转换类
 10     /// </summary>
 11     public class PinYinConverter
 12     {
 13         #region 数组信息
 14 
 15         private static int[] pyValue = new int[] 
 16 
 17         {
 18             -20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, 
 19 
 20             -20230, -20051, -20036, -20032, -20026, -20002, -19990, -19986, -19982,
 21 
 22             -19976, -19805, -19784, -19775, -19774, -19763, -19756, -19751, -19746, 
 23 
 24             -19741, -19739, -19728, -19725, -19715, -19540, -19531, -19525, -19515, 
 25 
 26             -19500, -19484, -19479, -19467, -19289, -19288, -19281, -19275, -19270, 
 27 
 28             -19263, -19261, -19249, -19243, -19242, -19238, -19235, -19227, -19224, 
 29 
 30             -19218, -19212, -19038, -19023, -19018, -19006, -19003, -18996, -18977,
 31 
 32             -18961, -18952, -18783, -18774, -18773, -18763, -18756, -18741, -18735, 
 33 
 34             -18731, -18722, -18710, -18697, -18696, -18526, -18518, -18501, -18490,
 35 
 36             -18478, -18463, -18448, -18447, -18446, -18239, -18237, -18231, -18220,
 37 
 38             -18211, -18201, -18184, -18183, -18181, -18012, -17997, -17988, -17970, 
 39 
 40             -17964, -17961, -17950, -17947, -17931, -17928, -17922, -17759, -17752, 
 41 
 42             -17733, -17730, -17721, -17703, -17701, -17697, -17692, -17683, -17676,
 43 
 44             -17496, -17487, -17482, -17468, -17454, -17433, -17427, -17417, -17202, 
 45 
 46             -17185, -16983, -16970, -16942, -16915, -16733, -16708, -16706, -16689, 
 47 
 48             -16664, -16657, -16647, -16474, -16470, -16465, -16459, -16452, -16448, 
 49 
 50             -16433, -16429, -16427, -16423, -16419, -16412, -16407, -16403, -16401, 
 51 
 52             -16393, -16220, -16216, -16212, -16205, -16202, -16187, -16180, -16171,
 53 
 54             -16169, -16158, -16155, -15959, -15958, -15944, -15933, -15920, -15915, 
 55 
 56             -15903, -15889, -15878, -15707, -15701, -15681, -15667, -15661, -15659, 
 57 
 58             -15652, -15640, -15631, -15625, -15454, -15448, -15436, -15435, -15419,
 59 
 60             -15416, -15408, -15394, -15385, -15377, -15375, -15369, -15363, -15362, 
 61 
 62             -15183, -15180, -15165, -15158, -15153, -15150, -15149, -15144, -15143, 
 63 
 64             -15141, -15140, -15139, -15128, -15121, -15119, -15117, -15110, -15109, 
 65 
 66             -14941, -14937, -14933, -14930, -14929, -14928, -14926, -14922, -14921,
 67 
 68             -14914, -14908, -14902, -14894, -14889, -14882, -14873, -14871, -14857, 
 69 
 70             -14678, -14674, -14670, -14668, -14663, -14654, -14645, -14630, -14594,
 71 
 72             -14429, -14407, -14399, -14384, -14379, -14368, -14355, -14353, -14345,
 73 
 74             -14170, -14159, -14151, -14149, -14145, -14140, -14137, -14135, -14125, 
 75 
 76             -14123, -14122, -14112, -14109, -14099, -14097, -14094, -14092, -14090, 
 77 
 78             -14087, -14083, -13917, -13914, -13910, -13907, -13906, -13905, -13896, 
 79 
 80             -13894, -13878, -13870, -13859, -13847, -13831, -13658, -13611, -13601,
 81 
 82             -13406, -13404, -13400, -13398, -13395, -13391, -13387, -13383, -13367, 
 83 
 84             -13359, -13356, -13343, -13340, -13329, -13326, -13318, -13147, -13138, 
 85 
 86             -13120, -13107, -13096, -13095, -13091, -13076, -13068, -13063, -13060, 
 87 
 88             -12888, -12875, -12871, -12860, -12858, -12852, -12849, -12838, -12831,
 89 
 90             -12829, -12812, -12802, -12607, -12597, -12594, -12585, -12556, -12359,
 91 
 92             -12346, -12320, -12300, -12120, -12099, -12089, -12074, -12067, -12058,
 93 
 94             -12039, -11867, -11861, -11847, -11831, -11798, -11781, -11604, -11589, 
 95 
 96             -11536, -11358, -11340, -11339, -11324, -11303, -11097, -11077, -11067,
 97 
 98             -11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018,
 99 
100             -11014, -10838, -10832, -10815, -10800, -10790, -10780, -10764, -10587,
101 
102             -10544, -10533, -10519, -10331, -10329, -10328, -10322, -10315, -10309, 
103 
104             -10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254 
105 
106         };
107 
108         private static string[] pyName = new string[]
109 
110          { 
111              "A", "Ai", "An", "Ang", "Ao", "Ba", "Bai", "Ban", "Bang", "Bao", "Bei", 
112 
113              "Ben", "Beng", "Bi", "Bian", "Biao", "Bie", "Bin", "Bing", "Bo", "Bu",
114 
115              "Ba", "Cai", "Can", "Cang", "Cao", "Ce", "Ceng", "Cha", "Chai", "Chan",
116 
117              "Chang", "Chao", "Che", "Chen", "Cheng", "Chi", "Chong", "Chou", "Chu",
118 
119              "Chuai", "Chuan", "Chuang", "Chui", "Chun", "Chuo", "Ci", "Cong", "Cou",
120 
121              "Cu", "Cuan", "Cui", "Cun", "Cuo", "Da", "Dai", "Dan", "Dang", "Dao", "De", 
122 
123              "Deng", "Di", "Dian", "Diao", "Die", "Ding", "Diu", "Dong", "Dou", "Du", 
124 
125              "Duan", "Dui", "Dun", "Duo", "E", "En", "Er", "Fa", "Fan", "Fang", "Fei", 
126 
127              "Fen", "Feng", "Fo", "Fou", "Fu", "Ga", "Gai", "Gan", "Gang", "Gao", "Ge", 
128 
129              "Gei", "Gen", "Geng", "Gong", "Gou", "Gu", "Gua", "Guai", "Guan", "Guang", 
130 
131              "Gui", "Gun", "Guo", "Ha", "Hai", "Han", "Hang", "Hao", "He", "Hei", "Hen", 
132 
133              "Heng", "Hong", "Hou", "Hu", "Hua", "Huai", "Huan", "Huang", "Hui", "Hun",
134 
135              "Huo", "Ji", "Jia", "Jian", "Jiang", "Jiao", "Jie", "Jin", "Jing", "Jiong", 
136 
137              "Jiu", "Ju", "Juan", "Jue", "Jun", "Ka", "Kai", "Kan", "Kang", "Kao", "Ke",
138 
139              "Ken", "Keng", "Kong", "Kou", "Ku", "Kua", "Kuai", "Kuan", "Kuang", "Kui", 
140 
141              "Kun", "Kuo", "La", "Lai", "Lan", "Lang", "Lao", "Le", "Lei", "Leng", "Li",
142 
143              "Lia", "Lian", "Liang", "Liao", "Lie", "Lin", "Ling", "Liu", "Long", "Lou", 
144 
145              "Lu", "Lv", "Luan", "Lue", "Lun", "Luo", "Ma", "Mai", "Man", "Mang", "Mao",
146 
147              "Me", "Mei", "Men", "Meng", "Mi", "Mian", "Miao", "Mie", "Min", "Ming", "Miu",
148 
149              "Mo", "Mou", "Mu", "Na", "Nai", "Nan", "Nang", "Nao", "Ne", "Nei", "Nen", 
150 
151              "Neng", "Ni", "Nian", "Niang", "Niao", "Nie", "Nin", "Ning", "Niu", "Nong", 
152 
153              "Nu", "Nv", "Nuan", "Nue", "Nuo", "O", "Ou", "Pa", "Pai", "Pan", "Pang",
154 
155              "Pao", "Pei", "Pen", "Peng", "Pi", "Pian", "Piao", "Pie", "Pin", "Ping", 
156 
157              "Po", "Pu", "Qi", "Qia", "Qian", "Qiang", "Qiao", "Qie", "Qin", "Qing",
158 
159              "Qiong", "Qiu", "Qu", "Quan", "Que", "Qun", "Ran", "Rang", "Rao", "Re",
160 
161              "Ren", "Reng", "Ri", "Rong", "Rou", "Ru", "Ruan", "Rui", "Run", "Ruo", 
162 
163              "Sa", "Sai", "San", "Sang", "Sao", "Se", "Sen", "Seng", "Sha", "Shai", 
164 
165              "Shan", "Shang", "Shao", "She", "Shen", "Sheng", "Shi", "Shou", "Shu", 
166 
167              "Shua", "Shuai", "Shuan", "Shuang", "Shui", "Shun", "Shuo", "Si", "Song", 
168 
169              "Sou", "Su", "Suan", "Sui", "Sun", "Suo", "Ta", "Tai", "Tan", "Tang", 
170 
171              "Tao", "Te", "Teng", "Ti", "Tian", "Tiao", "Tie", "Ting", "Tong", "Tou",
172 
173              "Tu", "Tuan", "Tui", "Tun", "Tuo", "Wa", "Wai", "Wan", "Wang", "Wei",
174 
175              "Wen", "Weng", "Wo", "Wu", "Xi", "Xia", "Xian", "Xiang", "Xiao", "Xie",
176 
177              "Xin", "Xing", "Xiong", "Xiu", "Xu", "Xuan", "Xue", "Xun", "Ya", "Yan",
178 
179              "Yang", "Yao", "Ye", "Yi", "Yin", "Ying", "Yo", "Yong", "You", "Yu", 
180 
181              "Yuan", "Yue", "Yun", "Za", "Zai", "Zan", "Zang", "Zao", "Ze", "Zei",
182 
183              "Zen", "Zeng", "Zha", "Zhai", "Zhan", "Zhang", "Zhao", "Zhe", "Zhen", 
184 
185              "Zheng", "Zhi", "Zhong", "Zhou", "Zhu", "Zhua", "Zhuai", "Zhuan", 
186 
187              "Zhuang", "Zhui", "Zhun", "Zhuo", "Zi", "Zong", "Zou", "Zu", "Zuan",
188 
189              "Zui", "Zun", "Zuo" 
190          };
191 
192         #region 二级汉字
193         /// <summary>
194         /// 二级汉字数组
195         /// </summary>
196         private static string[] otherChinese = new string[]
197         {
198             "","","","","廿","","","","","","","","","","丿"
199             ,"","","","","","","","","","","","","","","",""
200             ,"","","","","","","","","","","","","","","",""
201             ,"","","","","","","","","","","","","","","",""
202             ,"","","","","","","","","","","","","","","",""
203             ,"","","","","","","","","","","","","","",""
204             ,"","","","","","","","","","","","","","",""
205             ,"","","","","","","","","","","","","","","",""
206             ,"","","","","","","","","","","","","","","",""
207             ,"","","","","","","","","","","","","","","",""
208             ,"","","","","","","","","","","","","","","",""
209             ,"","","","","","","","","","","","","","",""
210             ,"","","","","","","","","","","","","","",""
211             ,"","","","","","","","","","","","","","","",""
212             ,"","","","诿","","","","","","","","","","","",""
213             ,"","","","","","","","","","","","","","","",""
214             ,"","","","","","","","","","","","","","","",""
215             ,"","","","","","","","","","","","","","",""
216             ,"","","","","","","","","","","","","","",""
217             ,"","","","","","","","","","","","","","","",""
218             ,"","","","","","","","","","","","","","","",""
219             ,"","","","","","","","","","","","","","","",""
220             ,"","","","","","","","","","","","","","","",""
221             ,"","","","","","","","","","","","","","",""
222             ,"","","","","","","","","","","","","","",""
223             ,"","","","","","","","","","","","","","","",""
224             ,"","","","","","","","","","","","","","","",""
225             ,"","","","","","","","","","","","","","","",""
226             ,"","","","","","","","","","","","","","","",""
227             ,"","","","","","","","","","","","","","",""
228             ,"","","","","","","","","","","","","","",""
229             ,"","","","","","","","","","","","","","","",""
230             ,"","","","","","","","","","","","","","","",""
231             ,"","","","","","","","","","","","","","","",""
232             ,"","","","","","","","","","","","","","","",""
233             ,"","","","","","","","","","","","","","",""
234             ,"","","","","","","","","","","","","","",""
235             ,"","","","","","","","","","","","","","","",""
236             ,"","","","","","","","","","","","","","","",""
237             ,"","","","","","","","","","","","","","","",""
238             ,"","","","","","","","","","","","","","","",""
239             ,"","","","","","","","","","","","","","",""
240             ,"","","","","","","","","","","","","","",""
241             ,"","","","","","","","","","","","","","","",""
242             ,"","","","","","","","","","","","","","","",""
243             ,"","","","","","","","","","","","","","","",""
244             ,"","","","","","","","","","","","","","","",""
245             ,"","","","","","","","","","","","","","",""
246             ,"","","","","","","","","","","","","","",""
247             ,"","","","","","","","","","","","","","","",""
248             ,"","","","","","","","","","","","","","","",""
249             ,"","","","","","","","","","","","","","","",""
250             ,"","","","","","","","","","","","","","","",""
251             ,"","","","","","","","","","","","","","",""
252             ,"","","","","","","","","","","","","","",""
253             ,"","","","","","","","","","","","","","","",""
254             ,"","","","","","","","","","","","","","","",""
255             ,"","","","","","","","","","","","","","","",""
256             ,"","","","","","","","","","","","","","","",""
257             ,"","","","","","","","","","","","","","",""
258             ,"","","","","","","","","","","","","","",""
259             ,"","","","","","","","","","","","","","","",""
260             ,"","","","","","","","","","","","","","","",""
261             ,"","","","","","","","","","","","","","","",""
262             ,"","","","","","","","","","","","","","","",""
263             ,"","","","","","","","","","","","","","",""
264             ,"","","","","","","","","","","","","","",""
265             ,"","","","","","","","","","","","","","","",""
266             ,"","","","","","","","","","","","","","","",""
267             ,"","","","","","","","","","","","","","","",""
268             ,"","","","","","","","","","","","","","","",""
269             ,"","","","","","","","","","","","","","",""
270             ,"","","","","","","","","","","","","","",""
271             ,"","","","","","","","","","","","","","","",""
272             ,"","","","涿","","","","","","","","","","","",""
273             ,"","","","","","","","","","","","","","","",""
274             ,"","","","","","","","","","","","","","","",""
275             ,"","","","","","","","","","","","","","",""
276             ,"","","","","","","","","","","","","","",""
277             ,"","","","","","","","","","","","","","","",""
278             ,"","","","","","","","","","","","","","","",""
279             ,"","","","","","","","","","","","","","","",""
280             ,"","","","","","","","","","","","","","","",""
281             ,"","","","","","","","","","","","","","",""
282             ,"","","","","","","","","","","","","","",""
283             ,"","","","","","","","","","","","","","","",""
284             ,"","","","","","","","","","","","","","","",""
285             ,"","","","","","","","","","","","","","","",""
286             ,"","","","","驿","","","","","","","","","","",""
287             ,"","","","","","","","","","","","","","",""
288             ,"","","","","","","","","","","","","","",""
289             ,"","","","","","","","","","","","","","","",""
290             ,"","","","","","","","","","","","","","","",""
291             ,"","","","","","","","","","","","","","","",""
292             ,"","","","","","","","","","","","","","","",""
293             ,"","","","","","","","","","","","","","",""
294             ,"","","","","","","","","","","","","","",""
295             ,"","","","","","","","","","","","","","","",""
296             ,"","","","","","","","","","","","","","","",""
297             ,"","","","","","","","","","","","","","","",""
298             ,"","","","","","","","","","","","","","","",""
299             ,"","","","","","","","","","","","","","",""
300             ,"","","","","","","","","","","","","","",""
301             ,"","","","","","","","","","","","","","","",""
302             ,"","","","","","","","","槿","","","","","","",""
303             ,"","","","","","","","","","","","","","","",""
304             ,"","","","","","","","","","","","","","","",""
305             ,"","","","","","","","","","","","","","",""
306             ,"","","","","","","","","","","","","","",""
307             ,"","","","","","","","","","","","","","","",""
308             ,"","","","","","","","","","","","","","","",""
309             ,"","","","","","","","","","","","","","","",""
310             ,"","","","","","","","","","","","","","","",""
311             ,"","","","","","","","","","","","","","",""
312             ,"","","","","","","","","","","","","","",""
313             ,"","","","","","","","","","","","","","","",""
314             ,"","","","","","","","","","","","","","","",""
315             ,"","","","","","","","","","","","","","","",""
316             ,"","","","","","","","","","","","","","","",""
317             ,"","","","","","","","","","","","","","",""
318             ,"","","","","","","","","","","","","","",""
319             ,"","","","","","","","","","","","","","","",""
320             ,"","","","","","","","","","","","","","","",""
321             ,"","","","","","","","","","","","","","","",""
322             ,"","","","","","","","","","","","","","","",""
323             ,"","","","","","","","","","","","","","",""
324             ,"","","","","","","","","","","","","","",""
325             ,"","","","","","","","","","","","","","","",""
326             ,"","","","","","","","","","","","","","","",""
327             ,"","","","","","","","","","","","","","","",""
328             ,"","","","","","","","","","","","","","","",""
329             ,"","","","","","","","","","","","","","",""
330             ,"","","","","","","","","","","","","","",""
331             ,"","","","","","","","","","","","","","","",""
332             ,"","","","","","","","","","","","","","","",""
333             ,"","","","","","","","","","","","","","","",""
334             ,"","","","","","","","","","","","","","","",""
335             ,"","","","","","","","","","","","","","",""
336             ,"","","","","","","","","","","","","","",""
337             ,"","","","","","","","","","","","","","","",""
338             ,"","","","","","","","","","","","","","","",""
339             ,"","","","","","","","","","","","","","","",""
340             ,"","","","","","","","","","","","","","","",""
341             ,"","","","","","","","","","","","","","",""
342             ,"","","","","","","","","","","","","","",""
343             ,"","","","","","","","","","","","","","","",""
344             ,"","","","","","","","","","","","","","","",""
345             ,"","","","","","","","","","","","","","","",""
346             ,"","","","","","","","","","","","","","","",""
347             ,"","","","","","","","","","","","","","",""
348             ,"","","","","","","","","","","","","","",""
349             ,"","","","","","","","","","","","","","","",""
350             ,"","","","","","","","","","","","","","","",""
351             ,"","","","","","","","","","","","","","","",""
352             ,"","","","","","","","","","","","","","","",""
353             ,"","","","","","","","","","","","","","",""
354             ,"","","","","","","","","","","","","","",""
355             ,"","","","","","","","","","","","","","","",""
356             ,"","","","","","","","","","","","","","","",""
357             ,"","","","","","","","","","","","","","","",""
358             ,"","","","","","","","","","","","","","","",""
359             ,"","","","","","","","","","","","","","",""
360             ,"","","","","","","","","","","","","","",""
361             ,"","","","","","","","","","","","","","","",""
362             ,"","","","","","","","","","","","","","","",""
363             ,"","","","","","","","","","","","","","","",""
364             ,"","","","","","","","","","","","","","","",""
365             ,"","","","","","","","","","","","","","",""
366             ,"","","","","","","","","","","","","","",""
367             ,"","","","","","","","","","","","","","","",""
368             ,"","","","","","","","","","","","","","","",""
369             ,"","","","","","","","","","","","","","","",""
370             ,"羿","","","","","","","","","","","","","","",""
371             ,"","","","","","","","","","","","","","",""
372             ,"","","","","","","","","","","","","","",""
373             ,"","","","","","","","","","","","","","","",""
374             ,"","趿","","","","","","","","","","","","","",""
375             ,"","","","","","","","","","","","","","","",""
376             ,"","","","","","","","","","","","","","","",""
377             ,"","","","","","","","","","","","","","",""
378             ,"","","","","","","","","","","","","","",""
379             ,"","","","","","","","","","","","","","","",""
380             ,"","","","","","","","","","","","","","","","鱿"
381             ,"","","","","","","","","","","","","","","",""
382             ,"","","","","","","","","","","","","","","",""
383             ,"","","","","","","","","","","","","","",""
384             ,"","","","","","","","","","","","","","",""
385             ,"","","","","","","","","","","","","","","",""
386             ,"","","","","","","","","","","","","","","",""
387             ,"","","","","","","","","","","","","","","",""
388             ,"","","","","","","","","","","","","","","",""
389             ,"","","","","","","","","","","","","","",""
390         };
391 
392         /// <summary>
393         /// 二级汉字对应拼音数组
394         /// </summary>
395         private static string[] otherPinYin = new string[]
396            {                         
397                "Chu","Ji","Wu","Gai","Nian","Sa","Pi","Gen","Cheng","Ge","Nao","E","Shu","Yu","Pie","Bi",
398                 "Tuo","Yao","Yao","Zhi","Di","Xin","Yin","Kui","Yu","Gao","Tao","Dian","Ji","Nai","Nie","Ji",
399                 "Qi","Mi","Bei","Se","Gu","Ze","She","Cuo","Yan","Jue","Si","Ye","Yan","Fang","Po","Gui",
400                 "Kui","Bian","Ze","Gua","You","Ce","Yi","Wen","Jing","Ku","Gui","Kai","La","Ji","Yan","Wan",
401                 "Kuai","Piao","Jue","Qiao","Huo","Yi","Tong","Wang","Dan","Ding","Zhang","Le","Sa","Yi","Mu","Ren",
402                 "Yu","Pi","Ya","Wa","Wu","Chang","Cang","Kang","Zhu","Ning","Ka","You","Yi","Gou","Tong","Tuo",
403                 "Ni","Ga","Ji","Er","You","Kua","Kan","Zhu","Yi","Tiao","Chai","Jiao","Nong","Mou","Chou","Yan",
404                 "Li","Qiu","Li","Yu","Ping","Yong","Si","Feng","Qian","Ruo","Pai","Zhuo","Shu","Luo","Wo","Bi",
405                 "Ti","Guan","Kong","Ju","Fen","Yan","Xie","Ji","Wei","Zong","Lou","Tang","Bin","Nuo","Chi","Xi",
406                 "Jing","Jian","Jiao","Jiu","Tong","Xuan","Dan","Tong","Tun","She","Qian","Zu","Yue","Cuan","Di","Xi",
407                 "Xun","Hong","Guo","Chan","Kui","Bao","Pu","Hong","Fu","Fu","Su","Si","Wen","Yan","Bo","Gun",
408                 "Mao","Xie","Luan","Pou","Bing","Ying","Luo","Lei","Liang","Hu","Lie","Xian","Song","Ping","Zhong","Ming",
409                 "Yan","Jie","Hong","Shan","Ou","Ju","Ne","Gu","He","Di","Zhao","Qu","Dai","Kuang","Lei","Gua",
410                 "Jie","Hui","Shen","Gou","Quan","Zheng","Hun","Xu","Qiao","Gao","Kuang","Ei","Zou","Zhuo","Wei","Yu",
411                 "Shen","Chan","Sui","Chen","Jian","Xue","Ye","E","Yu","Xuan","An","Di","Zi","Pian","Mo","Dang",
412                 "Su","Shi","Mi","Zhe","Jian","Zen","Qiao","Jue","Yan","Zhan","Chen","Dan","Jin","Zuo","Wu","Qian",
413                 "Jing","Ban","Yan","Zuo","Bei","Jing","Gai","Zhi","Nie","Zou","Chui","Pi","Wei","Huang","Wei","Xi",
414                 "Han","Qiong","Kuang","Mang","Wu","Fang","Bing","Pi","Bei","Ye","Di","Tai","Jia","Zhi","Zhu","Kuai",
415                 "Qie","Xun","Yun","Li","Ying","Gao","Xi","Fu","Pi","Tan","Yan","Juan","Yan","Yin","Zhang","Po",
416                 "Shan","Zou","Ling","Feng","Chu","Huan","Mai","Qu","Shao","He","Ge","Meng","Xu","Xie","Sou","Xie",
417                 "Jue","Jian","Qian","Dang","Chang","Si","Bian","Ben","Qiu","Ben","E","Fa","Shu","Ji","Yong","He",
418                 "Wei","Wu","Ge","Zhen","Kuang","Pi","Yi","Li","Qi","Ban","Gan","Long","Dian","Lu","Che","Di",
419                 "Tuo","Ni","Mu","Ao","Ya","Die","Dong","Kai","Shan","Shang","Nao","Gai","Yin","Cheng","Shi","Guo",
420                 "Xun","Lie","Yuan","Zhi","An","Yi","Pi","Nian","Peng","Tu","Sao","Dai","Ku","Die","Yin","Leng",
421                 "Hou","Ge","Yuan","Man","Yong","Liang","Chi","Xin","Pi","Yi","Cao","Jiao","Nai","Du","Qian","Ji",
422                 "Wan","Xiong","Qi","Xiang","Fu","Yuan","Yun","Fei","Ji","Li","E","Ju","Pi","Zhi","Rui","Xian",
423                 "Chang","Cong","Qin","Wu","Qian","Qi","Shan","Bian","Zhu","Kou","Yi","Mo","Gan","Pie","Long","Ba",
424                 "Mu","Ju","Ran","Qing","Chi","Fu","Ling","Niao","Yin","Mao","Ying","Qiong","Min","Tiao","Qian","Yi",
425                 "Rao","Bi","Zi","Ju","Tong","Hui","Zhu","Ting","Qiao","Fu","Ren","Xing","Quan","Hui","Xun","Ming",
426                 "Qi","Jiao","Chong","Jiang","Luo","Ying","Qian","Gen","Jin","Mai","Sun","Hong","Zhou","Kan","Bi","Shi",
427                 "Wo","You","E","Mei","You","Li","Tu","Xian","Fu","Sui","You","Di","Shen","Guan","Lang","Ying",
428                 "Chun","Jing","Qi","Xi","Song","Jin","Nai","Qi","Ba","Shu","Chang","Tie","Yu","Huan","Bi","Fu",
429                 "Tu","Dan","Cui","Yan","Zu","Dang","Jian","Wan","Ying","Gu","Han","Qia","Feng","Shen","Xiang","Wei",
430                 "Chan","Kai","Qi","Kui","Xi","E","Bao","Pa","Ting","Lou","Pai","Xuan","Jia","Zhen","Shi","Ru",
431                 "Mo","En","Bei","Weng","Hao","Ji","Li","Bang","Jian","Shuo","Lang","Ying","Yu","Su","Meng","Dou",
432                 "Xi","Lian","Cu","Lin","Qu","Kou","Xu","Liao","Hui","Xun","Jue","Rui","Zui","Ji","Meng","Fan",
433                 "Qi","Hong","Xie","Hong","Wei","Yi","Weng","Sou","Bi","Hao","Tai","Ru","Xun","Xian","Gao","Li",
434                 "Huo","Qu","Heng","Fan","Nie","Mi","Gong","Yi","Kuang","Lian","Da","Yi","Xi","Zang","Pao","You",
435                 "Liao","Ga","Gan","Ti","Men","Tuan","Chen","Fu","Pin","Niu","Jie","Jiao","Za","Yi","Lv","Jun",
436                 "Tian","Ye","Ai","Na","Ji","Guo","Bai","Ju","Pou","Lie","Qian","Guan","Die","Zha","Ya","Qin",
437                 "Yu","An","Xuan","Bing","Kui","Yuan","Shu","En","Chuai","Jian","Shuo","Zhan","Nuo","Sang","Luo","Ying",
438                 "Zhi","Han","Zhe","Xie","Lu","Zun","Cuan","Gan","Huan","Pi","Xing","Zhuo","Huo","Zuan","Nang","Yi",
439                 "Te","Dai","Shi","Bu","Chi","Ji","Kou","Dao","Le","Zha","A","Yao","Fu","Mu","Yi","Tai",
440                 "Li","E","Bi","Bei","Guo","Qin","Yin","Za","Ka","Ga","Gua","Ling","Dong","Ning","Duo","Nao",
441                 "You","Si","Kuang","Ji","Shen","Hui","Da","Lie","Yi","Xiao","Bi","Ci","Guang","Yue","Xiu","Yi",
442                 "Pai","Kuai","Duo","Ji","Mie","Mi","Zha","Nong","Gen","Mou","Mai","Chi","Lao","Geng","En","Zha",
443                 "Suo","Zao","Xi","Zuo","Ji","Feng","Ze","Nuo","Miao","Lin","Zhuan","Zhou","Tao","Hu","Cui","Sha",
444                 "Yo","Dan","Bo","Ding","Lang","Li","Shua","Chuo","Die","Da","Nan","Li","Kui","Jie","Yong","Kui",
445                 "Jiu","Sou","Yin","Chi","Jie","Lou","Ku","Wo","Hui","Qin","Ao","Su","Du","Ke","Nie","He",
446                 "Chen","Suo","Ge","A","En","Hao","Dia","Ai","Ai","Suo","Hei","Tong","Chi","Pei","Lei","Cao",
447                 "Piao","Qi","Ying","Beng","Sou","Di","Mi","Peng","Jue","Liao","Pu","Chuai","Jiao","O","Qin","Lu",
448                 "Ceng","Deng","Hao","Jin","Jue","Yi","Sai","Pi","Ru","Cha","Huo","Nang","Wei","Jian","Nan","Lun",
449                 "Hu","Ling","You","Yu","Qing","Yu","Huan","Wei","Zhi","Pei","Tang","Dao","Ze","Guo","Wei","Wo",
450                 "Man","Zhang","Fu","Fan","Ji","Qi","Qian","Qi","Qu","Ya","Xian","Ao","Cen","Lan","Ba","Hu",
451                 "Ke","Dong","Jia","Xiu","Dai","Gou","Mao","Min","Yi","Dong","Qiao","Xun","Zheng","Lao","Lai","Song",
452                 "Yan","Gu","Xiao","Guo","Kong","Jue","Rong","Yao","Wai","Zai","Wei","Yu","Cuo","Lou","Zi","Mei",
453                 "Sheng","Song","Ji","Zhang","Lin","Deng","Bin","Yi","Dian","Chi","Pang","Cu","Xun","Yang","Hou","Lai",
454                 "Xi","Chang","Huang","Yao","Zheng","Jiao","Qu","San","Fan","Qiu","An","Guang","Ma","Niu","Yun","Xia",
455                 "Pao","Fei","Rong","Kuai","Shou","Sun","Bi","Juan","Li","Yu","Xian","Yin","Suan","Yi","Guo","Luo",
456                 "Ni","She","Cu","Mi","Hu","Cha","Wei","Wei","Mei","Nao","Zhang","Jing","Jue","Liao","Xie","Xun",
457                 "Huan","Chuan","Huo","Sun","Yin","Dong","Shi","Tang","Tun","Xi","Ren","Yu","Chi","Yi","Xiang","Bo",
458                 "Yu","Hun","Zha","Sou","Mo","Xiu","Jin","San","Zhuan","Nang","Pi","Wu","Gui","Pao","Xiu","Xiang",
459                 "Tuo","An","Yu","Bi","Geng","Ao","Jin","Chan","Xie","Lin","Ying","Shu","Dao","Cun","Chan","Wu",
460                 "Zhi","Ou","Chong","Wu","Kai","Chang","Chuang","Song","Bian","Niu","Hu","Chu","Peng","Da","Yang","Zuo",
461                 "Ni","Fu","Chao","Yi","Yi","Tong","Yan","Ce","Kai","Xun","Ke","Yun","Bei","Song","Qian","Kui",
462                 "Kun","Yi","Ti","Quan","Qie","Xing","Fei","Chang","Wang","Chou","Hu","Cui","Yun","Kui","E","Leng",
463                 "Zhui","Qiao","Bi","Su","Qie","Yong","Jing","Qiao","Chong","Chu","Lin","Meng","Tian","Hui","Shuan","Yan",
464                 "Wei","Hong","Min","Kang","Ta","Lv","Kun","Jiu","Lang","Yu","Chang","Xi","Wen","Hun","E","Qu",
465                 "Que","He","Tian","Que","Kan","Jiang","Pan","Qiang","San","Qi","Si","Cha","Feng","Yuan","Mu","Mian",
466                 "Dun","Mi","Gu","Bian","Wen","Hang","Wei","Le","Gan","Shu","Long","Lu","Yang","Si","Duo","Ling",
467                 "Mao","Luo","Xuan","Pan","Duo","Hong","Min","Jing","Huan","Wei","Lie","Jia","Zhen","Yin","Hui","Zhu",
468                 "Ji","Xu","Hui","Tao","Xun","Jiang","Liu","Hu","Xun","Ru","Su","Wu","Lai","Wei","Zhuo","Juan",
469                 "Cen","Bang","Xi","Mei","Huan","Zhu","Qi","Xi","Song","Du","Zhuo","Pei","Mian","Gan","Fei","Cong",
470                 "Shen","Guan","Lu","Shuan","Xie","Yan","Mian","Qiu","Sou","Huang","Xu","Pen","Jian","Xuan","Wo","Mei",
471                 "Yan","Qin","Ke","She","Mang","Ying","Pu","Li","Ru","Ta","Hun","Bi","Xiu","Fu","Tang","Pang",
472                 "Ming","Huang","Ying","Xiao","Lan","Cao","Hu","Luo","Huan","Lian","Zhu","Yi","Lu","Xuan","Gan","Shu",
473                 "Si","Shan","Shao","Tong","Chan","Lai","Sui","Li","Dan","Chan","Lian","Ru","Pu","Bi","Hao","Zhuo",
474                 "Han","Xie","Ying","Yue","Fen","Hao","Ba","Bao","Gui","Dang","Mi","You","Chen","Ning","Jian","Qian",
475                 "Wu","Liao","Qian","Huan","Jian","Jian","Zou","Ya","Wu","Jiong","Ze","Yi","Er","Jia","Jing","Dai",
476                 "Hou","Pang","Bu","Li","Qiu","Xiao","Ti","Qun","Kui","Wei","Huan","Lu","Chuan","Huang","Qiu","Xia",
477                 "Ao","Gou","Ta","Liu","Xian","Lin","Ju","Xie","Miao","Sui","La","Ji","Hui","Tuan","Zhi","Kao",
478                 "Zhi","Ji","E","Chan","Xi","Ju","Chan","Jing","Nu","Mi","Fu","Bi","Yu","Che","Shuo","Fei",
479                 "Yan","Wu","Yu","Bi","Jin","Zi","Gui","Niu","Yu","Si","Da","Zhou","Shan","Qie","Ya","Rao",
480                 "Shu","Luan","Jiao","Pin","Cha","Li","Ping","Wa","Xian","Suo","Di","Wei","E","Jing","Biao","Jie",
481                 "Chang","Bi","Chan","Nu","Ao","Yuan","Ting","Wu","Gou","Mo","Pi","Ai","Pin","Chi","Li","Yan",
482                 "Qiang","Piao","Chang","Lei","Zhang","Xi","Shan","Bi","Niao","Mo","Shuang","Ga","Ga","Fu","Nu","Zi",
483                 "Jie","Jue","Bao","Zang","Si","Fu","Zou","Yi","Nu","Dai","Xiao","Hua","Pian","Li","Qi","Ke",
484                 "Zhui","Can","Zhi","Wu","Ao","Liu","Shan","Biao","Cong","Chan","Ji","Xiang","Jiao","Yu","Zhou","Ge",
485                 "Wan","Kuang","Yun","Pi","Shu","Gan","Xie","Fu","Zhou","Fu","Chu","Dai","Ku","Hang","Jiang","Geng",
486                 "Xiao","Ti","Ling","Qi","Fei","Shang","Gun","Duo","Shou","Liu","Quan","Wan","Zi","Ke","Xiang","Ti",
487                 "Miao","Hui","Si","Bian","Gou","Zhui","Min","Jin","Zhen","Ru","Gao","Li","Yi","Jian","Bin","Piao",
488                 "Man","Lei","Miao","Sao","Xie","Liao","Zeng","Jiang","Qian","Qiao","Huan","Zuan","Yao","Ji","Chuan","Zai",
489                 "Yong","Ding","Ji","Wei","Bin","Min","Jue","Ke","Long","Dian","Dai","Po","Min","Jia","Er","Gong",
490                 "Xu","Ya","Heng","Yao","Luo","Xi","Hui","Lian","Qi","Ying","Qi","Hu","Kun","Yan","Cong","Wan",
491                 "Chen","Ju","Mao","Yu","Yuan","Xia","Nao","Ai","Tang","Jin","Huang","Ying","Cui","Cong","Xuan","Zhang",
492                 "Pu","Can","Qu","Lu","Bi","Zan","Wen","Wei","Yun","Tao","Wu","Shao","Qi","Cha","Ma","Li",
493                 "Pi","Miao","Yao","Rui","Jian","Chu","Cheng","Cong","Xiao","Fang","Pa","Zhu","Nai","Zhi","Zhe","Long",
494                 "Jiu","Ping","Lu","Xia","Xiao","You","Zhi","Tuo","Zhi","Ling","Gou","Di","Li","Tuo","Cheng","Kao",
495                 "Lao","Ya","Rao","Zhi","Zhen","Guang","Qi","Ting","Gua","Jiu","Hua","Heng","Gui","Jie","Luan","Juan",
496                 "An","Xu","Fan","Gu","Fu","Jue","Zi","Suo","Ling","Chu","Fen","Du","Qian","Zhao","Luo","Chui",
497                 "Liang","Guo","Jian","Di","Ju","Cou","Zhen","Nan","Zha","Lian","Lan","Ji","Pin","Ju","Qiu","Duan",
498                 "Chui","Chen","Lv","Cha","Ju","Xuan","Mei","Ying","Zhen","Fei","Ta","Sun","Xie","Gao","Cui","Gao",
499                 "Shuo","Bin","Rong","Zhu","Xie","Jin","Qiang","Qi","Chu","Tang","Zhu","Hu","Gan","Yue","Qing","Tuo",
500                 "Jue","Qiao","Qin","Lu","Zun","Xi","Ju","Yuan","Lei","Yan","Lin","Bo","Cha","You","Ao","Mo",
501                 "Cu","Shang","Tian","Yun","Lian","Piao","Dan","Ji","Bin","Yi","Ren","E","Gu","Ke","Lu","Zhi",
502                 "Yi","Zhen","Hu","Li","Yao","Shi","Zhi","Quan","Lu","Zhe","Nian","Wang","Chuo","Zi","Cou","Lu",
503                 "Lin","Wei","Jian","Qiang","Jia","Ji","Ji","Kan","Deng","Gai","Jian","Zang","Ou","Ling","Bu","Beng",
504                 "Zeng","Pi","Po","Ga","La","Gan","Hao","Tan","Gao","Ze","Xin","Yun","Gui","He","Zan","Mao",
505                 "Yu","Chang","Ni","Qi","Sheng","Ye","Chao","Yan","Hui","Bu","Han","Gui","Xuan","Kui","Ai","Ming",
506                 "Tun","Xun","Yao","Xi","Nang","Ben","Shi","Kuang","Yi","Zhi","Zi","Gai","Jin","Zhen","Lai","Qiu",
507                 "Ji","Dan","Fu","Chan","Ji","Xi","Di","Yu","Gou","Jin","Qu","Jian","Jiang","Pin","Mao","Gu",
508                 "Wu","Gu","Ji","Ju","Jian","Pian","Kao","Qie","Suo","Bai","Ge","Bo","Mao","Mu","Cui","Jian",
509                 "San","Shu","Chang","Lu","Pu","Qu","Pie","Dao","Xian","Chuan","Dong","Ya","Yin","Ke","Yun","Fan",
510                 "Chi","Jiao","Du","Die","You","Yuan","Guo","Yue","Wo","Rong","Huang","Jing","Ruan","Tai","Gong","Zhun",
511                 "Na","Yao","Qian","Long","Dong","Ka","Lu","Jia","Shen","Zhou","Zuo","Gua","Zhen","Qu","Zhi","Jing",
512                 "Guang","Dong","Yan","Kuai","Sa","Hai","Pian","Zhen","Mi","Tun","Luo","Cuo","Pao","Wan","Niao","Jing",
513                 "Yan","Fei","Yu","Zong","Ding","Jian","Cou","Nan","Mian","Wa","E","Shu","Cheng","Ying","Ge","Lv",
514                 "Bin","Teng","Zhi","Chuai","Gu","Meng","Sao","Shan","Lian","Lin","Yu","Xi","Qi","Sha","Xin","Xi",
515                 "Biao","Sa","Ju","Sou","Biao","Biao","Shu","Gou","Gu","Hu","Fei","Ji","Lan","Yu","Pei","Mao",
516                 "Zhan","Jing","Ni","Liu","Yi","Yang","Wei","Dun","Qiang","Shi","Hu","Zhu","Xuan","Tai","Ye","Yang",
517                 "Wu","Han","Men","Chao","Yan","Hu","Yu","Wei","Duan","Bao","Xuan","Bian","Tui","Liu","Man","Shang",
518                 "Yun","Yi","Yu","Fan","Sui","Xian","Jue","Cuan","Huo","Tao","Xu","Xi","Li","Hu","Jiong","Hu",
519                 "Fei","Shi","Si","Xian","Zhi","Qu","Hu","Fu","Zuo","Mi","Zhi","Ci","Zhen","Tiao","Qi","Chan",
520                 "Xi","Zhuo","Xi","Rang","Te","Tan","Dui","Jia","Hui","Nv","Nin","Yang","Zi","Que","Qian","Min",
521                 "Te","Qi","Dui","Mao","Men","Gang","Yu","Yu","Ta","Xue","Miao","Ji","Gan","Dang","Hua","Che",
522                 "Dun","Ya","Zhuo","Bian","Feng","Fa","Ai","Li","Long","Zha","Tong","Di","La","Tuo","Fu","Xing",
523                 "Mang","Xia","Qiao","Zhai","Dong","Nao","Ge","Wo","Qi","Dui","Bei","Ding","Chen","Zhou","Jie","Di",
524                 "Xuan","Bian","Zhe","Gun","Sang","Qing","Qu","Dun","Deng","Jiang","Ca","Meng","Bo","Kan","Zhi","Fu",
525                 "Fu","Xu","Mian","Kou","Dun","Miao","Dan","Sheng","Yuan","Yi","Sui","Zi","Chi","Mou","Lai","Jian",
526                 "Di","Suo","Ya","Ni","Sui","Pi","Rui","Sou","Kui","Mao","Ke","Ming","Piao","Cheng","Kan","Lin",
527                 "Gu","Ding","Bi","Quan","Tian","Fan","Zhen","She","Wan","Tuan","Fu","Gang","Gu","Li","Yan","Pi",
528                 "Lan","Li","Ji","Zeng","He","Guan","Juan","Jin","Ga","Yi","Po","Zhao","Liao","Tu","Chuan","Shan",
529                 "Men","Chai","Nv","Bu","Tai","Ju","Ban","Qian","Fang","Kang","Dou","Huo","Ba","Yu","Zheng","Gu",
530                 "Ke","Po","Bu","Bo","Yue","Mu","Tan","Dian","Shuo","Shi","Xuan","Ta","Bi","Ni","Pi","Duo",
531                 "Kao","Lao","Er","You","Cheng","Jia","Nao","Ye","Cheng","Diao","Yin","Kai","Zhu","Ding","Diu","Hua",
532                 "Quan","Ha","Sha","Diao","Zheng","Se","Chong","Tang","An","Ru","Lao","Lai","Te","Keng","Zeng","Li",
533                 "Gao","E","Cuo","Lve","Liu","Kai","Jian","Lang","Qin","Ju","A","Qiang","Nuo","Ben","De","Ke",
534                 "Kun","Gu","Huo","Pei","Juan","Tan","Zi","Qie","Kai","Si","E","Cha","Sou","Huan","Ai","Lou",
535                 "Qiang","Fei","Mei","Mo","Ge","Juan","Na","Liu","Yi","Jia","Bin","Biao","Tang","Man","Luo","Yong",
536                 "Chuo","Xuan","Di","Tan","Jue","Pu","Lu","Dui","Lan","Pu","Cuan","Qiang","Deng","Huo","Zhuo","Yi",
537                 "Cha","Biao","Zhong","Shen","Cuo","Zhi","Bi","Zi","Mo","Shu","Lv","Ji","Fu","Lang","Ke","Ren",
538                 "Zhen","Ji","Se","Nian","Fu","Rang","Gui","Jiao","Hao","Xi","Po","Die","Hu","Yong","Jiu","Yuan",
539                 "Bao","Zhen","Gu","Dong","Lu","Qu","Chi","Si","Er","Zhi","Gua","Xiu","Luan","Bo","Li","Hu",
540                 "Yu","Xian","Ti","Wu","Miao","An","Bei","Chun","Hu","E","Ci","Mei","Wu","Yao","Jian","Ying",
541                 "Zhe","Liu","Liao","Jiao","Jiu","Yu","Hu","Lu","Guan","Bing","Ding","Jie","Li","Shan","Li","You",
542                 "Gan","Ke","Da","Zha","Pao","Zhu","Xuan","Jia","Ya","Yi","Zhi","Lao","Wu","Cuo","Xian","Sha",
543                 "Zhu","Fei","Gu","Wei","Yu","Yu","Dan","La","Yi","Hou","Chai","Lou","Jia","Sao","Chi","Mo",
544                 "Ban","Ji","Huang","Biao","Luo","Ying","Zhai","Long","Yin","Chou","Ban","Lai","Yi","Dian","Pi","Dian",
545                 "Qu","Yi","Song","Xi","Qiong","Zhun","Bian","Yao","Tiao","Dou","Ke","Yu","Xun","Ju","Yu","Yi",
546                 "Cha","Na","Ren","Jin","Mei","Pan","Dang","Jia","Ge","Ken","Lian","Cheng","Lian","Jian","Biao","Chu",
547                 "Ti","Bi","Ju","Duo","Da","Bei","Bao","Lv","Bian","Lan","Chi","Zhe","Qiang","Ru","Pan","Ya",
548                 "Xu","Jun","Cun","Jin","Lei","Zi","Chao","Si","Huo","Lao","Tang","Ou","Lou","Jiang","Nou","Mo",
549                 "Die","Ding","Dan","Ling","Ning","Guo","Kui","Ao","Qin","Han","Qi","Hang","Jie","He","Ying","Ke",
550                 "Han","E","Zhuan","Nie","Man","Sang","Hao","Ru","Pin","Hu","Qian","Qiu","Ji","Chai","Hui","Ge",
551                 "Meng","Fu","Pi","Rui","Xian","Hao","Jie","Gong","Dou","Yin","Chi","Han","Gu","Ke","Li","You",
552                 "Ran","Zha","Qiu","Ling","Cheng","You","Qiong","Jia","Nao","Zhi","Si","Qu","Ting","Kuo","Qi","Jiao",
553                 "Yang","Mou","Shen","Zhe","Shao","Wu","Li","Chu","Fu","Qiang","Qing","Qi","Xi","Yu","Fei","Guo",
554                 "Guo","Yi","Pi","Tiao","Quan","Wan","Lang","Meng","Chun","Rong","Nan","Fu","Kui","Ke","Fu","Sou",
555                 "Yu","You","Lou","You","Bian","Mou","Qin","Ao","Man","Mang","Ma","Yuan","Xi","Chi","Tang","Pang",
556                 "Shi","Huang","Cao","Piao","Tang","Xi","Xiang","Zhong","Zhang","Shuai","Mao","Peng","Hui","Pan","Shan","Huo",
557                 "Meng","Chan","Lian","Mie","Li","Du","Qu","Fou","Ying","Qing","Xia","Shi","Zhu","Yu","Ji","Du",
558                 "Ji","Jian","Zhao","Zi","Hu","Qiong","Po","Da","Sheng","Ze","Gou","Li","Si","Tiao","Jia","Bian",
559                 "Chi","Kou","Bi","Xian","Yan","Quan","Zheng","Jun","Shi","Gang","Pa","Shao","Xiao","Qing","Ze","Qie",
560                 "Zhu","Ruo","Qian","Tuo","Bi","Dan","Kong","Wan","Xiao","Zhen","Kui","Huang","Hou","Gou","Fei","Li",
561                 "Bi","Chi","Su","Mie","Dou","Lu","Duan","Gui","Dian","Zan","Deng","Bo","Lai","Zhou","Yu","Yu",
562                 "Chong","Xi","Nie","Nv","Chuan","Shan","Yi","Bi","Zhong","Ban","Fang","Ge","Lu","Zhu","Ze","Xi",
563                 "Shao","Wei","Meng","Shou","Cao","Chong","Meng","Qin","Niao","Jia","Qiu","Sha","Bi","Di","Qiang","Suo",
564                 "Jie","Tang","Xi","Xian","Mi","Ba","Li","Tiao","Xi","Zi","Can","Lin","Zong","San","Hou","Zan",
565                 "Ci","Xu","Rou","Qiu","Jiang","Gen","Ji","Yi","Ling","Xi","Zhu","Fei","Jian","Pian","He","Yi",
566                 "Jiao","Zhi","Qi","Qi","Yao","Dao","Fu","Qu","Jiu","Ju","Lie","Zi","Zan","Nan","Zhe","Jiang",
567                 "Chi","Ding","Gan","Zhou","Yi","Gu","Zuo","Tuo","Xian","Ming","Zhi","Yan","Shai","Cheng","Tu","Lei",
568                 "Kun","Pei","Hu","Ti","Xu","Hai","Tang","Lao","Bu","Jiao","Xi","Ju","Li","Xun","Shi","Cuo",
569                 "Dun","Qiong","Xue","Cu","Bie","Bo","Ta","Jian","Fu","Qiang","Zhi","Fu","Shan","Li","Tuo","Jia",
570                 "Bo","Tai","Kui","Qiao","Bi","Xian","Xian","Ji","Jiao","Liang","Ji","Chuo","Huai","Chi","Zhi","Dian",
571                 "Bo","Zhi","Jian","Die","Chuai","Zhong","Ju","Duo","Cuo","Pian","Rou","Nie","Pan","Qi","Chu","Jue",
572                 "Pu","Fan","Cu","Zhu","Lin","Chan","Lie","Zuan","Xie","Zhi","Diao","Mo","Xiu","Mo","Pi","Hu",
573                 "Jue","Shang","Gu","Zi","Gong","Su","Zhi","Zi","Qing","Liang","Yu","Li","Wen","Ting","Ji","Pei",
574                 "Fei","Sha","Yin","Ai","Xian","Mai","Chen","Ju","Bao","Tiao","Zi","Yin","Yu","Chuo","Wo","Mian",
575                 "Yuan","Tuo","Zhui","Sun","Jun","Ju","Luo","Qu","Chou","Qiong","Luan","Wu","Zan","Mou","Ao","Liu",
576                 "Bei","Xin","You","Fang","Ba","Ping","Nian","Lu","Su","Fu","Hou","Tai","Gui","Jie","Wei","Er",
577                 "Ji","Jiao","Xiang","Xun","Geng","Li","Lian","Jian","Shi","Tiao","Gun","Sha","Huan","Ji","Qing","Ling",
578                 "Zou","Fei","Kun","Chang","Gu","Ni","Nian","Diao","Shi","Zi","Fen","Die","E","Qiu","Fu","Huang",
579                 "Bian","Sao","Ao","Qi","Ta","Guan","Yao","Le","Biao","Xue","Man","Min","Yong","Gui","Shan","Zun",
580                 "Li","Da","Yang","Da","Qiao","Man","Jian","Ju","Rou","Gou","Bei","Jie","Tou","Ku","Gu","Di",
581                 "Hou","Ge","Ke","Bi","Lou","Qia","Kuan","Bin","Du","Mei","Ba","Yan","Liang","Xiao","Wang","Chi",
582                 "Xiang","Yan","Tie","Tao","Yong","Biao","Kun","Mao","Ran","Tiao","Ji","Zi","Xiu","Quan","Jiu","Bin",
583                 "Huan","Lie","Me","Hui","Mi","Ji","Jun","Zhu","Mi","Qi","Ao","She","Lin","Dai","Chu","You",
584                 "Xia","Yi","Qu","Du","Li","Qing","Can","An","Fen","You","Wu","Yan","Xi","Qiu","Han","Zha"
585            };
586         #endregion 二级汉字
587         #region 变量定义
588         // GB2312-80 标准规范中第一个汉字的机内码.即"啊"的机内码
589         private const int firstChCode = -20319;
590         // GB2312-80 标准规范中最后一个汉字的机内码.即"齄"的机内码
591         private const int lastChCode = -2050;
592         // GB2312-80 标准规范中最后一个一级汉字的机内码.即"座"的机内码
593         private const int lastOfOneLevelChCode = -10247;
594         // 配置中文字符
595         //static Regex regex = new Regex("[\u4e00-\u9fa5]$");
596 
597         #endregion
598         #endregion
599 
600         /// <summary>
601         /// 取拼音第一个字段
602         /// </summary>        
603         /// <param name="ch"></param>        
604         /// <returns></returns>        
605         public static String GetFirst(Char ch)
606         {
607             var rs = Get(ch);
608             if (!String.IsNullOrEmpty(rs)) rs = rs.Substring(0, 1);
609 
610             return rs;
611         }
612 
613         /// <summary>
614         /// 取拼音第一个字段
615         /// </summary>
616         /// <param name="str"></param>
617         /// <returns></returns>
618         public static String GetFirst(String str)
619         {
620             if (String.IsNullOrEmpty(str)) return String.Empty;
621 
622             var sb = new StringBuilder(str.Length + 1);
623             var chs = str.ToCharArray();
624 
625             for (var i = 0; i < chs.Length; i++)
626             {
627                 sb.Append(GetFirst(chs[i]));
628             }
629 
630             return sb.ToString();
631         }
632 
633         /// <summary>
634         /// 获取单字拼音
635         /// </summary>
636         /// <param name="ch"></param>
637         /// <returns></returns>
638         public static String Get(Char ch)
639         {
640             // 拉丁字符            
641             if (ch <= '\x00FF') return ch.ToString();
642 
643             // 标点符号、分隔符            
644             if (Char.IsPunctuation(ch) || Char.IsSeparator(ch)) return ch.ToString();
645 
646             // 非中文字符            
647             if (ch < '\x4E00' || ch > '\x9FA5') return ch.ToString();
648 
649             var arr = Encoding.GetEncoding("gb2312").GetBytes(ch.ToString());
650             //Encoding.Default默认在中文环境里虽是GB2312,但在多变的环境可能是其它
651             //var arr = Encoding.Default.GetBytes(ch.ToString()); 
652             var chr = (Int16)arr[0] * 256 + (Int16)arr[1] - 65536;
653 
654             //***// 单字符--英文或半角字符  
655             if (chr > 0 && chr < 160) return ch.ToString();
656             #region 中文字符处理
657 
658             // 判断是否超过GB2312-80标准中的汉字范围
659             if (chr > lastChCode || chr < firstChCode)
660             {
661                 return ch.ToString(); ;
662             }
663             // 如果是在一级汉字中
664             else if (chr <= lastOfOneLevelChCode)
665             {
666                 // 将一级汉字分为12块,每块33个汉字.
667                 for (int aPos = 11; aPos >= 0; aPos--)
668                 {
669                     int aboutPos = aPos * 33;
670                     // 从最后的块开始扫描,如果机内码大于块的第一个机内码,说明在此块中
671                     if (chr >= pyValue[aboutPos])
672                     {
673                         // Console.WriteLine("存在于第 " + aPos.ToString() + " 块,此块的第一个机内码是: " + pyValue[aPos * 33].ToString());
674                         // 遍历块中的每个音节机内码,从最后的音节机内码开始扫描,
675                         // 如果音节内码小于机内码,则取此音节
676                         for (int i = aboutPos + 32; i >= aboutPos; i--)
677                         {
678                             if (pyValue[i] <= chr)
679                             {
680                                 // Console.WriteLine("找到第一个小于要查找机内码的机内码: " + pyValue[i].ToString());
681                                 return pyName[i];
682                             }
683                         }
684                         break;
685                     }
686                 }
687             }
688             // 如果是在二级汉字中
689             else
690             {
691                 int pos = Array.IndexOf(otherChinese, ch.ToString());
692                 if (pos != decimal.MinusOne)
693                 {
694                     return otherPinYin[pos];
695                 }
696             }
697             #endregion 中文字符处理
698 
699             //if (chr < -20319 || chr > -10247) { // 不知道的字符  
700             //    return null;  
701 
702             //for (var i = pyValue.Length - 1; i >= 0; i--)
703             //{                
704             //    if (pyValue[i] <= chr) return pyName[i];//这只能对应数组已经定义的           
705             //}             
706 
707             return String.Empty;
708         }
709 
710         /// <summary>
711         /// 把汉字转换成拼音(全拼)
712         /// </summary>
713         /// <param name="str">汉字字符串</param>
714         /// <returns>转换后的拼音(全拼)字符串</returns>
715         public static String Get(String str)
716         {
717             if (String.IsNullOrEmpty(str)) return String.Empty;
718 
719             var sb = new StringBuilder(str.Length * 10);
720             var chs = str.ToCharArray();
721 
722             for (var j = 0; j < chs.Length; j++)
723             {
724                 sb.Append(Get(chs[j]));
725             }
726 
727             return sb.ToString();
728         }
729     }
730 
731 }
汉字拼音转换类
复制代码

11.安全加密帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Text;
  5 using System.Security.Cryptography;
  6 using System.IO;
  7 
  8 namespace Utilities
  9 {
 10     /// <summary>
 11     /// 安全加密帮助类
 12     /// </summary>
 13     public class SecurityHelper
 14     {
 15         /// <summary> 
 16         /// DES加解密工具类
 17         /// </summary> 
 18         public class DESEncrypt
 19         {
 20             //默认密钥向量
 21             private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
 22             /// <summary>
 23             /// DES加密字符串
 24             /// </summary>
 25             /// <param name="encryptString">待加密的字符串</param>
 26             /// <param name="encryptKey">加密密钥,要求为8位</param>
 27             /// <returns>加密成功返回加密后的字符串,失败返回源串</returns>
 28             public static string Encode(string encryptString, string encryptKey)
 29             {                
 30                 encryptKey = StringHelper.GetSubString(encryptKey, 8, "");
 31                 encryptKey = encryptKey.PadRight(8, ' ');
 32                 byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
 33                 byte[] rgbIV = Keys;
 34                 byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
 35                 DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
 36                 MemoryStream mStream = new MemoryStream();
 37                 CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
 38                 cStream.Write(inputByteArray, 0, inputByteArray.Length);
 39                 cStream.FlushFinalBlock();
 40                 return Convert.ToBase64String(mStream.ToArray());
 41 
 42             }
 43             /// <summary>
 44             /// DES解密字符串
 45             /// </summary>
 46             /// <param name="decryptString">待解密的字符串</param>
 47             /// <param name="decryptKey">解密密钥,要求为8位,和加密密钥相同</param>
 48             /// <returns>解密成功返回解密后的字符串,失败返源串</returns>
 49             public static string Decode(string decryptString, string decryptKey)
 50             {
 51                 try
 52                 {
 53                     decryptKey = StringHelper.GetSubString(decryptKey, 8, "");
 54                     decryptKey = decryptKey.PadRight(8, ' ');
 55                     byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey);
 56                     byte[] rgbIV = Keys;
 57                     byte[] inputByteArray = Convert.FromBase64String(decryptString);
 58                     DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
 59 
 60                     MemoryStream mStream = new MemoryStream();
 61                     CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
 62                     cStream.Write(inputByteArray, 0, inputByteArray.Length);
 63                     cStream.FlushFinalBlock();
 64                     return Encoding.UTF8.GetString(mStream.ToArray());
 65                 }
 66                 catch
 67                 {
 68                     return null;
 69                 }
 70             }
 71         }
 72         /// <summary> 
 73         /// AES加解密工具类
 74         /// </summary> 
 75         public class AESEncrypt
 76         {
 77             private static byte[] Keys = { 0x41, 0x72, 0x65, 0x79, 0x6F, 0x75, 0x6D, 0x79, 0x53, 0x6E, 0x6F, 0x77, 0x6D, 0x61, 0x6E, 0x3F };
 78             /// <summary>
 79             /// 加密指定字符串
 80             /// </summary>
 81             /// <param name="encryptString">要加密的字符串</param>
 82             /// <param name="encryptKey">密钥</param>
 83             /// <returns>加密后的字符串</returns>
 84             public static string Encode(string encryptString, string encryptKey)
 85             {
 86                 encryptKey = StringHelper.GetSubString(encryptKey, 32, "");
 87                 encryptKey = encryptKey.PadRight(32, ' ');
 88 
 89                 RijndaelManaged rijndaelProvider = new RijndaelManaged();
 90                 rijndaelProvider.Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 32));
 91                 rijndaelProvider.IV = Keys;
 92                 ICryptoTransform rijndaelEncrypt = rijndaelProvider.CreateEncryptor();
 93 
 94                 byte[] inputData = Encoding.UTF8.GetBytes(encryptString);
 95                 byte[] encryptedData = rijndaelEncrypt.TransformFinalBlock(inputData, 0, inputData.Length);
 96 
 97                 return Convert.ToBase64String(encryptedData);
 98             }
 99             /// <summary>
100             /// 解密指定的字符串
101             /// </summary>
102             /// <param name="decryptString">调用Encode加密方法加密过的字符串</param>
103             /// <param name="decryptKey">密钥</param>
104             /// <returns>解密后的字符串</returns>
105             public static string Decode(string decryptString, string decryptKey)
106             {
107                 try
108                 {
109                     decryptKey = StringHelper.GetSubString(decryptKey, 32, "");
110                     decryptKey = decryptKey.PadRight(32, ' ');
111 
112                     RijndaelManaged rijndaelProvider = new RijndaelManaged();
113                     rijndaelProvider.Key = Encoding.UTF8.GetBytes(decryptKey);
114                     rijndaelProvider.IV = Keys;
115                     ICryptoTransform rijndaelDecrypt = rijndaelProvider.CreateDecryptor();
116 
117                     byte[] inputData = Convert.FromBase64String(decryptString);
118                     byte[] decryptedData = rijndaelDecrypt.TransformFinalBlock(inputData, 0, inputData.Length);
119 
120                     return Encoding.UTF8.GetString(decryptedData);
121                 }
122                 catch
123                 {
124                     return "";
125                 }
126 
127             }
128         }
129         /// <summary>
130         /// 
131         /// </summary>
132         public class MD5
133         {
134             /// <summary>
135             /// 加密字符串
136             /// </summary>
137             /// <param name="sourceString"></param>
138             /// <returns></returns>
139             public static string Encrypt(string sourceString)
140             {
141                 if (string.IsNullOrEmpty(sourceString))
142                 {
143                     throw new Exception("<Encrypt Error>sourceString is null");
144                 }
145 
146                 var md5 = new MD5CryptoServiceProvider();
147                 var buffer = md5.ComputeHash(Encoding.UTF8.GetBytes(sourceString));
148                 var sb = new StringBuilder(32);
149                 foreach (var t in buffer)
150                 {
151                     sb.Append(t.ToString("X2"));
152                 }
153 
154                 md5.Dispose();
155                 return sb.ToString();
156             }
157 
158             /// <summary>
159             /// 16位MD5加密
160             /// </summary>
161             /// <param name="sourceString"></param>
162             /// <returns></returns>
163             public static string Encrypt16(string sourceString)
164             {
165                 var md5 = new MD5CryptoServiceProvider();
166                 string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(sourceString)), 4, 8);
167                 t2 = t2.Replace("-", "");
168                 return t2;
169             }
170         } 
171         
172     }
173 }
安全加密帮助类
复制代码

12.SqlServer连接帮助类

复制代码
  1 using System;
  2 using System.Configuration;
  3 using System.Data;
  4 using System.Data.SqlClient;
  5 using System.Collections;
  6 
  7 namespace Utilities
  8 {
  9     /// <summary>
 10     /// SqlHelper 的摘要说明。
 11     /// </summary>
 12     public class SqlHelper
 13     {    
 14         public static readonly string ImgConnectionString = ConfigurationManager.ConnectionStrings["ResConnectionString"].ConnectionString;
 15         public static readonly string AppConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;//@"Data Source=.\SeanDB;Initial Catalog=YSD;Persist Security Info=True;User ID=sa;Password=123@qwe";//
 16         // Hashtable to store cached parameters
 17         private static Hashtable parmCache = Hashtable.Synchronized(new Hashtable());
 18 
 19         /// <summary>
 20         /// 数据分页取的是全部列
 21         /// </summary>
 22         /// <param name="objName">您要查询的表或试图</param>
 23         /// <param name="colNames">您要取得列名例如:Id,Name</param>
 24         /// <param name="whereSql">条件语句例如:"where price>10"</param>
 25         /// <param name="orderSql">排序语句例如:"order by price desc,BTime"</param>
 26         /// <param name="pageSize">每页记录数</param>
 27         /// <param name="pageNum">当前页码</param>
 28         /// <param name="recordCount">满足条件的记录总数量</param>
 29         /// <returns>承载数据的DataTable对象</returns>
 30         public static DataTable GetObjectsPaged(string objName,string colNames,string whereSql, string orderSql, int pageSize, int pageNum, out int recordCount)
 31         {
 32             DataSet ds = new DataSet();
 33             SqlCommand cmd = new SqlCommand("proc_Data_Paged",new SqlConnection(SqlHelper.AppConnectionString));
 34             cmd.CommandType = CommandType.StoredProcedure;
 35             cmd.Parameters.Add("@objName", SqlDbType.VarChar).Value = objName;
 36             cmd.Parameters.Add("@colNames", SqlDbType.VarChar).Value = colNames;
 37             cmd.Parameters.Add("@WhereSql", SqlDbType.VarChar).Value = whereSql;
 38             cmd.Parameters.Add("@OrderSql", SqlDbType.VarChar).Value = orderSql;
 39             cmd.Parameters.Add("@PageSize", SqlDbType.Int).Value = pageSize;
 40             cmd.Parameters.Add("@PageNum", SqlDbType.Int).Value = pageNum;
 41             SqlParameter pa = cmd.Parameters.Add("@RowCount", SqlDbType.Int);
 42             pa.Direction = ParameterDirection.Output;
 43             SqlDataAdapter ada = new SqlDataAdapter(cmd);
 44             ada.Fill(ds);
 45             recordCount = Convert.ToInt32(pa.Value);
 46             return ds.Tables[0];
 47         }       
 48 
 49         /// <summary>
 50         /// Execute a SqlCommand (that returns no resultset) against the database specified in the connection string 
 51         /// using the provided parameters.
 52         /// </summary>
 53         /// <remarks>
 54         /// e.g.:
 55         ///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
 56         /// </remarks>
 57         /// <param name="connectionString">a valid connection string for a SqlConnection</param>
 58         /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
 59         /// <param name="commandText">the stored procedure name or T-SQL command</param>
 60         /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
 61         /// <returns>an int representing the number of rows affected by the command</returns>
 62         public static int ExecuteNonQuery(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
 63         {
 64             SqlCommand cmd = new SqlCommand();
 65 
 66             using (SqlConnection conn = new SqlConnection(connectionString))
 67             {
 68                 PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
 69                 int val = cmd.ExecuteNonQuery();
 70                 cmd.Parameters.Clear();
 71                 return val;
 72             }
 73         }
 74         /// <summary>
 75         /// 在一个事物中执行一组Sql语句
 76         /// </summary>
 77         /// <param name="connectionString">连接字符串</param>
 78         /// <param name="cmdTexts">sql语句数组</param>
 79         /// <returns></returns>
 80         public static string ExecuteSqlsInTransaction(string connectionString, string[] cmdTexts)
 81         {
 82             SqlConnection conn = new SqlConnection(connectionString);
 83             conn.Open();
 84             SqlTransaction tran = conn.BeginTransaction();
 85             try
 86             {
 87                 foreach (string sql in cmdTexts)
 88                 {
 89                     if(sql !="")
 90                         ExecuteNonQuery(tran, CommandType.Text, sql, null);
 91                 }
 92                 tran.Commit();
 93                 return "True";
 94             }
 95             catch (SqlException ex)
 96             {
 97                 tran.Rollback();
 98                 return "False:"+ex.Message;
 99             }
100             finally
101             {
102                 conn.Close();
103             }
104         }
105 
106 
107         /// <summary>
108         /// Execute a SqlCommand (that returns no resultset) against an existing database connection 
109         /// using the provided parameters.
110         /// </summary>
111         /// <remarks>
112         /// e.g.:  
113         ///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
114         /// </remarks>
115         /// <param name="conn">an existing database connection</param>
116         /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
117         /// <param name="commandText">the stored procedure name or T-SQL command</param>
118         /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
119         /// <returns>an int representing the number of rows affected by the command</returns>
120         public static int ExecuteNonQuery(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
121         {
122 
123             SqlCommand cmd = new SqlCommand();
124 
125             PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
126             int val = cmd.ExecuteNonQuery();
127             cmd.Parameters.Clear();
128             return val;
129         }
130         /// <summary>
131         /// Execute a SqlCommand (that returns no resultset) using an existing SQL Transaction 
132         /// using the provided parameters.
133         /// </summary>
134         /// <remarks>
135         /// e.g.:  
136         ///  int result = ExecuteNonQuery(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
137         /// </remarks>
138         /// <param name="trans">an existing sql transaction</param>
139         /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
140         /// <param name="commandText">the stored procedure name or T-SQL command</param>
141         /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
142         /// <returns>an int representing the number of rows affected by the command</returns>
143         public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
144         {
145             SqlCommand cmd = new SqlCommand();
146             PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, commandParameters);
147             int val = cmd.ExecuteNonQuery();
148             cmd.Parameters.Clear();
149             return val;
150         }
151         /// <summary>
152         ///  Get a DataSet
153         /// </summary>
154         /// <param name="connectionString"></param>
155         /// <param name="cmdType"></param>
156         /// <param name="cmdText"></param>
157         /// <param name="tableName"></param>
158         /// <param name="commandParameters"></param>
159         /// <returns></returns>
160         public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText, string tableName, params SqlParameter[] commandParameters)
161         {
162             SqlCommand cmd = new SqlCommand();
163             SqlDataAdapter sda = new SqlDataAdapter(cmd);
164             DataSet ds = new DataSet();
165             using (SqlConnection conn = new SqlConnection(connectionString))
166             {
167                 PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
168                 sda.Fill(ds, tableName);
169                 cmd.Parameters.Clear();
170                 return ds;
171             }
172         }
173         public static DataSet ExecuteDataSet(string connectionString, CommandType cmdType, string cmdText,params SqlParameter[] commandParameters)
174         {
175             SqlCommand cmd = new SqlCommand();
176             SqlDataAdapter sda = new SqlDataAdapter(cmd);
177             DataSet ds = new DataSet();
178             using (SqlConnection conn = new SqlConnection(connectionString))
179             {
180                 PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
181                 sda.Fill(ds);
182                 cmd.Parameters.Clear();
183                 return ds;
184             }
185         }
186         /// <summary>
187         /// Get a DataSet
188         /// </summary>
189         /// <param name="connectionString"></param>
190         /// <param name="trans"></param>
191         /// <param name="cmdType"></param>
192         /// <param name="cmdText"></param>
193         /// <param name="tableName"></param>
194         /// <param name="commandParameters"></param>
195         /// <returns></returns>
196         public static DataSet ExecuteDataSet(string connectionString, SqlTransaction trans, CommandType cmdType, string cmdText, string tableName, params SqlParameter[] commandParameters)
197         {
198             SqlCommand cmd = new SqlCommand();
199             SqlDataAdapter sda = new SqlDataAdapter(cmd);
200             DataSet ds = new DataSet();
201             using (SqlConnection conn = new SqlConnection(connectionString))
202             {
203                 PrepareCommand(cmd, conn, trans, cmdType, cmdText, commandParameters);
204                 sda.Fill(ds, tableName);
205                 cmd.Parameters.Clear();
206                 return ds;
207             }
208         }
209        
210 
211         /// <summary>
212         /// Execute a SqlCommand that returns a resultset against the database specified in the connection string 
213         /// using the provided parameters.
214         /// </summary>
215         /// <remarks>
216         /// e.g.:  
217         ///  SqlDataReader r = ExecuteReader(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
218         /// </remarks>
219         /// <param name="connectionString">a valid connection string for a SqlConnection</param>
220         /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
221         /// <param name="commandText">the stored procedure name or T-SQL command</param>
222         /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
223         /// <returns>A SqlDataReader containing the results</returns>
224         public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
225         {
226             SqlCommand cmd = new SqlCommand();
227             SqlConnection conn = new SqlConnection(connectionString);
228 
229             // we use a try/catch here because if the method throws an exception we want to 
230             // close the connection throw code, because no datareader will exist, hence the 
231             // commandBehaviour.CloseConnection will not work
232             try
233             {
234                 PrepareCommand(cmd, conn, null, cmdType, cmdText, commandParameters);
235                 SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
236                 cmd.Parameters.Clear();
237                 return rdr;
238             }
239             catch
240             {
241                 conn.Close();
242                 throw;
243             }
244         }
245 
246         /// <summary>
247         /// Execute a SqlCommand that returns the first column of the first record against the database specified in the connection string 
248         /// using the provided parameters.
249         /// </summary>
250         /// <remarks>
251         /// e.g.:  
252         ///  Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
253         /// </remarks>
254         /// <param name="connectionString">a valid connection string for a SqlConnection</param>
255         /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
256         /// <param name="commandText">the stored procedure name or T-SQL command</param>
257         /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
258         /// <returns>An object that should be converted to the expected type using Convert.To{Type}</returns>
259         public static object ExecuteScalar(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
260         {
261             SqlCommand cmd = new SqlCommand();
262 
263             using (SqlConnection connection = new SqlConnection(connectionString))
264             {
265                 PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
266                 object val = cmd.ExecuteScalar();
267                 cmd.Parameters.Clear();
268                 return val;
269             }
270         }
271 
272         /// <summary>
273         /// Execute a SqlCommand that returns the first column of the first record against an existing database connection 
274         /// using the provided parameters.
275         /// </summary>
276         /// <remarks>
277         /// e.g.:  
278         ///  Object obj = ExecuteScalar(connString, CommandType.StoredProcedure, "PublishOrders", new SqlParameter("@prodid", 24));
279         /// </remarks>
280         /// <param name="conn">an existing database connection</param>
281         /// <param name="commandType">the CommandType (stored procedure, text, etc.)</param>
282         /// <param name="commandText">the stored procedure name or T-SQL command</param>
283         /// <param name="commandParameters">an array of SqlParamters used to execute the command</param>
284         /// <returns>An object that should be converted to the expected type using Convert.To{Type}</returns>
285         public static object ExecuteScalar(SqlConnection connection, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
286         {
287 
288             SqlCommand cmd = new SqlCommand();
289 
290             PrepareCommand(cmd, connection, null, cmdType, cmdText, commandParameters);
291             object val = cmd.ExecuteScalar();
292             cmd.Parameters.Clear();
293             return val;
294         }
295 
296         /// <summary>
297         /// add parameter array to the cache
298         /// </summary>
299         /// <param name="cacheKey">Key to the parameter cache</param>
300         /// <param name="cmdParms">an array of SqlParamters to be cached</param>
301         public static void CacheParameters(string cacheKey, params SqlParameter[] commandParameters)
302         {
303             parmCache[cacheKey] = commandParameters;
304         }
305 
306         /// <summary>
307         /// Retrieve cached parameters
308         /// </summary>
309         /// <param name="cacheKey">key used to lookup parameters</param>
310         /// <returns>Cached SqlParamters array</returns>
311         public static SqlParameter[] GetCachedParameters(string cacheKey)
312         {
313             SqlParameter[] cachedParms = (SqlParameter[])parmCache[cacheKey];
314 
315             if (cachedParms == null)
316                 return null;
317 
318             SqlParameter[] clonedParms = new SqlParameter[cachedParms.Length];
319 
320             for (int i = 0, j = cachedParms.Length; i < j; i++)
321                 clonedParms[i] = (SqlParameter)((ICloneable)cachedParms[i]).Clone();
322 
323             return clonedParms;
324         }
325 
326         /// <summary>
327         /// Prepare a command for execution
328         /// </summary>
329         /// <param name="cmd">SqlCommand object</param>
330         /// <param name="conn">SqlConnection object</param>
331         /// <param name="trans">SqlTransaction object</param>
332         /// <param name="cmdType">Cmd type e.g. stored procedure or text</param>
333         /// <param name="cmdText">Command text, e.g. Select * from Products</param>
334         /// <param name="cmdParms">SqlParameters to use in the command</param>
335         private static void PrepareCommand(SqlCommand cmd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] cmdParms)
336         {
337 
338             if (conn.State != ConnectionState.Open)
339                 conn.Open();
340 
341             cmd.Connection = conn;
342             cmd.CommandText = cmdText;
343 
344             if (trans != null)
345                 cmd.Transaction = trans;
346 
347             cmd.CommandType = cmdType;
348 
349             if (cmdParms != null)
350             {
351                 foreach (SqlParameter parm in cmdParms)
352                     cmd.Parameters.Add(parm);
353             }
354         }
355         public static int ChangeErrorNum(int num)
356         {
357             if (num == 2601)
358                 return -1;
359             if (num == 547)
360                 return -2;
361             return 0;
362         }
363     }
364 }
SqlHelper
复制代码

13.SQLite连接帮助类

复制代码
  1 //说明:本类是对文件型数据库进行访问的工具类,需要引入System.Data.SQLite.dll
  2 
  3 //using System;
  4 //using System.Collections.Generic;
  5 //using System.Data;
  6 //using System.Data.Common;
  7 //using System.Linq;
  8 //using System.Text;
  9 //using System.Data.SQLite;
 10 
 11 //namespace Quiz
 12 //{
 13 //    public class SQLiteHelper
 14 //    {
 15 //        SQLiteConnection _connection;
 16 //        /// <summary>
 17 //        /// SQLite连接
 18 //        /// </summary>
 19 //        public SQLiteConnection MyConnection
 20 //        {
 21 //            get
 22 //            {                
 23 //                if (_connection == null)
 24 //                {
 25 //                    _connection = new SQLiteConnection(string.Format("Data Source={0}Content/DB;Version=3;", AppDomain.CurrentDomain.SetupInformation.ApplicationBase));
 26 //                }
 27 //                return _connection;
 28 //            }
 29 //        }
 30 
 31 //        /// <summary>
 32 //        /// SQLite增删改
 33 //        /// </summary>
 34 //        /// <param name="sql">要执行的sql语句</param>
 35 //        /// <param name="parameters">所需参数</param>
 36 //        /// <returns>所受影响的行数</returns>
 37 //        public int ExecuteNonQuery(string sql, SQLiteParameter[] parameters)
 38 //        {
 39 //            SQLiteTransaction transaction = null;
 40 //            try
 41 //            {
 42 //                int affectedRows = 0;
 43 //                MyConnection.Open();
 44 //                transaction = MyConnection.BeginTransaction();
 45 //                SQLiteCommand command = new SQLiteCommand(sql, MyConnection);
 46 //                command.CommandText = sql;
 47 //                if (parameters != null)
 48 //                {
 49 //                    for (int i = 0; i < parameters.Length; i++)
 50 //                    {
 51 //                        command.Parameters.Add(parameters[i]);
 52 //                    }
 53 //                }
 54 //                affectedRows = command.ExecuteNonQuery();
 55 //                transaction.Commit();
 56 
 57 //                return affectedRows;
 58 //            }
 59 //            catch (SQLiteException ex) {
 60 //                if(transaction !=null)
 61 //                    transaction.Rollback();
 62 //                return 0;
 63 //            }
 64 //            finally
 65 //            {
 66 //                if (_connection.State != ConnectionState.Closed)
 67 //                    _connection.Close();
 68 //            }
 69 //        }
 70 //        public int ExecuteNonQuery(List<String> sqls)
 71 //        {
 72 //            SQLiteTransaction transaction = null;
 73 //            try
 74 //            {
 75 //                int affectedRows = 0;
 76 //                MyConnection.Open();
 77 //                transaction = MyConnection.BeginTransaction();
 78 //                SQLiteCommand command = new SQLiteCommand(MyConnection);
 79 //                foreach (String sql in sqls)
 80 //                {
 81 //                    command.CommandText = sql;
 82 //                    affectedRows += command.ExecuteNonQuery();
 83 //                }                
 84 //                transaction.Commit();
 85 //                return affectedRows;
 86 //            }
 87 //            catch (SQLiteException ex)
 88 //            {
 89 //                if (transaction != null)
 90 //                    transaction.Rollback();
 91 //                return 0;
 92 //            }
 93 //            finally
 94 //            {
 95 //                if (_connection.State != ConnectionState.Closed)
 96 //                    _connection.Close();
 97 //            }
 98 //        }
 99 
100 //        /// <summary>
101 //        /// SQLite查询
102 //        /// </summary>
103 //        /// <param name="sql">要执行的sql语句</param>
104 //        /// <param name="parameters">所需参数</param>
105 //        /// <returns>结果DataTable</returns>
106 //        public DataTable ExecuteDataTable(string sql, SQLiteParameter[] parameters)
107 //        {
108 //            DataTable data = new DataTable();
109 //            SQLiteCommand command = new SQLiteCommand(sql, MyConnection);
110 //            if (parameters != null)
111 //            {
112 //                for (int i = 0; i < parameters.Length; i++)
113 //                {
114 //                    command.Parameters.Add(parameters[i]);
115 //                }                
116 //            }
117 //            SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
118 //            adapter.Fill(data);
119 
120 //            return data;
121 //        }
122 
123 //        ///// <summary>
124 //        ///// 查询数据库表信息
125 //        ///// </summary>
126 //        ///// <returns>数据库表信息DataTable</returns>
127 //        //DataTable GetSchema()
128 //        //{
129 //        //    DataTable data = new DataTable();
130 
131 //        //    data = connection.GetSchema("TABLES");
132 
133 //        //    return data;
134 //        //}
135 //    }
136 //}
SQLite
复制代码

14.字符串帮助类

复制代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.IO;
using System.Data;

namespace Utilities
{
    /// <summary>
    /// 字符串帮助类
    /// </summary>
    public static class StringHelper
    {
        /// <summary>
        /// 邮箱地址正则表达式
        /// </summary>
        public static Regex RegexEamil = new Regex(@"^[a-z]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?$", RegexOptions.IgnoreCase);
        /// <summary>
        /// 手机号正则表达式
        /// </summary>
        public static Regex RegexMobilePhone = new Regex("^[1][0-9]{10}$");
        /// <summary>
        /// 固话号正则表达式
        /// </summary>
        public static Regex RegexPhone = new Regex(@"^(\d{3,4}-?)?\d{7,8}$");
        /// <summary>
        /// IP正则表达式
        /// </summary>
        public static Regex RegexIP = new Regex(@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$");
        /// <summary>
        /// 日期正则表达式 yyyy-MM-dd,不是很准确
        /// </summary>
        public static Regex RegexDate = new Regex(@"[12](\d{3})-[01]?\d-[0123]?\d");
        /// <summary>
        /// 数值(包括整数和小数)正则表达式
        /// </summary>
        public static Regex RegexNumeric = new Regex(@"^[-]?[0-9]+(\.[0-9]+)?$");
        /// <summary>
        /// 邮政编码正则表达式
        /// </summary>
        public static Regex RegexZipcoder = new Regex(@"^\d{6}$");

        /// <summary>
        /// 将字符串数组拼接成用单引号括起来的字符串。
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public static string ToSqlIdString(this String[] ids)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < ids.Length; i++)
            {
                if (i == 0)
                    sb.Append("'").Append(ids[i]).Append("'");
                else
                    sb.Append(",'").Append(ids[i]).Append("'");
            }
            return sb.ToString();
        }
        /// <summary>
        /// 处理答案
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string ToChoiceAnswer(this string s)
        {
            string da = "ABCDEFGHIGKLMN";
            List<char> nd = new List<char>();
            foreach (var c in s)
            {
                var cx = c.ToString().ToUpper();
                if (da.Contains(cx))
                    nd.Add(cx[0]);
            }
            nd.Sort();
            var ans = "";
            foreach (var c in nd)
                ans += c;
            return ans.ToString();
        }

        static Dictionary<int, string> dic = new Dictionary<int, string>();
        static Regex OutWebURL = new Regex("://[\\s\\S]*?/", RegexOptions.IgnoreCase);
        static StringHelper()
        {
            dic.Add(0, "");
            dic.Add(1, "");
            dic.Add(2, "");
            dic.Add(3, "");
            dic.Add(4, "");
            dic.Add(5, "");
            dic.Add(6, "");
            dic.Add(7, "");
            dic.Add(8, "");
            dic.Add(9, "");
        }

        /// <summary>
        /// 将 Stream 转化成 string
        /// </summary>
        /// <param name="s">Stream流</param>
        /// <returns>string</returns>
        public static string ConvertStreamToString(Stream s)
        {
            string strResult = "";
            StreamReader sr = new StreamReader(s, Encoding.UTF8);

            Char[] read = new Char[256];
            // Read 256 charcters at a time.    
            int count = sr.Read(read, 0, 256);
            while (count > 0)
            {
                // Dump the 256 characters on a string and display the string onto the console.
                string str = new String(read, 0, count);
                strResult += str;
                count = sr.Read(read, 0, 256);
            }
            // 释放资源
            sr.Close();
            return strResult;
        }

        /// <summary>
        /// 输出由同一字符组成的指定长度的字符串
        /// </summary>
        /// <param name="Char">输出字符,如:A</param>
        /// <param name="i">指定长度</param>
        /// <returns></returns>
        public static string Strings(char Char, int i)
        {
            string strResult = null;

            for (int j = 0; j < i; j++)
            {
                strResult += Char;
            }
            return strResult;
        }

        /// <summary>
        /// 返回字符串的字节长度
        /// </summary>
        /// <param name="str">指定字符串</param>
        /// <returns>字节个数</returns>
        public static int GetLen(string str)
        {
            int intResult = 0;
            Encoding gb2312 = Encoding.GetEncoding("gb2312");
            byte[] bytes = gb2312.GetBytes(str);
            intResult = bytes.Length;
            return intResult;
        }
        #region 随机数
        /// <summary>
        /// 获取指定长度的纯数字随机数字串
        /// </summary>
        /// <param name="intLong">数字串长度</param>
        /// <returns>字符串</returns>
        public static string GetRandomNum(int intLong)
        {
            string strResult = "";

            Random r = new Random(DateTime.Now.Millisecond);
            for (int i = 0; i < intLong; i++)
            {
                strResult = strResult + r.Next(10);
            }

            return strResult;
        }

        /// <summary>
        /// 获取一个由26个小写字母组成的指定长度的随即字符串
        /// </summary>
        /// <param name="intLong">指定长度</param>
        /// <returns></returns>
        public static string GetRandomLetters(int intLong)
        {
            string strResult = "";
            string[] array = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

            Random r = new Random();

            for (int i = 0; i < intLong; i++)
            {
                strResult += array[r.Next(26)];
            }

            return strResult;
        }

        /// <summary>
        /// 获取一个由数字和26个小写字母组成的指定长度的随即字符串
        /// </summary>
        /// <param name="intLong">指定长度</param>
        /// <returns></returns>
        public static string GetRandomNumAndLetters(int intLong)
        {
            string strResult = "";
            string[] array = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };

            Random r = new Random();

            for (int i = 0; i < intLong; i++)
            {
                strResult += array[r.Next(36)];
            }

            return strResult;
        }
        #endregion

        #region 正则表达式的使用

        /// <summary>
        /// 判断字符串是否为有效的邮件地址
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static bool IsValidEmail(string email)
        {
            return Regex.IsMatch(email, @"^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$");
        }
        /// <summary>
        /// 判断字符串是否为有效的URL地址
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static bool IsValidURL(string url)
        {
            return Regex.IsMatch(url, @"^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*[^\.\,\)\(\s]$");
        }

        /// <summary>
        /// 判断字符串是否为Int类型的
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsValidInt(string val)
        {
            return Regex.IsMatch(val, @"^[1-9]\d*\.?[0]*$");
        }

        /// <summary>
        /// 检测字符串是否全为正整数
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsNum(string str)
        {
            bool blResult = true;//默认状态下是数字

            if (str == "")
                blResult = false;
            else
            {
                foreach (char Char in str)
                {
                    if (!char.IsNumber(Char))
                    {
                        blResult = false;
                        break;
                    }
                }
                if (blResult)
                {
                    if (int.Parse(str) == 0)
                        blResult = false;
                }
            }
            return blResult;
        }
        /// <summary>
        /// 检测字符串是否全为数字型
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsDouble(string str)
        {
            bool blResult = true;//默认状态下是数字

            if (str == "")
                blResult = false;
            else
            {
                foreach (char Char in str)
                {
                    if (!char.IsNumber(Char) && Char.ToString() != "-")
                    {
                        blResult = false;
                        break;
                    }
                }
            }
            return blResult;
        }
        /// <summary>
        /// 判断输入的字符串是否完全匹配正则
        /// </summary>
        /// <param name="RegexExpression">正则表达式</param>
        /// <param name="str">待判断的字符串</param>
        /// <returns></returns>
        public static bool IsValiable(string RegexExpression, string str)
        {
            bool blResult = false;

            Regex rep = new Regex(RegexExpression, RegexOptions.IgnoreCase);

            //blResult = rep.IsMatch(str);
            Match mc = rep.Match(str);

            if (mc.Success)
            {
                if (mc.Value == str) blResult = true;
            }
            return blResult;
        }

        /// <summary>
        /// 转换代码中的URL路径为绝对URL路径
        /// </summary>
        /// <param name="sourceString">源代码</param>
        /// <param name="replaceURL">替换要添加的URL</param>
        /// <returns>string</returns>
        public static string ConvertURL(string sourceString, string replaceURL)
        {
            Regex rep = new Regex(" (src|href|background|value)=('|\"|)([^('|\"|)http://].*?)('|\"| |>)");
            sourceString = rep.Replace(sourceString, " $1=$2" + replaceURL + "$3$4");
            return sourceString;
        }

        /// <summary>
        /// 获取代码中所有图片的以HTTP开头的URL地址
        /// </summary>
        /// <param name="sourceString">代码内容</param>
        /// <returns>ArrayList</returns>
        public static List<string> GetImgFileUrl(string sourceString)
        {
            List<string> imgArray = new List<string>();
            Regex r = new Regex("<IMG(.*?)src=('|\"|)(http://.*?)('|\"| |>)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = r.Matches(sourceString);
            for (int i = 0; i < mc.Count; i++)
            {
                if (!imgArray.Contains(mc[i].Result("$3")))
                {
                    imgArray.Add(mc[i].Result("$3"));
                }
            }
            return imgArray;
        }

        /// <summary>
        /// 获取代码中所有文件的以HTTP开头的URL地址
        /// </summary>
        /// <param name="sourceString">代码内容</param>
        /// <returns>ArrayList</returns>
        public static Dictionary<int, string> GetFileUrlPath(string sourceString)
        {
            Dictionary<int, string> url = new Dictionary<int, string>();
            Regex r = new Regex(" (src|href|background|value)=('|\"|)(http://.*?)('|\"| |>)",
                RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = r.Matches(sourceString);
            for (int i = 0; i < mc.Count; i++)
            {
                if (!url.ContainsValue(mc[i].Result("$3")))
                {
                    url.Add(i, mc[i].Result("$3"));
                }
            }
            return url;
        }

        /// <summary>
        /// 获取一条SQL语句中的所参数
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns></returns>
        public static List<string> SqlParame(string sql)
        {
            List<string> list = new List<string>();
            Regex r = new Regex(@"@(?<x>[0-9a-zA-Z]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = r.Matches(sql);
            for (int i = 0; i < mc.Count; i++)
            {
                list.Add(mc[i].Result("$1"));
            }
            return list;
        }

        /// <summary>
        /// 获取一条SQL语句中的所参数
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <returns></returns>
        public static List<string> OracleParame(string sql)
        {
            List<string> list = new List<string>();
            Regex r = new Regex(@":(?<x>[0-9a-zA-Z]*)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = r.Matches(sql);
            for (int i = 0; i < mc.Count; i++)
            {
                list.Add(mc[i].Result("$1"));
            }

            return list;
        }

        /// <summary>
        /// 将HTML代码转化成纯文本
        /// </summary>
        /// <param name="sourceHTML">HTML代码</param>
        /// <returns></returns>
        public static string ConvertText(string sourceHTML)
        {
            string strResult = "";
            Regex r = new Regex("<(.*?)>", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            MatchCollection mc = r.Matches(sourceHTML);

            if (mc.Count == 0)
            {
                strResult = sourceHTML;
            }
            else
            {
                strResult = sourceHTML;
                for (int i = 0; i < mc.Count; i++)
                {
                    strResult = strResult.Replace(mc[i].ToString(), "");
                }
            }
            return strResult.Replace("&nbsp;", "");
        }
        #endregion

        /// <summary>
        /// 封装XML数据串
        /// </summary>
        /// <param name="str"></param>
        /// <returns>string</returns>
        public static string ConvertXmlString(string str)
        {
            return "<![CDATA[" + str + "]]>";
        }

        /// <summary>
        /// 对字符串进行 HTML 编码操作,用于无法使用Server类的场景。
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static string HtmlEncode(string str)
        {
            str = str.Replace("&", "&amp;");
            str = str.Replace("'", "''");
            str = str.Replace("\"", "&quot;");
            str = str.Replace(" ", "&nbsp;");
            str = str.Replace("<", "&lt;");
            str = str.Replace(">", "&gt;");
            str = str.Replace("\n", "<br>");
            return str;
        }
        /// <summary>
        /// 对 HTML 字符串进行解码操作,用于无法使用Server类的场景。
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns></returns>
        public static string HtmlDecode(string str)
        {
            str = str.Replace("<br>", "\n");
            str = str.Replace("&gt;", ">");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("&quot;", "\"");
            return str;
        }

        /// <summary>
        /// 对脚本程序进行处理
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string ConvertScript(string str)
        {
            string strResult = "";
            if (str != "")
            {
                StringReader sr = new StringReader(str);
                string rl;
                do
                {
                    strResult += sr.ReadLine();
                } while ((rl = sr.ReadLine()) != null);
            }

            strResult = strResult.Replace("\"", "&quot;");
            return strResult;
        }

        /// <summary>
        /// 过滤屏蔽的字符串
        /// </summary>
        /// <param name="source"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public static string FilterString(string source, string[] filter)
        {
            StringBuilder sb = new StringBuilder(source);

            foreach (String str in filter)
            {
                sb.Replace(str, "*");
            }

            return sb.ToString();
        }
        /// <summary>
        /// 随机产生一个Color字符串。例如 ffee99
        /// </summary>
        /// <returns></returns>
        public static string GetColorString()
        {
            Guid uid = Guid.NewGuid();
            string sid = uid.ToString().Replace("-", "");
            Random r = new Random(DateTime.Now.Millisecond);
            return uid.ToString().Substring(r.Next(24), 6);
        }
        /// <summary>
        /// 对source,按照“#”进行分割,获取第num个字符串的值
        /// </summary>
        /// <param name="source"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string GetSplitString(string source, int num)
        {
            return GetSplitString(source, "#", num);
        }
        /// <summary>
        /// 对source,按照指定的字符串以split进行分割,获取第num个字符串的值
        /// </summary>
        /// <param name="source"></param>
        /// <param name="split"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string GetSplitString(string source, string split, int num)
        {
            try
            {
                string[] strs = source.Split(new string[] { split }, StringSplitOptions.RemoveEmptyEntries);
                return strs[num];
            }
            catch
            {
                return "Empty";
            }
        }
        /// <summary>
        /// 获取一个唯一值
        /// </summary>
        /// <returns></returns>
        public static string GetUniqueString()
        {
            string str = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + (new Random()).Next();
            return str;
        }


        /// <summary>
        /// 格式化占用空间大小的输出
        /// </summary>
        /// <param name="size">大小</param>
        /// <returns>返回 String</returns>
        public static string FormatNUM(long size)
        {
            decimal NUM;
            string strResult;

            if (size > 1073741824)
            {
                NUM = (Convert.ToDecimal(size) / Convert.ToDecimal(1073741824));
                strResult = NUM.ToString("N") + " G";
            }
            else if (size > 1048576)
            {
                NUM = (Convert.ToDecimal(size) / Convert.ToDecimal(1048576));
                strResult = NUM.ToString("N") + " M";
            }
            else if (size > 1024)
            {
                NUM = (Convert.ToDecimal(size) / Convert.ToDecimal(1024));
                strResult = NUM.ToString("N") + " KB";
            }
            else
            {
                strResult = size + " 字节";
            }

            return strResult;
        }
        /// <summary>
        /// 获取指定汉字拼音的首字母
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetFirstLetter(string str)
        {
            int i = 0;
            ushort key = 0;
            string strResult = string.Empty;

            //创建两个不同的encoding对象
            Encoding unicode = Encoding.Unicode;
            //创建GBK码对象
            Encoding gbk = Encoding.GetEncoding(936);
            //将unicode字符串转换为字节
            byte[] unicodeBytes = unicode.GetBytes(str);
            //再转化为GBK码
            byte[] gbkBytes = Encoding.Convert(unicode, gbk, unicodeBytes);
            while (i < gbkBytes.Length)
            {
                //如果为数字\字母\其他ASCII符号
                if (gbkBytes[i] <= 127)
                {
                    strResult = strResult + (char)gbkBytes[i];
                    i++;
                }
                #region 否则生成汉字拼音简码,取拼音首字母
                else
                {

                    key = (ushort)(gbkBytes[i] * 256 + gbkBytes[i + 1]);
                    if (key >= '\uB0A1' && key <= '\uB0C4')
                    {
                        strResult = strResult + "A";
                    }
                    else if (key >= '\uB0C5' && key <= '\uB2C0')
                    {
                        strResult = strResult + "B";
                    }
                    else if (key >= '\uB2C1' && key <= '\uB4ED')
                    {
                        strResult = strResult + "C";
                    }
                    else if (key >= '\uB4EE' && key <= '\uB6E9')
                    {
                        strResult = strResult + "D";
                    }
                    else if (key >= '\uB6EA' && key <= '\uB7A1')
                    {
                        strResult = strResult + "E";
                    }
                    else if (key >= '\uB7A2' && key <= '\uB8C0')
                    {
                        strResult = strResult + "F";
                    }
                    else if (key >= '\uB8C1' && key <= '\uB9FD')
                    {
                        strResult = strResult + "G";
                    }
                    else if (key >= '\uB9FE' && key <= '\uBBF6')
                    {
                        strResult = strResult + "H";
                    }
                    else if (key >= '\uBBF7' && key <= '\uBFA5')
                    {
                        strResult = strResult + "J";
                    }
                    else if (key >= '\uBFA6' && key <= '\uC0AB')
                    {
                        strResult = strResult + "K";
                    }
                    else if (key >= '\uC0AC' && key <= '\uC2E7')
                    {
                        strResult = strResult + "L";
                    }
                    else if (key >= '\uC2E8' && key <= '\uC4C2')
                    {
                        strResult = strResult + "M";
                    }
                    else if (key >= '\uC4C3' && key <= '\uC5B5')
                    {
                        strResult = strResult + "N";
                    }
                    else if (key >= '\uC5B6' && key <= '\uC5BD')
                    {
                        strResult = strResult + "O";
                    }
                    else if (key >= '\uC5BE' && key <= '\uC6D9')
                    {
                        strResult = strResult + "P";
                    }
                    else if (key >= '\uC6DA' && key <= '\uC8BA')
                    {
                        strResult = strResult + "Q";
                    }
                    else if (key >= '\uC8BB' && key <= '\uC8F5')
                    {
                        strResult = strResult + "R";
                    }
                    else if (key >= '\uC8F6' && key <= '\uCBF9')
                    {
                        strResult = strResult + "S";
                    }
                    else if (key >= '\uCBFA' && key <= '\uCDD9')
                    {
                        strResult = strResult + "T";
                    }
                    else if (key >= '\uCDDA' && key <= '\uCEF3')
                    {
                        strResult = strResult + "W";
                    }
                    else if (key >= '\uCEF4' && key <= '\uD188')
                    {
                        strResult = strResult + "X";
                    }
                    else if (key >= '\uD1B9' && key <= '\uD4D0')
                    {
                        strResult = strResult + "Y";
                    }
                    else if (key >= '\uD4D1' && key <= '\uD7F9')
                    {
                        strResult = strResult + "Z";
                    }
                    else
                    {
                        strResult = strResult + "?";
                    }
                    i = i + 2;
                }
                #endregion
            }//end while

            return strResult;
        }
        /// <summary>
        /// 获取文件名
        /// </summary>
        /// <param name="filePath">包含有文件名的字符串</param>
        /// <returns></returns>
        public static string GetFileName(string filePath)
        {
            if (filePath.IndexOf("\\") > 0)
            {
                return filePath.Substring(filePath.LastIndexOf("\\") + 1);
            }
            else
                return filePath.Substring(filePath.LastIndexOf("/") + 1);
        }
        /// <summary>
        /// 获取fileName的扩展名
        /// </summary>
        /// <param name="fileName">文件名称</param>
        /// <returns></returns>
        public static string GetExtName(string fileName)
        {
            string fileExt = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();
            if (fileExt == "jpeg")
                fileExt = "jpg";
            return fileExt;
        }
        /// <summary>
        /// 获取指定data中前len个字符构成的字符串
        /// </summary>
        /// <param name="data"></param>
        /// <param name="len"></param>
        /// <returns></returns>
        public static string GetSubstring(string data, int len)
        {
            if (data.Length > len)
                return data.Substring(0, len) + "...";
            else
                return data;
        }
        /// <summary>
        /// 获取指定data的指定类型的字符编号
        /// </summary>
        /// <param name="data">从1到999</param>
        /// <param name="type">从1到8</param>
        /// <returns></returns>
        public static string ToNum(this int data, int type)
        {
            switch (type)
            {
                case 1://汉字显示
                    return string.Format("{0}:", GetCh(data));
                case 2:
                    return string.Format("{0}、", data);
                case 3:
                    return string.Format("({0})、", data);
                case 4:
                    return string.Format("({0})、", GetZM(data, true));
                case 5:
                    return string.Format("({0})、", GetZM(data, false));
                case 6:
                    return "";
                case 7:
                    return "";
                default:
                    return "";
            }
        }
        static string GetCh(int data)
        {
            int b = data / 100;
            int s = (data - 100 * b) / 10;
            int g = data % 10;
            string ret = dic[b] + dic[s] + dic[g];
            if (ret[0] == '')
                ret = ret.Substring(1);
            if (ret[0] == '')
                ret = ret.Substring(1);
            return ret;
        }
        static string GetZM(int data, bool isBig)
        {
            int s = data / 26;
            int y = data % 26;
            string ret = "";
            char A = 'a';
            if (isBig)
                A = 'A';
            if (s > 0)
                ret = ((char)(A + s)).ToString();
            if (y > 0)
                ret += ((char)(A + y)).ToString();
            if (y == 0)
                ret += "Z";
            return ret;
        }

        #region 安全性

        /// <summary>
        /// 对传递的参数字符串进行处理,防止注入式攻击
        /// </summary>
        /// <param name="str">传递的参数字符串</param>
        /// <returns>String</returns>
        public static string ConvertSql(string str)
        {
            str = str.Trim();
            str = str.Replace("'", "''");
            str = str.Replace(";--", "");
            str = str.Replace("=", "");
            str = str.Replace(" or ", "");
            str = str.Replace(" and ", "");
            return str;
        }
        /// <summary>
        /// 移除不安全代码,防止页面攻击
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string GetSafeCode(string str)
        {
            StringBuilder builder = new StringBuilder(str);
            Regex regex = new Regex(@"<script[\s\S]*?>[\s\S]*?</script>", RegexOptions.IgnoreCase);
            foreach (Match match in regex.Matches(builder.ToString()))
            {
                builder.Replace(match.Value, "");
            }
            regex = new Regex(@"<script[\s\S]*?/>", RegexOptions.IgnoreCase);
            foreach (Match match2 in regex.Matches(builder.ToString()))
            {
                builder.Replace(match2.Value, "");
            }
            regex = new Regex(@"<iframe[\s\S]*?/>", RegexOptions.IgnoreCase);
            foreach (Match match3 in regex.Matches(builder.ToString()))
            {
                builder.Replace(match3.Value, "");
            }
            regex = new Regex(@"<iframe[\s\S]*?>[\s\S]*?</iframe>", RegexOptions.IgnoreCase);
            foreach (Match match4 in regex.Matches(builder.ToString()))
            {
                builder.Replace(match4.Value, "");
            }
            return builder.ToString();
        }
        #endregion

        #region Html源代码处理
        /// <summary>
        /// 移除HTML标记
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string RemoveHtmlCode(string str)
        {
            StringBuilder builder = new StringBuilder(str);
            Regex regex = new Regex(@"<[\s\S]*?>", RegexOptions.IgnoreCase);
            foreach (Match match in regex.Matches(builder.ToString()))
            {
                builder.Replace(match.Value, "");
            }
            builder.Replace("&nbsp;", " ");
            return builder.ToString().Trim();
        }

        /// <summary>
        /// 移除HTML代码的某些标记
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string RemoveHtmlCode(string str, params String[] labels)
        {
            StringBuilder builder = new StringBuilder(str);

            foreach (String tempstr in labels)
            {
                Regex regex = new Regex(@"<\/{0,1}" + tempstr + @"[\s\S]*?>", RegexOptions.IgnoreCase);
                foreach (Match match in regex.Matches(builder.ToString()))
                {
                    builder.Replace(match.Value, "");
                }
            }

            builder.Replace("&nbsp;", " ");
            return builder.ToString().Trim();
        }

        /// <summary>
        /// 移除所有标签的某些属性
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string RemoveHtmlAttributeCode(string str, params String[] attributes)
        {
            StringBuilder builder = new StringBuilder(str);

            Regex regexHtmlLabel = new Regex(@"<[\s\S]*?>", RegexOptions.IgnoreCase);

            foreach (Match match in regexHtmlLabel.Matches(builder.ToString()))
            {   //原始标签赋值给os临时变量
                String tempLable = match.Value;
                //最外层需要替换掉的标签字符串
                String replaceLabel = tempLable;
                foreach (string attribute in attributes)
                {
                    Regex regexAttribute = new Regex(attribute + @"=\S*?( |>)", RegexOptions.IgnoreCase);
                    //找到标签中对应的属性
                    foreach (Match matchTemp in regexAttribute.Matches(replaceLabel))
                    {
                        //找到替换后的临时变量
                        tempLable = tempLable.Replace(matchTemp.Value.TrimEnd('>'), "");
                        //最外层替换
                        builder.Replace(replaceLabel, tempLable);
                        //替换掉的标签字符串修改
                        replaceLabel = tempLable;
                    }
                }

            }

            return builder.ToString().Trim();

        }

        /// <summary>
        /// 移除指定标签的某些属性
        /// </summary>
        /// <param name="htmlStr">html格式的字符串</param>
        /// <param name="label">指定的标签</param>
        /// <param name="attributes">属性名称集合</param>
        /// <returns>移除后的新字符串</returns>
        public static string RemoveHtmlAttributeCode(string htmlStr, String label, params String[] attributes)
        {
            StringBuilder builder = new StringBuilder(htmlStr);

            Regex regexHtmlLabel = new Regex(@"<\/{0,1}" + label + @"[\s\S]*?>", RegexOptions.IgnoreCase);

            foreach (Match match in regexHtmlLabel.Matches(builder.ToString()))
            {   //原始标签赋值给os临时变量
                String tempLable = match.Value;

                //最外层需要替换掉的标签字符串
                String replaceLabel = tempLable;
                foreach (string attribute in attributes)
                {

                    Regex regexAttribute = new Regex(attribute + @"=\S*?( |>)", RegexOptions.IgnoreCase);


                    //找到标签中对应的属性
                    foreach (Match matchTemp in regexAttribute.Matches(replaceLabel))
                    {

                        //找到替换后的临时变量
                        tempLable = tempLable.Replace(matchTemp.Value.TrimEnd('>'), "");

                        //最外层替换
                        builder.Replace(replaceLabel, tempLable);

                        //替换掉的标签字符串修改
                        replaceLabel = tempLable;
                    }

                }

            }

            return builder.ToString().Trim();

        }

        /// <summary>
        /// 移除指定标签的某个属性
        /// </summary>
        /// <param name="htmlStr">html格式的字符串</param>
        /// <param name="label">指定的标签</param>
        /// <param name="attribute">属性名称</param>
        /// <returns>移除后的新字符串</returns>
        public static string RemoveHtmlAttributeCode(string htmlStr, String label, String attribute)
        {
            StringBuilder builder = new StringBuilder(htmlStr);

            Regex regex = new Regex(@"<\/{0,1}" + label + @"[\s\S]*?>", RegexOptions.IgnoreCase);

            Regex regexAttribute = new Regex(attribute + @"=\S*?( |>)", RegexOptions.IgnoreCase);

            //找到匹配到标签
            foreach (Match match in regex.Matches(builder.ToString()))
            {
                //原始标签赋值给os临时变量
                String tempLable = match.Value;

                //最外层需要替换掉的标签字符串
                String replaceLabel = tempLable;

                //找到标签中对应的属性
                foreach (Match matchTemp in regexAttribute.Matches(replaceLabel))
                {

                    //找到替换后的临时变量
                    tempLable = tempLable.Replace(matchTemp.Value.TrimEnd('>'), "");

                    //最外层替换
                    builder.Replace(replaceLabel, tempLable);

                    //替换掉的标签字符串修改
                    replaceLabel = tempLable;
                }
            }

            return builder.ToString();
        }
        /// <summary>
        /// 移除除了指定域名的其他URL
        /// </summary>
        /// <param name="str">Html字符串</param>
        /// <param name="myDomain">自己的域名,如:fund123.cn</param>
        /// <returns>结果字符串</returns>
        public static string RemoveUrlLink(String str, String myDomain)
        {
            StringBuilder builder = new StringBuilder(str);

            //找到所有的href连接
            Regex regex = new Regex(@" href=[\s\S]*?( |>)", RegexOptions.IgnoreCase);

            foreach (Match match in regex.Matches(builder.ToString()))
            {
                //如果连接中存在域名则替换
                if (match.Value.ToLower().IndexOf(myDomain.ToLower()) == -1)
                {
                    String replaceStr = match.Value.TrimEnd('>');
                    builder.Replace(replaceStr, " ");
                }
            }

            return builder.ToString().Trim();
        }
        #endregion


        /// <summary>
        /// 判断是否存在别人的连接
        /// </summary>
        /// <param name="str"></param>
        /// <param name="myDomain"></param>
        /// <returns></returns>
        public static Boolean HasUrlLink(String str, String myDomain)
        {

            //找到所有的href连接
            Regex regex = new Regex(@" href=[\s\S]*?( |>)", RegexOptions.IgnoreCase);

            foreach (Match match in regex.Matches(str))
            {
                //如果连接中存在域名则返回true
                if (match.Value.ToLower().IndexOf(myDomain.ToLower()) == -1)
                {
                    return true;
                }

            }

            return false;
        }

        /// <summary>
        /// 处理外网连接替换
        /// </summary>
        /// <param name="str"></param>
        /// <param name="myDomain"></param>
        public static String DealOutSiteURL(String str, String myDomain)
        {
            StringBuilder sb = new StringBuilder(str);

            foreach (Match match in OutWebURL.Matches(str))
            {
                if (match.Value.ToLower().IndexOf(myDomain) == -1)
                {
                    sb.Replace(match.Value, "");
                }
            }

            return sb.ToString();
        }


        #region 老式Sql分页
        /// <summary>
        /// 获取分页操作SQL语句(对于排序的字段必须建立索引,优化分页提取方式)
        /// </summary>
        /// <param name="tblName">操作表名称</param>
        /// <param name="fldName">排序的索引字段</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">每页显示记录数</param>
        /// <param name="totalRecord">总记录数</param>
        /// <param name="OrderType">排序方式(0升序,1为降序)</param>
        /// <param name="strWhere">检索的条件语句,不需要再加WHERE关键字</param>
        /// <returns></returns>
        public static string ConstructSplitSQL(string tblName,
                                                string fldName,
                                                int PageIndex,
                                                int PageSize,
                                                int totalRecord,
                                                int OrderType,
                                                string strWhere)
        {
            string strSQL = "";
            string strOldWhere = "";
            string rtnFields = "*";

            // 构造检索条件语句字符串
            if (strWhere != "")
            {
                // 去除不合法的字符,防止SQL注入式攻击
                strWhere = strWhere.Replace("'", "''");
                strWhere = strWhere.Replace("--", "");
                strWhere = strWhere.Replace(";", "");

                strOldWhere = " AND " + strWhere + " ";

                strWhere = " WHERE " + strWhere + " ";
            }

            // 升序操作
            if (OrderType == 0)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    //strSQL += "WHERE (" + fldName + " >= ( SELECT MAX(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                    strSQL += strWhere + "ORDER BY " + fldName + " ASC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " > ( SELECT MAX(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                }
            }
            // 降序操作
            else if (OrderType == 1)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    //strSQL += "WHERE (" + fldName + " <= ( SELECT MIN(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                    strSQL += strWhere + "ORDER BY " + fldName + " DESC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " < ( SELECT MIN(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                }
            }
            else // 异常处理
            {
                throw new DataException("未指定任何排序类型。0升序,1为降序");
            }

            return strSQL;
        }


        /// <summary>
        /// 获取分页操作SQL语句(对于排序的字段必须建立索引)
        /// </summary>
        /// <param name="tblName">操作表名</param>
        /// <param name="fldName">操作索引字段名称</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">每页显示记录数</param>
        /// <param name="rtnFields">返回字段集合,中间用逗号格开。返回全部用“*”</param>
        /// <param name="OrderType">排序方式(0升序,1为降序)</param>
        /// <param name="strWhere">检索的条件语句,不需要再加WHERE关键字</param>
        /// <returns></returns>
        public static string ConstructSplitSQL(string tblName,
                                                string fldName,
                                                int PageIndex,
                                                int PageSize,
                                                string rtnFields,
                                                int OrderType,
                                                string strWhere)
        {
            string strSQL = "";
            string strOldWhere = "";

            // 构造检索条件语句字符串
            if (strWhere != "")
            {
                // 去除不合法的字符,防止SQL注入式攻击
                strWhere = strWhere.Replace("'", "''");
                strWhere = strWhere.Replace("--", "");
                strWhere = strWhere.Replace(";", "");

                strOldWhere = " AND " + strWhere + " ";

                strWhere = " WHERE " + strWhere + " ";
            }

            // 升序操作
            if (OrderType == 0)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    //strSQL += "WHERE (" + fldName + " >= ( SELECT MAX(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                    strSQL += strWhere + "ORDER BY " + fldName + " ASC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " > ( SELECT MAX(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                }
            }
            // 降序操作
            else if (OrderType == 1)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    //strSQL += "WHERE (" + fldName + " <= ( SELECT MIN(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                    strSQL += strWhere + "ORDER BY " + fldName + " DESC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " < ( SELECT MIN(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                }
            }
            else // 异常处理
            {
                throw new DataException("未指定任何排序类型。0升序,1为降序");
            }

            return strSQL;
        }


        /// <summary>
        /// 获取分页操作SQL语句(对于排序的字段必须建立索引)
        /// </summary>
        /// <param name="tblName">操作表名</param>
        /// <param name="fldName">操作索引字段名称</param>
        /// <param name="unionCondition">用于连接的条件,例如: LEFT JOIN UserInfo u ON (u.UserID = b.UserID)</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">每页显示记录数</param>
        /// <param name="rtnFields">返回字段集合,中间用逗号格开。返回全部用“*”</param>
        /// <param name="OrderType">排序方式,0升序,1为降序</param>
        /// <param name="strWhere">检索的条件语句,不需要再加WHERE关键字</param>
        /// <returns></returns>
        public static string ConstructSplitSQL(string tblName,
            string fldName,
            string unionCondition,
            int PageIndex,
            int PageSize,
            string rtnFields,
            int OrderType,
            string strWhere)
        {
            string strSQL = "";
            string strOldWhere = "";

            // 构造检索条件语句字符串
            if (strWhere != "")
            {
                // 去除不合法的字符,防止SQL注入式攻击
                strWhere = strWhere.Replace("'", "''");
                strWhere = strWhere.Replace("--", "");
                strWhere = strWhere.Replace(";", "");

                strOldWhere = " AND " + strWhere + " ";

                strWhere = " WHERE " + strWhere + " ";
            }

            // 升序操作
            if (OrderType == 0)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + unionCondition + " ";

                    //strSQL += "WHERE (" + fldName + " >= ( SELECT MAX(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                    strSQL += strWhere + "ORDER BY " + fldName + " ASC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + unionCondition + " ";

                    strSQL += "WHERE (" + fldName + " > ( SELECT MAX(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                }
            }
            // 降序操作
            else if (OrderType == 1)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + unionCondition + " ";

                    //strSQL += "WHERE (" + fldName + " <= ( SELECT MIN(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                    strSQL += strWhere + "ORDER BY " + fldName + " DESC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + unionCondition + " ";

                    strSQL += "WHERE (" + fldName + " < ( SELECT MIN(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                }
            }
            else // 异常处理
            {
                throw new DataException("未指定任何排序类型。0升序,1为降序");
            }

            return strSQL;
        }


        /// <summary>
        /// 获取分页操作SQL语句(对于排序的字段必须建立索引)
        /// </summary>
        /// <param name="tblName">操作表名</param>
        /// <param name="fldName">操作索引字段名称</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">每页显示记录数</param>
        /// <param name="rtnFields">返回字段集合,中间用逗号格开。返回全部用“*”</param>
        /// <param name="OrderType">排序方式(0升序,1为降序)</param>
        /// <param name="strWhere">检索的条件语句,不需要再加WHERE关键字</param>
        /// <returns></returns>
        public static string ConstructSplitSQL_TOP(string tblName,
                                                    string fldName,
                                                    int PageIndex,
                                                    int PageSize,
                                                    string rtnFields,
                                                    int OrderType,
                                                    string strWhere)
        {
            string strSQL = "";
            string strOldWhere = "";

            // 构造检索条件语句字符串
            if (strWhere != "")
            {
                // 去除不合法的字符,防止SQL注入式攻击
                strWhere = strWhere.Replace("'", "''");
                strWhere = strWhere.Replace("--", "");
                strWhere = strWhere.Replace(";", "");

                strOldWhere = " AND " + strWhere + " ";

                strWhere = " WHERE " + strWhere + " ";
            }

            // 升序操作
            if (OrderType == 0)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += strWhere + " ORDER BY " + fldName + " ASC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " > ( SELECT MAX(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                }
            }
            // 降序操作
            else if (OrderType == 1)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += strWhere + " ORDER BY " + fldName + " DESC";
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " < ( SELECT MIN(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                }
            }
            else // 异常处理
            {
                throw new DataException("未指定任何排序类型。0升序,1为降序");
            }

            return strSQL;
        }

        /// <summary>
        /// 获取分页操作SQL语句(对于排序的字段必须建立索引)
        /// </summary>
        /// <param name="tblName">操作表名</param>
        /// <param name="fldName">操作索引字段名称</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="PageSize">每页显示记录数</param>
        /// <param name="rtnFields">返回字段集合,中间用逗号格开。返回全部用“*”</param>
        /// <param name="OrderType">排序方式(0升序,1为降序)</param>
        /// <param name="sort">排序表达式</param>
        /// <param name="strWhere">检索的条件语句,不需要再加WHERE关键字</param>
        /// <returns></returns>
        public static string ConstructSplitSQL_sort(string tblName,
            string fldName,
            int PageIndex,
            int PageSize,
            string rtnFields,
            int OrderType,
            string sort,
            string strWhere)
        {
            string strSQL = "";
            string strOldWhere = "";

            // 构造检索条件语句字符串
            if (strWhere != "")
            {
                // 去除不合法的字符,防止SQL注入式攻击
                strWhere = strWhere.Replace("'", "''");
                strWhere = strWhere.Replace("--", "");
                strWhere = strWhere.Replace(";", "");

                strOldWhere = " AND " + strWhere + " ";

                strWhere = " WHERE " + strWhere + " ";
            }

            if (sort != "") sort = " ORDER BY " + sort;

            // 升序操作
            if (OrderType == 0)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    //strSQL += "WHERE (" + fldName + " >= ( SELECT MAX(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " ASC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " ASC";
                    strSQL += strWhere + sort;
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " > ( SELECT MAX(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + sort + " ) AS T )) ";

                    strSQL += strOldWhere + sort;
                }
            }
            // 降序操作
            else if (OrderType == 1)
            {
                if (PageIndex == 1)
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    //strSQL += "WHERE (" + fldName + " <= ( SELECT MIN(" + fldName + ") FROM (SELECT TOP 1 " + fldName + " FROM " + tblName + strWhere + " ORDER BY " + fldName + " DESC ) AS T )) ";

                    //strSQL += strOldWhere + "ORDER BY " + fldName + " DESC";
                    strSQL += strWhere + sort;
                }
                else
                {
                    strSQL += "SELECT TOP " + PageSize + " " + rtnFields + " FROM " + tblName + " ";

                    strSQL += "WHERE (" + fldName + " < ( SELECT MIN(" + fldName + ") FROM (SELECT TOP " + ((PageIndex - 1) * PageSize) + " " + fldName + " FROM " + tblName + strWhere + sort + " ) AS T )) ";

                    strSQL += strOldWhere + sort;
                }
            }
            else // 异常处理
            {
                throw new DataException("未指定主索引排序类型。0升序,1为降序");
            }

            return strSQL;
        }

        #endregion

        /// <summary>
        /// 服务于AES/DES加解密类的方法
        /// </summary>
        /// <param name="p_SrcString"></param>
        /// <param name="p_Length"></param>
        /// <param name="p_TailString"></param>
        /// <returns></returns>
        public static string GetSubString(string p_SrcString, int p_Length, string p_TailString)
        {
            string text = p_SrcString;
            if (p_Length < 0)
            {
                return text;
            }
            byte[] sourceArray = Encoding.Default.GetBytes(p_SrcString);
            if (sourceArray.Length <= p_Length)
            {
                return text;
            }
            int length = p_Length;
            int[] numArray = new int[p_Length];
            byte[] destinationArray = null;
            int num2 = 0;
            for (int i = 0; i < p_Length; i++)
            {
                if (sourceArray[i] > 0x7f)
                {
                    num2++;
                    if (num2 == 3)
                    {
                        num2 = 1;
                    }
                }
                else
                {
                    num2 = 0;
                }
                numArray[i] = num2;
            }
            if ((sourceArray[p_Length - 1] > 0x7f) && (numArray[p_Length - 1] == 1))
            {
                length = p_Length + 1;
            }
            destinationArray = new byte[length];
            Array.Copy(sourceArray, destinationArray, length);
            return (Encoding.Default.GetString(destinationArray) + p_TailString);
        }
    }
}
字符串帮助类
复制代码

15.时间日期管理类,主要用来进行年月日与周的换算

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Text;
  4 
  5 namespace Utilities
  6 {
  7     /// <summary>
  8     /// 时间日期管理类,主要用来进行年月日与周的换算。
  9     /// YCL 20080810
 10     /// </summary>
 11     public class TimeUtility
 12     {
 13        
 14 
 15         public static DateTime DefaultTime
 16         {
 17             get
 18             {
 19                 return DateTime.Parse("1900/1/1");
 20             }
 21         }
 22         public static DateTime ChangQi
 23         {
 24             get
 25             {
 26                 return DateTime.Parse("2900/1/1");
 27             }
 28         }
 29 
 30         public static DateTime GetBirthday(string pid)
 31         {
 32             int year = Convert.ToInt32( pid.Substring(6, 4));
 33             int month = Convert.ToInt32(pid.Substring(10, 2));
 34             int day = Convert.ToInt32(pid.Substring(12,2));
 35             return new DateTime(year, month, day);
 36         }
 37 
 38         #region 阳历处理区 
 39         public static DateTime GetBegin( DateTime dt)
 40         {
 41             return new DateTime(dt.Year, dt.Month, dt.Day);
 42         }
 43         public static DateTime GetEnd(DateTime dt)
 44         {
 45             return new DateTime(dt.Year, dt.Month, dt.Day,23,59,59);
 46         }
 47         /// <summary>
 48         /// 获取一个月的开始和结束时间
 49         /// </summary>
 50         /// <param name="year"></param>
 51         /// <param name="month"></param>
 52         /// <param name="begin"></param>
 53         /// <param name="end"></param>
 54         /// <param name="sp"></param>
 55         /// </summary>
 56         public static void GetBeginAndEnd(int year, int month, out DateTime begin, out DateTime end,string sp="-")
 57         {
 58             begin = Convert.ToDateTime(year + sp + month + sp + 1);
 59             switch (month)
 60             {
 61                 case 1:
 62                 case 3:
 63                 case 5:
 64                 case 7:
 65                 case 8:
 66                 case 10:
 67                 case 12:
 68                     end = Convert.ToDateTime(year + sp + month + sp + 31 + " 23:00:00");
 69                     break;
 70                 case 4:
 71                 case 6:
 72                 case 9:
 73                 case 11:
 74                     end = Convert.ToDateTime(year + sp + month + sp + 30 + " 23:00:00");
 75                     break;
 76                 case 2:
 77                     if (year % 4 == 0)
 78                         end = Convert.ToDateTime(year + sp + month + sp + 29 + " 23:00:00");
 79                     else
 80                         end = Convert.ToDateTime(year + sp + month + sp + 28 + " 23:00:00");
 81                     break;
 82                 default:
 83                     end = end = Convert.ToDateTime(year + sp + month + sp + 30 + " 23:00:00");
 84                     break;
 85             }
 86         }
 87         /// <summary>
 88         /// 获取如:“2009-01-01”格式的日期字符串
 89         /// </summary>
 90         /// <param name="year">年份</param>
 91         /// <param name="month">月份</param>
 92         /// <param name="day">日期</param>
 93         /// <returns></returns>
 94         public static string Get8CTime(int year, int month, int day)
 95         {
 96             string m = month.ToString();
 97             string d = day.ToString();
 98             if (month <= 9)
 99                 m = "0" + month.ToString();
100             if (day <= 9)
101                 d = "0" + day.ToString();
102             return year + "-" + m + "-" + d;
103         }
104         /// <summary>
105         /// 获取如:“2009-01-01”格式的日期字符串
106         /// </summary>
107         /// <param name="time">日期</param>
108         /// <returns>满足8个字符的日期</returns>
109         public static string Get8CTime(DateTime time)
110         {
111             return Get8CTime(time.Year, time.Month, time.Day);
112         }
113         /// <summary>
114         /// 设置指定日期所对应的开始和终止时分秒
115         /// </summary>
116         /// <param name="dt"></param>
117         /// <param name="b"></param>
118         /// <param name="e"></param>
119         public static void SetDayRange(DateTime dt, out DateTime b, out DateTime e)
120         {
121             int y = dt.Year;
122             int m = dt.Month;
123             int d = dt.Day;
124             b = new DateTime(y, m, d, 0, 0, 0);
125             e = new DateTime(y, m, d, 23, 59, 59);
126         }
127         /// <summary>
128         /// 计算指定日期所在周的开始时间和终止时间
129         /// </summary>
130         /// <param name="time">指定的日期</param>
131         /// <param name="begin">本周的开始时间</param>
132         /// <param name="end">本周的截止时间</param>
133         /// <returns>指定日期在当前月中是第几周(本月有几个周六,就有几周)</returns>
134         public static int SetWeekRange(DateTime time, out DateTime begin, out DateTime end)
135         {
136             DayOfWeek w = time.DayOfWeek;            
137             int a = (int)w;
138             begin = time.AddDays(-a);
139             if (a != 6)
140             {
141                 end = time.AddDays(7 - a);
142                 end = DateTime.Parse(end.ToShortDateString()).AddMinutes(-1);//本周的最后一天至23时59分59秒
143             }
144             else
145             {
146                 end = time;
147                 end = DateTime.Parse(end.ToShortDateString()).AddDays(1).AddSeconds(-1);
148 
149             }
150             begin = DateTime.Parse(begin.ToShortDateString());//本周的第一天从0时0分0秒算起
151             //
152             int weeks = GetWeeks(time.Year, time.Month);
153             DateTime st = GetFirstSaturday(time.Year, time.Month);
154             st = DateTime.Parse(st.ToShortDateString()).AddDays(1).AddMinutes(-1);
155             for (int i = 0; i < weeks; i++)
156             {
157                 if (time <= st)
158                 {
159                     return i + 1;
160                 }
161                 st = st.AddDays(7);
162             }
163             return 1;
164         }
165         /// <summary>
166         /// 天数
167         /// </summary>
168         /// <param name="time"></param>
169         /// <returns></returns>
170         public static int GetWeekNum(DateTime time)
171         {
172             DateTime begin, end;
173             return SetWeekRange(time, out begin, out end);
174         }
175         /// <summary>
176         /// 计算指定年,月,周的开始时间和终止时间
177         /// </summary>
178         /// <param name="year">年份</param>
179         /// <param name="month">月份</param>
180         /// <param name="weeks"></param>
181         /// <param name="begin">计算得出的开始时间</param>
182         /// <param name="end">计算得出的截止时间</param>
183         public static void SetWeekRange(int year, int month, int weeks, out DateTime begin, out DateTime end)
184         {
185             if (weeks <= GetWeeks(year, month))
186             {
187                 DateTime time = GetFirstSaturday(year, month);
188                 while (true)
189                 {
190                     int i = SetWeekRange(time, out begin, out end);
191                     if (i == weeks)
192                         return;
193                     time = time.AddDays(7);
194                 }
195             }
196             else
197                 throw new Exception("您指定的周不存在!");
198         }
199 
200         /// <summary>
201         /// 获取指定年的月共有几周(指定月份有几个周六就是有几周)
202         /// </summary>
203         /// <param name="year">年份</param>
204         /// <param name="month">月份</param>
205         /// <returns>共几周</returns>
206         public static int GetWeeks(int year, int month)
207         {
208             DateTime time = GetFirstSaturday(year, month);
209             int m = time.AddDays(28).Month;//加完4周,看月份
210             if (m == month)
211                 return 5;
212             else
213                 return 4;
214         }
215         /// <summary>
216         /// 找到指定年月分的第一个周六
217         /// </summary>
218         /// <param name="year"></param>
219         /// <param name="month"></param>
220         /// <returns></returns>
221         public static DateTime GetFirstSaturday(int year, int month)
222         {
223             //找到第一个周六,然后加7,看是否是本月,如果是再加7,直到不是即可。
224             int days = DateTime.DaysInMonth(year, month);
225             DateTime time = DateTime.Parse(year + "-" + month + "-1");
226             //找到第一个星期六
227             for (int i = 0; i < 7; i++)
228             {
229                 if (time.DayOfWeek == DayOfWeek.Saturday)
230                     break;
231                 else
232                     time = time.AddDays(1);
233             }
234             return time;
235         }
236         /// <summary>
237         /// 查询星期几
238         /// </summary>
239         /// <param name="day"></param>
240         /// <returns></returns>
241         public static string GetXingQi(DateTime day)
242         {
243             int beginSeg, endSeg;
244             return GetXingQi(day, out beginSeg,out endSeg);
245         }
246         /// <summary>
247         /// 获取指定日期的星期
248         /// </summary>
249         /// <param name="day">指定的日期</param>
250         /// <param name="beginSeg">起始时间段</param>
251         /// <param name="endSeg">终止时间段</param>
252         /// <returns></returns>
253         public static string GetXingQi(DateTime day, out int beginSeg, out int endSeg)
254         {
255             switch (day.DayOfWeek)
256             {
257                 case DayOfWeek.Monday:
258                     beginSeg = 6;
259                     endSeg = 10;
260                     return "";
261                 case DayOfWeek.Tuesday:
262                     beginSeg = 11;
263                     endSeg = 15;
264                     return "";
265                 case DayOfWeek.Wednesday:
266                     beginSeg = 16;
267                     endSeg = 20;
268                     return "";
269                 case DayOfWeek.Thursday:
270                     beginSeg = 21;
271                     endSeg = 25;
272                     return "";
273                 case DayOfWeek.Friday:
274                     beginSeg = 26;
275                     endSeg = 30;
276                     return "";
277                 case DayOfWeek.Saturday:
278                     beginSeg = 31;
279                     endSeg = 35;
280                     return "";
281                 default:
282                     beginSeg = 1;
283                     endSeg = 5;
284                     return "";
285             }
286         }
287 
288         #endregion
289 
290         #region 农历部分
291         //天干 
292         private static string[] TianGan = { "", "", "", "", "", "", "", "", "", "" };
293         //地支 
294         private static string[] DiZhi = { "", "", "", "", "", "", "", "", "", "", "", "" };
295         //十二生肖 
296         private static string[] ShengXiao = { "", "", "", "", "", "", "", "", "", "", "", "" };
297         //农历日期 
298         private static string[] DayName = {"*","初一","初二","初三","初四","初五", 
299 
300 "初六","初七","初八","初九","初十", 
301 
302 "十一","十二","十三","十四","十五", 
303 
304 "十六","十七","十八","十九","二十", 
305 
306 "廿一","廿二","廿三","廿四","廿五", 
307 
308 "廿六","廿七","廿八","廿九","三十"};
309 
310         //农历月份 
311         private static string[] MonthName = { "*", "", "", "", "", "", "", "", "", "", "", "十一", "" };
312 
313         //公历月计数天 
314         private static int[] MonthAdd = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
315 
316         //农历数据 
317         private static int[] LunarData = {2635,333387,1701,1748,267701,694,2391,133423,1175,396438 
318 
319 ,3402,3749,331177,1453,694,201326,2350,465197,3221,3402 
320 
321 ,400202,2901,1386,267611,605,2349,137515,2709,464533,1738 
322 
323 ,2901,330421,1242,2651,199255,1323,529706,3733,1706,398762 
324 
325 ,2741,1206,267438,2647,1318,204070,3477,461653,1386,2413 
326 
327 ,330077,1197,2637,268877,3365,531109,2900,2922,398042,2395 
328 
329 ,1179,267415,2635,661067,1701,1748,398772,2742,2391,330031 
330 
331 ,1175,1611,200010,3749,527717,1452,2742,332397,2350,3222 
332 
333 ,268949,3402,3493,133973,1386,464219,605,2349,334123,2709 
334 
335 ,2890,267946,2773,592565,1210,2651,395863,1323,2707,265877};
336         /// <summary>
337         ///  获取对应日期的农历,并带回天干地支生肖 
338         /// </summary>
339         /// <param name="dtDay">公历日期</param>
340         /// <param name="td">天干地支</param>
341         /// <param name="sx">生肖</param>
342         /// <returns>农历日期</returns>
343         public static string GetLunarCalendar(DateTime dtDay, out string td, out string sx)
344         {
345             string sYear = dtDay.Year.ToString();
346             string sMonth = dtDay.Month.ToString();
347             string sDay = dtDay.Day.ToString();
348             int year;
349             int month;
350             int day;
351             try
352             {
353                 year = int.Parse(sYear);
354                 month = int.Parse(sMonth);
355                 day = int.Parse(sDay);
356             }
357             catch
358             {
359                 year = DateTime.Now.Year;
360                 month = DateTime.Now.Month;
361                 day = DateTime.Now.Day;
362             }
363 
364 
365 
366             int nTheDate;
367             int nIsEnd;
368             int k, m, n, nBit, i;
369             string calendar = string.Empty;
370             //计算到初始时间1921年2月8日的天数:1921-2-8(正月初一) 
371             nTheDate = (year - 1921) * 365 + (year - 1921) / 4 + day + MonthAdd[month - 1] - 38;
372             if ((year % 4 == 0) && (month > 2))
373                 nTheDate += 1;
374             //计算天干,地支,月,日 
375             nIsEnd = 0;
376             m = 0;
377             k = 0;
378             n = 0;
379             while (nIsEnd != 1)
380             {
381                 if (LunarData[m] < 4095)
382                     k = 11;
383                 else
384                     k = 12;
385                 n = k;
386 
387                 while (n >= 0)
388                 {
389                     //获取LunarData[m]的第n个二进制位的值 
390                     nBit = LunarData[m];
391                     for (i = 1; i < n + 1; i++)
392                         nBit = nBit / 2;
393                     nBit = nBit % 2;
394                     if (nTheDate <= (29 + nBit))
395                     {
396                         nIsEnd = 1;
397                         break;
398                     }
399                     nTheDate = nTheDate - 29 - nBit;
400                     n = n - 1;
401                 }
402 
403                 if (nIsEnd == 1)
404                     break;
405                 m = m + 1;
406             }
407 
408             year = 1921 + m;
409             month = k - n + 1;
410             day = nTheDate;
411             // return year + "-" + month + "-" + day;
412 
413             // #region 格式化日期显示为三月廿四 
414 
415             if (k == 12)
416             {
417                 if (month == LunarData[m] / 65536 + 1)
418                     month = 1 - month;
419                 else if (month > LunarData[m] / 65536 + 1)
420                     month = month - 1;
421             }
422             //生肖 
423             sx = ShengXiao[(year - 4) % 60 % 12].ToString() + "";
424 
425             // //天干地支
426             td = TianGan[(year - 4) % 60 % 10].ToString() + DiZhi[(year - 4) % 60 % 12].ToString();
427 
428 
429             //农历月 
430             if (month < 1)
431                 calendar += "" + MonthName[-1 * month].ToString() + "";
432             else
433                 calendar += MonthName[month].ToString() + "";
434             //农历日 
435             calendar += DayName[day].ToString() + "";
436             return calendar;
437 
438             // #endregion 
439 
440         }
441         /// <summary> 
442         /// 获取对应日期的农历 
443         /// </summary> 
444         /// <param name="dtDay">公历日期</param> 
445         /// <returns>农历日期</returns> 
446         public static string GetLunarCalendar(DateTime dtDay)
447         {
448             string sYear = dtDay.Year.ToString();
449             string sMonth = dtDay.Month.ToString();
450             string sDay = dtDay.Day.ToString();
451             int year;
452             int month;
453             int day;
454             try
455             {
456                 year = int.Parse(sYear);
457                 month = int.Parse(sMonth);
458                 day = int.Parse(sDay);
459             }
460             catch
461             {
462                 year = DateTime.Now.Year;
463                 month = DateTime.Now.Month;
464                 day = DateTime.Now.Day;
465             }
466             int nTheDate;
467             int nIsEnd;
468             int k, m, n, nBit, i;
469             string calendar = string.Empty;
470             //计算到初始时间1921年2月8日的天数:1921-2-8(正月初一) 
471             nTheDate = (year - 1921) * 365 + (year - 1921) / 4 + day + MonthAdd[month - 1] - 38;
472             if ((year % 4 == 0) && (month > 2))
473                 nTheDate += 1;
474             //计算天干,地支,月,日 
475             nIsEnd = 0;
476             m = 0;
477             k = 0;
478             n = 0;
479             while (nIsEnd != 1)
480             {
481                 if (LunarData[m] < 4095)
482                     k = 11;
483                 else
484                     k = 12;
485                 n = k;
486 
487                 while (n >= 0)
488                 {
489                     //获取LunarData[m]的第n个二进制位的值 
490                     nBit = LunarData[m];
491                     for (i = 1; i < n + 1; i++)
492                         nBit = nBit / 2;
493                     nBit = nBit % 2;
494                     if (nTheDate <= (29 + nBit))
495                     {
496                         nIsEnd = 1;
497                         break;
498                     }
499                     nTheDate = nTheDate - 29 - nBit;
500                     n = n - 1;
501                 }
502 
503                 if (nIsEnd == 1)
504                     break;
505                 m = m + 1;
506             }
507 
508             year = 1921 + m;
509             month = k - n + 1;
510             day = nTheDate;
511 
512             if (k == 12)
513             {
514                 if (month == LunarData[m] / 65536 + 1)
515                     month = 1 - month;
516                 else if (month > LunarData[m] / 65536 + 1)
517                     month = month - 1;
518             }
519             //农历月 
520             if (month < 1)
521                 calendar += "" + MonthName[-1 * month].ToString() + "";
522             else
523                 calendar += MonthName[month].ToString() + "";
524             //农历日 
525             calendar += DayName[day].ToString() + "";
526             return calendar;
527         }
528         #endregion
529 
530         #region 节气部分——支持1901-2050
531         static string[] SolarTerms = 
532             { 
533                 "小寒", "大寒", "立春", "雨水", 
534                 "惊蛰", "春分", "清明", "谷雨", 
535                 "立夏", "小满", "芒种", "夏至", 
536                 "小暑", "大暑", "立秋", "处暑", 
537                 "白露", "秋分", "寒露", "霜降", 
538                 "立冬", "小雪", "大雪", "冬至"};
539         //数组gLanarHoliDay存放每年的二十四节气对应的阳历日期 
540         //每年的二十四节气对应的阳历日期几乎固定,平均分布于十二个月中 
541         // 1月 2月 3月 4月 5月 6月 
542         //小寒 大寒 立春 雨水 惊蛰 春分 清明 谷雨 立夏 小满 芒种 夏至 
543         // 7月 8月 9月 10月 11月 12月 
544         //小暑 大暑 立秋 处暑 白露 秋分 寒露 霜降 立冬 小雪 大雪 冬至 
545         //********************************************************************************* 
546         // 节气无任何确定规律,所以只好存表,要节省空间,所以. 
547         //**********************************************************************************} 
548         //数据格式说明: 
549         //如1901年的节气为 
550         // 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月 
551         // 6, 21, 4, 19, 6, 21, 5, 21, 6,22, 6,22, 8, 23, 8, 24, 8, 24, 8, 24, 8, 23, 8, 22 
552         // 9, 6, 11,4, 9, 6, 10,6, 9,7, 9,7, 7, 8, 7, 9, 7, 9, 7, 9, 7, 8, 7, 15 
553         //上面第一行数据为每月节气对应日期,15减去每月第一个节气,每月第二个节气减去15得第二行 
554         // 这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存放 
555         //第二个节气的数据,可得下表 
556         static byte[] gLunarHolDay =
557             { 
558                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1901 
559                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1902 
560                 0x96, 0xA5, 0x87, 0x96, 0x87, 0x87, 0x79, 0x69, 0x69, 0x69, 0x78, 0x78, //1903 
561                 0x86, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x78, 0x87, //1904 
562                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1905 
563                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1906 
564                 0x96, 0xA5, 0x87, 0x96, 0x87, 0x87, 0x79, 0x69, 0x69, 0x69, 0x78, 0x78, //1907 
565                 0x86, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1908 
566                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1909 
567                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1910 
568                 0x96, 0xA5, 0x87, 0x96, 0x87, 0x87, 0x79, 0x69, 0x69, 0x69, 0x78, 0x78, //1911 
569                 0x86, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1912 
570                 0x95, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1913 
571                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1914 
572                 0x96, 0xA5, 0x97, 0x96, 0x97, 0x87, 0x79, 0x79, 0x69, 0x69, 0x78, 0x78, //1915 
573                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1916 
574                 0x95, 0xB4, 0x96, 0xA6, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x87, //1917 
575                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x77, //1918 
576                 0x96, 0xA5, 0x97, 0x96, 0x97, 0x87, 0x79, 0x79, 0x69, 0x69, 0x78, 0x78, //1919 
577                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1920            
578 
579                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x87, //1921 
580                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x77, //1922 
581                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x69, 0x69, 0x78, 0x78, //1923 
582                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1924 
583                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x87, //1925 
584                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1926 
585                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1927 
586                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1928 
587                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1929 
588                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1930 
589                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x87, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1931 
590                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1932 
591                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1933 
592                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1934 
593                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1935 
594                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1936 
595                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1937 
596                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1938 
597                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1939 
598                 0x96, 0xA5, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1940 
599                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1941 
600                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1942 
601                 0x96, 0xA4, 0x96, 0x96, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1943 
602                 0x96, 0xA5, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1944 
603                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1945 
604                 0x95, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1946 
605                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1947 
606                 0x96, 0xA5, 0xA6, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1948 
607                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x79, 0x78, 0x79, 0x77, 0x87, //1949 
608                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1950 
609                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x79, 0x79, 0x79, 0x69, 0x78, 0x78, //1951 
610                 0x96, 0xA5, 0xA6, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1952 
611                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1953 
612                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x68, 0x78, 0x87, //1954 
613                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1955 
614                 0x96, 0xA5, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1956 
615                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1957 
616                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1958 
617                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1959 
618                 0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1960 
619                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1961 
620                 0x96, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1962 
621                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1963 
622                 0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1964 
623                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1965 
624                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1966 
625                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1967 
626                 0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1968 
627                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1969 
628                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1970 
629                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x79, 0x69, 0x78, 0x77, //1971 
630                 0x96, 0xA4, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1972 
631                 0xA5, 0xB5, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1973 
632                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1974 
633                 0x96, 0xB4, 0x96, 0xA6, 0x97, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1975 
634                 0x96, 0xA4, 0xA5, 0xB5, 0xA6, 0xA6, 0x88, 0x89, 0x88, 0x78, 0x87, 0x87, //1976 
635                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1977 
636                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x78, 0x87, //1978 
637                 0x96, 0xB4, 0x96, 0xA6, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1979 
638                 0x96, 0xA4, 0xA5, 0xB5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1980 
639                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x77, 0x87, //1981 
640                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1982 
641                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x78, 0x79, 0x78, 0x69, 0x78, 0x77, //1983 
642                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x87, //1984 
643                 0xA5, 0xB4, 0xA6, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //1985 
644                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1986 
645                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x79, 0x78, 0x69, 0x78, 0x87, //1987 
646                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //1988 
647                 0xA5, 0xB4, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1989 
648                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //1990 
649                 0x95, 0xB4, 0x96, 0xA5, 0x86, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1991 
650                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //1992 
651                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1993 
652                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1994 
653                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x76, 0x78, 0x69, 0x78, 0x87, //1995 
654                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //1996 
655                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //1997 
656                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //1998 
657                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //1999 
658                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //2000 
659                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2001 
660                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //2002 
661                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //2003 
662                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //2004 
663                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2005 
664                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2006 
665                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x69, 0x78, 0x87, //2007 
666                 0x96, 0xB4, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2008 
667                 0xA5, 0xB3, 0xA5, 0xB5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2009 
668                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2010 
669                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x78, 0x87, //2011 
670                 0x96, 0xB4, 0xA5, 0xB5, 0xA5, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2012 
671                 0xA5, 0xB3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x87, //2013 
672                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2014 
673                 0x95, 0xB4, 0x96, 0xA5, 0x96, 0x97, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //2015 
674                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2016 
675                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x87, //2017 
676                 0xA5, 0xB4, 0xA6, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2018 
677                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //2019 
678                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x86, //2020 
679                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //2021 
680                 0xA5, 0xB4, 0xA5, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2022 
681                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x79, 0x77, 0x87, //2023 
682                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x96, //2024 
683                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //2025 
684                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2026 
685                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //2027 
686                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x96, //2028 
687                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //2029 
688                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2030 
689                 0xA5, 0xB4, 0x96, 0xA5, 0x96, 0x96, 0x88, 0x78, 0x78, 0x78, 0x87, 0x87, //2031 
690                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x96, //2032 
691                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x86, //2033 
692                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x78, 0x88, 0x78, 0x87, 0x87, //2034 
693                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2035 
694                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x96, //2036 
695                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x86, //2037 
696                 0xA5, 0xB3, 0xA5, 0xA5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2038 
697                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2039 
698                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x96, //2040 
699                 0xA5, 0xC3, 0xA5, 0xB5, 0xA5, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2041 
700                 0xA5, 0xB3, 0xA5, 0xB5, 0xA6, 0xA6, 0x88, 0x88, 0x88, 0x78, 0x87, 0x87, //2042 
701                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2043 
702                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x88, 0x87, 0x96, //2044 
703                 0xA5, 0xC3, 0xA5, 0xB4, 0xA5, 0xA6, 0x87, 0x88, 0x87, 0x78, 0x87, 0x86, //2045 
704                 0xA5, 0xB3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x88, 0x78, 0x87, 0x87, //2046 
705                 0xA5, 0xB4, 0x96, 0xA5, 0xA6, 0x96, 0x88, 0x88, 0x78, 0x78, 0x87, 0x87, //2047 
706                 0x95, 0xB4, 0xA5, 0xB4, 0xA5, 0xA5, 0x97, 0x87, 0x87, 0x88, 0x86, 0x96, //2048 
707                 0xA4, 0xC3, 0xA5, 0xA5, 0xA5, 0xA6, 0x97, 0x87, 0x87, 0x78, 0x87, 0x86, //2049 
708                 0xA5, 0xC3, 0xA5, 0xB5, 0xA6, 0xA6, 0x87, 0x88, 0x78, 0x78, 0x87, 0x87}; //2050 
709 
710         /// <summary>
711         /// 获取指定时间的节气 
712         /// </summary>
713         /// <param name="time">公历日期</param>
714         /// <returns>节气名称</returns>
715         public static string GetSolarTerm(DateTime time)
716         {
717             byte Flag;
718             int Day, iYear, iMonth, iDay;
719             iYear = time.Year;
720             if ((iYear < 1901) || (iYear > 2050))
721             { return ""; };
722             iMonth = time.Month;
723             iDay = time.Day;
724             Flag = gLunarHolDay[(iYear - 1901) * 12 + iMonth - 1];
725             if (iDay < 15)
726             { Day = 15 - ((Flag >> 4) & 0x0f); }
727             else
728             { Day = (Flag & 0x0f) + 15; };
729             if (iDay == Day)
730             {
731                 if (iDay > 15)
732                 {
733                     return SolarTerms[(iMonth - 1) * 2 + 1];
734                 }
735                 else
736                 {
737                     return SolarTerms[(iMonth - 1) * 2];
738                 }
739             }
740             else
741             { return ""; };
742         }
743         #endregion
744 
745         #region 星座部分
746         private static string[] ConstellationName = 
747             { 
748                 "白羊座", "金牛座", "双子座", 
749                 "巨蟹座", "狮子座", "处女座", 
750                 "天秤座", "天蝎座", "射手座", 
751                 "摩羯座", "水瓶座", "双鱼座"};
752         //计算指定日期的星座序号 
753         static int GetConstellation(DateTime time)
754         {
755             int Y, M, D;
756             Y = time.Year;
757             M = time.Month;
758             D = time.Day;
759             Y = M * 100 + D;
760             if (((Y >= 321) && (Y <= 419))) { return 0; }
761             else if ((Y >= 420) && (Y <= 520)) { return 1; }
762             else if ((Y >= 521) && (Y <= 620)) { return 2; }
763             else if ((Y >= 621) && (Y <= 722)) { return 3; }
764             else if ((Y >= 723) && (Y <= 822)) { return 4; }
765             else if ((Y >= 823) && (Y <= 922)) { return 5; }
766             else if ((Y >= 923) && (Y <= 1022)) { return 6; }
767             else if ((Y >= 1023) && (Y <= 1121)) { return 7; }
768             else if ((Y >= 1122) && (Y <= 1221)) { return 8; }
769             else if ((Y >= 1222) || (Y <= 119)) { return 9; }
770             else if ((Y >= 120) && (Y <= 218)) { return 10; }
771             else if ((Y >= 219) && (Y <= 320)) { return 11; }
772             else { return -1; };
773         }
774         /// <summary>
775         /// 计算指定日期的星座名称 
776         /// </summary>
777         /// <param name="time">公历日期</param>
778         /// <returns>星座名称</returns>
779         public static string GetConstellationName(DateTime time)
780         {
781             int Constellation;
782             Constellation = GetConstellation(time);
783             if ((Constellation >= 0) && (Constellation <= 11))
784             { return ConstellationName[Constellation]; }
785             else
786             { return ""; };
787         }
788 
789         #endregion
790     }
791 }
时间日期管理类
复制代码

16.WebHelper帮助类

复制代码
   1 using System;
   2 using System.Collections.Generic;
   3 using System.Collections.Specialized;
   4 using System.IO;
   5 using System.Linq;
   6 using System.Net;
   7 using System.Text;
   8 using System.Text.RegularExpressions;
   9 using System.Web;
  10 using HttpCookie = System.Web.HttpCookie;
  11 using Newtonsoft.Json;
  12 using RestSharp;//Nuget使用104.5.0版本
  13 
  14 
  15 namespace Utilities
  16 {
  17     /// <summary>
  18     /// 
  19     /// </summary>
  20     public class WebHelper
  21     {
  22         //浏览器列表
  23         private static readonly string[] Browserlist = { "ie", "chrome", "mozilla", "netscape", "firefox", "opera", "konqueror" };
  24         //搜索引擎列表
  25         private static readonly string[] Searchenginelist = { "baidu", "google", "360", "sogou", "bing", "msn", "sohu", "soso", "sina", "163", "yahoo", "jikeu" };
  26         //meta正则表达式
  27         private static readonly Regex Metaregex = new Regex("<meta([^<]*)charset=([^<]*)[\"']", RegexOptions.IgnoreCase | RegexOptions.Multiline);
  28 
  29         #region 编码
  30 
  31         /// <summary>
  32         /// HTML解码
  33         /// </summary>
  34         /// <returns></returns>
  35         public static string HtmlDecode(string s)
  36         {
  37             return HttpUtility.HtmlDecode(s);
  38         }
  39 
  40         /// <summary>
  41         /// HTML编码
  42         /// </summary>
  43         /// <returns></returns>
  44         public static string HtmlEncode(string s)
  45         {
  46             return HttpUtility.HtmlEncode(s);
  47         }
  48 
  49         /// <summary>
  50         /// URL解码
  51         /// </summary>
  52         /// <returns></returns>
  53         public static string UrlDecode(string s)
  54         {
  55             return HttpUtility.UrlDecode(s);
  56         }
  57 
  58         /// <summary>
  59         /// URL编码
  60         /// </summary>
  61         /// <returns></returns>
  62         public static string UrlEncode(string s)
  63         {
  64             return HttpUtility.UrlEncode(s);
  65         }
  66 
  67         #endregion
  68 
  69         #region Cookie
  70 
  71         /// <summary>
  72         /// 删除指定名称的Cookie
  73         /// </summary>
  74         /// <param name="name">Cookie名称</param>
  75         public static void DeleteCookie(string name)
  76         {
  77             HttpCookie cookie = new HttpCookie(name);
  78             cookie.Expires = DateTime.Now.AddYears(-1);
  79             HttpContext.Current.Response.AppendCookie(cookie);
  80         }
  81 
  82         /// <summary>
  83         /// 获得指定名称的Cookie值
  84         /// </summary>
  85         /// <param name="name">Cookie名称</param>
  86         /// <returns></returns>
  87         public static string GetCookie(string name)
  88         {
  89             HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
  90             if (cookie != null)
  91                 return cookie.Value;
  92 
  93             return string.Empty;
  94         }
  95 
  96         /// <summary>
  97         /// 获得指定名称的Cookie中特定键的值
  98         /// </summary>
  99         /// <param name="name">Cookie名称</param>
 100         /// <param name="key"></param>
 101         /// <returns></returns>
 102         public static string GetCookie(string name, string key)
 103         {
 104             HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
 105             if (cookie != null && cookie.HasKeys)
 106             {
 107                 string v = cookie[key];
 108                 if (v != null)
 109                     return v;
 110             }
 111 
 112             return string.Empty;
 113         }
 114 
 115         /// <summary>
 116         /// 设置指定名称的Cookie的值
 117         /// </summary>
 118         /// <param name="name">Cookie名称</param>
 119         /// <param name="value"></param>
 120         public static void SetCookie(string name, string value)
 121         {
 122             HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
 123             if (cookie != null)
 124                 cookie.Value = value;
 125             else
 126                 cookie = new HttpCookie(name, value);
 127 
 128             HttpContext.Current.Response.AppendCookie(cookie);
 129         }
 130 
 131         /// <summary>
 132         /// 设置指定名称的Cookie的值
 133         /// </summary>
 134         /// <param name="name">Cookie名称</param>
 135         /// <param name="value"></param>
 136         /// <param name="expires">过期时间</param>
 137         public static void SetCookie(string name, string value, double expires)
 138         {
 139             HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
 140             if (cookie == null)
 141                 cookie = new HttpCookie(name);
 142 
 143             cookie.Value = value;
 144             cookie.Expires = DateTime.Now.AddMinutes(expires);
 145             HttpContext.Current.Response.AppendCookie(cookie);
 146         }
 147 
 148         /// <summary>
 149         /// 设置指定名称的Cookie特定键的值
 150         /// </summary>
 151         /// <param name="name">Cookie名称</param>
 152         /// <param name="key"></param>
 153         /// <param name="value"></param>
 154         public static void SetCookie(string name, string key, string value)
 155         {
 156             HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
 157             if (cookie == null)
 158                 cookie = new HttpCookie(name);
 159 
 160             cookie[key] = value;
 161             HttpContext.Current.Response.AppendCookie(cookie);
 162         }
 163 
 164         /// <summary>
 165         /// 设置指定名称的Cookie特定键的值
 166         /// </summary>
 167         /// <param name="name">Cookie名称</param>
 168         /// <param name="key"></param>
 169         /// <param name="value"></param>
 170         /// <param name="expires">过期时间</param>
 171         public static void SetCookie(string name, string key, string value, double expires)
 172         {
 173             HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
 174             if (cookie == null)
 175                 cookie = new HttpCookie(name);
 176 
 177             cookie[key] = value;
 178             cookie.Expires = DateTime.Now.AddMinutes(expires);
 179             HttpContext.Current.Response.AppendCookie(cookie);
 180         }
 181 
 182         #endregion
 183 
 184         #region 客户端信息
 185 
 186         /// <summary>
 187         /// 是否是get请求
 188         /// </summary>
 189         /// <returns></returns>
 190         public static bool IsGet()
 191         {
 192             return HttpContext.Current.Request.HttpMethod == "GET";
 193         }
 194 
 195         /// <summary>
 196         /// 是否是post请求
 197         /// </summary>
 198         /// <returns></returns>
 199         public static bool IsPost()
 200         {
 201             return HttpContext.Current.Request.HttpMethod == "POST";
 202         }
 203 
 204         /// <summary>
 205         /// 是否是Ajax请求
 206         /// </summary>
 207         /// <returns></returns>
 208         public static bool IsAjax()
 209         {
 210             return HttpContext.Current.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
 211         }
 212 
 213         /// <summary>
 214         /// 获得查询字符串中的值
 215         /// </summary>
 216         /// <param name="key"></param>
 217         /// <param name="defaultValue">默认值</param>
 218         /// <returns></returns>
 219         public static string GetQueryString(string key, string defaultValue)
 220         {
 221             string value = HttpContext.Current.Request.QueryString[key];
 222             return !string.IsNullOrWhiteSpace(value) ? value : defaultValue;
 223         }
 224 
 225         /// <summary>
 226         /// 获得查询字符串中的值
 227         /// </summary>
 228         /// <param name="key"></param>
 229         /// <returns></returns>
 230         public static string GetQueryString(string key)
 231         {
 232             return GetQueryString(key, "");
 233         }
 234 
 235         /// <summary>
 236         /// 获得查询字符串中的值
 237         /// </summary>
 238         /// <param name="key"></param>
 239         /// <param name="defaultValue">默认值</param>
 240         /// <returns></returns>
 241         public static int GetQueryInt(string key, int defaultValue)
 242         {
 243             return TypeHelper.StringToInt(HttpContext.Current.Request.QueryString[key], defaultValue);
 244         }
 245 
 246         /// <summary>
 247         /// 获得查询字符串中的值
 248         /// </summary>
 249         /// <param name="key"></param>
 250         /// <returns></returns>
 251         public static int GetQueryInt(string key)
 252         {
 253             return GetQueryInt(key, 0);
 254         }
 255 
 256         /// <summary>
 257         /// 获得表单中的值
 258         /// </summary>
 259         /// <param name="key"></param>
 260         /// <param name="defaultValue">默认值</param>
 261         /// <returns></returns>
 262         public static string GetFormString(string key, string defaultValue)
 263         {
 264             string value = HttpContext.Current.Request.Form[key];
 265             if (!string.IsNullOrWhiteSpace(value))
 266                 return value;
 267             else
 268                 return defaultValue;
 269         }
 270 
 271         /// <summary>
 272         /// 获得表单中的值
 273         /// </summary>
 274         /// <param name="key"></param>
 275         /// <returns></returns>
 276         public static string GetFormString(string key)
 277         {
 278             return GetFormString(key, "");
 279         }
 280 
 281         /// <summary>
 282         /// 获得表单中的值
 283         /// </summary>
 284         /// <param name="key"></param>
 285         /// <param name="defaultValue">默认值</param>
 286         /// <returns></returns>
 287         public static int GetFormInt(string key, int defaultValue)
 288         {
 289             return TypeHelper.StringToInt(HttpContext.Current.Request.Form[key], defaultValue);
 290         }
 291 
 292         /// <summary>
 293         /// 获得表单中的值
 294         /// </summary>
 295         /// <param name="key"></param>
 296         /// <returns></returns>
 297         public static int GetFormInt(string key)
 298         {
 299             return GetFormInt(key, 0);
 300         }
 301 
 302         /// <summary>
 303         /// 获得请求中的值
 304         /// </summary>
 305         /// <param name="key"></param>
 306         /// <param name="defaultValue">默认值</param>
 307         /// <returns></returns>
 308         public static string GetRequestString(string key, string defaultValue)
 309         {
 310             if (HttpContext.Current.Request.Form[key] != null)
 311                 return GetFormString(key, defaultValue);
 312             else
 313                 return GetQueryString(key, defaultValue);
 314         }
 315 
 316         /// <summary>
 317         /// 获得请求中的值
 318         /// </summary>
 319         /// <param name="key"></param>
 320         /// <returns></returns>
 321         public static string GetRequestString(string key)
 322         {
 323             if (HttpContext.Current.Request.Form[key] != null)
 324                 return GetFormString(key);
 325             else
 326                 return GetQueryString(key);
 327         }
 328 
 329         /// <summary>
 330         /// 获得请求中的值
 331         /// </summary>
 332         /// <param name="key"></param>
 333         /// <param name="defaultValue">默认值</param>
 334         /// <returns></returns>
 335         public static int GetRequestInt(string key, int defaultValue)
 336         {
 337             if (HttpContext.Current.Request.Form[key] != null)
 338                 return GetFormInt(key, defaultValue);
 339             else
 340                 return GetQueryInt(key, defaultValue);
 341         }
 342 
 343         /// <summary>
 344         /// 获得请求中的值
 345         /// </summary>
 346         /// <param name="key"></param>
 347         /// <returns></returns>
 348         public static int GetRequestInt(string key)
 349         {
 350             if (HttpContext.Current.Request.Form[key] != null)
 351                 return GetFormInt(key);
 352             else
 353                 return GetQueryInt(key);
 354         }
 355 
 356         /// <summary>
 357         /// 获得上次请求的url
 358         /// </summary>
 359         /// <returns></returns>
 360         public static string GetUrlReferrer()
 361         {
 362             Uri uri = HttpContext.Current.Request.UrlReferrer;
 363             if (uri == null)
 364                 return string.Empty;
 365 
 366             return uri.ToString();
 367         }
 368 
 369         /// <summary>
 370         /// 获得请求的主机部分
 371         /// </summary>
 372         /// <returns></returns>
 373         public static string GetHost()
 374         {
 375             return HttpContext.Current.Request.Url.Host;
 376         }
 377 
 378         /// <summary>
 379         /// 获得请求的url
 380         /// </summary>
 381         /// <returns></returns>
 382         public static string GetUrl()
 383         {
 384             return HttpContext.Current.Request.Url.ToString();
 385         }
 386 
 387         /// <summary>
 388         /// 获得请求的原始url
 389         /// </summary>
 390         /// <returns></returns>
 391         public static string GetRawUrl()
 392         {
 393             return HttpContext.Current.Request.RawUrl;
 394         }
 395 
 396         /// <summary>
 397         /// 获得请求的ip
 398         /// </summary>
 399         /// <returns></returns>
 400         public static string GetIP()
 401         {
 402             string ip = string.Empty;
 403             if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
 404                 ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
 405             else
 406                 ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
 407 
 408             if (string.IsNullOrEmpty(ip) || ! StringHelper.RegexIP.IsMatch(ip))
 409                 ip = "127.0.0.1";
 410             return ip;
 411         }
 412 
 413         /// <summary>
 414         /// 获得请求的浏览器类型
 415         /// </summary>
 416         /// <returns></returns>
 417         public static string GetBrowserType()
 418         {
 419             string type = HttpContext.Current.Request.Browser.Type;
 420             if (string.IsNullOrEmpty(type) || type == "unknown")
 421                 return "未知";
 422             return type.ToLower();
 423         }
 424 
 425         /// <summary>
 426         /// 获得请求的浏览器名称
 427         /// </summary>
 428         /// <returns></returns>
 429         public static string GetBrowserName()
 430         {
 431             string name = HttpContext.Current.Request.Browser.Browser;
 432             if (string.IsNullOrEmpty(name) || name == "unknown")
 433                 return "未知";
 434 
 435             return name.ToLower();
 436         }
 437 
 438         /// <summary>
 439         /// 获得请求的浏览器版本
 440         /// </summary>
 441         /// <returns></returns>
 442         public static string GetBrowserVersion()
 443         {
 444             string version = HttpContext.Current.Request.Browser.Version;
 445             if (string.IsNullOrEmpty(version) || version == "unknown")
 446                 return "未知";
 447 
 448             return version;
 449         }
 450 
 451         /// <summary>
 452         /// 获得请求客户端的操作系统类型
 453         /// </summary>
 454         /// <returns></returns>
 455         public static string GetOSType()
 456         {
 457             string type = "未知";
 458             string userAgent = HttpContext.Current.Request.UserAgent;
 459 
 460             if (userAgent.Contains("NT 6.1"))
 461             {
 462                 type = "Windows 7";
 463             }
 464             else if (userAgent.Contains("NT 5.1"))
 465             {
 466                 type = "Windows XP";
 467             }
 468             else if (userAgent.Contains("NT 6.2"))
 469             {
 470                 type = "Windows 8";
 471             }
 472             else if (userAgent.Contains("android"))
 473             {
 474                 type = "Android";
 475             }
 476             else if (userAgent.Contains("iphone"))
 477             {
 478                 type = "IPhone";
 479             }
 480             else if (userAgent.Contains("Mac"))
 481             {
 482                 type = "Mac";
 483             }
 484             else if (userAgent.Contains("NT 6.0"))
 485             {
 486                 type = "Windows Vista";
 487             }
 488             else if (userAgent.Contains("NT 5.2"))
 489             {
 490                 type = "Windows 2003";
 491             }
 492             else if (userAgent.Contains("NT 5.0"))
 493             {
 494                 type = "Windows 2000";
 495             }
 496             else if (userAgent.Contains("98"))
 497             {
 498                 type = "Windows 98";
 499             }
 500             else if (userAgent.Contains("95"))
 501             {
 502                 type = "Windows 95";
 503             }
 504             else if (userAgent.Contains("Me"))
 505             {
 506                 type = "Windows Me";
 507             }
 508             else if (userAgent.Contains("NT 4"))
 509             {
 510                 type = "Windows NT4";
 511             }
 512             else if (userAgent.Contains("Unix"))
 513             {
 514                 type = "UNIX";
 515             }
 516             else if (userAgent.Contains("Linux"))
 517             {
 518                 type = "Linux";
 519             }
 520             else if (userAgent.Contains("SunOS"))
 521             {
 522                 type = "SunOS";
 523             }
 524 
 525             return type;
 526         }
 527 
 528         /// <summary>
 529         /// 获得请求客户端的操作系统名称
 530         /// </summary>
 531         /// <returns></returns>
 532         public static string GetOSName()
 533         {
 534             string name = HttpContext.Current.Request.Browser.Platform;
 535             if (string.IsNullOrEmpty(name))
 536                 return "未知";
 537 
 538             return name;
 539         }
 540 
 541         /// <summary>
 542         /// 判断是否是浏览器请求
 543         /// </summary>
 544         /// <returns></returns>
 545         public static bool IsBrowser()
 546         {
 547             string name = GetBrowserName();
 548             foreach (string item in Browserlist)
 549             {
 550                 if (name.Contains(item))
 551                     return true;
 552             }
 553             return false;
 554         }
 555 
 556         /// <summary>
 557         /// 是否是移动设备请求
 558         /// </summary>
 559         /// <returns></returns>
 560         public static bool IsMobile()
 561         {
 562             if (HttpContext.Current.Request.Browser.IsMobileDevice)
 563                 return true;
 564 
 565             bool isTablet = false;
 566             if (bool.TryParse(HttpContext.Current.Request.Browser["IsTablet"], out isTablet) && isTablet)
 567                 return true;
 568 
 569             return false;
 570         }
 571 
 572         /// <summary>
 573         /// 判断是否是搜索引擎爬虫请求
 574         /// </summary>
 575         /// <returns></returns>
 576         public static bool IsCrawler()
 577         {
 578             bool result = HttpContext.Current.Request.Browser.Crawler;
 579             if (!result)
 580             {
 581                 string referrer = GetUrlReferrer();
 582                 if (referrer.Length > 0)
 583                 {
 584                     foreach (string item in Searchenginelist)
 585                     {
 586                         if (referrer.Contains(item))
 587                             return true;
 588                     }
 589                 }
 590             }
 591             return result;
 592         }
 593 
 594         #endregion
 595 
 596         #region Http
 597 
 598         /// <summary>
 599         /// 获得参数列表
 600         /// </summary>
 601         /// <param name="data">数据</param>
 602         /// <returns></returns>
 603         public static NameValueCollection GetParmList(string data)
 604         {
 605             NameValueCollection parmList = new NameValueCollection(StringComparer.OrdinalIgnoreCase);
 606             if (!string.IsNullOrEmpty(data))
 607             {
 608                 int length = data.Length;
 609                 for (int i = 0; i < length; i++)
 610                 {
 611                     int startIndex = i;
 612                     int endIndex = -1;
 613                     while (i < length)
 614                     {
 615                         char c = data[i];
 616                         if (c == '=')
 617                         {
 618                             if (endIndex < 0)
 619                                 endIndex = i;
 620                         }
 621                         else if (c == '&')
 622                         {
 623                             break;
 624                         }
 625                         i++;
 626                     }
 627                     string key;
 628                     string value;
 629                     if (endIndex >= 0)
 630                     {
 631                         key = data.Substring(startIndex, endIndex - startIndex);
 632                         value = data.Substring(endIndex + 1, (i - endIndex) - 1);
 633                     }
 634                     else
 635                     {
 636                         key = data.Substring(startIndex, i - startIndex);
 637                         value = string.Empty;
 638                     }
 639                     parmList[key] = value;
 640                     if ((i == (length - 1)) && (data[i] == '&'))
 641                         parmList[key] = string.Empty;
 642                 }
 643             }
 644             return parmList;
 645         }
 646 
 647         /// <summary>
 648         /// 获得http请求数据
 649         /// </summary>
 650         /// <param name="url">请求地址</param>
 651         /// <param name="postData">发送数据</param>
 652         /// <returns></returns>
 653         public static string GetRequestData(SortedDictionary<string, string> postData, string url)
 654         {
 655             return GetRequestData(url, Method.POST, postData);
 656         }
 657 
 658         /// <summary>
 659         /// 获得http请求数据
 660         /// </summary>
 661         /// <param name="url">请求地址</param>
 662         /// <param name="method">请求方式</param>
 663         /// <param name="postData">发送数据</param>
 664         /// <returns></returns>
 665         public static string GetRequestData(string url, Method method, SortedDictionary<string, string> postData)
 666         {
 667             return GetRequestData(url, method, postData, Encoding.UTF8);
 668         }
 669 
 670         /// <summary>
 671         /// 获得http请求数据
 672         /// </summary>
 673         /// <param name="url">请求地址</param>
 674         /// <param name="method">请求方式</param>
 675         /// <param name="postData">发送数据</param>
 676         /// <param name="encoding">编码</param>
 677         /// <returns></returns>
 678         public static string GetRequestData(string url, Method method, SortedDictionary<string, string> postData, Encoding encoding)
 679         {
 680             return GetRequestData(url, method, postData, encoding, 20000);
 681         }
 682 
 683         /// <summary>
 684         /// 获得http请求数据
 685         /// </summary>
 686         /// <param name="url">请求地址</param>
 687         /// <param name="method">请求方式</param>
 688         /// <param name="postData">发送数据</param>
 689         /// <param name="encoding">编码</param>
 690         /// <param name="timeout">超时值</param>
 691         /// <returns></returns>
 692         public static string GetRequestData(string url, Method method, SortedDictionary<string, string> postData, Encoding encoding, int timeout)
 693         {
 694 
 695             if (!(url.Contains("http://") || url.Contains("https://")))
 696                 url = "http://" + url;
 697 
 698             var client = new RestClient(url);
 699             var request = new RestRequest(method) { Timeout = timeout };
 700 
 701             //将参数 加入请求
 702             if (postData != null && postData.Any())
 703             {
 704                 foreach (var item in postData.Keys)
 705                 {
 706                     request.AddParameter(item, postData[item], ParameterType.GetOrPost);
 707                 }
 708             }
 709             //执行
 710             var response = client.Execute(request);
 711 
 712             return response.StatusCode == HttpStatusCode.OK ? response.Content : "";
 713 
 714 
 715             //if (!(url.Contains("http://") || url.Contains("https://")))
 716             //    url = "http://" + url;
 717 
 718             ////var request = (HttpWebRequest)WebRequest.Create(url);
 719             //request.Method = method.Trim().ToLower();
 720             //request.Timeout = timeout;
 721             //request.AllowAutoRedirect = true;
 722             //request.ContentType = "text/html";
 723             //request.Accept = "text/html, application/xhtml+xml, */*,zh-CN";
 724             ////request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
 725             //request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
 726 
 727             //try
 728             //{
 729             //    if (!string.IsNullOrEmpty(postData) && request.Method == "post")
 730             //    {
 731             //        byte[] buffer = encoding.GetBytes(postData);
 732             //        request.ContentLength = buffer.Length;
 733             //        request.GetRequestStream().Write(buffer, 0, buffer.Length);
 734             //    }
 735 
 736             //    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
 737             //    {
 738             //        if (encoding == null)
 739             //        {
 740             //            MemoryStream stream = new MemoryStream();
 741             //            if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
 742             //                new GZipStream(response.GetResponseStream(), CompressionMode.Decompress).CopyTo(stream, 10240);
 743             //            else
 744             //                response.GetResponseStream().CopyTo(stream, 10240);
 745 
 746             //            byte[] RawResponse = stream.ToArray();
 747             //            string temp = Encoding.Default.GetString(RawResponse, 0, RawResponse.Length);
 748             //            Match meta = Metaregex.Match(temp);
 749             //            string charter = (meta.Groups.Count > 2) ? meta.Groups[2].Value : string.Empty;
 750             //            charter = charter.Replace("\"", string.Empty).Replace("'", string.Empty).Replace(";", string.Empty);
 751             //            if (charter.Length > 0)
 752             //            {
 753             //                charter = charter.ToLower().Replace("iso-8859-1", "gbk");
 754             //                encoding = Encoding.GetEncoding(charter);
 755             //            }
 756             //            else
 757             //            {
 758             //                if (response.CharacterSet.ToLower().Trim() == "iso-8859-1")
 759             //                {
 760             //                    encoding = Encoding.GetEncoding("gbk");
 761             //                }
 762             //                else
 763             //                {
 764             //                    if (string.IsNullOrEmpty(response.CharacterSet.Trim()))
 765             //                    {
 766             //                        encoding = Encoding.UTF8;
 767             //                    }
 768             //                    else
 769             //                    {
 770             //                        encoding = Encoding.GetEncoding(response.CharacterSet);
 771             //                    }
 772             //                }
 773             //            }
 774             //            return encoding.GetString(RawResponse);
 775             //        }
 776             //        StreamReader reader = null;
 777             //        if (response.ContentEncoding != null && response.ContentEncoding.Equals("gzip", StringComparison.InvariantCultureIgnoreCase))
 778             //        {
 779             //            using (reader = new StreamReader(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress), encoding))
 780             //            {
 781             //                return reader.ReadToEnd();
 782             //            }
 783             //        }
 784             //        using (reader = new StreamReader(response.GetResponseStream(), encoding))
 785             //        {
 786             //            try
 787             //            {
 788             //                return reader.ReadToEnd();
 789             //            }
 790             //            catch
 791             //            {
 792             //                return "close";
 793             //            }
 794 
 795             //        }
 796             //    }
 797 
 798             //}
 799             //catch
 800             //{
 801             //    return "error";
 802             //}
 803         }
 804 
 805         #endregion
 806 
 807         #region .NET
 808 
 809         /// <summary>
 810         /// 获得当前应用程序的信任级别
 811         /// </summary>
 812         /// <returns></returns>
 813         public static AspNetHostingPermissionLevel GetTrustLevel()
 814         {
 815             AspNetHostingPermissionLevel trustLevel = AspNetHostingPermissionLevel.None;
 816             //权限列表
 817             AspNetHostingPermissionLevel[] levelList = new AspNetHostingPermissionLevel[] {
 818                                                                                             AspNetHostingPermissionLevel.Unrestricted,
 819                                                                                             AspNetHostingPermissionLevel.High,
 820                                                                                             AspNetHostingPermissionLevel.Medium,
 821                                                                                             AspNetHostingPermissionLevel.Low,
 822                                                                                             AspNetHostingPermissionLevel.Minimal
 823                                                                                             };
 824 
 825             foreach (AspNetHostingPermissionLevel level in levelList)
 826             {
 827                 try
 828                 {
 829                     //通过执行Demand方法检测是否抛出SecurityException异常来设置当前应用程序的信任级别
 830                     new AspNetHostingPermission(level).Demand();
 831                     trustLevel = level;
 832                     break;
 833                 }
 834                 catch//(SecurityException ex)
 835                 {
 836                     continue;
 837                 }
 838             }
 839             return trustLevel;
 840         }
 841 
 842         /// <summary>
 843         /// 修改web.config文件
 844         /// </summary>
 845         /// <returns></returns>
 846         private static bool TryWriteWebConfig()
 847         {
 848             try
 849             {
 850                 File.SetLastWriteTimeUtc(IoHelper.GetMapPath("~/web.config"), DateTime.UtcNow);
 851                 return true;
 852             }
 853             catch
 854             {
 855                 return false;
 856             }
 857         }
 858 
 859         /// <summary>
 860         /// 修改global.asax文件
 861         /// </summary>
 862         /// <returns></returns>
 863         private static bool TryWriteGlobalAsax()
 864         {
 865             try
 866             {
 867                 File.SetLastWriteTimeUtc(IoHelper.GetMapPath("~/global.asax"), DateTime.UtcNow);
 868                 return true;
 869             }
 870             catch
 871             {
 872                 return false;
 873             }
 874         }
 875 
 876         /// <summary>
 877         /// 重启应用程序
 878         /// </summary>
 879         public static void RestartAppDomain()
 880         {
 881             if (GetTrustLevel() > AspNetHostingPermissionLevel.Medium)//如果当前信任级别大于Medium,则通过卸载应用程序域的方式重启
 882             {
 883                 HttpRuntime.UnloadAppDomain();
 884                 TryWriteGlobalAsax();
 885             }
 886             else//通过修改web.config方式重启应用程序
 887             {
 888                 bool success = TryWriteWebConfig();
 889                 if (!success)
 890                 {
 891                     throw new Exception("修改web.config文件重启应用程序");
 892                 }
 893 
 894                 success = TryWriteGlobalAsax();
 895                 if (!success)
 896                 {
 897                     throw new Exception("修改global.asax文件重启应用程序");
 898                 }
 899             }
 900 
 901         }
 902 
 903         #endregion
 904 
 905     }
 906     /// <summary>
 907     /// 类型帮助类
 908     /// </summary>
 909     public class TypeHelper
 910     {
 911         #region 转Int
 912 
 913         /// <summary>
 914         /// 将string类型转换成int类型
 915         /// </summary>
 916         /// <param name="s">目标字符串</param>
 917         /// <param name="defaultValue">默认值</param>
 918         /// <returns></returns>
 919         public static int StringToInt(string s, int defaultValue)
 920         {
 921             if (!string.IsNullOrWhiteSpace(s))
 922             {
 923                 int result;
 924                 if (int.TryParse(s, out result))
 925                     return result;
 926             }
 927 
 928             return defaultValue;
 929         }
 930 
 931         /// <summary>
 932         /// 将string类型转换成int类型
 933         /// </summary>
 934         /// <param name="s">目标字符串</param>
 935         /// <returns></returns>
 936         public static int StringToInt(string s)
 937         {
 938             return StringToInt(s, 0);
 939         }
 940 
 941         /// <summary>
 942         /// 将object类型转换成int类型
 943         /// </summary>
 944         /// <param name="o">目标对象</param>
 945         /// <param name="defaultValue">默认值</param>
 946         /// <returns></returns>
 947         public static int ObjectToInt(object o, int defaultValue)
 948         {
 949             if (o != null)
 950                 return StringToInt(o.ToString(), defaultValue);
 951 
 952             return defaultValue;
 953         }
 954 
 955         /// <summary>
 956         /// 将object类型转换成int类型
 957         /// </summary>
 958         /// <param name="o">目标对象</param>
 959         /// <returns></returns>
 960         public static int ObjectToInt(object o)
 961         {
 962             return ObjectToInt(o, 0);
 963         }
 964 
 965         #endregion
 966 
 967         #region 转Long
 968 
 969         /// <summary>
 970         /// 将string类型转换成int类型
 971         /// </summary>
 972         /// <param name="s">目标字符串</param>
 973         /// <param name="defaultValue">默认值</param>
 974         /// <returns></returns>
 975         public static long StringToLong(string s, long defaultValue)
 976         {
 977             if (!string.IsNullOrWhiteSpace(s))
 978             {
 979                 long result;
 980                 if (long.TryParse(s, out result))
 981                     return result;
 982             }
 983 
 984             return defaultValue;
 985         }
 986 
 987         /// <summary>
 988         /// 将string类型转换成int类型
 989         /// </summary>
 990         /// <param name="s">目标字符串</param>
 991         /// <returns></returns>
 992         public static long StringToLong(string s)
 993         {
 994             return StringToLong(s, 0);
 995         }
 996 
 997         /// <summary>
 998         /// 将object类型转换成int类型
 999         /// </summary>
1000         /// <param name="o">目标对象</param>
1001         /// <param name="defaultValue">默认值</param>
1002         /// <returns></returns>
1003         public static long ObjectToLong(object o, long defaultValue)
1004         {
1005             if (o != null)
1006                 return StringToLong(o.ToString(), defaultValue);
1007 
1008             return defaultValue;
1009         }
1010 
1011         /// <summary>
1012         /// 将object类型转换成int类型
1013         /// </summary>
1014         /// <param name="o">目标对象</param>
1015         /// <returns></returns>
1016         public static long ObjectToLong(object o)
1017         {
1018             return ObjectToLong(o, 0);
1019         }
1020 
1021         #endregion
1022 
1023         #region 转Bool
1024 
1025         /// <summary>
1026         /// 将string类型转换成bool类型
1027         /// </summary>
1028         /// <param name="s">目标字符串</param>
1029         /// <param name="defaultValue">默认值</param>
1030         /// <returns></returns>
1031         public static bool StringToBool(string s, bool defaultValue)
1032         {
1033             if (s == "false")
1034                 return false;
1035             else if (s == "true")
1036                 return true;
1037 
1038             return defaultValue;
1039         }
1040 
1041         /// <summary>
1042         /// 将string类型转换成bool类型
1043         /// </summary>
1044         /// <param name="s">目标字符串</param>
1045         /// <returns></returns>
1046         public static bool ToBool(string s)
1047         {
1048             return StringToBool(s, false);
1049         }
1050 
1051         /// <summary>
1052         /// 将object类型转换成bool类型
1053         /// </summary>
1054         /// <param name="o">目标对象</param>
1055         /// <param name="defaultValue">默认值</param>
1056         /// <returns></returns>
1057         public static bool ObjectToBool(object o, bool defaultValue)
1058         {
1059             if (o != null)
1060                 return StringToBool(o.ToString(), defaultValue);
1061 
1062             return defaultValue;
1063         }
1064 
1065         /// <summary>
1066         /// 将object类型转换成bool类型
1067         /// </summary>
1068         /// <param name="o">目标对象</param>
1069         /// <returns></returns>
1070         public static bool ObjectToBool(object o)
1071         {
1072             return ObjectToBool(o, false);
1073         }
1074 
1075         #endregion
1076 
1077         #region 转DateTime
1078 
1079         /// <summary>
1080         /// 将string类型转换成datetime类型
1081         /// </summary>
1082         /// <param name="s">目标字符串</param>
1083         /// <param name="defaultValue">默认值</param>
1084         /// <returns></returns>
1085         public static DateTime StringToDateTime(string s, DateTime defaultValue)
1086         {
1087             if (!string.IsNullOrWhiteSpace(s))
1088             {
1089                 DateTime result;
1090                 if (DateTime.TryParse(s, out result))
1091                     return result;
1092             }
1093             return defaultValue;
1094         }
1095 
1096         /// <summary>
1097         /// 将string类型转换成datetime类型
1098         /// </summary>
1099         /// <param name="s">目标字符串</param>
1100         /// <returns></returns>
1101         public static DateTime StringToDateTime(string s)
1102         {
1103             return StringToDateTime(s, DateTime.Now);
1104         }
1105 
1106         /// <summary>
1107         /// 将object类型转换成datetime类型
1108         /// </summary>
1109         /// <param name="o">目标对象</param>
1110         /// <param name="defaultValue">默认值</param>
1111         /// <returns></returns>
1112         public static DateTime ObjectToDateTime(object o, DateTime defaultValue)
1113         {
1114             if (o != null)
1115                 return StringToDateTime(o.ToString(), defaultValue);
1116 
1117             return defaultValue;
1118         }
1119 
1120         /// <summary>
1121         /// 将object类型转换成datetime类型
1122         /// </summary>
1123         /// <param name="o">目标对象</param>
1124         /// <returns></returns>
1125         public static DateTime ObjectToDateTime(object o)
1126         {
1127             return ObjectToDateTime(o, DateTime.Now);
1128         }
1129 
1130         #endregion
1131 
1132         #region 转Decimal
1133 
1134         /// <summary>
1135         /// 将string类型转换成decimal类型
1136         /// </summary>
1137         /// <param name="s">目标字符串</param>
1138         /// <param name="defaultValue">默认值</param>
1139         /// <returns></returns>
1140         public static decimal StringToDecimal(string s, decimal defaultValue)
1141         {
1142             if (!string.IsNullOrWhiteSpace(s))
1143             {
1144                 decimal result;
1145                 if (decimal.TryParse(s, out result))
1146                     return result;
1147             }
1148 
1149             return defaultValue;
1150         }
1151 
1152         /// <summary>
1153         /// 将string类型转换成decimal类型
1154         /// </summary>
1155         /// <param name="s">目标字符串</param>
1156         /// <returns></returns>
1157         public static decimal StringToDecimal(string s)
1158         {
1159             return StringToDecimal(s, 0m);
1160         }
1161 
1162         /// <summary>
1163         /// 将object类型转换成decimal类型
1164         /// </summary>
1165         /// <param name="o">目标对象</param>
1166         /// <param name="defaultValue">默认值</param>
1167         /// <returns></returns>
1168         public static decimal ObjectToDecimal(object o, decimal defaultValue)
1169         {
1170             if (o != null)
1171                 return StringToDecimal(o.ToString(), defaultValue);
1172 
1173             return defaultValue;
1174         }
1175 
1176         /// <summary>
1177         /// 将object类型转换成decimal类型
1178         /// </summary>
1179         /// <param name="o">目标对象</param>
1180         /// <returns></returns>
1181         public static decimal ObjectToDecimal(object o)
1182         {
1183             return ObjectToDecimal(o, 0m);
1184         }
1185 
1186         #endregion
1187     }
1188 }
WebHelper
复制代码

17.文件操作帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.IO;
  4 using System.Linq;
  5 using System.Text;
  6 using System.Threading;
  7 using System.Threading.Tasks;
  8 
  9 namespace CrackPlateform.Models
 10 {
 11     public class FileHelper
 12     {
 13         static ReaderWriterLockSlim LogWriteLock = new ReaderWriterLockSlim();
 14         public static string ReadFile(string Path, Encoding encode)
 15         {
 16             Dictionary<int, string> dic = new Dictionary<int, string>();
 17             StringBuilder sb = new StringBuilder();
 18             try
 19             {
 20                 LogWriteLock.EnterReadLock();
 21                 if (!System.IO.File.Exists(Path))
 22                 {
 23                     sb = null;
 24                 }
 25                 else
 26                 {
 27                     StreamReader f2 = new StreamReader(Path, encode);
 28                     String line;
 29                     int i = 0;
 30                     while ((line = f2.ReadLine()) != null)//按行读取 line为每行的数据
 31                     {
 32                         i++;
 33                         dic.Add(i, line);
 34                     }
 35                     foreach (var item in dic)
 36                     {
 37                         sb.Append(item.Value + "\n");
 38                     }
 39                     //s = f2.ReadToEnd();
 40                     f2.Close();
 41                     f2.Dispose();
 42                 }
 43             }
 44             catch (Exception ex)
 45             {
 46 
 47             }
 48             finally
 49             {
 50                 LogWriteLock.ExitReadLock();
 51             }
 52             return sb?.ToString();
 53         }
 54         /// <summary>
 55         /// 文件base64解码
 56         /// </summary>
 57         /// <param name="base64Str">文件base64编码</param>
 58         /// <param name="outPath">生成文件路径</param>
 59         public static void Base64ToOriFile(string base64Str, string outPath)
 60         {
 61             var contents = Convert.FromBase64String(base64Str);
 62             using (var fs = new FileStream(outPath, FileMode.Create, FileAccess.Write))
 63             {
 64                 fs.Write(contents, 0, contents.Length);
 65                 fs.Flush();
 66             }
 67         }
 68         /// <summary>
 69         /// 文件转为base64编码
 70         /// </summary>
 71         /// <param name="filePath"></param>
 72         /// <returns></returns>
 73         public static string FileToBase64Str(string filePath)
 74         {
 75             string base64Str = string.Empty;
 76             try
 77             {
 78                 using (FileStream filestream = new FileStream(filePath, FileMode.Open))
 79                 {
 80                     byte[] bt = new byte[filestream.Length];
 81 
 82                     //调用read读取方法
 83                     filestream.Read(bt, 0, bt.Length);
 84                     base64Str = Convert.ToBase64String(bt);
 85                     filestream.Close();
 86                 }
 87 
 88                 return base64Str;
 89             }
 90             catch (Exception ex)
 91             {
 92                 return base64Str;
 93             }
 94         }
 95 
 96         /// <summary>
 97         /// 将字典转换成name=value这种字符串格式
 98         /// </summary>
 99         /// <param name="dic"></param>
100         /// <returns></returns>
101         public static string DictionaryToStr(IDictionary<string, string> dic)
102         {
103             string strTemp = string.Empty;
104             foreach (KeyValuePair<string, string> item in dic)
105             {
106                 if (!string.IsNullOrEmpty(item.Key) && !string.IsNullOrEmpty(item.Value))
107                 {
108                     strTemp += item.Key + ":" + item.Value + "\r\n";
109                 }
110             }
111             return strTemp;
112         }
113     }
114 }
文件操作帮助类
复制代码

18.Redis帮助类

复制代码
 1 using CSRedis;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Threading.Tasks;
 6 
 7 namespace CrackPlateform.Models
 8 {
 9     public class RedisManager : IDisposable
10     {
11         public RedisManager() : this("127.0.0.1:6379")
12         {
13         }
14         public RedisManager(string ipAndPort)
15         {
16             var csredis = new CSRedis.CSRedisClient(ipAndPort + ",poolsize=100,preheat=true,writeBuffer=102400,tryit=3");
17             RedisHelper.Initialization(csredis);
18         }
19         private readonly object locker = new object();
20         public CSRedisClient Instance
21         {
22             get { return RedisHelper.Instance; }
23         }
24         public void Dispose()
25         {
26             lock (locker)
27             {
28                 RedisHelper.Instance.Dispose();
29             }
30         }
31     }
32 }
RedisManager
复制代码

19.RSAHelper帮助类

复制代码
  1 using System;
  2 using System.Collections.Generic;
  3 using System.IO;
  4 using System.Linq;
  5 using System.Security.Cryptography;
  6 using System.Text;
  7 using System.Threading.Tasks;
  8 
  9 namespace CrackPlateform.Models
 10 {
 11     public class RSAHelper
 12     {
 13         private readonly RSA _privateKeyRsaProvider;
 14         private readonly RSA _publicKeyRsaProvider;
 15         private readonly HashAlgorithmName _hashAlgorithmName;
 16         private readonly Encoding _encoding;
 17 
 18         /// <summary>
 19         /// 实例化RSAHelper
 20         /// </summary>
 21         /// <param name="rsaType">加密算法类型 RSA SHA1;RSA2 SHA256 密钥长度至少为2048</param>
 22         /// <param name="encoding">编码类型</param>
 23         /// <param name="privateKey">私钥</param>
 24         /// <param name="publicKey">公钥</param>
 25         public RSAHelper(RSAType rsaType, Encoding encoding, string privateKey, string publicKey = null)
 26         {
 27             _encoding = encoding;
 28             if (!string.IsNullOrEmpty(privateKey))
 29             {
 30                 _privateKeyRsaProvider = CreateRsaProviderFromPrivateKey(privateKey);
 31             }
 32 
 33             if (!string.IsNullOrEmpty(publicKey))
 34             {
 35                 _publicKeyRsaProvider = CreateRsaProviderFromPublicKey(publicKey);
 36             }
 37 
 38             _hashAlgorithmName = rsaType == RSAType.RSA ? HashAlgorithmName.SHA1 : HashAlgorithmName.SHA256;
 39         }
 40 
 41         #region 使用私钥签名
 42 
 43         /// <summary>
 44         /// 使用私钥签名
 45         /// </summary>
 46         /// <param name="data">原始数据</param>
 47         /// <returns></returns>
 48         public string Sign(string data)
 49         {
 50             byte[] dataBytes = _encoding.GetBytes(data);
 51 
 52             var signatureBytes = _privateKeyRsaProvider.SignData(dataBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1);
 53 
 54             return Convert.ToBase64String(signatureBytes);
 55         }
 56 
 57         #endregion
 58 
 59         #region 使用公钥验证签名
 60 
 61         /// <summary>
 62         /// 使用公钥验证签名
 63         /// </summary>
 64         /// <param name="data">原始数据</param>
 65         /// <param name="sign">签名</param>
 66         /// <returns></returns>
 67         public bool Verify(string data, string sign)
 68         {
 69             byte[] dataBytes = _encoding.GetBytes(data);
 70             byte[] signBytes = Convert.FromBase64String(sign);
 71 
 72             var verify = _publicKeyRsaProvider.VerifyData(dataBytes, signBytes, _hashAlgorithmName, RSASignaturePadding.Pkcs1);
 73 
 74             return verify;
 75         }
 76 
 77         #endregion
 78 
 79         #region 解密
 80 
 81         public string Decrypt(string cipherText)
 82         {
 83             if (_privateKeyRsaProvider == null)
 84             {
 85                 throw new Exception("_privateKeyRsaProvider is null");
 86             }
 87             return Encoding.UTF8.GetString(_privateKeyRsaProvider.Decrypt(Convert.FromBase64String(cipherText), RSAEncryptionPadding.Pkcs1));
 88         }
 89 
 90         #endregion
 91 
 92         #region 加密
 93 
 94         public string Encrypt(string text)
 95         {
 96             if (_publicKeyRsaProvider == null)
 97             {
 98                 throw new Exception("_publicKeyRsaProvider is null");
 99             }
100             return Convert.ToBase64String(_publicKeyRsaProvider.Encrypt(Encoding.UTF8.GetBytes(text), RSAEncryptionPadding.Pkcs1));
101         }
102 
103         #endregion
104 
105         #region 使用私钥创建RSA实例
106 
107         public RSA CreateRsaProviderFromPrivateKey(string privateKey)
108         {
109             var privateKeyBits = Convert.FromBase64String(privateKey);
110 
111             var rsa = RSA.Create();
112             var rsaParameters = new RSAParameters();
113 
114             using (BinaryReader binr = new BinaryReader(new MemoryStream(privateKeyBits)))
115             {
116                 byte bt = 0;
117                 ushort twobytes = 0;
118                 twobytes = binr.ReadUInt16();
119                 if (twobytes == 0x8130)
120                     binr.ReadByte();
121                 else if (twobytes == 0x8230)
122                     binr.ReadInt16();
123                 else
124                     throw new Exception("Unexpected value read binr.ReadUInt16()");
125 
126                 twobytes = binr.ReadUInt16();
127                 if (twobytes != 0x0102)
128                     throw new Exception("Unexpected version");
129 
130                 bt = binr.ReadByte();
131                 if (bt != 0x00)
132                     throw new Exception("Unexpected value read binr.ReadByte()");
133 
134                 rsaParameters.Modulus = binr.ReadBytes(GetIntegerSize(binr));
135                 rsaParameters.Exponent = binr.ReadBytes(GetIntegerSize(binr));
136                 rsaParameters.D = binr.ReadBytes(GetIntegerSize(binr));
137                 rsaParameters.P = binr.ReadBytes(GetIntegerSize(binr));
138                 rsaParameters.Q = binr.ReadBytes(GetIntegerSize(binr));
139                 rsaParameters.DP = binr.ReadBytes(GetIntegerSize(binr));
140                 rsaParameters.DQ = binr.ReadBytes(GetIntegerSize(binr));
141                 rsaParameters.InverseQ = binr.ReadBytes(GetIntegerSize(binr));
142             }
143 
144             rsa.ImportParameters(rsaParameters);
145             return rsa;
146         }
147 
148         #endregion
149 
150         #region 使用公钥创建RSA实例
151 
152         public RSA CreateRsaProviderFromPublicKey(string publicKeyString)
153         {
154             // encoded OID sequence for  PKCS #1 rsaEncryption szOID_RSA_RSA = "1.2.840.113549.1.1.1"
155             byte[] seqOid = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
156             byte[] seq = new byte[15];
157 
158             var x509Key = Convert.FromBase64String(publicKeyString);
159 
160             // ---------  Set up stream to read the asn.1 encoded SubjectPublicKeyInfo blob  ------
161             using (MemoryStream mem = new MemoryStream(x509Key))
162             {
163                 using (BinaryReader binr = new BinaryReader(mem))  //wrap Memory Stream with BinaryReader for easy reading
164                 {
165                     byte bt = 0;
166                     ushort twobytes = 0;
167 
168                     twobytes = binr.ReadUInt16();
169                     if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
170                         binr.ReadByte();    //advance 1 byte
171                     else if (twobytes == 0x8230)
172                         binr.ReadInt16();   //advance 2 bytes
173                     else
174                         return null;
175 
176                     seq = binr.ReadBytes(15);       //read the Sequence OID
177                     if (!CompareBytearrays(seq, seqOid))    //make sure Sequence for OID is correct
178                         return null;
179 
180                     twobytes = binr.ReadUInt16();
181                     if (twobytes == 0x8103) //data read as little endian order (actual data order for Bit String is 03 81)
182                         binr.ReadByte();    //advance 1 byte
183                     else if (twobytes == 0x8203)
184                         binr.ReadInt16();   //advance 2 bytes
185                     else
186                         return null;
187 
188                     bt = binr.ReadByte();
189                     if (bt != 0x00)     //expect null byte next
190                         return null;
191 
192                     twobytes = binr.ReadUInt16();
193                     if (twobytes == 0x8130) //data read as little endian order (actual data order for Sequence is 30 81)
194                         binr.ReadByte();    //advance 1 byte
195                     else if (twobytes == 0x8230)
196                         binr.ReadInt16();   //advance 2 bytes
197                     else
198                         return null;
199 
200                     twobytes = binr.ReadUInt16();
201                     byte lowbyte = 0x00;
202                     byte highbyte = 0x00;
203 
204                     if (twobytes == 0x8102) //data read as little endian order (actual data order for Integer is 02 81)
205                         lowbyte = binr.ReadByte();  // read next bytes which is bytes in modulus
206                     else if (twobytes == 0x8202)
207                     {
208                         highbyte = binr.ReadByte(); //advance 2 bytes
209                         lowbyte = binr.ReadByte();
210                     }
211                     else
212                         return null;
213                     byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };   //reverse byte order since asn.1 key uses big endian order
214                     int modsize = BitConverter.ToInt32(modint, 0);
215 
216                     int firstbyte = binr.PeekChar();
217                     if (firstbyte == 0x00)
218                     {   //if first byte (highest order) of modulus is zero, don't include it
219                         binr.ReadByte();    //skip this null byte
220                         modsize -= 1;   //reduce modulus buffer size by 1
221                     }
222 
223                     byte[] modulus = binr.ReadBytes(modsize);   //read the modulus bytes
224 
225                     if (binr.ReadByte() != 0x02)            //expect an Integer for the exponent data
226                         return null;
227                     int expbytes = (int)binr.ReadByte();        // should only need one byte for actual exponent data (for all useful values)
228                     byte[] exponent = binr.ReadBytes(expbytes);
229 
230                     // ------- create RSACryptoServiceProvider instance and initialize with public key -----
231                     var rsa = RSA.Create();
232                     RSAParameters rsaKeyInfo = new RSAParameters
233                     {
234                         Modulus = modulus,
235                         Exponent = exponent
236                     };
237                     rsa.ImportParameters(rsaKeyInfo);
238 
239                     return rsa;
240                 }
241 
242             }
243         }
244 
245         #endregion
246 
247         #region 导入密钥算法
248 
249         private int GetIntegerSize(BinaryReader binr)
250         {
251             byte bt = 0;
252             int count = 0;
253             bt = binr.ReadByte();
254             if (bt != 0x02)
255                 return 0;
256             bt = binr.ReadByte();
257 
258             if (bt == 0x81)
259                 count = binr.ReadByte();
260             else
261             if (bt == 0x82)
262             {
263                 var highbyte = binr.ReadByte();
264                 var lowbyte = binr.ReadByte();
265                 byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };
266                 count = BitConverter.ToInt32(modint, 0);
267             }
268             else
269             {
270                 count = bt;
271             }
272 
273             while (binr.ReadByte() == 0x00)
274             {
275                 count -= 1;
276             }
277             binr.BaseStream.Seek(-1, SeekOrigin.Current);
278             return count;
279         }
280 
281         private bool CompareBytearrays(byte[] a, byte[] b)
282         {
283             if (a.Length != b.Length)
284                 return false;
285             int i = 0;
286             foreach (byte c in a)
287             {
288                 if (c != b[i])
289                     return false;
290                 i++;
291             }
292             return true;
293         }
294 
295         #endregion
296 
297     }
298 
299     /// <summary>
300     /// RSA算法类型
301     /// </summary>
302     public enum RSAType
303     {
304         /// <summary>
305         /// SHA1
306         /// </summary>
307         RSA = 0,
308         /// <summary>
309         /// RSA2 密钥长度至少为2048
310         /// SHA256
311         /// </summary>
312         RSA2
313     }
314 }
RSAHelper
复制代码

20.SmtpHelper发送邮件

复制代码
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Net;
 5 using System.Net.Mail;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 
 9 namespace CrackPlateform.Models
10 {
11     public class SmtpHelper
12     {
13         // <summary>
14         /// SMTP发送邮件
15         /// </summary>
16         /// <param name="fromEmail">发送邮件地址</param>
17         /// <param name="toEmail">收件箱</param>
18         /// <param name="subject">邮箱主题</param>
19 
20         /// <param name="contentAttachment"></param>
21         /// <param name="fromEmailPwd">发送邮件密码</param>
22 
23         /// <returns></returns>
24 
25 
26         public static bool SendMailBySMTP(string fromEmail, string toEmail, string subject, string fromEmailPwd)
27         {
28             bool rr = true;
29             System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(fromEmail, toEmail);
30 
31             mail.SubjectEncoding = Encoding.UTF8;
32             mail.Subject = subject;
33             mail.IsBodyHtml = true; //是否允许内容为 HTML 格式
34             mail.BodyEncoding = Encoding.UTF8;
35             string emailContent = "邮件内容";
36 
37             mail.Body = emailContent;
38 
39           //  mail.Attachments.Add(contentAttachment); //添加一个附件
40 
41             SmtpClient smtp = new SmtpClient("smtp.qiye.163.com");//serviceFlag > 14 ? "smtp.qiye.163.com" : 
42             smtp.Port = 25;
43             smtp.EnableSsl = true;
44             smtp.Credentials = new NetworkCredential(fromEmail, fromEmailPwd); //SMTP 验证
45                                                                                //smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
46             smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
47 
48 
49             smtp.Send(mail);
50 
51 
52 
53             return rr;
54         }
55     }
56 }
SmtpHelper
复制代码

 

posted @   薛小谦  阅读(99)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示