public static ConsoleMonitorArgs ParseArgs(string[] args) { ConsoleMonitorArgs options = new ConsoleMonitorArgs(); if (!CommandLine.Parser.Default.ParseArguments(args, options)) { Console.WriteLine("Wrong params. Press any key to close."); foreach (string arg in args) { Console.WriteLine(arg); } Console.ReadKey(); Environment.Exit(100); } // Show results Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine(string.Format("Connection string: '{0}'", options.ConnectionString)); Console.WriteLine("Filters:"); Console.WriteLine(string.Format("Use OR between filters: '{0}'", options.UseOr)); Console.WriteLine(string.Format("Sender: '{0}'", options.Sender)); Console.WriteLine(string.Format("Recipient: '{0}'", options.Recipient)); Console.WriteLine(string.Format("Event: '{0}'", options.Event)); Console.WriteLine(string.Format("Method: '{0}'", options.Method)); Console.WriteLine(string.Format("LogFile: '{0}'", options.LogFile)); Console.WriteLine(string.Format("[Position] Top: '{0}' Left: '{1}'", options.Top, options.Left)); Console.WriteLine(string.Format("[Dimensions] Width: '{0}' Height:'{1}'", options.Width, options.Height)); Console.ResetColor(); return(options); }
private static void SetWindowPositionAndDimensions(ConsoleMonitorArgs options) { if (options.Left > 0 || options.Top > 0) { int xpos = options.Left; int ypos = options.Top; SetWindowPos(MyConsole, 0, xpos, ypos, 0, 0, SWP_NOSIZE); } if (options.Width > 0 && options.Height > 0) { Console.SetWindowSize(options.Width, options.Height); } }
static void Main(string[] args) { ConsoleMonitorArgs options = ConsoleMonitorArgs.ParseArgs(args); SetWindowPositionAndDimensions(options); Filter filter = new Filter(); filter.EventList = Filter.ParseCommaSeparatedIntegers(options.Event); filter.MethodList = Filter.ParseCommaSeparatedIntegers(options.Method); filter.RecipientList = Filter.ParseCommaSeparatedIntegers(options.Recipient); filter.SenderList = Filter.ParseCommaSeparatedIntegers(options.Sender); Console.ForegroundColor = ConsoleColor.Green; cancelationToken = new CancellationTokenSource(); Thread.Sleep(1000); Task.Factory.StartNew(() => Process(options.ConnectionString, filter, options.LogFile, cancelationToken.Token)) .ContinueWith(antecedant => { Console.WriteLine("Process Stopped."); if (options.LogFile != null && options.LogFile != string.Empty) { logFileStreamWriter.Close(); logFileFileStream.Close(); } }); Console.WriteLine("Press any key to exit."); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.S) { cancelationToken.Cancel(); Console.ReadKey(); } }