public async Task Run()
        {
            bool isFirst = true;

            try
            {
                while (true)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    var stateLogin = await _web.Login();

                    var resultContent = await _web.UpdatePage();

                    var list = ParsePage(resultContent);
                    ForecastDataStorage.Add(list);

                    if (isFirst)
                    {
                        for (int i = 0; i < _countSeeOld; i++)
                        {
                            var point = GetIdTime(resultContent);
                            if (string.IsNullOrEmpty(point))
                            {
                                break;
                            }

                            resultContent = await _web.SeeOld(point);

                            list = ParsePage(resultContent);
                            ForecastDataStorage.Add(list);
                        }

                        isFirst = false;
                    }

                    await Task.Delay(_timeSleep, cancellationToken);
                }
            }
            catch (TaskCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw;
            }
        }
Beispiel #2
0
        public async Task Run()
        {
            try
            {
label1:
                var stateLogin = await _web.Login();

                var timeEnd = DateTime.Now.AddMinutes(2);

                while (true)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        break;
                    }

                    if (DateTime.Now > timeEnd)
                    {
                        await _web.Logout();

                        await Task.Delay(30000);

                        goto label1;
                    }

                    var resultContent = await _web.UpdatePage();

                    var list = ParsePage(resultContent);
                    ForecastDataStorage.Add(list);

                    if (isFirst)
                    {
                        for (int i = 0; i < _countSeeOld; i++)
                        {
                            var point = GetIdTime(resultContent);
                            if (string.IsNullOrEmpty(point))
                            {
                                break;
                            }

                            resultContent = await _web.SeeOld(point);

                            list = ParsePage(resultContent);
                            ForecastDataStorage.Add(list);
                        }

                        isFirst = false;
                    }

                    await Task.Delay(_timeSleep, cancellationToken);
                }
            }
            catch (TaskCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                _logger.LogError(e, nameof(Run));
                currentErr++;
                if (countError < currentErr)
                {
                    await Task.Delay(100000);
                    await Run();
                }
                else
                {
                    throw;
                }
            }
        }