示例#1
0
        private static void PerfLoadNewRei(Guid formId, String rei, Int32 snapInterval, ControlCatalog catalog, IEnumerable<ControlRule> rules)
        {
            var newInstance = new ReportingEntityInstance(formId, rei);
            var fields = new String[]{ "FirstName", "LastName", "Age", "Email", "FavoriteFood" };

            Stopwatch sw = new Stopwatch();

            Console.WriteLine($"Starting the creation of {rei}");
            sw.Start();
            for (int i = 0; i < 10000; i++)
            {
                var field = fields[i % 5];
                newInstance.AddAnswer(field, catalog, rules, "answer" + i.ToString());

                EventStore.PersistEvents(_eventCollection, newInstance);

                if (i > 0 && i%snapInterval == 0)
                {
                    var snap = newInstance.TakeSnapshot();
                    EventStore.TakeSnapshot(_snapshotCollection, snap);
                }
            }
            sw.Stop();
            Console.WriteLine($"Took {sw.ElapsedMilliseconds} ms to write 10000 answers with interval of {snapInterval}");

            sw.Reset();

            sw.Start();
            var fullInstance = new ReportingEntityInstance(formId, rei);
            EventStore.LoadDomain(_eventCollection, fullInstance, formId, rei);
            sw.Stop();
            Console.WriteLine($"Took {sw.ElapsedMilliseconds} ms to load domain by replaying events");
            sw.Reset();

            sw.Start();
            var snapInstance = new ReportingEntityInstance(formId, rei);
            snapInstance.LoadSnapshot(EventStore.GetSnapshot(_snapshotCollection, rei));
            EventStore.LoadDomainStartingAtVersion(_eventCollection, snapInstance, formId, rei, snapInstance.Version);
            sw.Stop();
            Console.WriteLine($"Took {sw.ElapsedMilliseconds} ms to load domain from snapshot");

            Console.WriteLine("Replay instance status: ");
            DisplayDomainStatus(fullInstance);

            Console.WriteLine("Snapshot instance status: ");
            DisplayDomainStatus(snapInstance);
        }
示例#2
0
 private static ReportingEntityInstance LoadFromSnapshot(Guid formId, String rei)
 {
     var snapshot = EventStore.GetSnapshot(_snapshotCollection, rei);
     var instance = new ReportingEntityInstance(formId, rei);
     instance.LoadSnapshot(snapshot);
     EventStore.LoadDomainStartingAtVersion(_eventCollection, instance, instance.FormDefinitionId, instance.ReportingEntityId, instance.Version);
     return instance;
 }