public ChatClient(string streamPath, string userName) { _userName = userName; string key = "EventStore:BaseUrl"; string baseUrl = System.Configuration.ConfigurationManager.AppSettings[key]; if (string.IsNullOrEmpty(baseUrl)) { throw new Exception("AppSetting '{0}' has not been set".FormatWith(key)); } _eventStoreReader = new EventStoreReader(baseUrl, streamPath); _eventStoreWriter = new EventStoreWriter(baseUrl, streamPath); _messageRepository = new MessageRepository(_eventStoreReader); //_historyLogger = new LocalHistoryLogger(userName); //_historyReader = new LocalHistoryReader(userName); Feed = new ChatFeed(_messageRepository, _cancellationTokenSource.Token); _publisher = new ChatPublisher(); //_publisher.Subscribe(_historyLogger); _publisher.Subscribe(_eventStoreWriter); Queue = new ChatQueue(); Queue.Subscribe(_publisher); _publisher.Subscribe(Queue); // CAUTION? - two way loop... }
static void Main(string[] args) { var publisher = new ChatPublisher(); Console.WriteLine("Write 'exit' to end"); while (true) { Console.Write("Enter new message:"); var input = Console.ReadLine(); if (input != null && input.ToLowerInvariant() == "exit") { break; } publisher.Publish(input); } Console.ReadLine(); }
private static void AddPublisherIfNeeded(IChatPublisherSettings publisherSettings, IDictionary <long, ChatPublisher> publishers, ChatPublisher newChatPublisher) { var exist = publishers.ContainsKey(publisherSettings.ChatId); if (!exist) { newChatPublisher.Start(); publishers[publisherSettings.ChatId] = newChatPublisher; } else { if (publisherSettings.TimeSpan < publishers[publisherSettings.ChatId].PublisherSettings.TimeSpan) { publishers[publisherSettings.ChatId].Stop(); publishers[publisherSettings.ChatId].Dispose(); publishers.Remove(publisherSettings.ChatId, out _); newChatPublisher.Start(); publishers[publisherSettings.ChatId] = newChatPublisher; } } }