Esempio n. 1
0
 public Task SaveChangesAsync() =>
 _dbContext.SaveChangesAsync();
Esempio n. 2
0
 public async Task SaveChanges()
 {
     await _dbContext.SaveChangesAsync().ConfigureAwait(false);
 }
Esempio n. 3
0
        public async Task SaveChangesAsync()
        {
            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

            _scheduleCache.Clear();
        }
Esempio n. 4
0
        public async Task ExecuteAsync(IReadOnlyCollection <string> externalRefs, Action <string> logDebug, DateTime?thresholdDate = default, CancellationToken cancellationToken = default)
        {
            var dataCount = externalRefs.Count;

            var spots = new List <ReducedSpotDTO>();

            for (int i = 0; i <= dataCount / _spotBatchSize; i++)
            {
                var externalRefsBatch = externalRefs.Skip(i * _spotBatchSize).Take(_spotBatchSize).ToList();
                var spotsBatch        = await _dbContext.Query <SpotDbObject>()
                                        .Where(e => externalRefsBatch.Contains(e.ExternalSpotRef))
                                        .ProjectTo <ReducedSpotDTO>(_mapper.ConfigurationProvider).ToArrayAsync(cancellationToken);

                spots.AddRange(spotsBatch);
            }

            logDebug?.Invoke("Start attaching Multipart Spots");

            var multipartSpots = (await _dbContext.Query <SpotDbObject>()
                                  .Where(e => MultipartSpotTypes.All.Contains(e.MultipartSpot))
                                  .ProjectTo <ReducedSpotDTO>(_mapper.ConfigurationProvider)
                                  .ToArrayAsync(cancellationToken))
                                 .Where(x => externalRefs.All(r => r != x.ExternalSpotRef) || x.MultipartSpotPosition == MultipartSpotPositions.End)
                                 .ToArray();

            var spotsToDelete = new List <int>();

            foreach (var spot in spots)
            {
                if (!IsMultipartSpot(spot))
                {
                    spotsToDelete.Add(spot.Id);
                    continue;
                }

                if (!IsTopMultipart(spot))
                {
                    continue;
                }

                switch (spot.MultipartSpot)
                {
                case MultipartSpotTypes.TopTail:
                    var topTailDeletes = multipartSpots
                                         .Where(x => IsMultipartSpot(x) && x.MultipartSpot == spot.MultipartSpot)
                                         .Where(x => x.MultipartSpotRef == spot.MultipartSpotRef || x.ExternalSpotRef == spot.MultipartSpotRef)
                                         .ToArray();

                    if (!thresholdDate.HasValue || topTailDeletes.All(e => e.StartDateTime < thresholdDate))
                    {
                        spotsToDelete.AddRange(topTailDeletes.Select(e => e.Id));
                        spotsToDelete.Add(spot.Id);
                    }

                    break;

                case MultipartSpotTypes.SameBreak:
                    var sameBreakDeletes = multipartSpots
                                           .Where(x => IsMultipartSpot(x) && x.MultipartSpot == spot.MultipartSpot)
                                           .Where(x => MultipartSpotRefs(x).Contains(spot.ExternalSpotRef) ||
                                                  MultipartSpotRefs(spot).Contains(x.ExternalSpotRef) ||
                                                  MultipartSpotRefs(spot).Intersect(MultipartSpotRefs(x)).Any())
                                           .ToArray();

                    if (!thresholdDate.HasValue || sameBreakDeletes.All(e => e.StartDateTime < thresholdDate))
                    {
                        spotsToDelete.AddRange(sameBreakDeletes.Select(e => e.Id));
                        spotsToDelete.Add(spot.Id);
                    }

                    break;
                }
            }

            cancellationToken.ThrowIfCancellationRequested();

            var distinctSpotsToDelete = spotsToDelete.Distinct().ToArray();

            logDebug?.Invoke($"Spots count after attaching Multipart Spots {distinctSpotsToDelete.Length}");

            Delete(distinctSpotsToDelete);
            await _dbContext.SaveChangesAsync(cancellationToken);
        }