Beispiel #1
0
        public ManifestEntity Execute()
        {
            _DbContext.BeginTransaction(); //TODO should be using WebDbContentProvider

            var now           = _DateTimeProvider.Now();
            var releaseCutoff = now - TimeSpan.FromHours(_GaenContentConfig.ManifestLifetimeHours);

            var e = _DbContext.ManifestContent
                    .Where(x => x.Release > releaseCutoff)
                    .OrderByDescending(x => x.Release)
                    .Take(1)
                    .SingleOrDefault();

            if (e != null)
            {
                return(e);
            }

            _DbContext.BulkDelete(_DbContext.Set <ManifestEntity>().ToList()); //TODO execute sql.
            var content = JsonConvert.SerializeObject(_ManifestBuilder.Execute());
            var bytes   = Encoding.UTF8.GetBytes(content);

            e = new ManifestEntity
            {
                Release         = now,
                ContentTypeName = ContentHeaderValues.Json,
                Content         = bytes,
            };
            e.PublishingId = _PublishingId.Create(e.Content);
            _DbContext.ManifestContent.Add(e);
            _DbContext.SaveAndCommit();

            return(e);
        }
        public async Task <TContentEntity> Fill <TContentEntity, TContent>(TContentEntity e, TContent c) where TContentEntity : ContentEntity
        {
            e.Content         = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(c));
            e.PublishingId    = _PublishingId.Create(e.Content);
            e.ContentTypeName = MediaTypeNames.Application.Json;
            e.SignedContent   = await _SignedFormatter.SignedContentPacket(e.Content);

            e.SignedContentTypeName = MediaTypeNames.Application.Zip;
            return(e);
        }
        public async Task <TContentEntity> Fill <TContentEntity, TContent>(TContentEntity e, TContent c) where TContentEntity : ContentEntity
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (c == null)
            {
                throw new ArgumentNullException(nameof(c));
            }

            var contentJson  = _JsonSerializer.Serialize(c);
            var contentBytes = Encoding.UTF8.GetBytes(contentJson);

            e.PublishingId = _PublishingId.Create(contentBytes);
            e.Content      = await _SignedFormatter.SignedContentPacket(contentBytes);

            e.ContentTypeName = MediaTypeNames.Application.Zip;
            return(e);
        }
        public void Write(ExposureKeySetEntity[] things)
        {
            var entities = things.Select(x => new ExposureKeySetContentEntity
            {
                Content              = x.Content,
                CreatingJobName      = x.CreatingJobName,
                CreatingJobQualifier = x.CreatingJobQualifier,
                Release              = x.Created,
            }).ToList();

            foreach (var i in entities)
            {
                i.PublishingId = _PublishingId.Create(i.Content);
            }

            using (_DbContext.EnsureNoChangesOrTransaction().BeginTransaction())
            {
                _DbContext.BulkInsertAsync(entities);
                _DbContext.SaveAndCommit();
            }
        }
Beispiel #5
0
        public async Task Execute(ContentArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var contentBytes = Encoding.UTF8.GetBytes(args.Json);

            var e = new ContentEntity
            {
                Created         = _DateTimeProvider.Now(), //TODO audit stamp
                Release         = args.Release,
                Type            = args.ContentType,
                PublishingId    = _PublishingId.Create(contentBytes),
                Content         = await _SignedFormatter.SignedContentPacket(contentBytes),
                ContentTypeName = MediaTypeNames.Application.Zip
            };

            await _DbContext.AddAsync(e);
        }
        private async Task CommitResults()
        {
            _Logger.LogInformation($"Commit results - publish EKSs.");

            await using (_PublishingDbContext.BeginTransaction())
            {
                var move = _PublishingDbContext.Set <EksCreateJobOutputEntity>().Select(
                    x => new ExposureKeySetContentEntity
                {
                    Created              = _Start,
                    Release              = x.Release,
                    ContentTypeName      = MediaTypeNames.Application.Zip,
                    Content              = x.Content,
                    CreatingJobName      = x.CreatingJobName,
                    CreatingJobQualifier = x.CreatingJobQualifier,
                    PublishingId         = _PublishingId.Create(x.Content)
                }).ToArray();

                await using (_ContentDbContext.BeginTransaction())
                {
                    _ContentDbContext.Set <ExposureKeySetContentEntity>().AddRange(move);
                    _ContentDbContext.SaveAndCommit();
                }
            }

            _Logger.LogInformation($"Commit results - Mark TEKs as Published.");

            await using (_PublishingDbContext.BeginTransaction()) //Read-only
            {
                await using (_WorkflowDbContext.BeginTransaction())
                {
                    var count = 0;
                    var used  = _PublishingDbContext.Set <EksCreateJobInputEntity>()
                                .Where(x => x.Used)
                                .Skip(count)
                                .Select(x => x.Id)
                                .Take(100)
                                .ToArray();

                    while (used.Length > 0)
                    {
                        var zap = _WorkflowDbContext.TemporaryExposureKeys
                                  .Where(x => used.Contains(x.Id))
                                  .ToList();

                        foreach (var i in zap)
                        {
                            i.PublishingState = PublishingState.Published;
                        }

                        await _WorkflowDbContext.BulkUpdateAsync(zap, x => x.PropertiesToInclude = new List <string> {
                            nameof(TemporaryExposureKeyEntity.PublishingState)
                        });

                        count += used.Length;

                        used = _PublishingDbContext.Set <EksCreateJobInputEntity>()
                               .Where(x => x.Used)
                               .Skip(count)
                               .Select(x => x.Id)
                               .Take(100)
                               .ToArray();
                    }

                    _WorkflowDbContext.SaveAndCommit();
                }

                _Logger.LogInformation($"Cleanup job tables.");
                await _PublishingDbContext.Set <EksCreateJobInputEntity>().BatchDeleteAsync();

                await _PublishingDbContext.Set <EksCreateJobOutputEntity>().BatchDeleteAsync();

                _PublishingDbContext.SaveAndCommit();
            }
        }
        public async Task CommitResults()
        {
            await using (_ContentDbContext.BeginTransaction())
            {
                var move = _ContentDbContext.EksOutput.Select(
                    x => new ExposureKeySetContentEntity
                {
                    Release              = x.Release,
                    Content              = x.Content,
                    ContentTypeName      = MediaTypeNames.Application.Zip,
                    CreatingJobName      = x.CreatingJobName,
                    CreatingJobQualifier = x.CreatingJobQualifier,
                    PublishingId         = _PublishingId.Create(x.Content)
                }).ToArray();     //TODO copy? Cos it's the same DB cos 'policy'
                _ContentDbContext.ExposureKeySetContent.AddRange(move);
                _ContentDbContext.SaveAndCommit();
            }

            await using (_ContentDbContext.BeginTransaction()) //Read-only
                await using (_WorkflowDbContext.BeginTransaction())
                {
                    var count = 0;
                    var used  = _ContentDbContext.Set <EksCreateJobInputEntity>()
                                .Where(x => x.Used)
                                .Skip(count)
                                .Select(x => x.Id)
                                .Take(100)
                                .ToArray();

                    while (used.Length > 0)
                    {
                        var zap = _WorkflowDbContext.TemporaryExposureKeys
                                  .Where(x => used.Contains(x.Id))
                                  .ToList();

                        foreach (var i in zap)
                        {
                            i.PublishingState = PublishingState.Published;
                        }

                        await _WorkflowDbContext.BulkUpdateAsync(zap, x => x.PropertiesToInclude = new List <string>() { nameof(TemporaryExposureKeyEntity.PublishingState) });

                        count += used.Length;

                        used = _ContentDbContext.Set <EksCreateJobInputEntity>()
                               .Where(x => x.Used)
                               .Skip(count)
                               .Select(x => x.Id)
                               .Take(100)
                               .ToArray();
                    }

                    _WorkflowDbContext.SaveAndCommit();
                }

            await _ContentDbContext.EksInput.BatchDeleteAsync();

            await _ContentDbContext.EksOutput.BatchDeleteAsync();

            _ContentDbContext.SaveAndCommit();
        }