コード例 #1
0
        public CheckRepublicService(IOptions <NotificationOptions> notificationOptions, ILogger <CheckRepublicService> logger)
        {
            var options = notificationOptions.Value.CheckRepublicOptions;

            _heartGroupName = options.HeartGroupName;
            _client         = new HeartGroupClient(options.Url, options.Password);
            _lastHeartbeat  = DateTimeOffset.MinValue;
            _logger         = logger;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sandboxorg/CheckRepublic
        public static async Task MainAsync(string[] args, CancellationToken token)
        {
            {
                Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");

                var websiteTask = Task.Run(() => Website.Program.Main(new string[0]));

                var httpClient = new HttpClient();
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", "OldyaXRl");
                httpClient.Timeout = Timeout.InfiniteTimeSpan;

                for (int i = 0; i < 12; i++)
                {
                    try
                    {
                        var checksResponseString = await httpClient.GetStringAsync("http://localhost:5000/api/checks");

                        Console.WriteLine(Serialize(JsonConvert.DeserializeObject(checksResponseString)));
                        break;
                    }
                    catch
                    {
                        await Task.Delay(5000);
                    }
                }


                var heartGroupClient = new HeartGroupClient("http://localhost:5000", "Write");
                var heartbeat        = await heartGroupClient.CreateHeartbeatAsync("PoGoNotifications.PokemonEncounter", Environment.MachineName, token);

                Console.WriteLine(Serialize(heartbeat));

                var checkResponse = await httpClient.PostAsync("http://localhost:5000/api/checkrunner", new ByteArrayContent(new byte[0]));

                var checkResponseString = await checkResponse.Content.ReadAsStringAsync();

                Console.WriteLine(Serialize(JsonConvert.DeserializeObject(checkResponseString)));

                var notificationResponse = await httpClient.PostAsync("http://localhost:5000/api/notificationrunner", new ByteArrayContent(new byte[0]));

                var notificationResponseString = await notificationResponse.Content.ReadAsStringAsync();

                Console.WriteLine(Serialize(JsonConvert.DeserializeObject(notificationResponseString)));

                await websiteTask;
            }
        }