public ResourceBundleContentEntity Execute(string id) { return(_DbConfig.Set <ResourceBundleContentEntity>() .Where(x => x.PublishingId == id) .Take(1) .SingleOrDefault()); }
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); }
/// <summary> /// Returns null if not found. /// </summary> /// <param name="exposureKeySetId"></param> /// <returns></returns> public ExposureKeySetContentEntity Execute(string exposureKeySetId) { return(_DbConfig.Set <ExposureKeySetContentEntity>() .Where(x => x.PublishingId == exposureKeySetId) .Take(1) .ToArray() .SingleOrDefault()); }
public RiskCalculationContentEntity Execute(string id) { return(_DbContextProvider.Set <RiskCalculationContentEntity>() .Where(x => x.PublishingId == id) .Take(1) .ToArray() //TODO sql might let me drop this. .SingleOrDefault()); }
public RiskCalculationContentEntity Execute() { var now = _DateTimeProvider.Now(); return(_DbConfig.Set <RiskCalculationContentEntity>() .Where(x => x.Release <= now) .OrderByDescending(x => x.Release) .Take(1) .SingleOrDefault()); }
public async Task Execute() { var now = _UtcDateTimeProvider.Now(); var timeToDie = _DbConfig.Set <ExposureKeySetContentEntity>() .Where(x => x.Release < now - TimeSpan.FromDays(_GaenContentConfig.ExposureKeySetLifetimeDays)) .ToList(); await _DbConfig.BulkDeleteAsync(timeToDie); }
public async Task Execute() { var now = _UtcDateTimeProvider.Now(); var hushNow = _Context.Set <KeyReleaseWorkflowState>() .Where(x => x.Created < now - TimeSpan.FromDays(_GaenContentConfig.KeysLastSecretLifetimeDays)) .ToArray(); await _Context.BulkDeleteAsync(hushNow); }
public string[] Execute() { //TODO cant test this - inject! var expired = new StandardUtcDateTimeProvider().Now() - TimeSpan.FromDays(_GaenContentConfig.ExposureKeySetLifetimeDays); var result = _DbConfig.Set <ExposureKeySetContentEntity>() .Where(x => x.Release > expired) .Select(x => x.PublishingId) .ToArray(); return(result); }
public string Execute() { var now = _DateTimeProvider.Now(); return(_DbConfig.Set <T>() .Where(x => x.Release <= now) .OrderByDescending(x => x.Release) .Take(1) .Select(x => x.PublishingId) .SingleOrDefault()); }
public async Task <T?> Execute(string id) { return(_DbContextProvider.Set <T>() .SingleOrDefault(x => x.PublishingId == id)); //if (e == null) // return null; //return new BinaryContentResponse //{ // LastModified = e.Release, // PublishingId = e.PublishingId, // ContentTypeName = e.ContentTypeName, // Content = e.Content //}; }
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()); }
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 async Task Execute(HttpContext httpContext) { if (httpContext.Request.Headers.TryGetValue("if-none-match", out var etagValue)) { httpContext.Response.ContentLength = 0; httpContext.Response.StatusCode = 400; } var now = _DateTimeProvider.Now(); var content = _ContentDb.Set <ManifestEntity>() .Where(x => x.Release < now) .OrderByDescending(x => x.Release) .Take(1) .SingleOrDefault(); if (content == null) { httpContext.Response.StatusCode = 200; httpContext.Response.ContentLength = 0; return; } if (etagValue == content.PublishingId) { httpContext.Response.ContentLength = 0; httpContext.Response.StatusCode = 304; return; } httpContext.Response.Headers.Add("etag", content.PublishingId); httpContext.Response.Headers.Add("last-modified", content.Release.ToUniversalTime().ToString("r")); httpContext.Response.Headers.Add("content-type", content.SignedContentTypeName); httpContext.Response.Headers.Add("x-vws-signed", true.ToString()); httpContext.Response.StatusCode = 200; httpContext.Response.ContentLength = content.SignedContent.Length; await httpContext.Response.Body.WriteAsync(content.SignedContent); }
private async Task DeleteContent <T>(double lifetime) where T : ContentEntity { var now = _DateTimeProvider.Now(); var dbSet = _ContentDbContext.Set <T>(); var exceptEntity = dbSet .Where(x => x.Release <= now) .OrderByDescending(x => x.Release) .FirstOrDefault(); if (exceptEntity != null) { var id = exceptEntity.Id; var recordToDelete = dbSet .Where(x => x.Release <= now.AddDays(lifetime)) .Where(x => x.Id != id) .OrderByDescending(x => x.Release) .ToList(); await _ContentDbContext.BulkDeleteAsync(recordToDelete); } }
public async Task CommitResults() { await using (_ContentDbContext.BeginTransaction()) { var move = _ContentDbContext.EksOutput.Select( x => new ExposureKeySetContentEntity { Release = x.Release, Content = null, ContentTypeName = null, SignedContentTypeName = MediaTypeNames.Application.Zip, SignedContent = x.Content, CreatingJobName = x.CreatingJobName, CreatingJobQualifier = x.CreatingJobQualifier, PublishingId = _PublishingId.Create(x.Content) }).ToArray(); _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(); } }