首页 > 代码库 > REPL LOG

REPL LOG

using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions;using System.Threading;namespace ConsoleApplication3{    class Program    {        static void Main(string[] args)        {            Console.ForegroundColor = DefaultForeColor;            Console.BackgroundColor = DefaultBackColor;            Console.Clear();            Console.Title = "日志查询工具";            Msg(HelpText);                       while (true)            {                        var line = Console.ReadLine().ToLower();                if (constCommand.ContainsKey(line))                {                    Msg(constCommand[line]);                    continue;                }                new LogHelper(line).Open();            }        }                public static void Msg(string str)        {            Show(str, MessageForeColor);        }                public static void Show(string message , ConsoleColor color)        {            Console.ForegroundColor = MessageForeColor;            Console.WriteLine(message);            Console.ForegroundColor = DefaultForeColor;        }        public static ConsoleColor DefaultForeColor = ConsoleColor.White;        public static ConsoleColor DefaultBackColor = ConsoleColor.DarkBlue;        public static ConsoleColor MessageForeColor = ConsoleColor.DarkCyan;               public static string HelpText = "k+数字:\n\r 1.可定检查\n\r 2.创建订单\n\r 3.提交订单\n\r 4.中间产品层\n\rd/h+数字:\n\r 1.一天(h是小时)内日志\n\r 2.两天(h是小时)内日志\n\r以此类推... ";        public static List<string> KeyList = new List<string> { "xx", "yy", "zz", "88" };        public static Dictionary<string, string> constCommand = new Dictionary<string, string> { { "help", HelpText }, { "", "默认查询" } };        public class LogHelper        {            private string cmd,msg,url;            private int k, d, h;            public LogHelper(string cmd)            {                this.cmd = cmd.ToLower();             }                        private int GetNumber(string prefix)            {                Regex reg = new Regex( prefix + "([1-9]+)", RegexOptions.Compiled);                var match = reg.Match(cmd).Groups[1].ToString();                if (string.IsNullOrEmpty(match)) return 0;                return Convert.ToInt32(match);            }            public void Open()            {                k = GetNumber("k");                d = GetNumber("d");                h = GetNumber("h");                //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);                }                if (k > 0)                {                    key = "key=" + KeyList[k - 1];                }                Msg("正在打开1天内的可定检查日志...");                Thread.Sleep(500);                //System.Diagnostics.Process.Start("chrome.exe", "http:\\www."+line+".com");            }            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));            }        }    }}

 

REPL LOG