private void WriteDirectoryToObjFolder(ArticleDirectory directory) { string json = Json.Default.Serialize(directory); string directoryPath = ArticleConstants.Files.GetDirectoryFile(_option.BuildFolder !); File.WriteAllText(directoryPath, json); }
public async Task Set(ArticleDirectory articleDirectory, CancellationToken token = default) { articleDirectory.VerifyNotNull(nameof(articleDirectory)); _logger.LogTrace($"{nameof(Set)}: Writing"); await _dataLakeStore.Write(ArticleConstants.DirectoryFileName, articleDirectory.ToBytes(), true, token); }
public static byte[] ToBytes(this ArticleDirectory subject) { subject.Verify(); var json = Json.Default.Serialize(subject); return(Encoding.UTF8.GetBytes(json)); }
public async Task Set(ArticleDirectory record, CancellationToken token = default) { record.VerifyNotNull(nameof(record)); _logger.LogTrace($"{nameof(Set)}: actorKey={_actorKey}"); IDirectoryActor actor = _actorHost !.GetActor <IDirectoryActor>(_actorKey); await actor.Set(record, token); }
public async Task Set(ArticleDirectory articleDirectory, CancellationToken token) { articleDirectory.VerifyNotNull(nameof(articleDirectory)); _logger.LogTrace($"{nameof(Set)}: Writing"); await _directoryStore.Set(articleDirectory, token); _cache.Set(articleDirectory); }
public static void WriteToFile(this ArticleDirectory subject, string filePath) { filePath.VerifyNotEmpty(nameof(filePath)); subject.Verify(); var json = Json.Default.SerializeFormat(subject); File.WriteAllText(filePath, json); }
public async Task <IActionResult> Post([FromBody] ArticleDirectory record) { if (!record.IsValid()) { return(BadRequest()); } _logger.LogTrace($"{nameof(Post)}"); await _directoryService.Set(record); return(Ok()); }
public async Task Build(CancellationToken token) { _logger.LogInformation($"{nameof(Build)} - Build"); Context context = new(); await ScanManifest(context, token); _logger.LogInformation($"{nameof(Build)}: Count={context.Queue.Count}"); var directory = new ArticleDirectory { Articles = context.Queue.ToList(), }; WriteDirectoryToObjFolder(directory); }
public async Task GivenArticleManifest_WhenFullLifeCycle_ShouldPass() { TestWebsiteHost host = TestApplication.GetHost(); const int max = 10; var directory = new ArticleDirectory { Articles = Enumerable.Range(0, max) .Select(x => new ArticleManifest { ArticleId = $"ArticleId-{x}", Title = $"Title_{x}", Date = new DateTime(2020, 1, 5), }).ToList() }; await host.DirectoryClient.Set(directory); ArticleDirectory?readDirectory = await host.DirectoryClient.Get(); readDirectory.Should().NotBeNull(); directory.Articles.Count.Should().Be(readDirectory !.Articles.Count); var list = directory.Articles .Zip(readDirectory !.Articles, (o, i) => (o, i)) .ToList(); foreach (var item in list) { (item.o == item.i).Should().BeTrue(); } await host.DirectoryClient.Delete(); readDirectory = await host.DirectoryClient.Get(); readDirectory.Should().BeNull(); }
public ArticleDirectorySearch(ArticleDirectory articleDirectory) { articleDirectory.VerifyNotNull(nameof(articleDirectory)); _articleDirectory = articleDirectory; }
public static bool IsValid(this ArticleDirectory subject) => subject != null && subject.Articles != null;
public static void Verify(this ArticleDirectory subject) { subject.VerifyNotNull(nameof(subject)); subject.Articles.VerifyNotNull(nameof(subject)); }
public static IReadOnlyList <ArticleManifest> GetByTag(this ArticleDirectory subject, string tag) => subject.Articles .Where(x => x.GetReferences().Contains(tag, StringComparer.OrdinalIgnoreCase)) .ToList();
public static IReadOnlyList <string> GetReference(this ArticleDirectory subject) => subject.Articles .SelectMany(x => x.GetReferences()) .Distinct(StringComparer.OrdinalIgnoreCase) .OrderBy(x => x) .ToList();
public static IReadOnlyList <ArticleManifest> Get(this ArticleDirectory subject, params ArticleArea[] articleAreas) => subject.Articles .Select(x => (subject: x, ArticleId: (ArticleId)x.ArticleId))
public static IReadOnlyList <ArticleManifest> GetLatest(this ArticleDirectory subject) => subject.Articles .OrderByDescending(x => x.Date) .ToList();