public static async Task Main(string[] args)
        {
            var apiOptions = new ApiClientOptions
            {
                Scopes             = "WMTServerAPI.full_access WMTServerAPI.read_only",
                TokenClientOptions = new TokenClientOptions {
                    Address = "https://localhost:5006/connect/token", ClientId = "WMTServerDashboard", ClientSecret = "Client_AsturiasNetConf2020"
                }
            };

            using var httpClient = new HttpClient();
            var tokenClient  = new TokenClient(httpClient, apiOptions.TokenClientOptions);
            var tokenManager = new AccessTokenManager(new NullLogger <AccessTokenManager>(), new MemoryCache(new MemoryCacheOptions()), tokenClient, new OptionsWrapper <ApiClientOptions>(apiOptions));

            using var channel = GrpcChannel.ForAddress("https://localhost:5001");
            var client = new WindmillFarm.WindmillFarmClient(channel);

            var authHeader = new Metadata {
                { "Authorization", "Bearer " + (await tokenManager.GetApiTokenAsync()).AccessToken }
            };

            var windmills = client.RequestList(new WindmillListRequest(), authHeader);
            var guid      = windmills.Windmills.FirstOrDefault()?.WindmillId;

            if (Guid.TryParse(guid, out var windmillId))
            {
                Console.WriteLine($"Windmill info for {guid}");
                await TelemetryStreaming(windmillId, channel);
            }

            Console.WriteLine("Shutting down client");
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
 public AccessTokenManager(ILogger <AccessTokenManager> logger, IMemoryCache cache, TokenClient client, IOptions <ApiClientOptions> clientOptions)
 {
     this.logger        = logger;
     this.cache         = cache;
     this.client        = client;
     this.clientOptions = clientOptions.Value;
 }