public void Setup() { ctx = new DocmsContext(new DbContextOptionsBuilder <DocmsContext>() .UseInMemoryDatabase("DocumentHistoriesQueriesEventHandlerTests") .Options, new MockMediator()); sut = new DocumentHistoriesQueriesEventHandler(ctx); }
public async Task Setup() { ctx = new DocmsContext(new DbContextOptionsBuilder <DocmsContext>() .UseInMemoryDatabase("BlobsQueriesTests") .Options, new MockMediator()); sut = new BlobsQueries(ctx); ctx.BlobContainers.Add(new BlobContainer() { Path = "path1", Name = "path1", ParentPath = null }); ctx.BlobContainers.Add(new BlobContainer() { Path = "path1/subpath1", Name = "subpath1", ParentPath = "path1" }); ctx.BlobContainers.Add(new BlobContainer() { Path = "path2", Name = "path2", ParentPath = null }); ctx.Blobs.Add(new Blob() { Path = "path1/Blob1.txt", Name = "Blob1.txt", ParentPath = "path1" }); ctx.Blobs.Add(new Blob() { Path = "path1/Blob2.txt", Name = "Blob2.txt", ParentPath = "path1" }); ctx.Blobs.Add(new Blob() { Path = "path2/Blob1.txt", Name = "Blob1.txt", ParentPath = "path2" }); await ctx.SaveChangesAsync(); }
private void Deleted(DocmsContext ctx, string path, int contentId) { ctx.DocumentHistories.Add(DocumentHistory.DocumentDeleted( DateTime.UtcNow, contentId, path)); }
public ResetDocumentHistoriesCommandHandler( DocmsContext context, IDocumentRepository documentRepository, IDataStore dataStore) { _context = context; _documentRepository = documentRepository; _dataStore = dataStore; }
private void Updated(DocmsContext ctx, string path, int contentId) { var now = DateTime.UtcNow; ctx.DocumentHistories.Add(DocumentHistory.DocumentUpdated( DateTime.UtcNow, contentId, path, "stragekey", "text/plain", 5 + contentId.ToString().Length, Hash.CalculateHash(Encoding.UTF8.GetBytes("Hello" + contentId)), now, now)); }
private static async Task EnsureDirectoryExists(DocmsContext context, DocumentPath parent) { while (parent != null) { if (!await context.BlobContainers.AnyAsync(c => c.Path == parent.Value)) { context.BlobContainers.Add(new BlobContainer() { Path = parent.Value, Name = parent.Name, ParentPath = parent.Parent?.Value }); } parent = parent.Parent; } }
public async Task Setup() { ctx = new DocmsContext(new DbContextOptionsBuilder <DocmsContext>() .UseInMemoryDatabase("DocumentHistoriesQueriesTests") .Options, new MockMediator()); sut = new DocumentHistoriesQueries(ctx); Created(ctx, "path1/subpath1/document1.txt", 1); Created(ctx, "path1/subpath1/subsubpath1/document1.txt", 2); Created(ctx, "path1/subpath1/subsubpath1/document2.txt", 3); Created(ctx, "path1/subpath1/document2.txt", 4); Created(ctx, "path1/subpath1document2.txt", 5); Moved(ctx, "path1/subpath1/document2.txt", "path2/subpath1/document1.txt", 4); Updated(ctx, "path1/subpath1/document1.txt", 6); Deleted(ctx, "path1/subpath1/document1.txt", 6); Created(ctx, "path2/document1.txt", 7); await ctx.SaveChangesAsync(); }
public BlobsQueriesEventHandler(DocmsContext db) { _db = db; }
private async Task FixHistory(DocmsContext context, Document document, string path, List <DocumentHistory> histories) { var historiesToDelete = histories.Where(h => h.DocumentId < 0).ToList(); if (historiesToDelete.Count > 0) { logger.LogInformation("fixing history"); context.DocumentHistories.RemoveRange(historiesToDelete); await context.SaveChangesAsync(); } histories = histories .Where(h => h.DocumentId == document.Id) .OrderBy(h => h.Timestamp) .ToList(); var fixedHistory = new List <DocumentHistory>(); var currentHistory = default(DocumentHistory); foreach (var history in histories) { if (history == histories.First()) { // 最初のレコードは必ずcretead switch (history.Discriminator) { case DocumentHistoryDiscriminator.DocumentCreated: //問題なし currentHistory = history; if (histories.Count == 1 && currentHistory.StorageKey == document.StorageKey && currentHistory.Hash == document.Hash && currentHistory.FileSize == document.FileSize && currentHistory.Created == document.Created && currentHistory.LastModified == document.LastModified) { return; } break; case DocumentHistoryDiscriminator.DocumentUpdated: // エラー var createdHistory1 = new DocumentHistory() { Id = Guid.NewGuid(), Discriminator = DocumentHistoryDiscriminator.DocumentCreated, Timestamp = history.Timestamp, DocumentId = history.DocumentId, Path = path, StorageKey = history.StorageKey, ContentType = history.ContentType, FileSize = history.FileSize, Hash = history.Hash, Created = history.Created, LastModified = history.LastModified }; currentHistory = createdHistory1; break; case DocumentHistoryDiscriminator.DocumentDeleted: // エラー (回復不能) var createdHistory = histories.FirstOrDefault(h => h.Discriminator == DocumentHistoryDiscriminator.DocumentCreated || h.Discriminator == DocumentHistoryDiscriminator.DocumentUpdated); if (createdHistory == null) { createdHistory = new DocumentHistory() { Id = Guid.NewGuid(), Discriminator = DocumentHistoryDiscriminator.DocumentCreated, Timestamp = history.Timestamp.AddSeconds(-1), DocumentId = document.Id, Path = path, StorageKey = document.StorageKey, ContentType = document.ContentType, FileSize = document.FileSize, Hash = document.Hash, Created = document.Created, LastModified = document.LastModified }; } currentHistory = createdHistory; break; } fixedHistory.Add(currentHistory); } else if ( currentHistory.Discriminator != DocumentHistoryDiscriminator.DocumentDeleted && (currentHistory.StorageKey != history.StorageKey || currentHistory.Hash != history.Hash || currentHistory.FileSize != history.FileSize || currentHistory.Created != history.Created || currentHistory.LastModified != history.LastModified)) { // 最初のレコードは必ずcretead switch (history.Discriminator) { case DocumentHistoryDiscriminator.DocumentCreated: // エラー history.Discriminator = DocumentHistoryDiscriminator.DocumentUpdated; currentHistory = history; break; case DocumentHistoryDiscriminator.DocumentUpdated: // 正常 currentHistory = history; break; case DocumentHistoryDiscriminator.DocumentDeleted: if (string.IsNullOrEmpty(document.Path)) { // 正常 var deletedHistory = new DocumentHistory() { Id = Guid.NewGuid(), Discriminator = DocumentHistoryDiscriminator.DocumentDeleted, Timestamp = DateTime.UtcNow, DocumentId = document.Id, Path = path }; currentHistory = deletedHistory; } break; } fixedHistory.Add(currentHistory); } } if (currentHistory != null) { if (string.IsNullOrEmpty(document.Path) && currentHistory.Discriminator != DocumentHistoryDiscriminator.DocumentDeleted) { var deletedHistory = new DocumentHistory() { Id = Guid.NewGuid(), Discriminator = DocumentHistoryDiscriminator.DocumentDeleted, Timestamp = DateTime.UtcNow, DocumentId = document.Id, Path = path }; currentHistory = deletedHistory; fixedHistory.Add(currentHistory); } } if (currentHistory == null) { if (!string.IsNullOrEmpty(document.Path)) { var createdHistory = new DocumentHistory() { Id = Guid.NewGuid(), Discriminator = DocumentHistoryDiscriminator.DocumentCreated, Timestamp = DateTime.UtcNow, DocumentId = document.Id, Path = path, StorageKey = document.StorageKey, ContentType = document.ContentType, FileSize = document.FileSize, Hash = document.Hash, Created = document.Created, LastModified = document.LastModified }; currentHistory = createdHistory; fixedHistory.Add(currentHistory); } } if (!histories.Select(h => h.Id).SequenceEqual(fixedHistory.Select(h => h.Id))) { logger.LogInformation("fixing history"); context.DocumentHistories.RemoveRange(histories); await context.SaveChangesAsync(); context.DocumentHistories.AddRange(fixedHistory); await context.SaveChangesAsync(); } }
private async Task CheckAndFixStructure(DocmsContext context, Blob blob, ILookup <int, Document> documentsInContainer, ILookup <string, DocumentHistory> historiesInContainer) { logger.LogTrace("checking blob and document, path: {0}", blob.Path); var document = documentsInContainer[blob.DocumentId].FirstOrDefault(); if (document == null) { logger.LogWarning("document not exists."); logger.LogInformation("deleting blob"); context.Blobs.Remove(blob); logger.LogInformation("deleting history"); context.DocumentHistories.RemoveRange(context.DocumentHistories.Where(h => h.DocumentId == blob.DocumentId)); await context.SaveChangesAsync(); return; } if (string.IsNullOrEmpty(document.Path)) { logger.LogWarning("document has been deleted."); logger.LogInformation("deleting blob"); context.Blobs.Remove(blob); logger.LogInformation("fixing history"); await FixHistory(context, document, blob.Path, historiesInContainer[blob.Path].ToList()); logger.LogInformation("adding delete history"); context.DocumentHistories.Add(new DocumentHistory() { Id = Guid.NewGuid(), Discriminator = DocumentHistoryDiscriminator.DocumentDeleted, Timestamp = DateTime.UtcNow, DocumentId = document.Id, Path = blob.Path }); await context.SaveChangesAsync(); return; } await FixHistory(context, document, blob.Path, historiesInContainer[blob.Path].ToList()); if (document.Path != blob.Path) { logger.LogWarning("blob Path was wrong"); } if (document.Hash != blob.Hash) { logger.LogWarning("blob Hash was wrong"); } if (document.FileSize != blob.FileSize) { logger.LogWarning("blob FileSize was wrong"); } if (document.ContentType != blob.ContentType) { logger.LogWarning("blob ContentType was wrong"); } if (document.StorageKey != blob.StorageKey) { logger.LogWarning("blob StorageKey was wrong"); } if (document.Created != blob.Created) { logger.LogWarning("blob Created was wrong"); } if (document.LastModified != blob.LastModified) { logger.LogWarning("blob LastModified was wrong"); } }
public UsersQueries(VisualizationSystemContext vsDb, DocmsContext docmsDb) { _vsDb = vsDb; _docmsDb = docmsDb; }
public DeviceGrantsQueriesEventHandler(DocmsContext db, IUsersQueries usersQueries) { _db = db; _usersQueries = usersQueries; }
public DocumentRepository(DocmsContext context) { _context = context; }
public DocumentHistoriesQueriesEventHandler(DocmsContext db) { _db = db; }
public ClientsQueriesEventHandler(DocmsContext db) { _db = db; }
public DeviceGrantsQueries(DocmsContext db) { _db = db; }
public DeviceRepository(DocmsContext context) { _context = context; }
public ClientsQueries(DocmsContext context) { _context = context; }
public BlobsQueries(DocmsContext db) { _db = db; }
public void Setup() { ctx = new MockDocmsContext("BlobsQueriesEventHandlerTests"); sut = new BlobsQueriesEventHandler(ctx); }
public UpdateSecurityStampCommandHandler(DocmsContext context) { _context = context; }
public UpdateDeviceLastAccessTimeCommandHandler(DocmsContext context) { _context = context; }
public DocumentHistoriesQueries(DocmsContext ctx) { this.ctx = ctx; }
public ClientRepository(DocmsContext context) { _context = context; }