<commit_before>﻿using System;
using System.Collections.Generic;

namespace EventStreams {
    using Core.Domain;

    public class EventSource {
        private readonly IDictionary<Guid, AggregateRootObserver> _objects =
            new Dictionary<Guid, AggregateRootObserver>();

        public TAggregateRoot Create<TAggregateRoot>() where TAggregateRoot : class, IAggregateRoot, new() {
            var ar = new TAggregateRoot();
            var observer = new AggregateRootObserver(this, ar);
            _objects.Add(ar.Identity, observer);
            ar.Subscribe(observer);
            return ar;
        }

        internal void Commit(IAggregateRoot aggregateRoot, IEnumerable<EventArgs> uncommitedEvents) {
            
        }
    }

    internal sealed class AggregateRootObserver : IObserver<EventArgs> {
        private readonly EventSource _parentSource;
        private readonly IAggregateRoot _aggregateRoot;
        private readonly List<EventArgs> _uncommitted = new List<EventArgs>(4);

        public AggregateRootObserver(EventSource parentSource, IAggregateRoot aggregateRoot) {
            if (parentSource == null) throw new ArgumentNullException("parentSource");
            if (aggregateRoot == null) throw new ArgumentNullException("aggregateRoot");
            _parentSource = parentSource;
            _aggregateRoot = aggregateRoot;
        }

        public void OnNext(EventArgs value) {
            _uncommitted.Add(value);
        }

        public void OnError(Exception error) {
            
        }

        public void OnCompleted() {
            _parentSource.Commit(_aggregateRoot, _uncommitted);
        }
    }
}<commit_msg>Small thoughts on how EventSource will be structured.<commit_after>﻿using System;
using System.Collections.Generic;

namespace EventStreams {
    using Core.Domain;

    public class EventSource {
        private readonly IDictionary<Guid, AggregateRootObserver> _objects =
            new Dictionary<Guid, AggregateRootObserver>();

        public TAggregateRoot Create<TAggregateRoot>() where TAggregateRoot : class, IAggregateRoot, new() {
            var ar = new TAggregateRoot();
            var observer = new AggregateRootObserver(this, ar);
            _objects.Add(ar.Identity, observer);
            ar.Subscribe(observer);
            return ar;
        }

        //public TAggregateRoot Open<TAggregateRoot>(Guid identity) where TAggregateRoot : class, IAggregateRoot, new() {
            //var ar = Create<TAggregateRoot>()
        //}

        internal void Commit<TAggregateRoot>(TAggregateRoot aggregateRoot, IEnumerable<EventArgs> uncommittedEvents) where TAggregateRoot : class, IAggregateRoot, new() {
            
        }
    }

    internal sealed class AggregateRootObserver : IObserver<EventArgs> {
        private readonly EventSource _parentSource;
        private readonly IAggregateRoot _aggregateRoot;
        private readonly List<EventArgs> _uncommitted = new List<EventArgs>(4);

        public AggregateRootObserver(EventSource parentSource, IAggregateRoot aggregateRoot) {
            if (parentSource == null) throw new ArgumentNullException("parentSource");
            if (aggregateRoot == null) throw new ArgumentNullException("aggregateRoot");
            _parentSource = parentSource;
            _aggregateRoot = aggregateRoot;
        }

        public void OnNext(EventArgs value) {
            _uncommitted.Add(value);
        }

        public void OnError(Exception error) {
            
        }

        public void OnCompleted() {
            //_parentSource.Commit(_aggregateRoot, _uncommitted);
        }
    }
}
{'fraction_non_alphanumeric': 0.07747252747252747, 'fraction_numerical': 0.0005494505494505495, 'mean_word_length': 2.662977867203219, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1975329', 'n_tokens_mistral': 924, 'n_tokens_neox': 917, 'n_words': 226}