예제 #1
0
 private static void ShowData(Sample2Data data, bool dumpData)
 {
     Console.Clear();
     if (dumpData)
         Console.WriteLine("Data from storage!!!");
     Console.WriteLine("Next offset: {0}", data.NextOffset);
     Console.WriteLine("Distribution:");
     foreach (var pair in data.Distribution)
     {
         Console.WriteLine("[{0}]: {1}", pair.Key, pair.Value);
     }
 }
예제 #2
0
 private static void ShowData(Sample2Data data, bool dumpData)
 {
     Console.Clear();
     if (dumpData)
     {
         Console.WriteLine("Data from storage!!!");
     }
     Console.WriteLine("Next offset: {0}", data.NextOffset);
     Console.WriteLine("Distribution:");
     foreach (var pair in data.Distribution)
     {
         Console.WriteLine("[{0}]: {1}", pair.Key, pair.Value);
     }
 }
예제 #3
0
        static void ProcessNextIncrementOfEventsOrSleep(Sample2Data data, IRawEventStoreClient reader, ViewClient views)
        {
            var nextOffset = data.NextOffset;

            // try to read next 10000 events from the platform,
            // starting from the recorded offset.
            // This is more efficient, than reading one event by one, since it
            // reduces cost of reading/writing data by batching
            const int maxRecordCount = 10000;
            var       nextEvents     = reader.ReadAllEvents(new EventStoreOffset(nextOffset), maxRecordCount);
            var       emptyData      = true;

            // process
            foreach (var dataRecord in nextEvents)
            {
                // update next offset
                data.NextOffset = dataRecord.Next.OffsetInBytes;
                // update distribution
                if (data.Distribution.ContainsKey(dataRecord.EventData.Length))
                {
                    data.Distribution[dataRecord.EventData.Length]++;
                }
                else
                {
                    data.Distribution[dataRecord.EventData.Length] = 1;
                }
                emptyData = false;
            }

            if (emptyData)
            {
                // we didn't have any new data, so sleep
                const int seconds = 1;
                Thread.Sleep(seconds * 1000);
            }
            else
            {
                // we had some events incoming, so save projection
                // at least to update offset record
                PrintDataToConsole(data, false);
                views.WriteAsJson(data, ViewName);
            }
        }