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}]][/]"); } }
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"); }
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}]][/]"); } }
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"); }
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}]][/]"); } }
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); } }
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}]][/]"); } }
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:[/]" ); } }
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}]][/]"); } }