Beispiel #1
0
        static async Task <int> Main(string[] args)
        {
            var builder = new HostBuilder()
                          .ConfigureLogging(logging =>
            {
                logging.ClearProviders();
                logging.AddConsole();
            })
                          .ConfigureServices((hostContext, services) =>
            {
                GetuiConfiguration getuiConfiguration = new GetuiConfiguration()
                {
                    AppId        = "",
                    AppKey       = "",
                    MasterSecret = "",
                    ApiVersion   = "v2"
                };
                services.AddSingleton(getuiConfiguration);


                services.AddGetuiServiceApi();
            }).UseConsoleLifetime();

            var host = builder.Build();

            using (var serviceScope = host.Services.CreateScope())
            {
                var services = serviceScope.ServiceProvider;

                try
                {
                    var authTokenService         = services.GetRequiredService <AuthTokenService>();
                    var pushCommonMessageService = services.GetRequiredService <PushCommonMessageService>();
                    var authTokenResult          = await authTokenService.GetAuthToken();

                    PushResultMessage pushResultMessage = null;
                    //pushResultMessage = await PushSingleNotificationClientId(pushCommonMessageService);
                    pushResultMessage = await PushSingleTransmissionClientId(pushCommonMessageService);


                    ResultMessage resultMessage = await authTokenService.CloseAuth();


                    //ResultMessage resultMessage = await authTokenService.CloseAuth();

                    System.Console.ReadLine();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();

                    logger.LogError(ex, "An error occurred.");
                }
            }

            return(0);
        }
        private async Task <PushResultMessage> Push(string requestUri, CommonMessage commonMessage)
        {
            AuthTokenResult authTokenResult = await _authTokenService.GetAuthToken();

            if (authTokenResult == null)
            {
                return new PushResultMessage()
                       {
                           ClientHttpStatusCode = HttpStatusCode.BadRequest, Msg = "auth token is null", Code = 1
                       }
            }
            ;

            _client.SetAuthToken(authTokenResult.Data.AuthToken);
            HttpResponseMessage httpResponseMessage =
                await _client.PostAsync(requestUri, new JsonContent(commonMessage));

            PushResultMessage pushResultMessage = await httpResponseMessage.GetResultAsync <PushResultMessage>();

            _logger.LogInformation($"push result: {pushResultMessage}");
            return(pushResultMessage);
        }