Пример #1
0
        public async override Task Execute()
        {
            if (CanExecute())
            {
                _timer.Start();
                IHarvestRequestResult responsedoc = await ExecuteRequest();

                if (responsedoc != null)
                {
                    var clubs = new List <ExpandoObject>();
                    foreach (var cr in ParseClubsFromResponse(responsedoc))
                    {
                        clubs.Add(CreateSeasonParticipant(cr));
                    }
                    await _httpmanager.Post(clubs, $"{_participantsapiroot}/api/{_registrationsApiPath}"); // TODO: handle success/fail

                    _logger.LogDebug(string.Format("Stored club season registrations data to database for season '{0}'", SeasonKey));
                }
                else
                {
                    _logger.LogDebug(string.Format("Failed to store & commit club registations for season as no response was recieved from endpoint: '{0}'", SeasonKey));
                }
                HarvestHelper.FinaliseTimer(_timer);
            }
        }
Пример #2
0
        private JArray ParseClubsFromResponse(IHarvestRequestResult response)
        {
            var rawdata        = response.InnerHtml;
            int jsonstartindex = rawdata.IndexOf("DataStore.prime('standings',") + 28;
            int jsonendindex   = rawdata.IndexOf("]);", jsonstartindex) + 1;
            var rawjson        = "[" + rawdata.Substring(jsonstartindex, jsonendindex - jsonstartindex) + "]";
            var jsondata       = JsonConvert.DeserializeObject <JArray>(rawjson);

            return((JArray)jsondata[1]);
        }