using System; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using System.Threading; using CS = System.Console; namespace ConsoleApplication3 { class Program { static void Main(string[] args) { CS.ForegroundColor = DefaultForeColor; CS.BackgroundColor = DefaultBackColor; CS.Clear(); CS.Title = "日志查询工具"; Msg(LogHelper.HelpText); while (true) { var line = CS.ReadLine().ToLower(); if (line == "help") { Msg(LogHelper.HelpText); continue; } if (line == "cls") { CS.Clear(); continue; } if (line == "ec") { LogHelper.IsPro = !LogHelper.IsPro; if (LogHelper.IsPro) { Msg("切换为生产环境日志查询..."); } else { Msg("切换为测试环境日志查询..."); } continue; } new LogHelper(line).Open(); } } public static void Msg(string str) { Show(str, MessageForeColor); } public static void Show(string message, ConsoleColor color) { CS.ForegroundColor = MessageForeColor; CS.WriteLine(message); CS.ForegroundColor = DefaultForeColor; } public static ConsoleColor DefaultForeColor = ConsoleColor.White; public static ConsoleColor DefaultBackColor = ConsoleColor.DarkBlue; public static ConsoleColor MessageForeColor = ConsoleColor.DarkCyan; public class LogHelper { public static string HelpText; private const int support = 4; public static bool IsPro; public static List<string> KeyList = new List<string> { "xx", "yy", "zz", "88" }; public static List<string> TitleList = new List<string> { "可定检查", "创建订单", "提交订单", "中间产品层" }; static LogHelper() { HelpText = "k+数字(默认是k1): "; for (var i = 0; i < TitleList.Count; i++) { HelpText += (i + 1) + "." + TitleList[i] + " "; } HelpText += "默认会员,协议在数字前加0 d/h+数字(默认是d7): 1.一天(h是小时)内日志 2.两天(h是小时)内日志 以此类推... o+数字: 打开ordeidr=数字的日志 r+数字: 打开roomId=数字的日志 u+卡号: 开的uid=卡号的日志 c+数字: 打开cityID=数字的日志 help:查看命令 cls:清除屏幕 ec切换生产/测试环境"; } private string cmd, o, r, u, c;//o==orderid ,r == roomid,u=uid,c=cityid private int k, d, h; public LogHelper(string cmd) { this.cmd = cmd.ToLower(); } private int GetNumber(string prefix) { var contract = 0; var match = GetStr(prefix); if (string.IsNullOrEmpty(match)) return 0; if (match.StartsWith("0")) { contract = 3; } return Convert.ToInt32(match) + contract; } private string GetStr(string prefix) { Regex reg = new Regex(prefix + @"(d+)", RegexOptions.Compiled); return reg.Match(cmd).Groups[1].ToString(); } public void Open() { k = GetNumber("k"); d = GetNumber("d"); h = GetNumber("h"); o = GetStr("o"); r = GetStr("r"); u = GetStr("u"); c = GetStr("c"); //Msg(d.ToString() + k + h); string result = string.Empty; var dateStr = string.Empty; var key = string.Empty; var end = DateTime.Now; if (d > 0) { var begin = end.AddDays(-d); dateStr = getDateStr(begin, end); } else if (h > 0) { var begin = end.AddHours(-h); dateStr = getDateStr(begin, end); } else { var begin = end.AddDays(-7); dateStr = getDateStr(begin, end); } if (k > 0 && k < support) { key = "key=" + KeyList[k - 1]; } else if (k >= support) { key = "key=" + KeyList[k - support]; } else { key = "key=" + KeyList[0]; } Msg(string.Format("正在打开{0}{1}日志...", GetLogMsg(), IsPro ? "(生产环境)" : "(测试环境)")); Thread.Sleep(500); //System.Diagnostics.Process.Start("chrome.exe", "http:\www."+line+".com"); } private string GetLogMsg() { var result = string.Empty; if (d > 0) { result += d + "天内的"; } else if (h > 0) { result += h + "小时内的"; } else { result += "7天内的"; } if (k > 0 && k < support) { result += "会员" + TitleList[k - 1]; } else if (k >= support) { result += "协议" + TitleList[k - support]; } else { result += "会员" + TitleList[0]; } if (!string.IsNullOrEmpty(o)) { result += "&" + "orderId=" + o; } if (!string.IsNullOrEmpty(r)) { result += "&" + "roomId=" + r; } if (!string.IsNullOrEmpty(u)) { result += "&" + "uid=" + u; } if (!string.IsNullOrEmpty(c)) { result += "&" + "cityId=" + c; } return result; } private string getDateStr(DateTime begin, DateTime end) { string tf = "{0}~{1}"; var dformat = "yyyy-MM-dd HH:mm:ss"; return string.Format(tf, end.ToString(dformat), end.ToString(dformat)); } } } }