private async Task WriteOutput(EksCreateJobOutputEntity e)
        {
            await using (_ContentDbContext.BeginTransaction())
            {
                await _ContentDbContext.AddAsync(e);

                _ContentDbContext.SaveAndCommit();
            }
        }
Example #2
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 Execute()
        {
            await DeleteContent <RiskCalculationContentEntity>(_Config.ContentLifetimeDays);
            await DeleteContent <ResourceBundleContentEntity>(_Config.ContentLifetimeDays);
            await DeleteContent <AppConfigContentEntity>(_Config.ContentLifetimeDays);
            await DeleteContent <ExposureKeySetContentEntity>(_Config.ExposureKeySetLifetimeDays);

            _ContentDbContext.SaveAndCommit();
        }
        public async Task DropExampleContent()
        {
            await using var tx = await _DbContextProvider.Database.BeginTransactionAsync();

            foreach (var e in _DbContextProvider.AppConfigContent)
            {
                _DbContextProvider.AppConfigContent.Remove(e);
            }

            foreach (var e in _DbContextProvider.ResourceBundleContent)
            {
                _DbContextProvider.ResourceBundleContent.Remove(e);
            }

            foreach (var e in _DbContextProvider.RiskCalculationContent)
            {
                _DbContextProvider.RiskCalculationContent.Remove(e);
            }
            _DbContextProvider.SaveAndCommit();
        }
        public async Task <IActionResult> Execute(RiskCalculationConfigArgs args)
        {
            if (!_Validator.Valid(args))
            {
                return(new BadRequestResult());
            }

            await _Writer.Execute(args);

            _ContextProvider.SaveAndCommit();
            return(new OkResult());
        }
        public async Task <IActionResult> Execute(AppConfigArgs args)
        {
            if (!_Validator.Valid(args))
            {
                return(new BadRequestResult());
            }

            await _InsertDbCommand.Execute(args);

            _Context.SaveAndCommit();
            return(new OkResult());
        }
        public async Task <IActionResult> Execute(BinaryContentResponse content)
        {
            //TODO check sig!!!

            if (content == null)
            {
                return(new OkResult());
            }

            var e = new T
            {
                PublishingId          = content.PublishingId,
                Content               = content.Content,
                ContentTypeName       = content.ContentTypeName,
                SignedContent         = content.Content,
                SignedContentTypeName = MediaTypeNames.Application.Zip,
                Release               = content.LastModified,
            };

            //var config = new StandardEfDbConfig(_Configuration, "Content");
            //var builder = new SqlServerDbContextOptionsBuilder(config);
            //var _DbContext = new ExposureContentDbContext(builder.Build());

            try

            {
                await _DbContext.Set <T>().AddAsync(e);

                _DbContext.SaveAndCommit();
            }
            catch (DbUpdateException ex)
            {
                if ((ex?.InnerException as SqlException)?.Number == 2601)
                {
                    return(new ConflictResult());
                }

                throw;
            }
            catch (Exception ex)
            {
                throw;
            }

            return(new OkResult());
        }
Example #8
0
        public async Task AddExampleContent()
        {
            await using var tx = await _DbContextProvider.Database.BeginTransactionAsync();

            await Write(
                new ResourceBundleArgs
            {
                Release = _DateTimeProvider.Now(),
                Text    = new Dictionary <string, Dictionary <string, string> >
                {
                    {
                        "en-GB", new Dictionary <string, string>()
                        {
                            { "InfectedMessage", "You're possibly infected" }
                        }
                    },
                    {
                        "nl-NL", new Dictionary <string, string>
                        {
                            { "InfectedMessage", "U bent mogelijk geinvecteerd" }
                        }
                    }
                }
            }
                );



            var rbd = ReadFromResource <ResourceBundleArgs>("RiskCalcDefaults.json");

            rbd.Release = _DateTimeProvider.Now();
            await Write(rbd);

            var rcd = ReadFromResource <RiskCalculationConfigArgs>("RiskCalcDefaults.json");

            rcd.Release = _DateTimeProvider.Now();
            await Write(rcd);

            var acd = ReadFromResource <AppConfigArgs>("AppConfigDefaults.json");

            acd.Release = _DateTimeProvider.Now();
            await Write(acd);

            _DbContextProvider.SaveAndCommit();
        }
        public async Task <IActionResult> Execute(BinaryContentResponse content)
        {
            //TODO check sig!!!

            if (content == null)
            {
                return(new OkResult());
            }

            var e = new T
            {
                PublishingId          = content.PublishingId,
                Content               = content.Content,
                ContentTypeName       = content.ContentTypeName,
                SignedContent         = content.SignedContent,
                SignedContentTypeName = MediaTypeNames.Application.Zip,
                Release               = content.LastModified,
            };

            try
            {
                await _DbContext.Set <T>().AddAsync(e);

                _DbContext.SaveAndCommit();
            }
            catch (DbUpdateException ex)
            {
                if ((ex?.InnerException as SqlException)?.Number == 2601)
                {
                    return(new ConflictResult());
                }

                throw;
            }
            catch (Exception ex)
            {
                throw;
            }

            return(new OkResult());
        }
        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();
            }
        }
Example #11
0
        public async Task AddExampleContent()
        {
            await using var tx = await _DbContextProvider.Database.BeginTransactionAsync();

            await Write(
                new ResourceBundleArgs
            {
                Release = _DateTimeProvider.Now(),
                Text    = new Dictionary <string, Dictionary <string, string> >
                {
                    {
                        "en-GB", new Dictionary <string, string>()
                        {
                            { "InfectedMessage", "You're possibly infected" }
                        }
                    },
                    {
                        "nl-NL", new Dictionary <string, string>
                        {
                            { "InfectedMessage", "U bent mogelijk geinvecteerd" }
                        }
                    }
                }
            }
                );

            await Write(
                new ResourceBundleArgs
            {
                Release             = _DateTimeProvider.Now(),
                IsolationPeriodDays = 10,
                ObservedTemporaryExposureKeyRetentionDays = 14,
                TemporaryExposureKeyRetentionDays         = 15,
                Text = new Dictionary <string, Dictionary <string, string> >()
                {
                    {
                        "en-GB", new Dictionary <string, string>
                        {
                            { "FirstLong", "First" },
                            { "FirstShort", "1st" }
                        }
                    },
                    {
                        "nl-NL", new Dictionary <string, string>
                        {
                            { "FirstLong", "Eerste" },
                            { "FirstShort", "1ste" }
                        }
                    }
                }
            });

            await Write(
                new ResourceBundleArgs
            {
                Release = _DateTimeProvider.Now()
            }
                );

            await Write(
                new RiskCalculationConfigArgs
            {
                Release                          = new DateTime(2020, 6, 12),
                MinimumRiskScore                 = 1,
                DaysSinceLastExposureScores​     = new[] { 1, 2, 3, 4, 5, 6, 7, 8 },
                AttenuationScores​               = new[] { 1, 2, 3, 4, 5, 6, 7, 8 },
                DurationAtAttenuationThresholds​ = new[] { 42, 56 },
                DurationScores                   = new[] { 1, 2, 3, 4, 5, 6, 7, 8 },
                TransmissionRiskScores​          = new[] { 1, 2, 3, 4, 5, 6, 7, 8 },
            });

            await Write(
                new AppConfigArgs
            {
                Release           = _DateTimeProvider.Now(),
                ManifestFrequency = 5,
                DecoyProbability  = 1,
                Version           = 123345
            });

            _DbContextProvider.SaveAndCommit();
        }