Example #1
0
        private static void Main(string[] args)
        {
            _initContainer();
            logger.Log("Запуск обработки путей.").Wait();
            var cts = new CancellationTokenSource();

            apiDataProvider.Authenticate(cts.Token).Wait();
            while (_doMonitoring(cts.Token).Result)
            {
            }
            logger.Log("Завершение обработки путей.").Wait();
        }
Example #2
0
        private async static Task <bool> _doIndex(CancellationToken ct)
        {
            apiDataProvider.Authenticate(ct).Wait();

            var index = await apiDataProvider
                        .GetCurrentIndexAsync <TenderPlanIndex>(ct)
                        .ContinueWith(r => r.Result.ToDictionary(i => i.TenderPlanId));

            var files = await apiDataProvider
                        .GetUpdatedTenderPlansAsync <TenderPlanFileToIndex>(ct)
                        .ContinueWith(r => r.Result
                                      .Select(f => new { fid = f.FTPFileId, s = f.Name.Split("_") })
                                      .Where(p => p.s.Length == 3)
                                      .Select(s => new { FileId = s.fid, PlanId = s.s[1], Revision = long.Parse(s.s[2].Substring(0, s.s[2].LastIndexOf('.'))) })
                                      .GroupBy(
                                          t => t.PlanId,
                                          t => new { Rev = t.Revision, FId = t.FileId },
                                          (k, v) => new TenderPlanIndex
            {
                FTPFileId    = v.FirstOrDefault().FId,
                TenderPlanId = k,
                RevisionId   = v.Max(t => t.Rev)
            }
                                          )
                                      .ToList());

            var key         = new object();
            var filesToSend = new List <TenderPlanIndex>();

            files.AsParallel().ForAll(fti =>
            {
                if (index.Keys.Contains(fti.TenderPlanId) && index[fti.TenderPlanId].RevisionId < fti.RevisionId)
                {
                    lock (key)
                    {
                        filesToSend.Add(fti);
                    }
                }
                else if (!index.Keys.Contains(fti.TenderPlanId))
                {
                    lock (key)
                    {
                        filesToSend.Add(fti);
                    }
                }
            });

            return(await apiDataProvider.SendNewIndexedFiles(new StringContent(JsonConvert.SerializeObject(filesToSend), Encoding.UTF8, MediaTypeNames.Application.Json), ct));
        }
Example #3
0
        static async void _doWork()
        {
            var cts = new CancellationTokenSource();
            await apiDataProvider.Authenticate(cts.Token);

            var auction = await apiDataProvider.GetNextAuction(cts.Token);

            var job = configService.GetJob(auction, containerTag);
            await logger.Log(actionsService.RunJob(job));

            var result = await apiDataProvider.SetFutureAuctionOnServiceState(auction, cts.Token);

            if (result)
            {
                logger.Log("Успешно завершено").Wait();
            }
            else
            {
                logger.Log("Не удалось изменить статус аукциона").Wait();
            }
        }
        public async Task AuthenticateAsync(CancellationToken ct)
        {
            await logger.Log("Авторизация на площадке");

            ct.ThrowIfCancellationRequested();
            await apiDataProvider.Authenticate(ct);

            var step1GetResult = await httpClientService.GetAsync(configService.AuthStep1Url, ct);

            _throwIfDocumentError(step1GetResult);
            var step1PostResult = await httpClientService.PostAsync(configService.AuthStep1Url, await _getAuthStep2Form(step1GetResult, ct), ct);

            var step2GetResult = await httpClientService.GetAsync(configService.AuthStep2Url, ct);

            _throwIfDocumentError(step1GetResult);
            var step3PostResult = await httpClientService.PostAsync(configService.AuthStep3Url, _getAuthStep3Form(step2GetResult), ct);

            _throwIfDocumentError(step3PostResult);

            ct.ThrowIfCancellationRequested();
            await logger.Log("Авторизован как: " + step3PostResult.GetTextById("ctl00_loginctrl_link"));
        }