static async Task Main(string[] args) { try { Log.Debug("Starting execution"); // var targetIp = "https://*****:*****@"{ ""user"" : ""*****@*****.**"", ""password"": ""123456""}", Encoding.UTF8, MediaTypeNames.Application.Json); var grpcChannelOptions = GetChannelOptions(unsafeHttpClient); using var channel = GrpcChannel.ForAddress(targetIp, grpcChannelOptions); // var response = await grpcChannelOptions.HttpClient.PostAsync($"{targetIp}/Jwt/Authenticate", authentication); // var authenticationValue = await response.Content.ReadAsStringAsync(); // var authenticationModel = JsonSerializer.Deserialize<JwtAuthenticationResult>(authenticationValue, new JsonSerializerOptions(){PropertyNameCaseInsensitive = true}); // var token = authenticationModel.AccessToken; // Console.WriteLine(token); // // var token = // // "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiYWRtaW5AYWRtaW4uY29tIiwiYXVkIjoiUEMgUmVtb3RlIDIiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJhZG1pbmlzdHJhdG9yIiwiZXhwIjoxNjI1NzIxMzQ5LCJpc3MiOiJQQyBSZW1vdGUgMiJ9.kyQY4B-ZvfsIaBEtd-bGz-0GjrDOlbZwPsJ1zza8zvjwTJJIZ7AvMTLxRzrx1QuQSX45K-_ktrZd7jzr4I-haA"; // // var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"{targetIp}/Jwt/TokenVerify"); // requestMessage.Headers.Add("Authorization", $"Bearer " + token); // var testResponse = await grpcChannelOptions.HttpClient.SendAsync(requestMessage); // var testReply = await testResponse.Content.ReadAsStringAsync(); // Console.WriteLine($"{(int)testResponse.StatusCode} => {testReply}"); // // return; var client = new DesktopIntegrationService.DesktopIntegrationServiceClient(channel); Log.Info("Executing shutdown"); await client.ShutDownDelayedAsync(new ShutdownDelayedRequest() { Seconds = 60 }); await Task.Delay(5000); Log.Info("Execution shutdown abort"); await client.AbortShutDownAsync(new AbortShutdownRequest()); Log.Info("Execution complete."); } catch (Exception e) { Log.Error(e.ToString()); } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var voiceCommandServiceClient = new VoiceCommandService.VoiceCommandServiceClient(_namedPipeChannel); var desktopIntegrationServiceClient = new DesktopIntegrationService.DesktopIntegrationServiceClient(_namedPipeChannel); await _applicationStateTransmitter.ConfigurationDone; while (!stoppingToken.IsCancellationRequested) { try { _log.LogTrace("Attempting to update voice recognition"); using var scope = _serviceScopeFactory.CreateScope(); using var dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>(); var keyValueSettingsManager = scope.ServiceProvider.GetRequiredService <KeyValueSettingsManager>(); var feeds = await desktopIntegrationServiceClient.GetAudioFeedsAsync(new AudioFeedRequest()); if (await UpdateAudioFeedTableAsync(dbContext, feeds)) { _log.LogDebug("Feeds have been added to alias management"); } var recognitionEnabled = await keyValueSettingsManager.GetByKindAsBoolAsync(stoppingToken, KeyValueKind.VoiceRecognitionEnabled, false); if (recognitionEnabled) { await voiceCommandServiceClient.UpdateVoiceRecognitionAsync(await BuildUpdateRequest(stoppingToken, dbContext, feeds)); } if (!recognitionEnabled) { _log.LogTrace("Recognition is disabled"); } await Task.Delay(TimeSpan.FromSeconds(60), stoppingToken); } catch (Exception e) { _log.LogError(e, "ExecuteAsync"); } } }
public SimpleDesktopClient(DesktopIntegrationService.DesktopIntegrationServiceClient client) { _client = client; }
public GrpcApplicationAgent(GrpcChannel channel) { _channel = channel; _desktopIntegrationClient = new DesktopIntegrationService.DesktopIntegrationServiceClient(_channel); DesktopClient = new SimpleDesktopClient(_desktopIntegrationClient); }
public UserContextChannel(NamedPipeChannel channel, ILogger <UserContextChannel> logger) { _logger = logger; _service = new DesktopIntegrationService.DesktopIntegrationServiceClient(channel); }