public static DataArgs ParseArgs(string[] args) { DataArgs options = new DataArgs(); 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("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(DataArgs 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) { DataArgs options = DataArgs.ParseArgs(args); try { SetWindowPositionAndDimensions(options); string[] files = options.DataFile.Split(','); string[] senderIds = options.SenderId.Split(','); int taskId = int.Parse(senderIds[0]); taskFile = new FileInfo(files[0]); int projectId = int.Parse(senderIds[1]); projectFile = new FileInfo(files[1]); taskNetList = new TodoNetList(); projectNetList = new ProjectNetList(); taskNetList.Start <Todo>(options.ConnectionString, taskId, options.LogFile, taskFile); projectNetList.Start <Project>(options.ConnectionString, projectId, options.LogFile, projectFile); System.Timers.Timer autoSaveTimer = new System.Timers.Timer(); autoSaveTimer.Elapsed += autoSaveTimer_Elapsed; autoSaveTimer.Interval = 5000; autoSaveTimer.Enabled = true; System.Timers.Timer halfHourSaveTimer = new System.Timers.Timer(); halfHourSaveTimer.Elapsed += halfHourSaveTimer_Elapsed; halfHourSaveTimer.Interval = 1800000; halfHourSaveTimer.Enabled = true; } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(string.Format("Start Exception: {0}", ex.Message)); Console.ForegroundColor = ConsoleColor.Green; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Press any key to exit."); ConsoleKeyInfo key = Console.ReadKey(); if (key.Key == ConsoleKey.S) { Console.ReadKey(); } }