Beispiel #1
0
        public EventStream Load(IIdentity id)
        {
            Condition.Requires(id, "id").IsNotNull();

            NamedDataSet data = AppendOnlyStore.Load(id.Literal);

            if (data == null)
            {
                return(null);
            }

            List <IEvent> events = new List <IEvent>(data.Data.Select(d => (IEvent)Serializer.Deserialize(d)));
            EventStream   s      = new EventStream(data.Version, events);

            return(s);
        }
        public void Append(string name, byte[] data, long expectedVersion)
        {
            lock (StreamsLock) // Not the best performing thing to do, but who cares with this not-for-production implementation ...
              {
            NamedDataSet entry;
            if (!Streams.TryGetValue(name, out entry))
            {
              entry = new NamedDataSet(name);
              Streams[name] = entry;
            }
            if (entry.Version != expectedVersion)
              throw new VersionConflictException(expectedVersion, entry.Version, name);
            entry.Data.Add(data);
            entry.Version++;

            Events.Add(new DataItem(Events.Count+1, name, data));
              }
        }
Beispiel #3
0
        public void Append(string name, byte[] data, long expectedVersion)
        {
            lock (StreamsLock) // Not the best performing thing to do, but who cares with this not-for-production implementation ...
            {
                NamedDataSet entry;
                if (!Streams.TryGetValue(name, out entry))
                {
                    entry         = new NamedDataSet(name);
                    Streams[name] = entry;
                }
                if (entry.Version != expectedVersion)
                {
                    throw new VersionConflictException(expectedVersion, entry.Version, name);
                }
                entry.Data.Add(data);
                entry.Version++;

                Events.Add(new DataItem(Events.Count + 1, name, data));
            }
        }
 public NamedDataSet Load(string name)
 {
     NamedDataSet result = new NamedDataSet(name);
       LoadCommand.Parameters["@name"].Value = name;
       using (SqlDataReader r = LoadCommand.ExecuteReader())
       {
     while (r.Read())
     {
       byte[] data = (byte[])r["Data"];
       long version = (long)r["Version"];
       result.Data.Add(data);
       result.Version = version; // Ends up getting the last (biggest) value
     }
       }
       return result;
 }