Ejemplo n.º 1
0
        /// <summary>
        /// This is where console interaction begins, much like the static main()
        /// method in a traditional console app.
        /// </summary>
        public async override Task MainAsync()
        {
            var sysForeground = System.ConsoleColor.White;

            Console.BackgroundColor = System.ConsoleColor.DarkBlue;
            Console.Clear();

            Console.ForegroundColor = sysForeground;
            Console.WriteLine("Press any key to start the fun, including special keys such as [F1], [->], [Enter/Return], number pad, etc.");
            Console.WriteLine("Modify by simultaneously pressing [Shift], [Ctrl], [Alt], [Windows or ⌘].");
            Console.WriteLine("[Esc] to quit");

            Console.ForegroundColor = System.ConsoleColor.Cyan;

            System.ConsoleKey ck = System.ConsoleKey.NoName;
            while (System.ConsoleKey.Escape != ck)
            {
                var value = await Console.ReadKeyAsync();

                ck = value.Key;
                var s = ck.ToString();
                if (value.Modifiers != 0)
                {
                    s += " " + value.Modifiers.ToString();
                }
                Console.WriteLine(s);
            }
            ;

            Console.ForegroundColor = sysForeground;
            Console.WriteLine();
            Console.WriteLine("All done!");
        }
Ejemplo n.º 2
0
        } // End Task RunAsPlatformIndependentService

        // static async System.Threading.Tasks.Task MainTask(string[] args)
        protected async System.Threading.Tasks.Task RunAsWindowsService(string[] args)
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Console Debug mode
                GenericService svc = this.m_host.Services.GetService <System.ServiceProcess.ServiceBase>() as GenericService;
                svc.StartService(args);

                // System.Console.ReadLine();

                System.ConsoleKey cc = default(System.ConsoleKey);
                do
                {
                    // THIS IS MADNESS!!!   Madness huh?   THIS IS SPARTA!!!!!!!
                    while (!System.Console.KeyAvailable)
                    {
                        // System.Threading.Thread.Sleep(100);
                        await System.Threading.Tasks.Task.Delay(100);
                    }

                    cc = System.Console.ReadKey().Key;

                    if (cc == System.ConsoleKey.C)
                    {
                        System.Console.Clear();
                    }
                } while (cc != System.ConsoleKey.Enter);

                svc.Stop();
            }
            else
            {
                // Start service
                System.ServiceProcess.ServiceBase[] servicesToRun;
                servicesToRun = new System.ServiceProcess.ServiceBase[]
                {
                    this.m_host.Services.GetService <System.ServiceProcess.ServiceBase>()
                };

                System.ServiceProcess.ServiceBase.Run(servicesToRun);
            } // End else of if (System.Diagnostics.Debugger.IsAttached)

            // await System.Threading.Tasks.Task.CompletedTask;
        } // End Task RunAsWindowsService
Ejemplo n.º 3
0
        } // End Sub WaitForKeyPress

        static void WaitForEnter()
        {
            System.ConsoleKey cc = default(System.ConsoleKey);

            do
            {
                // THIS IS MADNESS!!!   Madness huh?   THIS IS SPARTA!!!!!!!
                while (!System.Console.KeyAvailable)
                {
                    System.Threading.Thread.Sleep(100);
                }

                cc = System.Console.ReadKey().Key;

                if (cc == System.ConsoleKey.C)
                {
                    System.Console.Clear();
                }
            } while (cc != System.ConsoleKey.Enter);
        } // End Sub WaitForEnter
Ejemplo n.º 4
0
 public ConsoleKeyInfo(char keyChar, System.ConsoleKey key, bool shift, bool alt, bool control)
 {
     throw null;
 }
Ejemplo n.º 5
0
        } // End Sub Main

        static void DoProfiling(string[] args)
        {
            // https://github.com/dotnet/coreclr/issues/8565
            // https://shazwazza.com/post/aspnet-core-application-shutdown-events/
            // Will not be executed when !windows
            WindowsFix.AddConsoleHandler(ConsoleCtrlCheck);

            System.AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            System.AppDomain.CurrentDomain.ProcessExit        += CurrentDomain_ProcessExit;
            System.Console.CancelKeyPress += Console_CancelKeyPress;

            System.Collections.Generic.Dictionary <string, string> defaultValues =
                new System.Collections.Generic.Dictionary <string, string>();

            defaultValues["server"] = GetPlatformDefaultInstance();
            defaultValues["db"]     = "COR_Basic_Demo_V4";

            System.Collections.Generic.Dictionary <string, Argument> arg_list =
                GetCommandLineArguments(args, defaultValues);


            if (arg_list["showinput"].IsPresent)
            {
                ShowInput(args);
                System.Console.WriteLine(System.Environment.NewLine);
                System.Console.WriteLine("--- Press any key to stop continue --- ");
                System.Console.ReadKey();
                return;
            }

            if (arg_list["list"].IsPresent)
            {
                ListValues(arg_list);
                System.Console.WriteLine(System.Environment.NewLine);
                System.Console.WriteLine("--- Press any key to stop continue --- ");
                System.Console.ReadKey();
                return;
            }

            if (arg_list["help"].IsPresent)
            {
                Help(arg_list);
                System.Console.WriteLine(System.Environment.NewLine);
                System.Console.WriteLine("--- Press any key to stop continue --- ");
                System.Console.ReadKey();
                return;
            }


            string server   = arg_list["server"].Value <string>();
            string db       = arg_list["db"].Value <string>();
            string username = arg_list["username"].Value <string>();
            string password = arg_list["password"].Value <string>();


            s_profiler = new ExpressProfiler.SqlServerProfiler(server, db, username, password);

            s_profiler.StartProfiling();


            System.Console.ResetColor();

            // System.Console.WriteLine("--- Press ENTER to stop profiling --- ");
            // System.Console.ReadLine();

            // System.Console.WriteLine("--- Press any key to stop profiling --- ");
            // System.Console.ReadKey();

            System.Console.WriteLine("--- Press ENTER to stop profiling --- ");

            System.ConsoleKey cc = default(System.ConsoleKey);

            do
            {
                // THIS IS MADNESS!!!   Madness huh?   THIS IS SPARTA!!!!!!!
                while (!System.Console.KeyAvailable)
                {
                    System.Threading.Thread.Sleep(100);
                }

                cc = System.Console.ReadKey().Key;

                if (cc == System.ConsoleKey.C)
                {
                    System.Console.Clear();
                }
            } while (cc != System.ConsoleKey.Enter);

            OnExit();
        } // End Sub Test
Ejemplo n.º 6
0
 public ConsoleKeyInfo(char keyChar, System.ConsoleKey key, bool shift, bool alt, bool control)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 7
0
 public abstract void Step(System.ConsoleKey direction);
Ejemplo n.º 8
0
        } // End Task RunAsPlatformIndependentService

        // static async System.Threading.Tasks.Task MainTask(string[] args)
        static async System.Threading.Tasks.Task RunAsWindowsService(string[] args)
        {
            Microsoft.Extensions.DependencyInjection.IServiceCollection services =
                new Microsoft.Extensions.DependencyInjection.ServiceCollection();

            // Create configuration builder
            Microsoft.Extensions.Configuration.IConfigurationBuilder configurationBuilder =
                new Microsoft.Extensions.Configuration.ConfigurationBuilder()
                .SetBasePath(System.IO.Directory.GetCurrentDirectory())
                // .AddIniFile(@"D:\inetpub\LdapService\LdapService.ini")
                //.AddJsonFile("appsettings.json")
            ;

            // Inject configuration
            services.AddSingleton <Microsoft.Extensions.Configuration.IConfiguration>(provider =>
            {
                return(configurationBuilder.Build());
            });


            // Inject Serilog
            services.AddLogging(options =>
            {
                options.SetMinimumLevel(LogLevel.Information);
                options.AddFilter(x => x >= LogLevel.Trace);

                options.AddConsole();
                options.AddDebug();

                /*
                 * options.AddSerilog(
                 *  new LoggerConfiguration()
                 *             .ReadFrom.Configuration(configurationBuilder.Build())
                 *             .CreateLogger()
                 *  );
                 */
            });


            // Inject common service
            services.AddSingleton(typeof(ICommonService), typeof(CommonSampleService));

            // Inject concrete implementation of the service
            services.AddSingleton(typeof(System.ServiceProcess.ServiceBase), typeof(GenericService));

            // My configuration
            services.AddSingleton(new MyConfig());

            services.Configure <SmtpConfig>(
                delegate(SmtpConfig config)
            {
                config.Server = "hello world";
                return;
            }
                );


            /*
             * // IConfiguration Configuration = null;
             *
             * // services.Configure<SmtpConfig>(Configuration.GetSection("Smtp"));
             * // IConfiguration iconf = Configuration.GetSection("Smtp");
             * Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<SmtpConfig>(
             *  services, iconf
             * );
             */


            // Build DI provider
            Microsoft.Extensions.DependencyInjection.ServiceProvider serviceProvider = services.BuildServiceProvider();


            if (System.Diagnostics.Debugger.IsAttached)
            {
                // Console Debug mode

                /*
                 * try
                 * {
                 *  IConfiguration confy = serviceProvider.GetService<IConfiguration>();
                 *  System.Console.WriteLine(confy);
                 *  // var sec = confy.GetSection("ErrorMail2");
                 *  // https://stackoverflow.com/questions/39169701/how-to-extract-a-list-from-appsettings-json-in-net-core
                 *  // foreach (var section in confy.GetChildren()) section.GetChildren();
                 *
                 *
                 *  // Fixes to IniStreamConfigurationProvider.cs:if (separator < 0)
                 *  var jobs = confy.GetSection("Jobs").Get<System.Collections.Generic.Dictionary<string, string>>();
                 *  var sec = confy.GetSection("ErrorMail2").Get<System.Collections.Generic.Dictionary<string, string>>();
                 *
                 *  // sec.Keys, sec.Values
                 *
                 *  System.Console.WriteLine(sec);
                 *  System.Console.WriteLine(jobs);
                 *
                 *
                 * }
                 * catch (System.Exception ex)
                 * {
                 *  System.Console.WriteLine(ex.Message);
                 * }
                 */



                GenericService svc = serviceProvider.GetService <System.ServiceProcess.ServiceBase>() as GenericService;
                svc.StartService(args);

                // System.Console.ReadLine();

                System.ConsoleKey cc = default(System.ConsoleKey);
                do
                {
                    // THIS IS MADNESS!!!   Madness huh?   THIS IS SPARTA!!!!!!!
                    while (!System.Console.KeyAvailable)
                    {
                        // System.Threading.Thread.Sleep(100);
                        await System.Threading.Tasks.Task.Delay(100);
                    }

                    cc = System.Console.ReadKey().Key;

                    if (cc == System.ConsoleKey.C)
                    {
                        System.Console.Clear();
                    }
                } while (cc != System.ConsoleKey.Enter);

                svc.Stop();
            }
            else
            {
                // Start service
                System.ServiceProcess.ServiceBase[] servicesToRun;
                servicesToRun = new System.ServiceProcess.ServiceBase[]
                {
                    serviceProvider.GetService <System.ServiceProcess.ServiceBase>()
                };

                System.ServiceProcess.ServiceBase.Run(servicesToRun);
            } // End else of if (System.Diagnostics.Debugger.IsAttached)

            // await System.Threading.Tasks.Task.CompletedTask;
        } // End Task RunAsWindowsService