Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        public void ExecuteBasicTest()
        {
            Niawa.WebNotify.IpcEventWebAPIAdapter.IpcEventWebAPIWriter webApiWriter = null;

            try
            {
                //Ad-Hoc Network Adapter
                nna = new NetController.NiawaAdHocNetworkAdapter(_udpPort, _ipAddress, _tcpPortRangeMin, _tcpPortRangeMax, _hostname, _applicationName);

                //web notify IPC Event Web API Adapter
                if (_webApiUrl.Trim().Length > 0)
                {
                    logger.Info("Web API Writer is enabled: " + _webApiUrl);

                    Niawa.Utilities.UtilsServiceBus utilsBus = new Utilities.UtilsServiceBus();
                    //string webApiUrl = "http://localhost:3465";
                    webApiWriter = new WebNotify.IpcEventWebAPIAdapter.IpcEventWebAPIWriter(_webApiUrl, utilsBus);
                    webApiWriter.AddIpcEventReader("NiawaAdHocNetworkAdapter");
                    webApiWriter.AddIpcEventReader("TcpReceiver");
                    webApiWriter.AddIpcEventReader("TcpSession");
                    webApiWriter.AddIpcEventReader("TcpSessionManager");
                    webApiWriter.AddIpcEventReader("TcpTransmitter");
                    webApiWriter.AddIpcEventReader("UdpReceiver");
                    webApiWriter.AddIpcEventReader("UdpTransmitter");
                    webApiWriter.Start();

                    logger.Info("Web API Command Reader is enabled: " + _webApiUrl);
                    webApiCmdReader = new WebNotify.IpcEventWebAPIAdapter.WebAPICommandReader(_webApiUrl, 10000, utilsBus);
                    //subscribe to command for refreshing status(=1)
                    webApiCmdReader.CommandSubscribe(1);
                    webApiCmdReader.Start();
                    t1 = new System.Threading.Thread(WebApiCommandListenThreadImpl);
                    t1.Start();

                }
                else
                {
                    logger.Info("Web API Writer is disabled");
                }

                //start ad-hoc network adapter
                nna.Start();

                int every5Times = 0;
                int every25Times = 0;

                while (1 == 1)
                {
                    _totalMessageCounter++;

                    //send ping message every 5 times (50 seconds)
                    if (every5Times == 0)
                    {
                        nna.TransmitPingMessage(false, string.Empty);
                        //nna.TransmitHandshakeMessage();

                    }
                    every5Times++;

                    //send handshake message every 25 times (250 seconds)
                    if (every25Times == 0)
                    {
                        nna.TransmitHandshakeMessage();

                    }
                    every25Times++;

                    //send test message every time (10 seconds)
                    nna.TcpSessionManager.SendMessage(_applicationName, "TestMsgType" + _totalMessageCounter.ToString(), "TestMsg contents " + _totalMessageCounter.ToString());

                    //increase test counters
                    if (every5Times > 5)
                        every5Times = 0;

                    if (every25Times > 25)
                        every25Times = 0;

                    //sleep for 10 seconds
                    System.Threading.Thread.Sleep(10000);

                }

            }
            finally
            {
                if (t1 != null) t1.Abort();

                if (webApiWriter != null)
                    webApiWriter.Dispose();

                if (webApiCmdReader != null)
                    webApiCmdReader.Dispose();
            }
        }