Esempio n. 1
0
        private void WriteDirectoryToObjFolder(ArticleDirectory directory)
        {
            string json          = Json.Default.Serialize(directory);
            string directoryPath = ArticleConstants.Files.GetDirectoryFile(_option.BuildFolder !);

            File.WriteAllText(directoryPath, json);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public static byte[] ToBytes(this ArticleDirectory subject)
        {
            subject.Verify();

            var json = Json.Default.Serialize(subject);

            return(Encoding.UTF8.GetBytes(json));
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        public async Task <IActionResult> Post([FromBody] ArticleDirectory record)
        {
            if (!record.IsValid())
            {
                return(BadRequest());
            }

            _logger.LogTrace($"{nameof(Post)}");

            await _directoryService.Set(record);

            return(Ok());
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        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;
        }
Esempio n. 11
0
 public static bool IsValid(this ArticleDirectory subject) => subject != null && subject.Articles != null;
Esempio n. 12
0
 public static void Verify(this ArticleDirectory subject)
 {
     subject.VerifyNotNull(nameof(subject));
     subject.Articles.VerifyNotNull(nameof(subject));
 }
Esempio n. 13
0
 public static IReadOnlyList <ArticleManifest> GetByTag(this ArticleDirectory subject, string tag) => subject.Articles
 .Where(x => x.GetReferences().Contains(tag, StringComparer.OrdinalIgnoreCase))
 .ToList();
Esempio n. 14
0
 public static IReadOnlyList <string> GetReference(this ArticleDirectory subject) => subject.Articles
 .SelectMany(x => x.GetReferences())
 .Distinct(StringComparer.OrdinalIgnoreCase)
 .OrderBy(x => x)
 .ToList();
Esempio n. 15
0
 public static IReadOnlyList <ArticleManifest> Get(this ArticleDirectory subject, params ArticleArea[] articleAreas) => subject.Articles
 .Select(x => (subject: x, ArticleId: (ArticleId)x.ArticleId))
Esempio n. 16
0
 public static IReadOnlyList <ArticleManifest> GetLatest(this ArticleDirectory subject) => subject.Articles
 .OrderByDescending(x => x.Date)
 .ToList();