Esempio n. 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 a new IpcEventTreeModelAdapter.
        /// </summary>
        /// <param name="formWindow"></param>
        /// <param name="formTreeView"></param>
        public IpcEventTreeModelAdapter(Forms.IpcTreeWebWindow formWindow, Forms.IpcEventMonitorMdiWindow mdiWindow, System.Windows.Forms.TreeView formTreeView)
        {
            _webURL = "file:///{0}/Html/IpcEventMonitorPane.html";

            _formWindow = formWindow;
            _mdiWindow = mdiWindow;
            _formTreeView = formTreeView;
            _webBrowser = _formWindow.WebBrowser1;

            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();

            //set up ipc logging for this class (to log events that occur in the tree model)
            _evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(_utilsBus);
            _evtWriter.Start();
            _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("IpcEventMonitor", true, "TreeModel", _utilsBus), "TreeModel");

            //instantiate view
            _view = new TreeModel.TreeModelViewImpl(_formWindow, _formTreeView);

            //instantiate node view factory
            _nodeViewFactory = new TreeModel.TreeModelNodeViewFactoryImpl(_webBrowser, _webURL);

            //instantiate tree model controller
            _treeModelController = new TreeModelNodeControls.TreeModelController(_view, _nodeViewFactory, _evtWriter.EvtConsumer, "IpcEventMonitor", string.Empty);
        }
Esempio n. 3
0
        public void Execute()
        {
            logger.Info("Executing UdpTestClient");

            //create utility bus
            Niawa.Utilities.UtilsServiceBus utilsBus = new Niawa.Utilities.UtilsServiceBus();

            //set up ipc logging
            Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(utilsBus);
            evtWriter.Start();
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "UdpReceiver", utilsBus), "UdpReceiver");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "UdpReceiverMsg", utilsBus), "UdpReceiverMsg");
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "UdpTransmitter", utilsBus), "UdpTransmitter");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "UdpTransmitterMsg", utilsBus), "UdpTransmitterMsg");

            transmitter = new Niawa.NetController.UdpTransmitter(_port, evtWriter.EvtConsumer, utilsBus, "TestApp.UdpTestClient", null);
            receiver = new Niawa.NetController.UdpReceiver(_port, evtWriter.EvtConsumer, utilsBus, "TestApp.UdpTestClient", null, true, transmitter);

            receiver.StartListening("UdpTestClient");
            transmitter.StartTransmitting("UdpTestClient");

            System.Threading.Thread t1 = new System.Threading.Thread(StateChangeThreadImpl);
            System.Threading.Thread t2 = new System.Threading.Thread(SendMessageThreadImpl);

            t1.Start();
            t2.Start();
        }
Esempio n. 4
0
        /// <summary>
        /// Instantiates IpcEventMonitor
        /// </summary>
        /// <param name="ipcGroup">IpcGroup to monitor for IpcEvents</param>
        public IpcEventMonitor(string ipcGroup)
        {
            _ipcGroup = ipcGroup;

            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();
        }
        public void Initialize()
        {
            /*
            _dgvMonitor.ColumnCount = 7;
            _dgvMonitor.Columns[0].Name = "SerialID";
            _dgvMonitor.Columns[1].Name = "EventID";
            _dgvMonitor.Columns[2].Name = "EventDate";
            _dgvMonitor.Columns[3].Name = "ApplicationName";
            _dgvMonitor.Columns[4].Name = "EventType";
            _dgvMonitor.Columns[5].Name = "EventDetail";
            _dgvMonitor.Columns[6].Name = "EventProperties";
            */

            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();

            evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcEvent, _utilsBus);

            try
            {
                InvokeJavascript("addHeader", "IpcEvent"); //, "EventProperties");
                //if (_browser.IsBusy)
                //{
                //    System.Threading.Thread.Sleep(100);
                //}
                //System.Threading.Thread.Sleep(1000);
                //_browser.Document.InvokeScript("addDefaultHeader");

            }
            catch (Exception ex)
            {
                _tsslStatus.Text = "Exception: " + ex.Message;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="eventType"></param>
 public TestEventWriter(string eventType, string nodeID, string parentNodeID)
 {
     _utilsBus = new Niawa.Utilities.UtilsServiceBus();
     _eventType = eventType;
     _nodeID = nodeID;
     _parentNodeID = parentNodeID;
 }
Esempio n. 7
0
        /// <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;
            }
        }
Esempio n. 8
0
        public IpcCommandAdapter()
        {
            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();

            _writer = Niawa.IpcController.IpcFactory.CreateIpcEventWriter("IpcEventMonitor", true, "NiawaAdHocNetworkAdapterCmd", _utilsBus);
            _writer.Start();

            _started = true;
        }
 /// <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;
 }
Esempio n. 10
0
        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>
        /// 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;
        }
Esempio n. 12
0
        /// <summary>
        /// Instantiates an IpcEventThread
        /// </summary>
        /// <param name="ipcType"></param>
        /// <param name="treeModelController"></param>
        /// <param name="tsslStatus"></param>
        /// <param name="utilsBus"></param>
        public IpcEventAdapter(string ipcType
            , Forms.IpcWebWindow formWindow)
        {
            _formWindow = formWindow;

            _ipcType = ipcType;

            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();

            evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcType, _utilsBus);
            t1 = new System.Threading.Thread(ListenThreadImpl);
        }
Esempio n. 13
0
        public void Initialize()
        {
            _dgvMonitor.ColumnCount = 7;
            _dgvMonitor.Columns[0].Name = "SerialID";
            _dgvMonitor.Columns[1].Name = "EventID";
            _dgvMonitor.Columns[2].Name = "EventDate";
            _dgvMonitor.Columns[3].Name = "ApplicationName";
            _dgvMonitor.Columns[4].Name = "NodeID";
            _dgvMonitor.Columns[5].Name = "ParentNodeID";
            _dgvMonitor.Columns[6].Name = "EventType";
            _dgvMonitor.Columns[7].Name = "EventMessage";
            _dgvMonitor.Columns[8].Name = "EventMessageDetail";

            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();

            evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcEvent, _utilsBus);
        }
Esempio n. 14
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>
        /// 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 a new IpcEventReaderThread.
        /// </summary>
        /// <param name="ipcType"></param>
        /// <param name="webWriter"></param>
        /// <param name="utilsBus"></param>
        public IpcEventReaderThread(string ipcType, IpcEventWebAPIWriter webWriter, Utilities.UtilsServiceBus utilsBus)
        {
            try
            {
                _description = "IpcEventReaderThread-" + ipcType;

                _ipcType = ipcType;
                _webWriter = webWriter;
                _utilsBus = utilsBus;

                //event reader
                evtReader = Niawa.IpcController.IpcFactory.CreateIpcEventReader(true, _ipcType, _utilsBus);

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

                //set thread status
                _threadStatus.Status = Niawa.Threading.ThreadStatus.STATUS_INITIALIZED;
            }
            catch (Exception ex)
            {
                logger.Error("[IpcEventReaderThread-" + ipcType + "-M] Error while instantiating: " + ex.Message, ex);
            }
        }
Esempio n. 17
0
        /// <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);
            }
        }
 public void TearDown()
 {
     _utilsBus = null;
 }
 public void Setup()
 {
     //create utility bus
     _utilsBus = new Niawa.Utilities.UtilsServiceBus();
 }
 public void Setup()
 {
     _utilsBus = new Niawa.Utilities.UtilsServiceBus();
 }
Esempio n. 21
0
        public void ExecuteTcpUnitTest1()
        {
            logger.Info(">>");
            logger.Info("Program started");

            //my IP address
            System.Net.IPAddress myAddress = Niawa.Utilities.NetUtils.FindLanAddress();
            int myPort = 2150;

            //remote client IP address
            System.Net.IPAddress remoteAddress = null;
            if (myAddress.ToString() == "192.168.2.14")
                remoteAddress = System.Net.IPAddress.Parse("192.168.2.6");
            else if (myAddress.ToString() == "192.168.2.6")
                remoteAddress = System.Net.IPAddress.Parse("192.168.2.14");
            else
                throw new Exception("The current IP address [" + myAddress.ToString() + "] doesn't have a configured test remote value");

            int remotePort = 2150;

            //create utility bus
            Niawa.Utilities.UtilsServiceBus utilsBus = new Niawa.Utilities.UtilsServiceBus();

            //set up ipc logging
            Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(utilsBus);
            evtWriter.Start();
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpReceiver", utilsBus), "TcpReceiver");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpReceiverMsg", utilsBus), "TcpReceiverMsg");
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpTransmitter", utilsBus), "TcpTransmitter");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpTransmitterMsg", utilsBus), "TcpTransmitterMsg");

            //receiver
            logger.Info("Test receiver");
            Niawa.NetController.TcpReceiver receiver = new Niawa.NetController.TcpReceiver(myAddress.ToString(), myPort, "(local)", evtWriter.EvtConsumer, utilsBus, "TestApp.TestClient", null);

            receiver.StartListening("TestClient");
            //System.Threading.Thread.Sleep(1500);

            //transmitter
            logger.Info("Test transmitter");
            Niawa.NetController.TcpTransmitter transmitter = new Niawa.NetController.TcpTransmitter(remoteAddress.ToString(), remotePort, evtWriter.EvtConsumer, utilsBus, "TestApp.TestClient", null);

            transmitter.StartTransmitting("TestClient");
            System.Threading.Thread.Sleep(1500);

            bool doneTesting = false;

            int ix = 0;
            while (!doneTesting)
            {
                ix++;
                //send test message
                transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType" + ix, "testMsg contents " + ix));
                System.Threading.Thread.Sleep(2500);

            }

            transmitter.StopTransmitting("TestClient", false);
            System.Threading.Thread.Sleep(1000);

            receiver.StopListening("TestClient", false);
            System.Threading.Thread.Sleep(1000);

            transmitter = null;
            receiver = null;

            logger.Info("Program stopped <<");
        }
        /// <summary>
        /// Creates a NiawaAdHocNetworkAdapter
        /// </summary>
        /// <param name="udpPort"></param>
        /// <param name="ipAddress"></param>
        /// <param name="tcpPortRangeMin"></param>
        /// <param name="tcpPortRangeMax"></param>
        /// <param name="hostname"></param>
        /// <param name="applicationName"></param>
        public NiawaAdHocNetworkAdapter(int udpPort, string ipAddress, int tcpPortRangeMin, int tcpPortRangeMax, string hostname, string applicationName)
        {
            try
            {
                _description = "NiawaAdHocNetworkAdapter";

                _udpPort = udpPort;
                _ipAddress = ipAddress;
                _tcpPortRangeMin = tcpPortRangeMin;
                _tcpPortRangeMax = tcpPortRangeMax;
                _hostname = hostname;
                _applicationName = applicationName;

                //create utility bus
                _utilsBus = new Niawa.Utilities.UtilsServiceBus();

                //set up ipc logging
                _evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(_utilsBus);
                _evtWriter.Start();

                //initialize event logging for this object
                _evtRaiser = new MsEventController.EventRaiser("NiawaAdHocNetworkAdapter", _applicationName, _description, _utilsBus);
                if (_evtWriter.EvtConsumer != null) _evtRaiser.AddEventConsumer(_evtWriter.EvtConsumer);
                //add ipc logging for this object
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "NiawaAdHocNetworkAdapter", _utilsBus), "NiawaAdHocNetworkAdapter");

                //add ipc logging for UDP
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpReceiver", _utilsBus), "UdpReceiver");
                //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpReceiverMsg", _utilsBus), "UdpReceiverMsg");
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpTransmitter", _utilsBus), "UdpTransmitter");
                //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "UdpTransmitterMsg", _utilsBus), "UdpTransmitterMsg");

                //add ipc logging for TCP
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpReceiver", _utilsBus), "TcpReceiver");
                //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpReceiverMsg", _utilsBus), "TcpReceiverMsg");
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpTransmitter", _utilsBus), "TcpTransmitter");
                //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpTransmitterMsg", _utilsBus), "TcpTransmitterMsg");

                //add ipc logging for TcpSession
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpSession", _utilsBus), "TcpSession");

                //add ipc logging for TcpSessionManager
                _evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpSessionManager", _utilsBus), "TcpSessionManager");
                //_evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter(_applicationName, true, "TcpSessionManagerMsg", _utilsBus), "TcpSessionManagerMsg");

                //ipc command reader
                _cmdReader = new IpcController.IpcCommandReader("NiawaAdHocNetworkAdapterCmd", CmdReaderImpl, _utilsBus, true);

                //thread health and status
                _threadStatus = new Niawa.Threading.ThreadStatus(_description, 60, _utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), string.Empty, _evtRaiser);
                _healthMonitor = new ThreadHealthMonitor(this);

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

                //add thread elective properties.
                _threadStatus.AddElectiveProperty("IpAddress", _ipAddress);
                _threadStatus.AddElectiveProperty("TcpPortRangeMin", _tcpPortRangeMin.ToString());
                _threadStatus.AddElectiveProperty("TcpPortRangeMax", _tcpPortRangeMax.ToString());
                _threadStatus.AddElectiveProperty("UdpPort", _udpPort.ToString());
                _threadStatus.AddElectiveProperty("Hostname", _hostname);

            }
            catch (Exception ex)
            {
                logger.Error("[NiawaAdHocNetworkAdapter-M] Error while instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
Esempio n. 23
0
        public void ExecuteUdpUnitTest1()
        {
            logger.Info(">>");
            logger.Info("Program started");

            //create utility bus
            Niawa.Utilities.UtilsServiceBus utilsBus = new Niawa.Utilities.UtilsServiceBus();

            //set up ipc logging
            Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(utilsBus);
            evtWriter.Start();
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "UdpReceiver", utilsBus), "UdpReceiver");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpReceiverMsg", utilsBus), "TcpReceiverMsg");
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "UdpTransmitter", utilsBus), "UdpTransmitter");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpTransmitterMsg", utilsBus), "TcpTransmitterMsg");

            Niawa.NetController.UdpTransmitter transmitter = new Niawa.NetController.UdpTransmitter(5001, evtWriter.EvtConsumer, utilsBus, "TestApp.TestClient",  null);
            transmitter.StartTransmitting("TestClient");

            Niawa.NetController.UdpReceiver receiver = new Niawa.NetController.UdpReceiver(5001, evtWriter.EvtConsumer, utilsBus, "TestApp.TestClient", null, true, transmitter);
            receiver.StartListening("TestClient");

            bool active = true;
            int ix = 0;
            while (active)
            {
                string lanAddress = Niawa.Utilities.NetUtils.FindLanAddress().ToString();
                transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg " + lanAddress + " contents " + ix));

                System.Threading.Thread.Sleep(1500);

                ix++;
            }
            /*
            receiver.SuspendListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");

            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            transmitter.SendMessage(new NetController.NiawaNetDatagram(Niawa.Utilities.NetUtils.FindLanAddress().ToString(), 5001, Guid.NewGuid(), "testHost", "testApp", "testMsgType", "testMsg contents 1"));
            receiver.ResumeListening("TestClient");
            */
            System.Threading.Thread.Sleep(1500);

            logger.Info("Program stopped <<");
        }
Esempio n. 24
0
        public void ExecuteTcpUnitTest0()
        {
            logger.Info(">>");
            logger.Info("Program started");

            //my IP address
            System.Net.IPAddress myAddress = Niawa.Utilities.NetUtils.FindLanAddress();
            int myPort = 2150;

            //remote client IP address
            System.Net.IPAddress remoteAddress = System.Net.IPAddress.Parse("192.168.2.6");
            int remotePort = 2150;

            //create utility bus
            Niawa.Utilities.UtilsServiceBus utilsBus = new Niawa.Utilities.UtilsServiceBus();

            //set up ipc logging
            Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter evtWriter = new Niawa.MsEventIpcEventAdapter.MsEventIpcEventWriter(utilsBus);
            evtWriter.Start();
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpReceiver", utilsBus), "TcpReceiver");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpReceiverMsg", utilsBus), "TcpReceiverMsg");
            evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpTransmitter", utilsBus), "TcpTransmitter");
            //evtWriter.AddIpcEventWriter(Niawa.IpcController.IpcFactory.CreateIpcEventWriter("Niawa.NetControllerTestClient", true, "TcpTransmitterMsg", utilsBus), "TcpTransmitterMsg");

            //receiver
            logger.Info("Test receiver");
            Niawa.NetController.TcpReceiver receiver = new Niawa.NetController.TcpReceiver(myAddress.ToString(), myPort, "(local)", evtWriter.EvtConsumer, utilsBus, "TestApp.TestClient", null);

            receiver.StartListening("TestClient");
            System.Threading.Thread.Sleep(1500);

            //transmitter
            logger.Info("Test transmitter");
            Niawa.NetController.TcpTransmitter transmitter = new Niawa.NetController.TcpTransmitter(remoteAddress.ToString(), remotePort, evtWriter.EvtConsumer, utilsBus, "TestApp.TestClient", null);

            transmitter.StartTransmitting("TestClient");
            System.Threading.Thread.Sleep(1500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType1", "testMsg contents 1"));
            System.Threading.Thread.Sleep(500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType2", "testMsg contents 2"));
            System.Threading.Thread.Sleep(1500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType3", "testMsg contents 3"));
            System.Threading.Thread.Sleep(500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType4", "testMsg contents 4"));
            System.Threading.Thread.Sleep(500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType5", "testMsg contents 5"));
            System.Threading.Thread.Sleep(1500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType6", "testMsg contents 6"));
            System.Threading.Thread.Sleep(1500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType7", "testMsg contents 7"));
            System.Threading.Thread.Sleep(1500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType8", "testMsg contents 8"));
            System.Threading.Thread.Sleep(500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType9", "testMsg contents 9"));
            System.Threading.Thread.Sleep(1500);

            //send test message
            transmitter.SendMessage(new NetController.NiawaNetMessage(myAddress.ToString(), myPort, "TestHost", remoteAddress.ToString(), remotePort, "TestHost", Guid.NewGuid(), "testApp", "testMsgType10", "testMsg contents 10"));
            System.Threading.Thread.Sleep(500);

            System.Threading.Thread.Sleep(3000);

            transmitter.StopTransmitting("TestClient", false);
            System.Threading.Thread.Sleep(1000);

            receiver.StopListening("TestClient", false);
            System.Threading.Thread.Sleep(1000);

            transmitter = null;
            receiver = null;

            logger.Info("Program stopped <<");
        }
        /// <summary>
        /// Initializes IpcTreeWebWindowFunctions.  Create a thread for each IPC Type Reader
        /// </summary>
        public void Initialize()
        {
            //create utility bus
            _utilsBus = new Niawa.Utilities.UtilsServiceBus();

            //create threads for each monitored IPC event type
            foreach (string ipcEvent in _ipcEvents)
            {
                threads.Add(ipcEvent, new IpcTreeWebWindowThread(ipcEvent, _tsslStatus, _utilsBus, this));
            }
        }