using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace InABox.Core { public interface IPostResult where TPostable : IPostable { /// /// All successful or failed s. /// public IEnumerable PostedEntities { get; } public IEnumerable SuccessfulEntities => PostedEntities.Where(x => x.PostedStatus == PostedStatus.Posted); public IEnumerable FailedEntities => PostedEntities.Where(x => x.PostedStatus == PostedStatus.PostFailed); public IEnumerable>>> Fragments { get; } } public class PostResult : IPostResult where TPostable : IPostable { private List posts = new List(); private Dictionary>> fragments = new Dictionary>>(); /// /// All successful or failed s. /// public IEnumerable PostedEntities => posts; public IEnumerable>>> Fragments => fragments.Select(x => new KeyValuePair>>(x.Key, x.Value)); public void AddSuccess(TPostable post) { post.Post(); posts.Add(post); } public void AddFailed(TPostable post, string note) { post.FailPost(note); posts.Add(post); } public void AddFragment(IPostableFragment fragment) { var type = fragment.GetType(); if (!fragments.TryGetValue(type, out var fragmentsList)) { fragmentsList = new List>(); fragments[type] = fragmentsList; } fragmentsList.Add(fragment); } } }