Example #1
0
        public void Record(IEnumerable<IEvent> eventBatch)
        {
            var recordedEvents = new List<RecordedEvent>();
            foreach (var e in eventBatch)
            {
                var timestamp = DateTime.Now.ToUniversalTime();
                var sequencenumber = timestamp.Ticks.ToString("00000000000000000000") + _eventCounter++.ToSequenceNumber();
                var re = new RecordedEvent(Guid.NewGuid(),
                                           timestamp,
                                           sequencenumber,
                                           e.Name,
                                           e.Context,
                                           e.Data);

                var edoc = new BsonDocument {
                    {"_id", re.Id.ToString()},
                    {"timestamp", re.Timestamp},
                    {"sequencenumber", re.Sequencenumber},
                    {"name", re.Name},
                    {"context", re.Context},
                    {"data", re.Data}
                };
                _eventCol.Insert(edoc);

                recordedEvents.Add(re);
            }
            recordedEvents.ForEach(OnRecorded);
        }
Example #2
0
        public void Write_read()
        {
            const string EVENTFILENAME = "event.txt";
            File.Delete(EVENTFILENAME);
            var sut = new FileStore();

            var e = new RecordedEvent(Guid.NewGuid(), new DateTime(2000, 5, 12, 10, 11, 12), "42", "e", "c", "d1\nd2");
            sut.Write(EVENTFILENAME, e);
            var r = sut.Read(EVENTFILENAME);

            Equalidator.AreEqual(r, e);
        }
Example #3
0
        private RecordedEvent Store(string name, string context, string data)
        {
            var timestamp = DateTime.Now.ToUniversalTime();
            var sequencenumber = ((long)(Directory.GetFiles(_folderpath).Length)).ToSequenceNumber();

            var @event = new RecordedEvent(Guid.NewGuid(), timestamp, sequencenumber, name, context, data);

            var filename = sequencenumber + ".txt";
            _filestore.Write(Path.Combine(_folderpath, filename), @event);

            return @event;
        }
Example #4
0
 public void Write(string filename, RecordedEvent @event)
 {
     using (var sw = new StreamWriter(filename))
     {
         sw.WriteLine("1.0");
         sw.WriteLine(@event.Timestamp.ToString("s"));
         sw.WriteLine(@event.Index);
         sw.WriteLine(@event.Name);
         sw.WriteLine(@event.Context);
         sw.Write(@event.Data);
     }
 }