Example #1
0
        private async Task Set(string ip, bool on, bool off, bool alert, byte?brightness, string color, uint light)
        {
            try
            {
                var command = new SetLightCommand {
                    IpAddress = ip, On = on, Off = off, Alert = alert, Brightness = brightness, Color = color, Light = light, WaitForUserInput = WaitForUserInput
                };
                await _mediator.Send(command);

                AnsiConsoleHelper.TitleRule(":light_bulb: Roamer systems dispatched. Lights have been adjusted...");

                var lights = await _mediator.Send(new ListLightsQuery { IpAddress = ip, WaitForUserInput = WaitForUserInput });

                OutputLights(lights);
            }
            catch (ArgumentException ae)
            {
                AnsiConsole.MarkupLine($"[red][[:cross_mark: {ae.Message}]][/]");
            }
            catch (InvalidOperationException ex)
            {
                AnsiConsole.MarkupLine("[red][[:cross_mark: Failed to register with the bridge.]][/]");
                AnsiConsole.WriteException(ex,
                                           ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes |
                                           ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
            }
        }
Example #2
0
        private async Task ListLights(string ip)
        {
            try
            {
                var lights = await _mediator.Send(new ListLightsQuery { IpAddress = ip, WaitForUserInput = WaitForUserInput });

                if (lights.Count() == 0)
                {
                    AnsiConsole.MarkupLine("[red][[:cross_mark: No lights found.]][/]");
                    return;
                }
                AnsiConsoleHelper.TitleRule(":light_bulb: Scans are complete. Found lights...");
                OutputLights(lights);
            }
            catch (ArgumentException ae)
            {
                AnsiConsole.MarkupLine($"[red][[:cross_mark: {ae.Message}]][/]");
            }
            catch (InvalidOperationException ex)
            {
                AnsiConsole.MarkupLine("[red][[:cross_mark: Failed to register with the bridge.]][/]");
                AnsiConsole.WriteException(ex,
                                           ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes |
                                           ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
            }
        }
Example #3
0
        public async Task Run(string[] args)
        {
            AnsiConsoleHelper.TitleRule(Sayings.Affirmative().EscapeMarkup(), "gold3_1");
            AnsiConsole.WriteLine();

            await _rootCommand.InvokeAsync(args);
        }
Example #4
0
        private async Task Execute(bool agenda)
        {
            var now = DateTime.Now;

            var query = new CalendarEventsQuery
            {
                MinDate = now,
                MaxDate = agenda ? new DateTime(now.Year, now.Month, now.Day, 23, 59, 59) : null
            };

            try
            {
                var events = await _mediator.Send(query);

                string title = agenda ? ":calendar: Today's agenda" : ":tear_off_calendar: Next event";

                AnsiConsoleHelper.TitleRule(title);

                try
                {
                    if (events.Count() > 0)
                    {
                        bool found = false;
                        foreach (var eventItem in events)
                        {
                            string start = eventItem.Start?.ToString(agenda ? "HH:mm" : "MMM dd HH:mm");
                            if (string.IsNullOrEmpty(start))
                            {
                                continue;
                            }
                            string end = eventItem.End?.ToString("-HH:mm") ?? "";
                            AnsiConsole.MarkupLine($"{eventItem.Start.GetEmoji()} [white]{start}{end}\t[/][silver]{eventItem.Summary}[/]");
                            found = true;
                            if (!agenda)
                            {
                                return;
                            }
                        }
                        if (found)
                        {
                            return;
                        }
                    }
                    AnsiConsole.MarkupLine("[white][[No upcoming events found.]][/]");
                }
                finally
                {
                    AnsiConsoleHelper.Rule("white");
                }
            }
            catch (UnauthorizedException ue)
            {
                AnsiConsole.MarkupLine($"[red][[:cross_mark: ${ue.Message}]][/]");
                return;
            }
            catch (UnconfiguredException ue)
            {
                AnsiConsole.MarkupLine($"[yellow][[:yellow_circle: ${ue.Message}]][/]");
            }
        }
Example #5
0
 private static void OutputLights(IEnumerable <HueLight> lights)
 {
     foreach (var light in lights)
     {
         AnsiConsole.MarkupLine($"[white]{light.Id,2}: {light.Name,-40}[/] [silver]{(light.On ? $":yellow_circle: {(light.Brightness * 100 / 255)}% #{light.Color}" : ":black_circle:")}[/]");
     }
     AnsiConsoleHelper.Rule("white");
 }
Example #6
0
        private async Task ViewLeaderboard(int year, int board)
        {
            try
            {
                var leaders = await _mediator.Send(new LeaderboardQuery { Year = year, Board = board });

                AnsiConsole.WriteLine();
                AnsiConsoleHelper.TitleRule($":christmas_tree: Advent of Code Leaderboard {year}");

                int place = 1;
                foreach (var member in leaders.Members.Values.OrderByDescending(m => m.LocalScore).ThenByDescending(m => m.Stars))
                {
                    AnsiConsole.Markup(string.Format("[white]{0,3}) {1,3}[/]  ", place++, member.LocalScore));

                    for (int d = 1; d <= 25; d++)
                    {
                        if (DateTime.Now.Date < new DateTime(year, 12, d))
                        {
                            AnsiConsole.Markup("[grey]·[/]");
                            continue;
                        }

                        string day = d.ToString();
                        string star;
                        if (member.CompletionDayLevel.ContainsKey(day))
                        {
                            Day completed = member.CompletionDayLevel[day];
                            if (completed.PartOneComplete && completed.PartTwoComplete)
                            {
                                star = "[yellow]*[/]";
                            }
                            else
                            {
                                star = "[white]*[/]";
                            }
                        }
                        else
                        {
                            star = "[grey]*[/]";
                        }
                        AnsiConsole.Markup(star);
                    }
                    AnsiConsole.MarkupLine($"[green]  {member.Name}[/]");
                }
                AnsiConsoleHelper.Rule("white");
            }
            catch (UnconfiguredException ex)
            {
                AnsiConsole.MarkupLine($"[yellow][[:yellow_circle: {ex.Message}]][/]");
            }
        }
Example #7
0
        private void DisplayShort(WeatherForecast weather)
        {
            AnsiConsoleHelper.TitleRule(":satellite_antenna: Satellite scans complete. Today's weather is...");

            int maxDesc = weather.Hourly.Select(h => h.Description).Max(d => d.Length);

            string desc = (weather.Current.Description).PadRight(maxDesc);

            AnsiConsole.MarkupLine($"[white]Current:[/][silver]  {weather.Current.Icon} {desc} {weather.Current.Temperature,3}°C FeelsLike {weather.Current.FeelsLike,3}°C[/]");

            DailyWeather today = weather.Daily.FirstOrDefault();

            desc = (today.Description).PadRight(maxDesc);
            AnsiConsole.MarkupLine($"[white]Today:[/][silver]    {today.Icon} {desc} {today.Temperature.Max,3}°C/{today.Temperature.Min,3}°C[/][silver] High/Low[/]");
        }
Example #8
0
        public void RunConfiguration(string name, string description)
        {
            AnsiConsoleHelper.TitleRule($":wrench: Configure {name}");
            AnsiConsole.MarkupLine($"[silver][[{description}]][/]");
            AnsiConsole.WriteLine();

            foreach (PropertyInfo prop in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.PropertyType == typeof(string) && p.GetCustomAttribute <HideAttribute>() == null))
            {
                ConfigureProperty(prop);
            }

            Enabled    = true;
            Configured = true;
            Save();
            AnsiConsoleHelper.Rule("white");
        }
Example #9
0
        private async Task View(int days)
        {
            try
            {
                IEnumerable <StravaActivity> activities = await _mediator.Send(new GetActivitiesQuery());

                AnsiConsoleHelper.TitleRule($":person_biking: Fitness activities from the last {days} days");

                var table = new Table();
                table.Border = TableBorder.Minimal;
                table.AddColumns("", "Day", ":calendar: Date", ":sports_medal: Distance", ":four_o_clock: Time", ":mount_fuji: Elevaton", ":growing_heart: Suffer", ":compass: Activity");
                table.Columns[0].LeftAligned();
                table.Columns[1].LeftAligned();
                table.Columns[2].LeftAligned();
                table.Columns[3].RightAligned();
                table.Columns[4].RightAligned();
                table.Columns[5].RightAligned();
                table.Columns[6].RightAligned();
                table.Columns[7].LeftAligned();

                var lastWeek = DateTime.Now.AddDays(-days).Date;
                foreach (var act in activities.Where(a => a.StartDate >= lastWeek).OrderBy(a => a.StartDate))
                {
                    table.AddRow(
                        act.Icon,
                        act.StartDate.ToString("ddd"),
                        act.StartDate.ToString("yyyy-MM-dd"),
                        $"{(act.Distance / 1000):0.0} km",
                        act.MovingTime.ToString(@"hh\:mm\:ss"),
                        $"{act.Elevation:0} m",
                        (act.SufferScore ?? 0).ToString(),
                        act.Name);
                }
                AnsiConsole.Render(table);

                AnsiConsoleHelper.Rule("white");
            }
            catch (UnconfiguredException ue)
            {
                AnsiConsole.MarkupLine($"[yellow][[:yellow_circle: {ue.Message}]][/]");
            }
            catch (UnauthorizedException ue)
            {
                AnsiConsole.MarkupLine($"[red][[:cross_mark: ${ue.Message}]][/]");
            }
        }
        public override int Execute(CommandContext context)
        {
            var appSettings = AppSettings.LoadFromFile();

            try
            {
                var cvrSystemHelper    = new CvrSystemWrapper(EVRApplicationType.VRApplication_Utility);
                var vrApplicationError = cvrSystemHelper.CvrApplications.RemoveApplicationManifest(Path.GetFullPath(appSettings.ApplicationManifestPath));
                AnsiConsoleHelper.MarkupLine(appSettings.LanguageDataSet.GetValue(vrApplicationError == EVRApplicationError.None ? nameof(LanguageDataSet.StreamVRRemoveManifestSuccess) : nameof(LanguageDataSet.StreamVRRemoveManifestFailure)), vrApplicationError == EVRApplicationError.None ? AnsiConsoleHelper.State.Success : AnsiConsoleHelper.State.Failure);
            }
            catch (Exception ex)
            {
                AnsiConsoleHelper.MarkupLine(appSettings.LanguageDataSet.GetValue(nameof(LanguageDataSet.StreamVRRemoveManifestFailure)), AnsiConsoleHelper.State.Failure);
                AnsiConsole.WriteException(ex);
                return(1);
            }
            return(0);
        }
Example #11
0
        private async Task ListBridges()
        {
            try
            {
                var bridges = await _mediator.Send(new ListBridgesQuery());

                AnsiConsoleHelper.TitleRule(":desktop_computer: SUDAR Scan Complete. Found bridges...");
                foreach (var bridge in bridges)
                {
                    AnsiConsole.MarkupLine($"[silver]{bridge.BridgeId} - {bridge.IpAddress}[/]");
                }
                AnsiConsoleHelper.Rule("white");
            }
            catch (Exception ex)
            {
                AnsiConsole.MarkupLine("[red][[:cross_mark: Failed to list bridges.]][/]");
                AnsiConsole.WriteException(ex,
                                           ExceptionFormats.ShortenPaths | ExceptionFormats.ShortenTypes |
                                           ExceptionFormats.ShortenMethods | ExceptionFormats.ShowLinks);
            }
        }
Example #12
0
        private async Task Execute(bool all)
        {
            try
            {
                WeatherForecast weather = await _mediator.Send(new WeatherQuery());

                if (all)
                {
                    DisplayLong(weather);
                }
                else
                {
                    DisplayShort(weather);
                }
                AnsiConsoleHelper.Rule("white");
            }
            catch (UnconfiguredException ue)
            {
                AnsiConsole.MarkupLine($"[yellow][[:yellow_circle: {ue.Message}]][/]");
            }
        }
Example #13
0
        private void DisplayLong(WeatherForecast weather)
        {
            DisplayShort(weather);

            DateTime last    = DateTime.MinValue;
            int      maxDesc = weather.Hourly.Select(h => h.Description).Max(d => d.Length);

            foreach (var hour in weather.Hourly)
            {
                DateTime dt = hour.DateTime;
                if (dt.Date != last.Date)
                {
                    AnsiConsoleHelper.Rule("white");
                    AnsiConsole.MarkupLine($":calendar: [white bold]{dt:ddd MMM dd}[/]");
                    AnsiConsoleHelper.Rule("silver");
                }
                last = dt;
                string desc = (hour.Description).PadRight(maxDesc);
                AnsiConsole.MarkupLine(
                    $"{dt.GetEmoji()} [silver]{dt:HH:mm}  {hour.Icon} {desc} {hour.Temperature,3}°C FeelsLike {hour.FeelsLike,3}°C {(int)(hour.ProbabilityOfPrecipitation),3}%:droplet:[/]"
                    );
            }
        }
Example #14
0
        private async Task View(string country, bool cases, bool deaths)
        {
            try
            {
                var c = country.GetCountry();
                if (c == Country.Unknown)
                {
                    AnsiConsole.MarkupLine($"[red][[:cross_mark: Could not find country ${country}]][/]");
                    return;
                }

                CovidData data = await _mediator.Send(new CovidCountryDataQuery { Country = c });

                AnsiConsoleHelper.TitleRule($":biohazard: Covid data for {country}");

                DisplayCountryData(data);
                AnsiConsole.WriteLine();

                if (cases)
                {
                    DisplayRegionalCases(data);
                    AnsiConsole.WriteLine();
                }

                if (deaths)
                {
                    DisplayRegionalDeaths(data);
                    AnsiConsole.WriteLine();
                }

                AnsiConsoleHelper.Rule("white");
            }
            catch (Exception ue)
            {
                AnsiConsole.MarkupLine($"[red][[:cross_mark: ${ue.Message}]][/]");
            }
        }