static void Main() { StorePath = ConfigurationManager.AppSettings["StorePath"]; if (string.IsNullOrWhiteSpace(StorePath)) { StorePath = @"C:\LokadData\dp-store"; } StoreConnection = ConfigurationManager.AppSettings["StoreConnection"]; if (string.IsNullOrWhiteSpace(StoreConnection)) { StoreConnection = "http://localhost:8080"; } // Use "default" container for reading/writing events _client = PlatformClient.ConnectToEventStore(StorePath, storeId: "default", platformServerEndpoint: StoreConnection); _view = PlatformClient.ConnectToViewStorage(StorePath, "sample1-views"); Console.WriteLine("You name:"); _userName = Console.ReadLine(); Console.WriteLine("Chat starting..."); _client.WriteEvent("", Encoding.UTF8.GetBytes("|join a new user " + _userName)); Task.Factory.StartNew(ScanChat, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness); WriteColorText(_userName + ">", ConsoleColor.Green); _userMessage = ""; while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.KeyChar != '\r') { _userMessage += keyInfo.KeyChar; } else { _client.WriteEvent("", Encoding.UTF8.GetBytes(string.Format("{0}|{1}", _userName, _userMessage))); Console.WriteLine(); WriteColorText(_userName + ">", ConsoleColor.Green); _userMessage = ""; } } }
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); } }
static void Main() { StorePath = ConfigurationManager.AppSettings["StorePath"]; if (string.IsNullOrWhiteSpace(StorePath)) StorePath = @"C:\LokadData\dp-store"; StoreConnection = ConfigurationManager.AppSettings["StoreConnection"]; if (string.IsNullOrWhiteSpace(StoreConnection)) StoreConnection = "http://localhost:8080"; // Use "default" container for reading/writing events _client = PlatformClient.ConnectToEventStore(StorePath, storeId : "default", platformServerEndpoint : StoreConnection); _view = PlatformClient.ConnectToViewStorage(StorePath, "sample1-views"); Console.WriteLine("You name:"); _userName = Console.ReadLine(); Console.WriteLine("Chat starting..."); _client.WriteEvent("", Encoding.UTF8.GetBytes("|join a new user " + _userName)); Task.Factory.StartNew(ScanChat, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness); WriteColorText(_userName + ">", ConsoleColor.Green); _userMessage = ""; while (true) { ConsoleKeyInfo keyInfo = Console.ReadKey(); if (keyInfo.KeyChar != '\r') _userMessage += keyInfo.KeyChar; else { _client.WriteEvent("", Encoding.UTF8.GetBytes(string.Format("{0}|{1}", _userName, _userMessage))); Console.WriteLine(); WriteColorText(_userName + ">", ConsoleColor.Green); _userMessage = ""; } } }
private static void CommentProjection(IRawEventStoreClient store, ViewClient views) { var data = views.ReadAsJsonOrGetNew<CommentDistributionView>(CommentDistributionView.FileName); var processingInfo = views.ReadAsJsonOrGetNew<ProcessingInfoView>(CommentDistributionView.FileName + ".info"); Console.WriteLine("Next comment offset: {0}", processingInfo.NextOffsetInBytes); while (true) { var nextOffset = processingInfo.NextOffsetInBytes; processingInfo.LastOffsetInBytes = processingInfo.NextOffsetInBytes; processingInfo.DateProcessingUtc = DateTime.UtcNow; var records = store.ReadAllEvents(new EventStoreOffset(nextOffset), 10000); var emptyData = true; foreach (var dataRecord in records) { processingInfo.NextOffsetInBytes = dataRecord.Next.OffsetInBytes; processingInfo.EventsProcessed += 1; var user = User.TryGetFromBinary(dataRecord.EventData); if (user != null) { data.Users[user.Id] = user; emptyData = false; continue; } var comment = Comment.TryGetFromBinary(dataRecord.EventData); if (comment != null) { if (data.Distribution.ContainsKey(comment.UserId)) data.Distribution[comment.UserId] += 1; else data.Distribution[comment.UserId] = 1; emptyData = false; } } if (emptyData) { views.WriteAsJson(processingInfo, CommentDistributionView.FileName + ".info"); Thread.Sleep(1000); } else { try { views.WriteAsJson(data, CommentDistributionView.FileName); views.WriteAsJson(processingInfo, CommentDistributionView.FileName + ".info"); } catch (Exception ex) { Console.WriteLine("Exception on writing view - {0}\r\n{1}", CommentDistributionView.FileName, ex.Message); } Console.WriteLine("Next comment offset: {0}", processingInfo.NextOffsetInBytes); } } }
private static void UserCommentsPerDayDistributionProjection(IRawEventStoreClient store, ViewClient views) { var data = views.ReadAsJsonOrGetNew<UserCommentsDistributionView>(UserCommentsDistributionView.FileName); var processingInfo = views.ReadAsJsonOrGetNew<ProcessingInfoView>(UserCommentsDistributionView.FileName + ".info"); Console.WriteLine("Next user offset: {0}", processingInfo.NextOffsetInBytes); while (true) { var nextOffcet = processingInfo.NextOffsetInBytes; var records = store.ReadAllEvents(new EventStoreOffset(nextOffcet), 10000); var emptyData = true; foreach (var dataRecord in records) { processingInfo.NextOffsetInBytes = dataRecord.Next.OffsetInBytes; var user = User.TryGetFromBinary(dataRecord.EventData); if (user != null) { data.Users[user.Id] = user; emptyData = false; continue; } var comment = Comment.TryGetFromBinary(dataRecord.EventData); if (comment != null) { if (!data.Distribution.ContainsKey(comment.UserId)) { data.Distribution.Add(comment.UserId, new long[7]); } var dayOfWeek = (int) comment.CreationDate.Date.DayOfWeek; data.Distribution[comment.UserId][dayOfWeek]++; processingInfo.EventsProcessed += 1; emptyData = false; } } if (emptyData) { views.WriteAsJson(processingInfo, UserCommentsDistributionView.FileName + ".info"); Thread.Sleep(1000); } else { try { views.WriteAsJson(data, UserCommentsDistributionView.FileName); views.WriteAsJson(processingInfo, UserCommentsDistributionView.FileName + ".info"); } catch (Exception ex) { Console.WriteLine("Exception on writing view - {0}\r\n{1}", UserCommentsDistributionView.FileName, ex.Message); } Console.WriteLine("Next user offset: {0}", processingInfo.NextOffsetInBytes); } } }
private static void TagProjection(IRawEventStoreClient store, ViewClient views) { var data = views.ReadAsJsonOrGetNew<TagsDistributionView>(TagsDistributionView.FileName); var processingInfo = views.ReadAsJsonOrGetNew<ProcessingInfoView>(TagsDistributionView.FileName + ".info"); Console.WriteLine("Next post offset: {0}", processingInfo.NextOffsetInBytes); while (true) { var nextOffcet = processingInfo.NextOffsetInBytes; processingInfo.LastOffsetInBytes = processingInfo.NextOffsetInBytes; processingInfo.DateProcessingUtc = DateTime.UtcNow; var records = store.ReadAllEvents(new EventStoreOffset(nextOffcet), 10000); var emptyData = true; foreach (var dataRecord in records) { processingInfo.NextOffsetInBytes = dataRecord.Next.OffsetInBytes; var post = Post.TryGetFromBinary(dataRecord.EventData); if (post == null) continue; foreach (var tag in post.Tags) { if (data.Distribution.ContainsKey(tag)) data.Distribution[tag]++; else data.Distribution[tag] = 1; } processingInfo.EventsProcessed += 1; emptyData = false; } if (emptyData) { views.WriteAsJson(processingInfo, TagsDistributionView.FileName + ".info"); Thread.Sleep(1000); } else { try { views.WriteAsJson(data, TagsDistributionView.FileName); views.WriteAsJson(processingInfo, TagsDistributionView.FileName + ".info"); } catch (Exception ex) { Console.WriteLine("Exception on writing view - {0}\r\n{1}", TagsDistributionView.FileName, ex.Message); } Console.WriteLine("Next post offset: {0}", processingInfo.NextOffsetInBytes); } } }
private static void CommentProjection(IRawEventStoreClient store, ViewClient views) { var data = views.ReadAsJsonOrGetNew <CommentDistributionView>(CommentDistributionView.FileName); var processingInfo = views.ReadAsJsonOrGetNew <ProcessingInfoView>(CommentDistributionView.FileName + ".info"); Console.WriteLine("Next comment offset: {0}", processingInfo.NextOffsetInBytes); while (true) { var nextOffset = processingInfo.NextOffsetInBytes; processingInfo.LastOffsetInBytes = processingInfo.NextOffsetInBytes; processingInfo.DateProcessingUtc = DateTime.UtcNow; var records = store.ReadAllEvents(new EventStoreOffset(nextOffset), 10000); var emptyData = true; foreach (var dataRecord in records) { processingInfo.NextOffsetInBytes = dataRecord.Next.OffsetInBytes; processingInfo.EventsProcessed += 1; var user = User.TryGetFromBinary(dataRecord.EventData); if (user != null) { data.Users[user.Id] = user; emptyData = false; continue; } var comment = Comment.TryGetFromBinary(dataRecord.EventData); if (comment != null) { if (data.Distribution.ContainsKey(comment.UserId)) { data.Distribution[comment.UserId] += 1; } else { data.Distribution[comment.UserId] = 1; } emptyData = false; } } if (emptyData) { views.WriteAsJson(processingInfo, CommentDistributionView.FileName + ".info"); Thread.Sleep(1000); } else { try { views.WriteAsJson(data, CommentDistributionView.FileName); views.WriteAsJson(processingInfo, CommentDistributionView.FileName + ".info"); } catch (Exception ex) { Console.WriteLine("Exception on writing view - {0}\r\n{1}", CommentDistributionView.FileName, ex.Message); } Console.WriteLine("Next comment offset: {0}", processingInfo.NextOffsetInBytes); } } }
private static void TagProjection(IRawEventStoreClient store, ViewClient views) { var data = views.ReadAsJsonOrGetNew <TagsDistributionView>(TagsDistributionView.FileName); var processingInfo = views.ReadAsJsonOrGetNew <ProcessingInfoView>(TagsDistributionView.FileName + ".info"); Console.WriteLine("Next post offset: {0}", processingInfo.NextOffsetInBytes); while (true) { var nextOffcet = processingInfo.NextOffsetInBytes; processingInfo.LastOffsetInBytes = processingInfo.NextOffsetInBytes; processingInfo.DateProcessingUtc = DateTime.UtcNow; var records = store.ReadAllEvents(new EventStoreOffset(nextOffcet), 10000); var emptyData = true; foreach (var dataRecord in records) { processingInfo.NextOffsetInBytes = dataRecord.Next.OffsetInBytes; var post = Post.TryGetFromBinary(dataRecord.EventData); if (post == null) { continue; } foreach (var tag in post.Tags) { if (data.Distribution.ContainsKey(tag)) { data.Distribution[tag]++; } else { data.Distribution[tag] = 1; } } processingInfo.EventsProcessed += 1; emptyData = false; } if (emptyData) { views.WriteAsJson(processingInfo, TagsDistributionView.FileName + ".info"); Thread.Sleep(1000); } else { try { views.WriteAsJson(data, TagsDistributionView.FileName); views.WriteAsJson(processingInfo, TagsDistributionView.FileName + ".info"); } catch (Exception ex) { Console.WriteLine("Exception on writing view - {0}\r\n{1}", TagsDistributionView.FileName, ex.Message); } Console.WriteLine("Next post offset: {0}", processingInfo.NextOffsetInBytes); } } }
private static void UserCommentsPerDayDistributionProjection(IRawEventStoreClient store, ViewClient views) { var data = views.ReadAsJsonOrGetNew <UserCommentsDistributionView>(UserCommentsDistributionView.FileName); var processingInfo = views.ReadAsJsonOrGetNew <ProcessingInfoView>(UserCommentsDistributionView.FileName + ".info"); Console.WriteLine("Next user offset: {0}", processingInfo.NextOffsetInBytes); while (true) { var nextOffcet = processingInfo.NextOffsetInBytes; var records = store.ReadAllEvents(new EventStoreOffset(nextOffcet), 10000); var emptyData = true; foreach (var dataRecord in records) { processingInfo.NextOffsetInBytes = dataRecord.Next.OffsetInBytes; var user = User.TryGetFromBinary(dataRecord.EventData); if (user != null) { data.Users[user.Id] = user; emptyData = false; continue; } var comment = Comment.TryGetFromBinary(dataRecord.EventData); if (comment != null) { if (!data.Distribution.ContainsKey(comment.UserId)) { data.Distribution.Add(comment.UserId, new long[7]); } var dayOfWeek = (int)comment.CreationDate.Date.DayOfWeek; data.Distribution[comment.UserId][dayOfWeek]++; processingInfo.EventsProcessed += 1; emptyData = false; } } if (emptyData) { views.WriteAsJson(processingInfo, UserCommentsDistributionView.FileName + ".info"); Thread.Sleep(1000); } else { try { views.WriteAsJson(data, UserCommentsDistributionView.FileName); views.WriteAsJson(processingInfo, UserCommentsDistributionView.FileName + ".info"); } catch (Exception ex) { Console.WriteLine("Exception on writing view - {0}\r\n{1}", UserCommentsDistributionView.FileName, ex.Message); } Console.WriteLine("Next user offset: {0}", processingInfo.NextOffsetInBytes); } } }
public void UseEventStore(string storeId = "default") { EventStores = PlatformClient.ConnectToEventStore(Options.StoreLocation, storeId, ClientHttpBase); }
static void Main() { RawDataPath = ConfigurationManager.AppSettings["RawDataPath"]; StorePath = ConfigurationManager.AppSettings["StorePath"]; StoreConnection = ConfigurationManager.AppSettings["StoreConnection"]; Console.WriteLine("This is Sample3.Dump tool"); Console.WriteLine("Using settings from the .config file"); Console.WriteLine(" RawDataPath (put stack overflow dump here): {0}", RawDataPath); Console.WriteLine(" StoreDataPath: {0}", StorePath); Console.WriteLine(" StoreConnection: {0}", StoreConnection); _reader = PlatformClient.ConnectToEventStore(StorePath, "sample3", StoreConnection); Thread.Sleep(2000); //waiting for server initialization var threads = new List<Task> { Task.Factory.StartNew(DumpComments, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness), Task.Factory.StartNew(DumpPosts, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness), Task.Factory.StartNew(DumpUsers, TaskCreationOptions.LongRunning | TaskCreationOptions.PreferFairness) }; Task.WaitAll(threads.ToArray()); }
public IndexedPages() { _store = PlatformClient.ConnectToEventStore(Settings.StorePath, Settings.StoreId, Settings.StoreConnection); }