Esempio n. 1
0
        private async Task GetParticipantData()
        {
            using (var clientParticipant = new HttpClient())
            {
                try
                {
                    clientParticipant.BaseAddress = new Uri(Url);
                    HttpResponseMessage responseParticipant = await clientParticipant.GetAsync(_participantEndpoint, _cts.Token);

                    if (responseParticipant.IsSuccessStatusCode)
                    {
                        using (ParticipantDataModel currentParticipantData =
                                   ParticipantDataModel.FromJson(responseParticipant.Content.ReadAsStringAsync().Result))
                        {
                            if (!currentParticipantData.Equals(_previousParticipantData))
                            {
                                _previousParticipantData = currentParticipantData;
                                CreateParticipantStreamLabel(currentParticipantData);

                                await GetDonationData();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, "Failed to get participant data");
                    //Logger.Error(e);
                }
            }
        }
Esempio n. 2
0
        public ExtraLifeStreamLabelService(ILogger <ExtraLifeStreamLabelService> logger)
        {
            _logger = logger;
            var builder = new ConfigurationBuilder().SetBasePath(GetAssemblyDirectory).AddJsonFile("appsettings.json");

            _config = builder.Build();
            _participantEndpoint =
                $"participants/{_config.GetSection("ExtraLifeData").Get<ExtraLifeData>().ParticipantId}";

            _donationsEndpoint       = $"{_participantEndpoint}/donations";
            _teamEndpoint            = $"teams/{_config.GetSection("ExtraLifeData").Get<ExtraLifeData>().TeamId}";
            _previousParticipantData = new ParticipantDataModel();
        }
Esempio n. 3
0
 private static void CreateParticipantStreamLabel(ParticipantDataModel currentParticipantData)
 {
     using (FileStream progressDataStream = new FileStream($"{_config.GetSection("ExtraLifeData").Get<ExtraLifeData>().StreamLabelOutputPath}//ExtraLifeProgress.txt",
                                                           FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
     {
         int percentage =
             Convert.ToInt32(currentParticipantData.GetPercentOfGoalReached());
         string progress =
             $"${currentParticipantData.SumDonations:N2} / ${currentParticipantData.FundraisingGoal:N2} ( {percentage}% )";
         progressDataStream.SetLength(0);
         progressDataStream.Write(new UTF8Encoding(true).GetBytes(progress), 0,
                                  progress.Length);
         Console.WriteLine($"{progress}");
     }
 }