public virtual bool AddSnapshot(ISnapshot snapshot)
        {
            if (snapshot == null)
            {
                return(false);
            }

            Logger.Debug(Messages.AddingSnapshot, snapshot.StreamId, snapshot.StreamRevision, snapshot.BucketId);

            try
            {
                return(TryRaven(() =>
                {
                    using (TransactionScope scope = OpenCommandScope())
                        using (IDocumentSession session = _store.OpenSession())
                        {
                            RavenSnapshot ravenSnapshot = snapshot.ToRavenSnapshot(_serializer);
                            session.Store(ravenSnapshot);
                            session.SaveChanges();
                            scope.Complete();
                        }

                    SaveStreamHead(snapshot.ToRavenStreamHead());

                    return true;
                }));
            }
            catch (Raven.Abstractions.Exceptions.ConcurrencyException)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public static Snapshot ToSnapshot(this RavenSnapshot snapshot, IDocumentSerializer serializer)
        {
            if (snapshot == null)
            {
                return(null);
            }

            return(new Snapshot(snapshot.BucketId, snapshot.StreamRevision, serializer.Deserialize <object>(snapshot.Payload)));
        }