using InABox.Core; using NPOI.SS.Formula.Functions; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InABox.Poster.Timberline; public class TimberlinePostResult : IPostResult where TPostable : IPostable where TExport : class { private List> items = new List>(); private Dictionary>> fragments = new Dictionary>>(); public IEnumerable Exports => items .Where(x => x.Item1.PostedStatus == PostedStatus.Posted) .NotNull(x => x.Item2); public IEnumerable PostedEntities => items.Select(x => x.Item1); public IEnumerable> Items => items; public IEnumerable>>> Fragments => fragments.Select(x => new KeyValuePair>>(x.Key, x.Value)); public void AddSuccess(TPostable post, TExport? export) { post.Post(); items.Add(new Tuple(post, export)); } public void AddFailed(TPostable post, string note) { post.FailPost(note); items.Add(new Tuple(post, null)); } public void AddFragment(IPostableFragment fragment) { if (!fragments.TryGetValue(fragment.GetType(), out var fragmentList)) { fragmentList = new List>(); fragments[fragment.GetType()] = fragmentList; } fragmentList.Add(fragment); } }