예제 #1
0
        public static int Main(string[] args)
        {
            var path   = new PathToEnlightenment();
            var sensei = new Sensei(Reporter.Output);

            return(path.Walk(sensei, AnsiConsole.GetOutput()));
        }
예제 #2
0
 /// <summary>
 /// Resets the Reporters to write to the current Console Out/Error.
 /// </summary>
 public static void Reset()
 {
     lock (_lock)
     {
         Output = new Reporter(AnsiConsole.GetOutput());
         Error  = new Reporter(AnsiConsole.GetError());
     }
 }
예제 #3
0
 /// <summary>
 /// Resets the Reporters to write to the current Console Out/Error.
 /// </summary>
 public static void Reset()
 {
     lock (_lock)
     {
         Output  = new Reporter(AnsiConsole.GetOutput());
         Error   = new Reporter(AnsiConsole.GetError());
         Verbose = IsVerbose ?
                   new Reporter(AnsiConsole.GetOutput()) :
                   NullReporter;
     }
 }
예제 #4
0
        private IServiceProvider ConfigureConsoleServices(IServiceCollection services)
        {
            services.AddOptions();

            services.AddLogging();

            //register config options
            services.Configure <MailHistoryDbSettings>(Config.GetSection("MailHistoryDbSettings"));

            services.Configure <TestMessageSettings>(Config.GetSection("TestMessageSettings"));

            services.Configure <MkSmtpMailerSettings>(Config.GetSection("MailSettings:MkSmtpMailerSettings"));

            services.Configure <SendGridMailerSettings>(Config.GetSection("MailSettings:SendGridMailerSettings"));

            services.Configure <SqlEntityHistoryStoreSettings>(Config.GetSection("MailHistoryDbSettings"));

            services.AddMailerSqlHistory(s => s.GetService <IOptions <SqlEntityHistoryStoreSettings> >().Value);



            ////alternate way to instantiate history
            //var connectionString = Config.GetValue<string>("MailHistoryDbSettings:ConnectionString");
            //services.AddMailerSqlHistory(settings => settings.ConnectionString = connectionString);

            ////another alternate way to instantiate history
            //var connectionString = Config.GetValue<string>("MailHistoryDbSettings:ConnectionString");
            //services.AddMailerSqlHistory(new SqlEntityHistoryStoreSettings { ConnectionString = connectionString });

            //Configure a mailer
            var activeMailService = Config.GetSection("MailSettings:ActiveMailService")?.Value.ToLowerInvariant();

            switch (activeMailService)
            {
            case "sendgrid":
                services.AddSendGridMailer(s => s.GetService <IOptions <SendGridMailerSettings> >().Value);
                break;

            case "mailkit":
                services.AddMkSmtpMailer(s => s.GetService <IOptions <MkSmtpMailerSettings> >().Value);
                break;
            }

            //snazzy
            services.AddSingleton(provider => AnsiConsole.GetOutput(true));

            //add the cli commands
            services.AddTransient <SendMail>();
            services.AddTransient <SendSimpleMessage>();
            services.AddTransient <SendTemplateMessage>();
            services.AddTransient <DropDb>();

            return(services.BuildServiceProvider());
        }
예제 #5
0
 private void ShowLogo()
 {
     // TODO: Enable multiple parameters in escape sequences
     AnsiConsole.GetOutput(_useConsoleColors).WriteLine(
         "\x1b[1m\x1b[37m" + Environment.NewLine +
         "                     _/\\__" + Environment.NewLine +
         "               ---==/    \\\\" + Environment.NewLine +
         "        \x1b[22m\x1b[35m ___  ___ \x1b[1m\x1b[37m  |\x1b[22m.\x1b[1m    \\|\\" + Environment.NewLine +
         "        \x1b[22m\x1b[35m| __|| __|\x1b[1m\x1b[37m  |  )   \\\\\\" + Environment.NewLine +
         "        \x1b[22m\x1b[35m| _| | _| \x1b[1m\x1b[37m  \\_/ |  //|\\\\" + Environment.NewLine +
         "        \x1b[22m\x1b[35m|___||_|  \x1b[1m\x1b[37m     /   \\\\\\/\\\\" + Environment.NewLine +
         "\x1b[22m\x1b[39m");
 }
예제 #6
0
        public static Reports CreateReports(bool verbose, bool quiet)
        {
            bool    useConsoleColor = _runtimeEnv.OperatingSystem == "Windows";
            IReport report          = new Report(AnsiConsole.GetOutput(useConsoleColor));
            Reports reports         = new Reports
            {
                Information = report,
                Verbose     = verbose ? report : Reports.Constants.NullReport,
                Error       = new Report(AnsiConsole.GetError(useConsoleColor))
            };

            reports.Quiet = (quiet ? reports.Verbose : report);
            return(reports);
        }
예제 #7
0
        public virtual void ShowLogo()
        {
            var useConsoleColors = _runtimeEnv.OperatingSystem == "Windows";

            // TODO: Enable multiple parameters in escape sequences
            AnsiConsole.GetOutput(useConsoleColors).WriteLine(
                "\x1b[1m\x1b[37m" + Environment.NewLine +
                "                     _/\\__" + Environment.NewLine +
                "               ---==/    \\\\" + Environment.NewLine +
                "        \x1b[22m\x1b[35m ___  ___ \x1b[1m\x1b[37m  |\x1b[22m.\x1b[1m    \\|\\" + Environment.NewLine +
                "        \x1b[22m\x1b[35m| __|| __|\x1b[1m\x1b[37m  |  )   \\\\\\" + Environment.NewLine +
                "        \x1b[22m\x1b[35m| _| | _| \x1b[1m\x1b[37m  \\_/ |  //|\\\\" + Environment.NewLine +
                "        \x1b[22m\x1b[35m|___||_|  \x1b[1m\x1b[37m     /   \\\\\\/\\\\" + Environment.NewLine +
                "\x1b[22m\x1b[39m");
        }
예제 #8
0
        public Reports CreateReports(bool verbose, bool quiet)
        {
            var useConsoleColor = _runtimeEnv.OperatingSystem == "Windows";

            IReport output  = new Report(AnsiConsole.GetOutput(useConsoleColor));
            var     reports = new Reports()
            {
                Information = output,
                Verbose     = verbose ? output : Reports.Constants.NullReport,
                Error       = new Report(AnsiConsole.GetError(useConsoleColor))
            };

            // If "--verbose" and "--quiet" are specified together, "--verbose" wins
            reports.Quiet = quiet ? reports.Verbose : output;

            return(reports);
        }
예제 #9
0
        static async Task <int> Watch(IConfiguration config)
        {
            try {
                var runner = new CommandRunner(config);
                Preamble(config);
                var cts = new CancellationTokenSource();
                Console.CancelKeyPress += (_, e) => cts.Cancel();
                await runner.Run(cts.Token);

                return(0);
            } catch (ArgumentException) {
                App.Current.ShowHelp();
                return(1);
            } catch (Exception e) {
                AnsiConsole
                .GetOutput()
                .WriteLine($"{"Unexpected error".Red().Bold()}: {e.Message}");
                return(2);
            }
        }
예제 #10
0
        private void LogInternal(string logLevel, string message)
        {
            var caption = string.Empty;

            if (_useConsoleColor)
            {
                switch (logLevel)
                {
                case Debug:
                    caption = "\x1b[35mdebug\x1b[39m";
                    break;

                case Information:
                    caption = "\x1b[32minfo \x1b[39m";
                    break;

                case Warning:
                    caption = "\x1b[33mwarn \x1b[39m";
                    break;

                case Error:
                    caption = "\x1b[31merror\x1b[39m";
                    break;

                case Verbose:
                    caption = "\x1b[35mtrace\x1b[39m";
                    break;
                }
            }
            else
            {
                caption = logLevel;
            }

            lock (Console.Out)
            {
                AnsiConsole.GetOutput(_useConsoleColor).WriteLine($"{caption}: {message}");
            }
        }
예제 #11
0
 public CommandOutputLogger(CommandOutputProvider commandOutputProvider, string loggerName)
 {
     _provider   = commandOutputProvider;
     _outConsole = AnsiConsole.GetOutput();
     _loggerName = loggerName;
 }
예제 #12
0
 void ErrorReceived(object sender, DataReceivedEventArgs e) =>
     AnsiConsole.GetOutput().WriteLine(e.Data.Red());
예제 #13
0
        static Program()
        {
            var useConsoleColors = PlatformServices.Default.Runtime.OperatingSystem == "Windows";

            _ansiConsole = AnsiConsole.GetOutput(useConsoleColors);
        }
예제 #14
0
 public CommandOutputLogger(CommandOutputProvider commandOutputProvider, bool useConsoleColor)
 {
     _provider   = commandOutputProvider;
     _outConsole = AnsiConsole.GetOutput(useConsoleColor);
 }
예제 #15
0
        // Print argument summary
        static void Preamble(IConfiguration config)
        {
            var dir = !String.IsNullOrEmpty(config.Directory) ?
                      config.Directory : Directory.GetCurrentDirectory();

            var workDir = !String.IsNullOrEmpty(config.WorkingDirectory) ?
                          config.WorkingDirectory : dir;

            var includes = (config.IncludePatterns?.Count ?? 0) > 0 ?
                           config.IncludePatterns : new[] { "**/*.*" };

            var @out = AnsiConsole.GetOutput();

            @out.WriteLine(
                "  ,——._.,——,—.\n" +
                " ( @ ) ( @ )  \\  [GlobWatch]\n" +
                "  `—´   `—´\n"
                );

            @out.WriteLine("- Watching:");
            foreach (var i in includes)
            {
                @out.WriteLine($"  - {i.Green().Bold()}");
            }

            if ((config.ExcludePatterns?.Count ?? 0) > 0)
            {
                @out.WriteLine("- Except:");
                foreach (var i in config.ExcludePatterns)
                {
                    @out.WriteLine($"  - {i.Red().Bold()}");
                }
            }

            @out.WriteLine($"- Inside: {dir.Cyan()}");

            if (config.IgnoreCase)
            {
                @out.WriteLine("- Ignore Case");
            }

            if (config.WatchedEvents != 0 && config.WatchedEvents != WatcherChangeTypes.All)
            {
                string events = null;
                if (config.WatchedEvents.HasFlag(WatcherChangeTypes.Created))
                {
                    events = "Created";
                }
                if (config.WatchedEvents.HasFlag(WatcherChangeTypes.Changed))
                {
                    events = events == null ? "Modified" : $"{events}, modified";
                }
                if (config.WatchedEvents.HasFlag(WatcherChangeTypes.Deleted))
                {
                    events = events == null ? "Deleted" : $"{events}, deleted";
                }
                if (config.WatchedEvents.HasFlag(WatcherChangeTypes.Renamed))
                {
                    events = events == null ? "Renamed" : $"{events}, renamed";
                }
                @out.WriteLine($"- For events of type: {events.Cyan()}");
            }

            @out.WriteLine($"- Using command: {config.Command.Cyan()}\n");

            if (workDir != dir)
            {
                @out.WriteLine($"- In working directory: {workDir.Cyan()}");
            }
        }