Beispiel #1
0
        public async Task <IPerformanceData[]> RequestProcess(IPerformanceFilter filter, CancellationToken cancellationToken)
        {
            Trace.TraceInformation("PlayBillResolver.RequestProcess started");
            DateTime[] months = filter.StartDate.GetMonthsBetween(filter.EndDate);

            List <IPerformanceData> performances = new List <IPerformanceData>();

            foreach (var dateTime in months)
            {
                cancellationToken.ThrowIfCancellationRequested();

                string content = await Request(dateTime, cancellationToken);

                performances.AddRange(await _playbillParser.Parse(content, cancellationToken));
            }

            cancellationToken.ThrowIfCancellationRequested();

            IEnumerable <IPerformanceData> filtered = performances.Where(item => _filterChecker.IsDataSuitable(item, filter)).ToArray();

            Task[] resolvePricesTasks = filtered
                                        .Select(item => Task.Run(async() =>
            {
                item.MinPrice = (await _ticketParser.ParseFromUrl(item.Url, cancellationToken)).GetMinPrice();
            }, cancellationToken)).ToArray();

            await Task.WhenAll(resolvePricesTasks.ToArray());

            Trace.TraceInformation(" PlayBillResolver.RequestProcess finished");
            return(filtered.ToArray());
        }
        public async Task <bool> ProcessSubscriptions()
        {
            await using var dbContext = _dbService.GetDbContext();

            Trace.TraceInformation("Process subscriptions started");
            PlaybillChangeEntity[] changes = dbContext.PerformanceChanges
                                             .Include(c => c.PlaybillEntity)
                                             .ThenInclude(p => p.Performance)
                                             .ThenInclude(p => p.Type)
                                             .Include(c => c.PlaybillEntity)
                                             .ThenInclude(p => p.Performance)
                                             .ThenInclude(p => p.Location)
                                             .AsNoTracking()
                                             .ToArray();

            bool dbIsDirty = false;

            foreach (SubscriptionEntity subscription in dbContext.Subscriptions.Include(s => s.PerformanceFilter))
            {
                var filter = subscription.PerformanceFilter;

                PlaybillChangeEntity[] performanceChanges = filter.PerformanceId >= 0
                    ? changes
                                                            .Where(p => p.PlaybillEntity.PerformanceId == filter.PerformanceId &&
                                                                   p.LastUpdate > subscription.LastUpdate &&
                                                                   (subscription.TrackingChanges & p.ReasonOfChanges) != 0)
                                                            .OrderBy(p => p.LastUpdate).ToArray()
                    : changes
                                                            .Where(p => _filterChecker.IsDataSuitable(p.PlaybillEntity.Performance.Location.Name,
                                                                                                      p.PlaybillEntity.Performance.Type.TypeName, p.PlaybillEntity.When, subscription.PerformanceFilter) &&
                                                                   p.LastUpdate > subscription.LastUpdate &&
                                                                   (subscription.TrackingChanges & p.ReasonOfChanges) != 0)
                                                            .OrderBy(p => p.LastUpdate).ToArray();

                if (!performanceChanges.Any() || !await SendMessages(subscription, performanceChanges))
                {
                    continue;
                }

                subscription.LastUpdate = performanceChanges.Last().LastUpdate;
                dbIsDirty = true;
            }

            if (dbIsDirty)
            {
                await dbContext.SaveChangesAsync();
            }

            Trace.TraceInformation("Process subscription finished");
            return(true);
        }
Beispiel #3
0
        public async Task <IPerformanceData[]> RequestProcess(DateTime startDate, DateTime endDate, IPerformanceFilter filter)
        {
            string content = await Request(startDate);

            IPerformanceData[] perfomances = _playBillParser.Parse(content).GetAwaiter().GetResult();

            IList <Task> tasks = new List <Task>();

            var filtredList = perfomances.Where(item => _filterChecker.IsDataSuitable(item, filter));

            foreach (var item in filtredList)
            {
                tasks.Add(Task.Run(async() => item.Tickets = await _ticketParser.ParseFromUrl(item.Url)));
            }

            Task.WaitAll(tasks.ToArray());

            Trace.TraceInformation("Parsing finished");
            Trace.TraceInformation("");

            return(filtredList.ToArray());
        }