} // CurrentDomain_ProcessExit /// <summary> /// Mains the main entry to the program. /// </summary> /// <param name="args">The arguments to the program.</param> /// <exception cref="System.NotImplementedException"> /// Exception thrown if incorrect parameters are passed to the command-line. /// </exception> public static void Main(string[] args) { try { LogEngine.Init(); LogEngine.ConsoleWriteLine( $"Version {Assembly.GetExecutingAssembly().GetName().Version}", ConsoleColor.Green); if (Configuration.DisableExternalEventsStreamEngine()) { LogEngine.WriteLog( Configuration.EngineName, "Warning the Device Provider Interface is disable, the GrabCaster point will be able to work in local mode only.", Constant.DefconThree, Constant.TaskCategoriesError, null, EventLogEntryType.Warning); } if (!Environment.UserInteractive) { Debug.WriteLine("GrabCaster-servicesToRun procedure initialization."); ServiceBase[] servicesToRun = { new NTWindowsService() }; Debug.WriteLine("GrabCaster-servicesToRun procedure starting."); ServiceBase.Run(servicesToRun); } else { if (args.Length == 0) { // Set Console windows Console.Title = Configuration.PointName(); Console.SetWindowPosition(0, 0); Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"[M] Run GrabCaster in MS-DOS Console mode."); Console.WriteLine(@"[I] Install GrabCaster Windows NT Service."); Console.WriteLine(@"[U] Uninstall GrabCaster Windows NT Service."); Console.WriteLine(@"[C] Clone a new GrabCaster Point."); Console.WriteLine(@"[Ctrl + C] Exit."); Console.ForegroundColor = ConsoleColor.White; var consoleKeyInfo = Console.ReadKey(); switch (consoleKeyInfo.Key) { case ConsoleKey.M: AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit; LogEngine.ConsoleWriteLine( "--GrabCaster Sevice Initialization--Start Engine.", ConsoleColor.Green); CoreEngine.StartEventEngine(null); Console.ReadLine(); break; case ConsoleKey.I: Console.ForegroundColor = ConsoleColor.White; Console.Clear(); CoreNtService.ServiceName = AskInputLine("Specify the Windows NT Service Name:"); CoreNtService.InstallService(); break; case ConsoleKey.U: Console.ForegroundColor = ConsoleColor.White; Console.Clear(); CoreNtService.ServiceName = AskInputLine("Specify the Windows NT Service Name:"); CoreNtService.StopService(); CoreNtService.UninstallService(); break; case ConsoleKey.C: //string CloneName = AskInputLine("Enter the Clone name."); Process.Start(Path.Combine(Application.StartupPath, "Create new Clone.cmd")); break; } } //if else { //Run in batch and console mode if (args.Length == 1 && args[0] == "-console".ToLower()) { LogEngine.ConsoleWriteLine( "--GrabCaster Sevice Initialization--Start Engine.", ConsoleColor.Green); CoreEngine.StartEventEngine(null); Console.ReadLine(); } else if (args.Length == 2 && args[0] == "-ntinstall".ToLower()) { CoreNtService.ServiceName = string.Concat("GrabCaster", args[1]); CoreNtService.InstallService(); Environment.Exit(0); } else if (args.Length == 2 && args[0] == "-ntuninstall".ToLower()) { CoreNtService.ServiceName = string.Concat("GrabCaster", args[1]); CoreNtService.StopService(); CoreNtService.UninstallService(); Environment.Exit(0); } else { Console.Clear(); LogEngine.ConsoleWriteLine( @"GrabCaster [-console] [-ntinstall servicename] [-ntuninstall servicename]", ConsoleColor.Green); LogEngine.ConsoleWriteLine("", ConsoleColor.DarkGreen); LogEngine.ConsoleWriteLine( @"[-console] Execute GrabCaster in MS Dos console mode.", ConsoleColor.Green); LogEngine.ConsoleWriteLine( "[-ntinstall servicename] Install jiGate as Windows NT Service servicename.", ConsoleColor.Green); LogEngine.ConsoleWriteLine( "[-ntuninstall servicename] Uninstall the GrabCaster Windows NT Service servicename.", ConsoleColor.Green); Console.ReadLine(); Environment.Exit(0); } } } // if } catch (NotImplementedException ex) { Methods.DirectEventViewerLog(ex); LogEngine.WriteLog( Configuration.EngineName, "Error in " + MethodBase.GetCurrentMethod().Name, Constant.DefconOne, Constant.TaskCategoriesError, ex, EventLogEntryType.Error); } catch (Exception ex) { Methods.DirectEventViewerLog(ex); Environment.Exit(0); } // try/catch finally { //Spool log queues if (LogEngine.QueueAbstractMessage != null) { LogEngine.QueueAbstractMessageOnPublish(LogEngine.QueueAbstractMessage.ToArray().ToList()); } if (LogEngine.QueueConsoleMessage != null) { LogEngine.QueueConsoleMessageOnPublish(LogEngine.QueueConsoleMessage.ToArray().ToList()); } } } // Main
} // CurrentDomain_ProcessExit /// <summary> /// Mains the main entry to the program. /// </summary> /// <param name="args">The arguments to the program.</param> /// <exception cref="System.NotImplementedException"> /// Exception thrown if incorrect parameters are passed to the command-line. /// </exception> public static void Main(string[] args) { try { LogEngine.Init(); Debug.WriteLine( $"Version {Assembly.GetExecutingAssembly().GetName().Version}", ConsoleColor.Green); if (!Environment.UserInteractive) { Debug.WriteLine( "GrabCaster-services To Run - Not UserInteractive Environment the service will start in ServiceBase mode."); if (args.Length > 0) { //Run in batch and console mode Debug.WriteLine( $"GrabCaster-services To Run - Command line > 0 start NT Service mode . args = {args[0]}."); switch (args[0].ToUpper()) { case "S": Debug.WriteLine("GrabCaster-services To Run - Service Fabric mode requested."); Debug.WriteLine( "--GrabCaster Sevice Initialization--Start Engine."); CoreEngine.StartEventEngine(null); Console.WriteLine("\rEngine started..."); Console.ReadLine(); break; case "M": AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit; Debug.WriteLine( "--GrabCaster Sevice Initialization--Start Engine."); CoreEngine.StartEventEngine(null); Console.WriteLine("\rEngine started..."); Console.ReadLine(); break; default: break; } } else { Debug.WriteLine("GrabCaster-services To Run - Command line = 0 start NT Service mode."); Debug.WriteLine( $"GrabCaster-services To Run - Environment.OSVersion:{Environment.OSVersion} Environment.Version:{Environment.Version}"); Debug.WriteLine("GrabCaster-services To Run procedure initialization."); ServiceBase[] servicesToRun = {new NTWindowsService()}; Debug.WriteLine("GrabCaster-services To Run procedure starting."); ServiceBase.Run(servicesToRun); } } else { if (args.Length == 0) { // Set Console windows Console.Title = ConfigurationBag.Configuration.PointName; Console.SetWindowPosition(0, 0); Console.Clear(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(@"[M] Run GrabCaster in MS-DOS Console mode."); Console.WriteLine(@"[I] Install GrabCaster Windows NT Service."); Console.WriteLine(@"[U] Uninstall GrabCaster Windows NT Service."); Console.WriteLine(@"[O] Clone a new GrabCaster Point."); Console.WriteLine(@"[Ctrl + C] Exit."); Console.ForegroundColor = ConsoleColor.White; var consoleKeyInfo = Console.ReadKey(); string param1 = ";"; switch (consoleKeyInfo.Key) { case ConsoleKey.M: AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit; Debug.WriteLine( "--GrabCaster Sevice Initialization--Start Engine.", ConsoleColor.Green); CoreEngine.StartEventEngine(null); Console.WriteLine("\rEngine started..."); Console.ReadLine(); break; case ConsoleKey.C: //string CloneName = AskInputLine("Enter the Clone name."); Process.Start(Path.Combine(Application.StartupPath, "Create new Clone.cmd")); break; case ConsoleKey.I: Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.WriteLine("Specify the Windows NT Service Name and press Enter:"); CoreNtService.ServiceName = AskInputLine("Specify the Windows NT Service Name:"); CoreNtService.InstallService(); break; case ConsoleKey.U: Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.WriteLine("Specify the Windows NT Service Name and press Enter:"); CoreNtService.ServiceName = AskInputLine("Specify the Windows NT Service Name:"); CoreNtService.StopService(); CoreNtService.UninstallService(); break; case ConsoleKey.S: //string CloneName = AskInputLine("Enter the Clone name."); Process.Start(Path.Combine(Application.StartupPath, "Create new Clone.cmd")); break; case ConsoleKey.B: param1 = AskInputLine("Enter the BizTalk installation folder."); Process.Start(Path.Combine(Application.StartupPath, $"Create new Clone.cmd {param1}")); break; case ConsoleKey.O: //string CloneName = AskInputLine("Enter the Clone name."); Process.Start(Path.Combine(Application.StartupPath, "Create new Clone.cmd")); break; } } //if else { //Run in batch and console mode if (args.Length == 1 && args[0].ToUpper() == "M") { Debug.WriteLine( "--GrabCaster Sevice Initialization--Start Engine.", ConsoleColor.Green); CoreEngine.StartEventEngine(null); Console.WriteLine("\rEngine started..."); Console.ReadLine(); } else if (args.Length == 2 && args[0].ToUpper() == "I") { CoreNtService.ServiceName = string.Concat("GrabCaster", args[1]); CoreNtService.InstallService(); Environment.Exit(0); } else if (args.Length == 2 && args[0].ToUpper() == "U") { CoreNtService.ServiceName = string.Concat("GrabCaster", args[1]); CoreNtService.StopService(); CoreNtService.UninstallService(); Environment.Exit(0); } else { Console.Clear(); Debug.WriteLine( @"GrabCaster [M] [I] [U]", ConsoleColor.Green); Debug.WriteLine("M", ConsoleColor.DarkGreen); Debug.WriteLine( @"[M] Execute GrabCaster in MS Dos console mode.", ConsoleColor.Green); Debug.WriteLine( "[I servicename] Install GrabCaster as Windows NT Service servicename.", ConsoleColor.Green); Debug.WriteLine( "[U servicename] Uninstall GrabCaster Windows NT Service servicename.", ConsoleColor.Green); Console.ReadLine(); Environment.Exit(0); } } } // if } catch (NotImplementedException ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, "Error in " + MethodBase.GetCurrentMethod().Name, Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); } catch (Exception ex) { LogEngine.WriteLog( ConfigurationBag.EngineName, "Error in " + MethodBase.GetCurrentMethod().Name, Constant.LogLevelError, Constant.TaskCategoriesError, ex, Constant.LogLevelError); Environment.Exit(0); } // try/catch finally { //Spool log queues if (LogEngine.QueueAbstractMessage != null) { LogEngine.QueueAbstractMessageOnPublish(LogEngine.QueueAbstractMessage.ToArray().ToList()); } if (LogEngine.QueueConsoleMessage != null) { LogEngine.QueueConsoleMessageOnPublish(LogEngine.QueueConsoleMessage.ToArray().ToList()); } } } // Main