public override async Task Read(Dictionary <string, string> properties) { var dataToConvert = new MockUser() { FirstName = "Jane", LastName = "Doe", Email = "*****@*****.**", LastLogin = "******" }; IEntityCollection row = new EntityCollection(); row.Entities.Add("AD User", dataToConvert); Data.Add(row); var context = new Dictionary <string, string>(); // context.Add(CollectorConstants.STATE_READER_DONE, Id); await SignalHandler(context); await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_DONE }); }
public override Task Publish(string senderId, List <object> data, Dictionary <string, string> context) { return(Task.Run(() => { var path = EndPointConfig.Properties["Path"]; if (string.IsNullOrEmpty(path)) { _logger.Error("Property 'Path' is missing from the end point config properties"); var stateEvent = new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_PUBLISHER_ERROR, ExtraInfo = "Path property is missing." }; _collector.SignalEvent(stateEvent); return; } CreateDirectory(EndPointConfig.Properties["Path"]); foreach (var point in data) { var entity = point as IEntity; var payload = JsonConvert.SerializeObject(entity); var logEntry = string.Format("Entity : {0}", payload); var fullPath = string.Format("{0}\\publisher-log.txt", path); using (StreamWriter file = new StreamWriter(fullPath, File.Exists(fullPath))) { file.WriteLine(logEntry); } } })); }
public override Task Publish(string senderId, List <object> data, Dictionary <string, string> context) { return(Task.Run(() => { if (context.ContainsKey("Result") && context["Result"].Equals("Done")) { // Handle the context, in this case we assume we are done. var stateEventDone = new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_PUBLISHER_DONE, ExtraInfo = "Publisher done." }; _collector.SignalEvent(stateEventDone); } if (!EndPointConfig.Properties.ContainsKey(CollectorConstants.KEY_FOLDER)) { _logger.Error("Property 'Path' is missing from the end point config properties"); var stateEvent = new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_PUBLISHER_ERROR, ExtraInfo = "Path property is missing." }; _collector.SignalEvent(stateEvent); return; } var path = EndPointConfig.Properties[CollectorConstants.KEY_FOLDER]; if (!Directory.Exists(path)) { CreateDirectory(path); } var fullPath = string.Format("{0}\\publisher-log-{1}{2}{3}{4}{5}.txt", path, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Year, DateTime.Now.Hour, DateTime.Now.Minute); foreach (var dataPoint in data) { var logEntry = dataPoint as LogEntry; var payload = JsonConvert.SerializeObject(logEntry); var line = string.Format("{0}\r\n", payload); using (StreamWriter file = new StreamWriter(fullPath, File.Exists(fullPath))) { file.WriteLine(payload); } } })); }
public override async Task Transform(string senderId, List <IEntityCollection> data, Dictionary <string, string> context) { foreach (var mapper in Mappers) { Data = mapper.Map(data); await SignalPublisher(context); } await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_TRANSFORMER_DONE }); }
public override async Task Publish(string senderId, List <object> data, Dictionary <string, string> context) { _senderId = senderId; _data = data; _invoked = true; _context = context; Console.WriteLine("Sender : {0}, Data {1}", senderId, data); await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_PUBLISHER_DONE }); }
public override async Task Read(Dictionary <string, string> properties) { IEntityCollection row = new EntityCollection(); row.Entities.Add("foo", "bar"); Data.Add(row); await SignalHandler(new Dictionary <string, string>()); await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_DONE }); }
/// <summary> /// Signal that we are done. /// </summary> /// <param name="properties">Any runtime properties required by the reader.</param> /// <returns></returns> private async Task SignalDone(Dictionary <string, string> properties) { var context = new Dictionary <string, string>(); context.Add(CollectorConstants.KEY_STATE, CollectorConstants.STATE_READER_DONE); await _handler.HandleData(_id, new List <IEntityCollection>(), context); _done = true; await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_DONE, ExtraInfo = properties }); }
public async Task PublishData(string senderId, List <object> data, Dictionary <string, string> context) { if (data != null && data.Count != 0) { await Publish(senderId, data, context); } // Only signal tha we are done when the reader is done. if (context.ContainsKey(CollectorConstants.KEY_STATE) && context[CollectorConstants.KEY_STATE] == CollectorConstants.STATE_READER_DONE) { _done = true; await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_PUBLISHER_DONE, ExtraInfo = context }); } }
public override async Task Read(Dictionary <string, string> properties) { var dateToConvert = "01/01/2018"; var timeToConvert = "01:00:55.000"; IEntityCollection row = new EntityCollection(); row.Entities.Add("Time", timeToConvert); row.Entities.Add("Date", dateToConvert); Data.Add(row); var context = new Dictionary <string, string>(); await SignalHandler(context); await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_DONE }); }
public async Task HandleData(string senderId, List <IEntityCollection> data, Dictionary <string, string> context) { if (data != null && data.Count != 0) { await Transform(senderId, data, context); } // Only signal tha we are done when the reader is done. if (context.ContainsKey(CollectorConstants.KEY_STATE)) { if (context[CollectorConstants.KEY_STATE] == CollectorConstants.STATE_READER_DONE) { _done = true; await _collector.SignalEvent(new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_TRANSFORMER_DONE, ExtraInfo = context }); await _handler.PublishData(Id, new List <object>(), context); } } }
public override async Task Read(Dictionary <string, string> properties) { try { if (!EndPointConfig.Properties.ContainsKey(CollectorConstants.KEY_FOLDER)) { _logger.Error("Property 'FolderName' is missing from the end point config properties"); var stateEvent1 = new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_ERROR, ExtraInfo = "FolderName property is missing." }; await _collector.SignalEvent(stateEvent1); return; } if (!EndPointConfig.Properties.ContainsKey(CollectorConstants.KEY_FILENAME)) { _logger.Error("Property 'FileName' is missing from the end point config properties"); var stateEvent2 = new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_ERROR, ExtraInfo = "FileName property is missing." }; await _collector.SignalEvent(stateEvent2); return; } var path = EndPointConfig.Properties[CollectorConstants.KEY_FOLDER]; var fileName = EndPointConfig.Properties[CollectorConstants.KEY_FILENAME]; var fullPath = string.Format(@"{0}\{1}", path, fileName); _logger.Info("Reading log file : " + fullPath); // context gets bubbled up to the transformer and possibly the publisher var context = new Dictionary <string, string>(); context.Add(fullPath, fileName); _logger.Info("Processing file {0}", fileName); if (_fileReader.Open(fullPath)) { string s = ""; while ((s = _fileReader.ReadLine()) != null) { // Each row is a line of text from the log var row = new EntityCollection(); // Split the log entry by spaces var entries = s.Split(' ', '|'); if (entries.Length > 6) { // TODO: How to handle exceptions in the log? if (entries[0].Contains("Exception")) { continue; } // From entry 6 on is the message, lets recreate it... /*var message = ""; * for (int i = 4; i < entries.Length; i++) * { * message = string.Format(CultureInfo.InvariantCulture, "{0} {1}", message, entries[i]); * }*/ // Now create our data entry... for (int i = 0; i < entries.Length; i++) { row.Entities.Add(string.Format("Col_{0}", i), entries[i]); } Data.Add(row); } } } // Tell the collector that we are done await SignalHandler(context); await SignalHandler(new Dictionary <string, string>() { { "Result", "Done" } }); var stateEvent = new StateEvent() { SenderId = Id, State = CollectorConstants.STATE_READER_DONE, ExtraInfo = "Done processing file." }; await _collector.SignalEvent(stateEvent); } catch (Exception e) { _logger.Error(e.Message); } }