REPL LOG

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 = ; public static bool IsPro; public static List<string> KeyList = new List<string> { "xx", "yy", "zz", "" };
public static List<string> TitleList = new List<string> { "可定检查", "创建订单", "提交订单", "中间产品层" }; static LogHelper()
{
HelpText = "k+数字(默认是k1):\n\r ";
for (var i = ; i < TitleList.Count; i++)
{
HelpText += (i + ) + "." + TitleList[i] + "\n\r ";
}
HelpText += "默认会员,协议在数字前加0\n\rd/h+数字(默认是d7):\n\r 1.一天(h是小时)内日志\n\r 2.两天(h是小时)内日志\n\r 以此类推...\n\ro+数字:\n\r 打开ordeidr=数字的日志\n\rr+数字:\n\r 打开roomId=数字的日志\n\ru+卡号:\n\r 开的uid=卡号的日志\n\rc+数字:\n\r 打开cityID=数字的日志\n\rhelp:查看命令\n\rcls:清除屏幕\n\rec切换生产/测试环境";
} 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 = ;
var match = GetStr(prefix);
if (string.IsNullOrEmpty(match)) return ;
if (match.StartsWith(""))
{
contract = ;
}
return Convert.ToInt32(match) + contract;
} private string GetStr(string prefix)
{
Regex reg = new Regex(prefix + @"(\d+)", RegexOptions.Compiled);
return reg.Match(cmd).Groups[].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 > )
{
var begin = end.AddDays(-d);
dateStr = getDateStr(begin, end);
}
else if (h > )
{
var begin = end.AddHours(-h);
dateStr = getDateStr(begin, end);
}
else
{
var begin = end.AddDays(-);
dateStr = getDateStr(begin, end);
} if (k > && k < support)
{
key = "key=" + KeyList[k - ];
}
else if (k >= support)
{
key = "key=" + KeyList[k - support];
}
else
{
key = "key=" + KeyList[];
} Msg(string.Format("正在打开{0}{1}日志...", GetLogMsg(), IsPro ? "(生产环境)" : "(测试环境)"));
Thread.Sleep();
//System.Diagnostics.Process.Start("chrome.exe", "http:\\www."+line+".com");
} private string GetLogMsg()
{
var result = string.Empty;
if (d > )
{
result += d + "天内的";
}
else if (h > )
{
result += h + "小时内的";
}
else
{
result += "7天内的";
} if (k > && k < support)
{
result += "会员" + TitleList[k - ];
}
else if (k >= support)
{
result += "协议" + TitleList[k - support];
}
else
{
result += "会员" + TitleList[];
} 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));
}
}
}
}
上一篇:通用PE u盘装Ghost Win7系统


下一篇:XSS原理及防范