Beispiel #1
0
        /// <summary>
        /// Initialize a TCP session with the receiver IP Address and port, and the Destination IP Address.  
        /// The destination port will be added when the transmitter is added.
        /// </summary>
        /// <param name="applicationName">The application name supplied by the caller</param>
        /// <param name="localIpAddress">The receiver IP Address</param>
        /// <param name="localPort">The receiver Port</param>
        /// <param name="remoteIpAddress">The destination IP Address</param>
        /// <param name="remoteHostname">The destination hostname</param>
        /// <param name="remoteHandshakePort">The destination handshake port, used to retrieve the session port</param>
        /// <param name="evtConsumer">The Niawa.MsEventController.EventConsumer created to handle events that are raised</param>
        /// <param name="utilsBus">The utility bus passed in by the caller</param>
        /// <param name="parentNodeID">The parent node ID passed in by the caller</param>
        public TcpSession(string applicationName, string localIpAddress, int localPort, string remoteIpAddress, string remoteHostname, int remoteHandshakePort, Niawa.MsEventController.EventConsumer evtConsumer, Niawa.Utilities.UtilsServiceBus utilsBus, string parentNodeID)
        {
            try
            {
                _applicationName = applicationName;
                _localIpAddress = localIpAddress;
                _localPort = localPort;
                _localPortRangeMin = 0;
                _localPortRangeMax = 0;
                _localPortRange = false;
                _remoteIpAddress = remoteIpAddress;
                _remoteHostname = remoteHostname;
                _remoteHandshakePort = remoteHandshakePort;
                _evtConsumer = evtConsumer;
                _utilsBus = utilsBus;
                _parentNodeID = parentNodeID;

                _sessionIdentifier = "TcpSession-" + _remoteIpAddress;

                Initialize();

            }
            catch (Exception ex)
            {
                logger.Error("[TcpSession] Error instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
        /// <summary>
        /// Instantiates IpcEventWriter by initializing MmfWriter.
        /// </summary>
        /// <param name="applicationName">Application name to use in MmfWriter</param>
        /// <param name="ipcType">Identifies and authenticates data for memory mapped file</param>
        /// <param name="ipcEventMessageLength">Length of data segment</param>
        /// <param name="ignoreIpcExceptions">True if write exceptions in MmfWriter should be handled by MmfWriter; false if they should be returned.</param>
        public IpcEventWriter(string applicationName, string ipcType, int ipcEventMessageLength, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreIpcExceptions)
        {
            try
            {
                _applicationName = applicationName;
                _ipcType = ipcType;
                _ipcEventMessageLength = ipcEventMessageLength;
                _ignoreIpcExceptions = ignoreIpcExceptions;

                //initialize serial ID generator
                id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_IPC_EVENT);

                //initialize MMF writer
                mmfWriter = new Niawa.IpcController.MmfBufferedWriter(_ipcType, _ipcEventMessageLength, utilsBus, _ignoreIpcExceptions);

                lockSection = new System.Threading.Semaphore(1, 1);

            }
            catch (Exception ex)
            {
                logger.Error("[IpcEventWriter " + _ipcType + "] Caught exception during IpcEventWriter instantiate: " + ex.Message, ex);

                if (ignoreIpcExceptions)
                { }
                else
                    throw ex;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Instantiates MmfWriter.
        /// </summary>
        /// <param name="ipcType">Identifies memory mapped file and used to authenticate outgoing messages.</param>
        /// <param name="bufferLength">Length of data segment</param>
        /// <param name="ignoreExceptions">True if exceptions should be handled; false if they should be returned to the caller.</param>
        public MmfWriter(string ipcType, int bufferLength, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreExceptions)
        {
            try
            {
                _sendQueue = new Queue<NiawaMmfContainer>();

                _ipcType = ipcType;
                _description = "MmfWriter " + _ipcType;
                _bufferLength = bufferLength;
                _ignoreExceptions = ignoreExceptions;

                //initialize serial ID generator
                id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_MMF_CONTAINER);

                //get random starting message ID
                Random rnd = new Random();
                int startingMsgID = rnd.Next(0, 100000);

                _msgID = startingMsgID;
                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

            }
            catch (Exception ex)
            {
                logger.Error("[" + _description + "-M] Exception while instantiating: " + ex.Message, ex);
                if (!ignoreExceptions)
                    throw ex;
            }
        }
 public TestTreeModelEventImpl(Niawa.IpcController.IpcEvent evt, string nodeID, string nodeText, string parentNodeID)
 {
     _evt = evt;
     _nodeID = nodeID;
     _nodeText = nodeText;
     _parentNodeID = parentNodeID;
 }
        /// <summary>
        /// Cache (if inactive view) or display (if active view) data received from IPC reader, 
        /// for a specified winform node.
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="threadID"></param>
        public void CacheOrDisplayEventData(Niawa.IpcController.IpcEvent evt, string threadID)
        {
            //acquire lock
            _treeModel.AcquireLock("CacheOrDisplayEventData");

            try
            {

                if (_treeModel.DoesNodeExist(threadID))
                {
                    _treeModel.GetNode(threadID).CacheOrDisplayEventData(evt);
                }
                else
                    throw new Exception("Cannot cache or display event data [" + evt.EventType + "]: ThreadID " + threadID + " does not exist");
            }
            catch (Exception ex)
            {
                logger.Error("Exception in CacheOrDisplayEventData: " + ex.Message + ex.StackTrace, ex);

                _tsslStatus.Text = "Exception in CacheOrDisplayEventData: " + ex.Message;

                ShowErrorMessage("Exception in CacheOrDisplayEventData: " + ex.Message + ex.StackTrace);

            }
            finally
            {
                //release lock
                if(_treeModel.IsLocked) _treeModel.ReleaseLock();

            }
        }
Beispiel #6
0
        /// <summary>
        /// Instantiates MmfReader.
        /// </summary>
        /// <param name="ipcType">Identifies memory mapped file and used to authenticate incoming data.</param>
        /// <param name="bufferLength">Length of data segment</param>
        /// <param name="ignoreExceptions">True if exceptions should be handled; false if they should be thrown to caller</param>
        public MmfReader(string ipcType, int bufferLength, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreExceptions)
        {
            try
            {
                _receiveQueue = new Queue<NiawaMmfContainer>();

                _ipcType = ipcType;
                _description = "MmfReader " + _ipcType;
                _bufferLength = bufferLength;
                _ignoreExceptions = ignoreExceptions;

                _lastMsgID = 0;
                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

            }
            catch (Exception ex)
            {
                logger.Error("[" + _description + "-M] Exception while instantiating: " + ex.Message, ex);
                if (!ignoreExceptions)
                    throw ex;
            }
        }
        /// <summary>
        /// Instantiate TcpSessionManager with specific utility bus, and event consumer passed in by caller
        /// </summary>
        /// <param name="ipAddress"></param>
        /// <param name="portRangeMin"></param>
        /// <param name="portRangeMax"></param>
        /// <param name="hostname"></param>
        /// <param name="applicationName"></param>
        /// <param name="evtConsumer"></param>
        /// <param name="utilsBus"></param>
        public TcpSessionManager(string ipAddress, int portRangeMin, int portRangeMax, string hostname, string applicationName, Niawa.Utilities.UtilsServiceBus utilsBus, Niawa.MsEventController.EventConsumer evtConsumer, string parentNodeID)
        {
            try
            {
                _description = "TcpSessionManager";
                _ipAddress = ipAddress;
                _handshakePort = 0;
                _portRangeMin = portRangeMin;
                _portRangeMax = portRangeMax;
                _hostname = hostname;
                _applicationName = applicationName;
                _tcpSessions = new SortedList<string, TcpSession>();

                _utilsBus = utilsBus;
                _evtConsumer = evtConsumer;

                //initialize event logging for this object
                _evtRaiser = new MsEventController.EventRaiser("TcpSessionManager", _applicationName, "TcpSessionManager", _utilsBus);
                _evtRaiser_HR = new MsEventController.EventRaiser("TcpSessionManager", _applicationName, "TcpSessionManager-HandshakeReceiver", _utilsBus);
                //_evtRaiserMsg = new MsEventController.EventRaiser("TcpSessionManagerMsg", _applicationName, "TcpSessionManagerMsg", _utilsBus);

                //add caller's event consumer, if supplied
                if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);
                if (_evtConsumer != null) _evtRaiser_HR.AddEventConsumer(_evtConsumer);
                //if (_evtConsumer != null) _evtRaiserMsg.AddEventConsumer(_evtConsumer);

                lockSection = new System.Threading.Semaphore(1, 1);

                _receiveQueue = new Queue<NiawaNetMessage>();

                Utilities.SerialId threadID_HR = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID);
                Utilities.SerialId threadID_SRL = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID);

                _t2_SRL_ThreadStatus = new Niawa.Threading.ThreadStatus("TcpSessionManager", 60, threadID_SRL.ToString(), parentNodeID, _evtRaiser);
                _t1_HR_ThreadStatus = new Niawa.Threading.ThreadStatus("TcpSessionManager-HandshakeReceiver", 60, threadID_HR.ToString(), threadID_SRL.ToString(), _evtRaiser_HR);

                //thread status
                _t1_HR_ThreadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;
                _t2_SRL_ThreadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

                //add thread elective properties.
                _t1_HR_ThreadStatus.AddElectiveProperty("IpAddress", _ipAddress);
                _t1_HR_ThreadStatus.AddElectiveProperty("HandshakePort", _handshakePort.ToString());
                _t1_HR_ThreadStatus.AddElectiveProperty("Hostname", _hostname.ToString());

                _t2_SRL_ThreadStatus.AddElectiveProperty("IpAddress", _ipAddress);
                _t2_SRL_ThreadStatus.AddElectiveProperty("HandshakePort", _handshakePort.ToString());
                _t2_SRL_ThreadStatus.AddElectiveProperty("Hostname", _hostname.ToString());
                _t2_SRL_ThreadStatus.AddElectiveProperty("PortRangeMin", _portRangeMin.ToString());
                _t2_SRL_ThreadStatus.AddElectiveProperty("PortRangeMax", _portRangeMax.ToString());

            }
            catch (Exception ex)
            {
                logger.Error("[TcpSessionManager-M] Error instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
        /// <summary>
        /// Instantiate TreeModelController
        /// </summary>
        /// <param name="view"></param>
        /// <param name="nodeViewFactory"></param>
        /// <param name="callerSessionID"></param>
        public TreeModelController(ITreeModelView view, ITreeModelNodeViewFactory nodeViewFactory, Niawa.MsEventController.EventConsumer evtConsumer, string applicationNameDetailed, string callerSessionID)
        {
            _description = "TreeModelController";
            _view = view;
            _nodeViewFactory = nodeViewFactory;
            _callerSessionID = callerSessionID;

            _treeModel = new TreeModel(_view, evtConsumer, applicationNameDetailed);
        }
 /// <summary>
 /// Instantiates IpcTreeWebWindowThread.  Contains threaded IPC event listener
 /// that synchronizes Winform tree view, and displays or caches data from IPC event
 /// </summary>
 /// <param name="ipcType"></param>
 /// <param name="tsslStatus"></param>
 /// <param name="utilsBus"></param>
 /// <param name="func"></param>
 public IpcTreeWebWindowThread(string ipcType
     , System.Windows.Forms.ToolStripStatusLabel tsslStatus
     , Niawa.Utilities.UtilsServiceBus utilsBus
     , IpcTreeWebWindowFunctions func)
 {
     _ipcType = ipcType;
     _tsslStatus = tsslStatus;
     _utilsBus = utilsBus;
     _func = func;
 }
 /// <summary>
 /// Add a message to the message queue.  This message will be consumed by the listener thread in this object.
 /// </summary>
 /// <param name="evt"></param>
 public void AddMessage(Niawa.IpcController.IpcEvent evt)
 {
     try
     {
         _ipcEventQueue.Enqueue(evt);
     }
     catch (Exception ex)
     {
         Trace.TraceError("TreeModelCacheAdapter: Could not add Ipc Event to message queue: " + ex.Message);
     }
 }
Beispiel #11
0
        /// <summary>
        /// Instantiates UdpReceiver with properties for ignoring transmitted udp messages.
        /// </summary>
        /// <param name="port">Port to monitor for UDP messages.</param>
        /// <param name="evtConsumer">Consumer for events raised by Niawa.MsEventController.EventRaiser</param>
        /// <param name="utilsBus"></param>
        /// <param name="applicationNameDetailed"></param>
        /// <param name="parentNodeID"></param>
        /// <param name="ignoreTransmittedUdpMessages"></param>
        /// <param name="udpTransmitter"></param>
        public UdpReceiver(int port
            , Niawa.MsEventController.EventConsumer evtConsumer
            , Niawa.Utilities.UtilsServiceBus utilsBus
            , string applicationNameDetailed
            , string parentNodeID
            , bool ignoreTransmittedUdpMessages
            , UdpTransmitter udpTransmitter)
        {
            _ignoreTransmittedUdpMessages = ignoreTransmittedUdpMessages;
            _udpTransmitter = udpTransmitter;

            Instantiate(port, evtConsumer, utilsBus, applicationNameDetailed, parentNodeID);
        }
Beispiel #12
0
        /// <summary>
        /// Instantiates TreeModel
        /// </summary>
        /// <param name="view"></param>
        /// <param name="evtConsumer"></param>
        public TreeModel(ITreeModelView view, Niawa.MsEventController.EventConsumer evtConsumer, string applicationNameDetailed)
        {
            _evtConsumer = evtConsumer;
            _view = view;

            //initialize event logging
            Niawa.Utilities.UtilsServiceBus utilsBus = new Utilities.UtilsServiceBus();
            _evtRaiser = new MsEventController.EventRaiser("TreeModel", applicationNameDetailed, "TreeModel", utilsBus);
            if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);

            //generate a new node ID
            threadNodeID = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString();
        }
        /// <summary>
        /// Instantiates an IpcEventThread
        /// </summary>
        /// <param name="ipcType"></param>
        /// <param name="treeModelController"></param>
        /// <param name="tsslStatus"></param>
        /// <param name="utilsBus"></param>
        public IpcEventTreeModelAdapterThread(string ipcType
            , Niawa.TreeModelNodeControls.TreeModelController treeModelController
            , System.Windows.Forms.ToolStripStatusLabel tsslStatus
            , Niawa.Utilities.UtilsServiceBus utilsBus
            , IpcEventTreeModelAdapter parentControl)
        {
            _treeModelController = treeModelController;
            _parentControl = parentControl;

            _ipcType = ipcType;
            _tsslStatus = tsslStatus;
            _utilsBus = utilsBus;
        }
Beispiel #14
0
        /// <summary>
        /// Event Raiser contains the mechanism to raise events.  Event consumers are added (subscribed) and removed (unsubscibed), and when an event
        /// is raised the consumers will receive the event and add to the queue to be handled by their implementor.
        /// </summary>
        /// <param name="applicationGroup"></param>
        /// <param name="applicationName"></param>
        /// <param name="applicationInstance"></param>
        /// <param name="utilsBus"></param>
        public EventRaiser(string applicationGroup, string applicationName, string applicationInstance, Niawa.Utilities.UtilsServiceBus utilsBus)
        {
            try
            {
                _applicationGroup = applicationGroup;
                _applicationName = applicationName;
                _applicationInstance = applicationInstance;

                //initialize serial ID generator
                id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_EVENT_MESSAGE);
            }
            catch (Exception ex)
            {
                logger.Error("[EventRaiser] Error while instantiating: " + ex.Message, ex);
            }
        }
Beispiel #15
0
        /// <summary>
        /// Creates an IpcEventWriter
        /// </summary>
        /// <param name="applicationName">Name of application writing Ipc events</param>
        /// <param name="applicationInstance">Instance of the application write Ipc events</param>
        /// <param name="ignoreIpcExceptions">True if write exceptions should be handled by the writer; false if writer exceptions should be returned to the caller.</param>
        /// <param name="ipcEventGroup">Used to create the IpcType, which is used to identify and authenticate IPC data.</param>
        /// <returns></returns>
        public static iEventWriter CreateIpcEventWriter(string applicationName, bool ignoreIpcExceptions, string ipcEventGroup, Niawa.Utilities.UtilsServiceBus utilsBus)
        {
            try
            {
                return new IpcEventWriter(applicationName, "Niawa.IpcEvent." + ipcEventGroup, IpcEvent.IPC_EVENT_MMF_LENGTH, utilsBus, ignoreIpcExceptions);
            }
            catch (Exception ex)
            {
                logger.Error("Caught exception during CreateIpcEventReader: " + ex.Message, ex);

                if (ignoreIpcExceptions)
                    return new NullIpcEventWriter();
                else
                    throw ex;
            }
        }
Beispiel #16
0
        /// <summary>
        /// Instantiates TcpReceiver
        /// </summary>
        /// <param name="ipAddress">IP address to monitor for TCP messages</param>
        /// <param name="port">Network port to monitor for TCP messages</param>
        /// <param name="evtConsumer">Consumer for events raised by Niawa.MsEventController.EventRaiser</param>
        public TcpReceiver(string ipAddress, int port, string remoteIpAddress, Niawa.MsEventController.EventConsumer evtConsumer, Niawa.Utilities.UtilsServiceBus utilsBus, string applicationNameDetailed, string parentNodeID)
        {
            try
            {
                _applicationNameDetailed = applicationNameDetailed;

                _ipAddress = ipAddress;
                _remoteIpAddress = remoteIpAddress;
                _port = port;
                _portMin = 0;
                _portMax = 0;

                lockSection = new System.Threading.Semaphore(1, 1);

                _description = "TcpReceiver " + _remoteIpAddress + ":" + _port.ToString();
                _receiveQueue = new Queue<NiawaNetMessage>();

                _evtConsumer = evtConsumer;
                _utilsBus = utilsBus;

                //initialize event logging
                _evtRaiser = new MsEventController.EventRaiser("TcpReceiver", _applicationNameDetailed, _description, utilsBus);
                //_evtRaiserMsg = new MsEventController.EventRaiser("TcpReceiverMsg", _applicationNameDetailed, _description, utilsBus);
                if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);
                //if (_evtConsumer != null) _evtRaiserMsg.AddEventConsumer(_evtConsumer);

                //thread status
                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 300, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), parentNodeID, _evtRaiser);

                //add thread elective properties.
                _threadStatus.AddElectiveProperty("IpAddress", _ipAddress);
                _threadStatus.AddElectiveProperty("RemoteIpAddress", _remoteIpAddress);
                _threadStatus.AddElectiveProperty("Port", _port.ToString());

                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED ;

            }
            catch (Exception ex)
            {
                logger.Error("[TcpReceiver-M] Error instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
        /// <summary>
        /// Add an IpcEventWriter, to using for logging incoming events.  Multiple IpcEventWriters can be added, and the writer will be used according to the incoming event type.
        /// </summary>
        /// <param name="eventWriter"></param>
        /// <param name="description"></param>
        public void AddIpcEventWriter(Niawa.IpcController.iEventWriter eventWriter, string description)
        {
            try
            {
                logger.Info("[" + _description + "-M] Adding IpcEventWriter [" + description + "]");

                if (_ipcEventWriters.ContainsKey(description))
                    throw new Exception("[" + _description + "-M] There is already an event writer registered with description [" + description + "]");

                if (!eventWriter.IsActive) eventWriter.Start();

                _ipcEventWriters.Add(description, eventWriter);

            }
            catch (Exception ex)
            {
                logger.Error("[" + _description + "-M] Error while adding Ipc event writer: " + ex.Message, ex);
            }
        }
Beispiel #18
0
        /// <summary>
        /// Instantiates UdpTransmitter.
        /// </summary>
        /// <param name="port">Port to transmit UDP messages on.</param>
        /// <param name="evtConsumer">Consumer for events raised by Niawa.MsEventController.EventRaiser</param>
        public UdpTransmitter(int port, Niawa.MsEventController.EventConsumer evtConsumer, Niawa.Utilities.UtilsServiceBus utilsBus, string applicationNameDetailed, string parentNodeID)
        {
            try
            {
                _applicationNameDetailed = applicationNameDetailed;

                _port = port;
                _sendQueue = new Queue<NiawaNetDatagram>();
                _sentMessageGuidBuffer = new List<Guid>();

                lockSection = new System.Threading.Semaphore(1, 1);
                lockSentMessageGuidBuffer = new System.Threading.Semaphore(1, 1);

                _description = "UdpTransmitter " + _port.ToString();
                _evtConsumer = evtConsumer;

                //initialize the endpoints
                _groupEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Broadcast, _port);
                //_localEP = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, _port);

                //initialize serial ID generator
                id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_NET_DATAGRAM);

                //initialize event logging
                _evtRaiser = new MsEventController.EventRaiser("UdpTransmitter", _applicationNameDetailed, _description, utilsBus);
                if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);

                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), parentNodeID, _evtRaiser);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

                //add thread elective properties.
                _threadStatus.AddElectiveProperty("Port", _port.ToString());

            }
            catch (Exception ex)
            {
                logger.Error("[UdpTransmitter-M] Error while instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
        /// <summary>
        /// MsEventIpcEventWriter consumes events (as raised by Niawa.MsEventController) and writes them to an IpcEventWriter (as implemented by Niawa.IpcController). 
        /// The event consumer is added (subscribed) to an event raiser by the caller to enable events to be processed in McEventIpcEventWriter.
        /// Multiple IpcEventWriters are registered here and events are written to the appropriate IpcEventWriter based on event type.
        /// </summary>
        public MsEventIpcEventWriter(Niawa.Utilities.UtilsServiceBus utilsBus)
        {
            try
            {
                _description = "MsEventIpcEventAdapter";
                _messages = new Queue<MsEventController.NiawaEventMessageArgs>();
                _evtConsumer = new MsEventController.EventConsumer(_messages);

                _ipcEventWriters = new SortedList<string, IpcController.iEventWriter>();
                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

            }
            catch (Exception ex)
            {
                logger.Error("[MsEventIpcEventAdapter-M] Error while instantiating: " + ex.Message, ex);
            }
        }
Beispiel #20
0
        /// <summary>
        /// Instantiates IpcEventReader by initializing MmfReader.
        /// </summary>
        /// <param name="ipcType">Identifies and authenticates data for memory mapped file</param>
        /// <param name="ipcEventMessageLength">Length of data segment</param>
        /// <param name="ignoreIpcExceptions">True if read exceptions in MmfReader should be handled by MmfReader; false if they should be returned.</param>
        public IpcEventReader(string ipcType, int ipcEventMessageLength, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreIpcExceptions)
        {
            try
            {
                _ipcType = ipcType;
                _ipcEventMessageLength = ipcEventMessageLength;
                _ignoreIpcExceptions = ignoreIpcExceptions;

                mmfReader = new Niawa.IpcController.MmfBufferedReader(_ipcType, _ipcEventMessageLength, utilsBus, _ignoreIpcExceptions);
            }
            catch (Exception ex)
            {
                logger.Error("[IpcEventReader " + _ipcType + "] Caught exception during IpcEventReader instantiate: " + ex.Message, ex);

                if (ignoreIpcExceptions)
                { }
                else
                    throw ex;
            }
        }
        /// <summary>
        /// Instantiates a new IpcEventWebApiWriter.
        /// </summary>
        /// <param name="webApiUrl"></param>
        /// <param name="utilsBus"></param>
        public IpcEventWebAPIWriter(string webApiUrl, Niawa.Utilities.UtilsServiceBus utilsBus)
        {
            try
            {
                _description = "IpcEventWebAPIWriter";
                _webApiUrl = webApiUrl;

                _utilsBus = utilsBus;
                _messages = new Queue<IpcController.IpcEvent>();
                _eventReaders = new SortedList<string, IpcEventReaderThread>();
                lockSection = new System.Threading.Semaphore(1, 1);

                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;
            }
            catch (Exception ex)
            {
                logger.Error("[IpcEventWebAPIWriter-M] Error while instantiating: " + ex.Message, ex);
            }

        }
        /// <summary>
        /// Instantiates IpcCommandReader
        /// </summary>
        /// <param name="ipcEvent"></param>
        /// <param name="readerFunction"></param>
        public IpcCommandReader(string ipcEvent, Func<Niawa.IpcController.IpcEvent, bool> readerFunction, Niawa.Utilities.UtilsServiceBus utilsBus, bool ignoreExceptions)
        {
            try
            {
                _ignoreExceptions = ignoreExceptions;
                _ipcEvent = ipcEvent;
                _description = "IpcCommandReader " + _ipcEvent;
                _readerFunction = readerFunction;
                evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcEvent, utilsBus);

                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

            }
            catch (Exception ex)
            {
                logger.Error("[" + _description + "-M] Exception while instantiating: " + ex.Message, ex);
                if (!ignoreExceptions)
                    throw ex;
            }
        }
        /// <summary>
        /// Instantiates a new WebAPICommandReader.
        /// </summary>
        /// <param name="webApiUrl"></param>
        /// <param name="utilsBus"></param>
        public WebAPICommandReader(string webApiUrl, int pollIntervalMs,  Niawa.Utilities.UtilsServiceBus utilsBus)
        {
            try 
            {
                _description = "WebAPICommandReader";
                _webApiUrl = webApiUrl;
                _pollIntervalMs = pollIntervalMs;
                if (pollIntervalMs < 1000)
                {
                    logger.Warn("[WebAPICommandReader-M] Warning: poll interval under minimum, setting to 1000 ms");
                    _pollIntervalMs = 1000;
                }
                if (pollIntervalMs > 60000)
                {
                    logger.Warn("[WebAPICommandReader-M] Warning: poll interval over maximum, setting to 60000 ms");
                    _pollIntervalMs = 60000;
                }


                lockSection = new System.Threading.Semaphore(1, 1);

                _utilsBus = utilsBus;
                _messages = new Queue<NiawaWebMessage>();
                _cachedMessages = new SortedList<int, NiawaWebMessage>();
                _subscribedCommands = new List<int>();

                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, null);
                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;
  
            }
            catch (Exception ex)
            {
                logger.Error("[WebAPICommandReader-M] Error while instantiating: " + ex.Message, ex);
            }
        }
Beispiel #24
0
 //public ThreadStatus(string description, int threadHealthTimeoutSecs, Niawa.Utilities.SerialId threadId)
 //{
 //    Instantiate(description, threadHealthTimeoutSecs, threadId, null, null);
 //}
 //public ThreadStatus(string description, int threadHealthTimeoutSecs, Niawa.Utilities.SerialId threadId, Niawa.Utilities.SerialId parentThreadId)
 //{
 //    Instantiate(description, threadHealthTimeoutSecs, threadId, parentThreadId, null);
 //}
 public ThreadStatus(string description, int threadHealthTimeoutSecs, string nodeID, string parentNodeID, Niawa.MsEventController.IEventRaiser evtRaiser)
 {
     Instantiate(description, threadHealthTimeoutSecs, nodeID, parentNodeID, evtRaiser);
 }
 /// <summary>
 /// Event Raiser contains the mechanism to raise events.  Event consumers are added (subscribed) and removed (unsubscibed), and when an event
 /// is raised the consumers will receive the event and add to the queue to be handled by their implementor.
 /// </summary>
 /// <param name="applicationGroup"></param>
 /// <param name="applicationName"></param>
 /// <param name="applicationInstance"></param>
 /// <param name="utilsBus"></param>
 public MockedEventRaiser(string applicationGroup, string applicationName, string applicationInstance, Niawa.Utilities.UtilsServiceBus utilsBus)
 {
     _applicationGroup = applicationGroup;
     _applicationName = applicationName;
     _applicationInstance = applicationInstance;
 }
Beispiel #26
0
        private void Instantiate(string description, int threadHealthTimeoutSecs, string nodeID, string parentNodeID, Niawa.MsEventController.IEventRaiser evtRaiser)
        {
            //initialize serial ID generator
            //Niawa.Utilities.SerialId id = utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_NET_MESSAGE);

            statusContainer = new ThreadStatusContainer();
            _evtRaiser = evtRaiser;
            _threadHealthTimeoutSecs = threadHealthTimeoutSecs;

            statusContainer.Description = description;
            statusContainer.NodeID = nodeID;
            statusContainer.ParentNodeID = parentNodeID;

            statusContainer.Initialized = true;
            statusContainer.InitializedDate = DateTime.Now;
            statusContainer.Status = STATUS_UNKNOWN;
        }
        /// <summary>
        /// Adds a message to the Web API Queue to be written.
        /// </summary>
        /// <param name="message"></param>
        public void AddMessageToQueue(Niawa.IpcController.IpcEvent message)
        {
            try
            {
                //attempt lock
                bool tryLock = lockSection.WaitOne(60000);
                if (!tryLock) throw new TimeoutException("[" + _description + "-M] Could not obtain lock while adding message to queue");

                try
                {
                    //add message to queue
                    _messages.Enqueue(message);
                }
                finally
                {
                    //release lock
                    lockSection.Release();
                }

            }
            catch (Exception ex)
            {
                logger.Error("[" + _description + "-M] Error while adding message to queue: " + ex.Message, ex);
            }
        }
        /// <summary>
        /// Caches data received from IPC Reader, and if the view is active, displays
        /// data on the view browser.
        /// </summary>
        /// <param name="evt"></param>
        public void CacheOrDisplayEventData(Niawa.IpcController.IpcEvent evt)
        {
            //cache and update status
            if (evt.EventType == "Status" || evt.EventType == "StatusReport")
            {
                _cachedStatusJson = evt.ToJson();

                if (_activeView)
                {
                    InvokeJavascript("resetStatusView", _cachedStatusJson);
                }
            }

            //cache and add event
            AcquireLock("CacheOrDisplayEventData");

            try
            {
                _cachedEvents.Add(evt.ToJson());
                if (_cachedEvents.Count > 100)
                    _cachedEvents.RemoveAt(0);

            }
            finally
            {
                if(IsLocked) ReleaseLock();
            }

            if (_activeView)
            {
                InvokeJavascript("addRow", evt.ToJson()); //, evtPropertiesSerialized);
            }
        }
Beispiel #29
0
        /// <summary>
        /// Private function for instantiating UdpReceiver.
        /// </summary>
        /// <param name="port"></param>
        /// <param name="evtConsumer"></param>
        /// <param name="utilsBus"></param>
        /// <param name="applicationNameDetailed"></param>
        /// <param name="parentNodeID"></param>
        private void Instantiate(int port
            , Niawa.MsEventController.EventConsumer evtConsumer
            , Niawa.Utilities.UtilsServiceBus utilsBus
            , string applicationNameDetailed
            , string parentNodeID)
        {
            try
            {
                _applicationNameDetailed = applicationNameDetailed;

                _port = port;
                _receiveQueue = new Queue<NiawaNetDatagram>();
                _evtConsumer = evtConsumer;

                lockSection = new System.Threading.Semaphore(1, 1);

                _description = "UdpReceiver " + _port.ToString();

                //initialize the endpoints
                /*v2*/
                //_recvEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
                //_localEP = new System.Net.IPEndPoint(System.Net.IPAddress.Loopback, _port);
                /*v3*/
                _recvEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, _port);

                //initialize event logging
                _evtRaiser = new MsEventController.EventRaiser("UdpReceiver", _applicationNameDetailed, _description, utilsBus);
                if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);

                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 300, utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), parentNodeID, _evtRaiser);

                //thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;

                //add thread elective properties.
                _threadStatus.AddElectiveProperty("Port", _port.ToString());

            }
            catch (Exception ex)
            {
                logger.Error("[UdpReceiver-M] Error while instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
Beispiel #30
0
 /// <summary>
 /// Instantiates UdpReceiver.
 /// </summary>
 /// <param name="port"></param>
 /// <param name="evtConsumer"></param>
 /// <param name="utilsBus"></param>
 /// <param name="applicationNameDetailed"></param>
 /// <param name="parentNodeID"></param>
 private UdpReceiver(int port
     , Niawa.MsEventController.EventConsumer evtConsumer
     , Niawa.Utilities.UtilsServiceBus utilsBus
     , string applicationNameDetailed
     , string parentNodeID)
 {
     Instantiate(port, evtConsumer, utilsBus, applicationNameDetailed, parentNodeID);
 }