Esempio n. 1
0
        public async Task <IList <IPosting> > CollectPostingsAsync(IContainer container, bool isIntegrationTest)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var allPostings = new List <IPosting>();

            var sourceFolder = await GetSourceFolderAsync(container, isIntegrationTest);

            if (sourceFolder == null)
            {
                return(allPostings);
            }

            var files  = Directory.GetFiles(sourceFolder.FullName, "*.txt").ToList();
            var reader = container.Resolve <ISourceFileReader>();

            foreach (var file in files)
            {
                await DataPresenter.WriteLineAsync($"File: {file}");

                var errorsAndInfos = new ErrorsAndInfos();
                var postings       = reader.ReadPostings(file, errorsAndInfos);
                if (errorsAndInfos.AnyErrors())
                {
                    await DataPresenter.WriteErrorsAsync(errorsAndInfos);

                    return(allPostings);
                }

                await DataPresenter.WriteLineAsync($"{postings.Count} posting/-s found");

                allPostings.AddRange(postings);
            }

            if (!allPostings.Any())
            {
                return(allPostings);
            }

            var maxDate = allPostings.Max(p => p.Date);
            var minDate = new DateTime(maxDate.Year - 1, 1, 1);
            await DataPresenter.WriteLineAsync($"{allPostings.Count(p => p.Date < minDate)} posting/-s removed");

            allPostings.RemoveAll(p => p.Date < minDate);

            return(allPostings);
        }
Esempio n. 2
0
        public static async Task WriteErrorsAsync(this IDataPresenter dataPresenter, IErrorsAndInfos errorsAndInfos)
        {
            var errors = errorsAndInfos.Errors.ToList();

            foreach (var error in errors)
            {
                await dataPresenter.WriteLineAsync(error);
            }
        }