Esempio n. 1
0
        /// <summary>
        /// Create new transaction.
        /// </summary>
        internal static TTransaction Create <TTransaction>(AbstractRepository repository, string description) where TTransaction : AbstractTransaction
        {
            var result  = TransactionBuilder.CreateInstance <TTransaction>(repository, description);
            var @params = new Dictionary <string, object> {
                { "description", description }
            };

            result._eventQueue = new ConcurrentQueue <EventData>();
            result.AddEvent(result, $"{typeof(TTransaction).Name} started.", @params);
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Load transaction from store.
        /// </summary>
        internal static TTransaction Load <TTransaction>(AbstractRepository repository, string identity) where TTransaction : AbstractTransaction
        {
            var events = repository.LoadEntity(identity).ToArray();
            var @event = events.First();

            if (@event.EventName != $"{typeof(TTransaction).Name} started." || @event.Identity != @event.Root || @event.Identity != @event.Transaction)
            {
                throw new InvalidOperationException("Unsupported type of transaction detected.");
            }
            return((TTransaction)TransactionBuilder.CreateInstance <TTransaction>(repository, (string)@event.Params["description"])
                   .LoadEvents(events.Skip(1)));
        }