예제 #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();
        }
예제 #2
0
        /// <summary>
        /// Instantiates TcpTransmitter
        /// </summary>
        /// <param name="ipAddress">IP Address to transmit TCP messages on</param>
        /// <param name="port">Network port to transmit TCP messages on</param>
        /// <param name="evtConsumer">Consumer for events raised by Niawa.MsEventController.EventRaiser</param>
        public TcpTransmitter(string ipAddress, int port, Niawa.MsEventController.EventConsumer evtConsumer, Niawa.Utilities.UtilsServiceBus utilsBus, string applicationNameDetailed, string parentNodeID)
        {
            try
            {
                _applicationNameDetailed = applicationNameDetailed;

                _ipAddress = ipAddress;
                _port = port;
                _evtConsumer = evtConsumer;

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

                _description = "TcpTransmitter " + _ipAddress + ":" + _port.ToString();
                _sendQueue = new Queue<NiawaNetMessage>();

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

                //initialize event logging
                _evtRaiser = new MsEventController.EventRaiser("TcpTransmitter", _applicationNameDetailed, _description, utilsBus);
                //_evtRaiserMsg = new MsEventController.EventRaiser("TcpTransmitterMsg", _applicationNameDetailed, _description, utilsBus);
                if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);
                //if (_evtConsumer != null) _evtRaiserMsg.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("IpAddress", _ipAddress);
                _threadStatus.AddElectiveProperty("Port", _port.ToString());

            }
            catch (Exception ex)
            {
                logger.Error("[TcpTransmitter-M] Error instantiating: " + ex.Message, ex);
                throw ex;
            }
        }
        /// <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;
            }
        }
예제 #4
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;
            }
        }
예제 #5
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;
            }
        }
예제 #6
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;
            }
        }
예제 #7
0
        /// <summary>
        /// Internal function to initialize the TcpSession.  Sets up a receiver with either a specific port or a port range.
        /// </summary>
        private void Initialize()
        {
            if (_localPortRange && _localPortRangeMin == 0 && _localPortRangeMax == 0)
            { throw new Exception("[" + _sessionIdentifier + "] When a port range is used, PortRangeMin and PortRangeMax values must be supplied."); }

            if (_localPortRange && _localPortRangeMin > _localPortRangeMax)
            { throw new Exception("[" + _sessionIdentifier + "] When a port range is used, PortRangeMax must be greater than PortRangeMin."); }

            if (!_localPortRange && _localPort == 0)
            { throw new Exception("[" + _sessionIdentifier + "] When a port range is not used, a value must be supplied for Port."); }

            //initialize event logging
            _evtRaiser = new MsEventController.EventRaiser("TcpSession", _applicationName, _sessionIdentifier, _utilsBus);
            if (_evtConsumer != null) _evtRaiser.AddEventConsumer(_evtConsumer);

            _threadStatus = new Niawa.Threading.ThreadStatus(_sessionIdentifier, 0, _utilsBus.InitializeSerialId(Niawa.Utilities.IdGeneratorUtils.ID_ROOT_NIAWA_THREAD_ID).ToString(), _parentNodeID, _evtRaiser);

            if (_localPortRange)
            {
                //port was not supplied
                _receiver = new TcpReceiver(_localIpAddress, _localPortRangeMin, _localPortRangeMax, _remoteIpAddress,  _evtConsumer, _utilsBus, _applicationName + ".TcpSession", _threadStatus.NodeID);
            }
            else
            {
                //port was supplied
                _receiver = new TcpReceiver(_localIpAddress, _localPort, _remoteIpAddress, _evtConsumer, _utilsBus, _applicationName + ".TcpSession", _threadStatus.NodeID);
            }

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

            //add thread elective properties.
            _threadStatus.AddElectiveProperty("LocalIpAddress", _localIpAddress);
            _threadStatus.AddElectiveProperty("LocalPort", _localPort.ToString());
            _threadStatus.AddElectiveProperty("LocalPortRangeMin", _localPortRangeMin.ToString());
            _threadStatus.AddElectiveProperty("LocalPortRangeMax", _localPortRangeMax.ToString());
            _threadStatus.AddElectiveProperty("RemoteIpAddress", _remoteIpAddress);
            _threadStatus.AddElectiveProperty("RemoteHandshakePort", _remoteHandshakePort.ToString());
            _threadStatus.AddElectiveProperty("RemoteHostname", _remoteHostname);
        }