Skip to content

Commit

Permalink
Add stopping token to history list
Browse files Browse the repository at this point in the history
  • Loading branch information
JKamsker committed Apr 24, 2024
1 parent 4710d71 commit c2765a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
20 changes: 15 additions & 5 deletions XSense-Extractor.Cli/Commands/GetHistoryCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Spectre.Console;
using Microsoft.Extensions.Hosting;

using Spectre.Console;
using Spectre.Console.Cli;

using System.Globalization;
Expand All @@ -13,9 +15,6 @@ namespace Commands;

internal class GetHistoryCommand : AsyncCommand<GetHistoryCommand.Settings>
{
private readonly XSenseApiClient _apiClient;
private Settings _settings;

public class Settings : CommandSettings
{
[CommandOption("--houseId <STATIONID>")]
Expand All @@ -41,9 +40,14 @@ public class Settings : CommandSettings
public string? Output { get; set; }
}

public GetHistoryCommand(XSenseApiClient apiClient)
private readonly XSenseApiClient _apiClient;
private readonly IHostApplicationLifetime _env;
private Settings _settings;

public GetHistoryCommand(XSenseApiClient apiClient, IHostApplicationLifetime env)
{
_apiClient = apiClient;
_env = env;
}

public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
Expand Down Expand Up @@ -71,9 +75,15 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se

private async Task DisplayLineByLine(Settings settings)
{
var token = _env.ApplicationStopping;
await foreach (var (house, station, device, time, temperature, humidity) in EnumerateSensoricHistoryAsync(settings))
{
AnsiConsole.MarkupLine($"[yellow]{time:yyyy-MM-dd HH:mm:ss}[/] [green]{temperature}°C[/] [blue]{humidity}%[/]");

if(token.IsCancellationRequested)
{
break;
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion XSense-Extractor.Cli/Commands/LoginCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Spectre.Console;
using Spectre.Console.Cli;

using XSenseExtractor;
using XSenseExtractor.Database;

namespace XSenseExtractor.Cli;
namespace Commands;

internal class LoginCommand : AsyncCommand<LoginCommand.Settings>
{
Expand Down
5 changes: 4 additions & 1 deletion XSense-Extractor.Cli/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using JKToolKit.Spectre.AutoCompletion.Completion;
using Commands;

using JKToolKit.Spectre.AutoCompletion.Completion;
using JKToolKit.Spectre.AutoCompletion.Integrations;

using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -104,6 +106,7 @@ private static string[] GetDebugParams(string[] args)
//return new[] { "stations" };

//return new[] { "history", "--output", "all.csv" };
return new[] { "history" };
}

return args;
Expand Down
2 changes: 1 addition & 1 deletion XSense-Extractor.Cli/XSense-Extractor.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<PropertyGroup>
<PackAsTool>true</PackAsTool>
<ToolCommandName>xsense-extractor</ToolCommandName>
<ToolCommandName>xsense</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageId>XSense-Extractor</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down

0 comments on commit c2765a8

Please sign in to comment.