Пример #1
0
        /// <summary>
        /// Get the latest <see cref="Snapshot"/> from storage.
        /// </summary>
        /// <returns>The most recent <see cref="Snapshot"/> of</returns>
        protected override Snapshot Get(Type aggregateRootType, string streamName)
        {
            MongoDbEventData query = MongoCollection
                                     .AsQueryable()
                                     .Where(snapshot => snapshot.AggregateId == streamName)
                                     .OrderByDescending(eventData => eventData.Version)
                                     .Take(1)
                                     .SingleOrDefault();

            return(EventDeserialiser.Deserialise(query));
        }
Пример #2
0
        /// <summary>
        /// Saves the provided <paramref name="snapshot"/> into storage.
        /// </summary>
        /// <param name="snapshot">the <see cref="Snapshot"/> to save and store.</param>
        public override void Save(Snapshot snapshot)
        {
            EventData eventData     = BuildEventData(snapshot);
            var       safeEventData = new MongoDbEventData(eventData);

            Logger.LogDebug("Adding an event to the MongoDB database", "MongoDbSnapshotStore\\Save");
            try
            {
                DateTime start = DateTime.Now;
                MongoCollection.InsertOne(safeEventData);
                DateTime end = DateTime.Now;
                Logger.LogDebug(string.Format("Adding data in the MongoDB database took {0}.", end - start), "MongoDbSnapshotStore\\Save");
            }
            finally
            {
                Logger.LogDebug("Adding an event to the MongoDB database... Done", "MongoDbSnapshotStore\\Save");
            }
        }
Пример #3
0
        /// <summary>
        /// Persist the provided <paramref name="eventData"/> into storage.
        /// </summary>
        /// <param name="eventData">The <see cref="EventData"/> to persist.</param>
        protected override void PersistEvent(EventData eventData)
        {
            var safeEventData = eventData as MongoDbEventData;

            if (safeEventData == null)
            {
                safeEventData = new MongoDbEventData(eventData);
            }
            Logger.LogDebug("Adding an event to the MongoDB database", "MongoDbEventStore\\PersistEvent");
            try
            {
                DateTime start = DateTime.Now;
                MongoCollection.InsertOne(safeEventData);
                DateTime end = DateTime.Now;
                Logger.LogDebug(string.Format("Adding data in the MongoDB database took {0}.", end - start), "MongoDbEventStore\\PersistEvent");
            }
            finally
            {
                Logger.LogDebug("Adding an event to the MongoDB database... Done", "MongoDbEventStore\\PersistEvent");
            }
        }