public TestTreeModelEventImpl(Niawa.IpcController.IpcEvent evt, string nodeID, string nodeText, string parentNodeID) { _evt = evt; _nodeID = nodeID; _nodeText = nodeText; _parentNodeID = parentNodeID; }
static void Main(string[] args) { /* //Niawa.IpcController.MmfWriter writer = new Niawa.IpcController.MmfWriter("Niawa.IpcEvent.TestEvent1", 131072, false); Niawa.IpcController.MmfWriter writer = new Niawa.IpcController.MmfWriter("Niawa.IpcEvent.TestEvent1", Niawa.IpcController.IpcEvent.IPC_EVENT_MMF_LENGTH, false); writer.StartWriting(); while (1 == 1) { Niawa.IpcController.IpcEvent evt = new Niawa.IpcController.IpcEvent(Guid.NewGuid(), System.DateTime.Now, "app1", "testEvent1", "eventDetail"); evt.AddProperty("propk1", "propv1"); evt.AddProperty("propk2", "propv2"); Niawa.IpcController.NiawaMmfContainer msg = new Niawa.IpcController.NiawaMmfContainer(System.DateTime.Now, "IpcEvent.Test1", evt.ToJson()); logger.Info("Writing message [" + evt.EventID + "]"); writer.WriteData(msg); System.Threading.Thread.Sleep(1500); } */ //create utility bus Niawa.Utilities.UtilsServiceBus utilsBus = new Niawa.Utilities.UtilsServiceBus(); Niawa.IpcController.iEventWriter evtWriter = Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.IpcControllerTestClient", false, "TestGroup1", utilsBus); evtWriter.Start(); int i = 0; while (1 == 1) { i++; string nodeID = "TestNodeID"; string parentNodeID = "TestParentNodeID"; Niawa.IpcController.IpcEvent evt = new Niawa.IpcController.IpcEvent(Guid.NewGuid(), System.DateTime.Now, "Niawa.IpcControllerTestClient", Environment.MachineName, "testEvent" + i, "eventMessage", "eventDetail", nodeID, parentNodeID); //evt.AddProperty("propk1", "propv1-" + i); //evt.AddProperty("propk2", "propv2-"+ i); logger.Info("Writing IPC test event" + i + ""); evtWriter.Write(evt); System.Threading.Thread.Sleep(10); evtWriter.Write(Environment.MachineName, "testEvent2", "eventMessage2", "eventDetail2", nodeID, parentNodeID); System.Threading.Thread.Sleep(50); } }
/// <summary> /// Writes a message to the Ipc event writer. /// </summary> private void WriteMessage(string eventType, string eventMessage, string messageDetail) { Niawa.IpcController.IpcEvent evt = new Niawa.IpcController.IpcEvent(); evt.EventID = Guid.NewGuid(); evt.EventDate = System.DateTime.Now; evt.ApplicationName = "IpcEventMonitor"; evt.ApplicationInstance = "IpcEventMonitor-" + Environment.MachineName; evt.NodeID = ""; evt.ParentNodeID = ""; evt.EventType = eventType; evt.EventMessage = eventMessage; evt.EventMessageDetail = messageDetail; _writer.Write(evt); }
public void UpdateView(TreeModelNodeControls.ITreeModelEvent evt) { //save the latest status event if (evt.IpcEvent.EventType == "Status") _latestStatusEvent = evt.IpcEvent; }
/// <summary> /// Writes a message to the Ipc event writer. /// </summary> /// <param name="message"></param> private void WriteMessage(MsEventController.NiawaEventMessageArgs message) { if (_ipcEventWriters.ContainsKey(message.ApplicationGroup)) { Niawa.IpcController.iEventWriter writer = _ipcEventWriters[message.ApplicationGroup]; //writer.Write(message.MessageType, "[" + message.ApplicationInstance + "] " + message.Message + " " + message.MessageDetail); Niawa.IpcController.IpcEvent evt = new Niawa.IpcController.IpcEvent(); evt.EventID = Guid.NewGuid(); evt.EventDate = System.DateTime.Now; evt.ApplicationName = message.ApplicationName; evt.ApplicationInstance = message.ApplicationInstance; evt.EventType = message.MessageType; evt.EventMessage = message.Message; evt.EventMessageDetail = message.MessageDetail; evt.NodeID = message.NodeID; evt.ParentNodeID = message.ParentNodeID; //if(message.ApplicationInstance.Trim().Length > 0) evt.AddProperty("instance", message.ApplicationInstance); //if(message.MessageDetail.Trim().Length > 0) evt.AddProperty("detail", message.MessageDetail); writer.Write(evt); } else { logger.Warn("[MsEventIpcEventAdapter] Could not find an event writer registered for [" + message.ApplicationGroup + "]; discarding message " + message.SerialID); } }
/// <summary> /// Creates and writes an event by enqueueing in MmfWriter. /// </summary> ///<param name="applicationInstance">Instance of the application to create in IpcEvent</param> /// <param name="eventType">Event type of IpcEvent to create</param> ///<param name="eventMessage">Event message to create in IpcEvent</param> /// <param name="eventMessageDetail">Event message detail to create in IpcEvent</param> /// <param name="nodeID">Event's Node ID</param> /// <param name="parentNodeID">Event's Parent Node ID</param> public void Write(string applicationInstance, string eventType, string eventMessage, string eventMessageDetail, string nodeID, string parentNodeID) { try { Niawa.IpcController.IpcEvent evt = new Niawa.IpcController.IpcEvent(Guid.NewGuid(), System.DateTime.Now, _applicationName, applicationInstance, eventType, eventMessage, eventMessageDetail, nodeID, parentNodeID); Write(evt); } catch (Exception ex) { logger.Error("[IpcEventWriter " + _ipcType + "] Caught exception during IpcEventWriter Write: " + ex.Message, ex); if (_ignoreIpcExceptions) { } else throw ex; } }
/// <summary> /// Reads the next event from the MmfReader message queue. /// </summary> /// <returns></returns> public IpcEvent ReadNextEvent() { try { if (!started) throw new Exception("[IpcEventReader " + _ipcType + "] Cannot read next IPC Event: IpcEventReader is not started."); while (1 == 1) { if (mmfReader.CountMessagesInBuffer() > 0) { Niawa.IpcController.NiawaMmfContainer msg = mmfReader.GetNextMessageFromBuffer(); if (msg.IpcType == _ipcType) { Niawa.IpcController.IpcEvent evt = new Niawa.IpcController.IpcEvent(msg.IpcData); logger.Debug("[IpcEventReader " + _ipcType + "] Reading IPC Event [" + evt.SerialID + "] from message [" + msg.SerialID + "]"); /* //inject SerialID into IpcEvent evt.SerialID = msg.SerialID; */ return evt; } else { //not the ipc type we're looking for, keep looking logger.Warn("[IpcEventReader " + _ipcType + "] Not processing message [" + msg.SerialID + "]: NiawaMmfContainer IpcType [" + msg.IpcType + "] does not match IpcEventReader IpcType [" + _ipcType + "]"); System.Threading.Thread.Sleep(500); } } else { //no messages in buffer System.Threading.Thread.Sleep(50); } } } catch (Exception ex) { logger.Error("[IpcEventReader " + _ipcType + "] Caught exception during IpcEventReader ReadNextEvent: " + ex.Message, ex); if (_ignoreIpcExceptions) { return null; } else throw ex; } }