/// <summary>
 /// Sets up and starts communications
 /// </summary>
 /// <param name="localURI">The IP address and port the FECS will
 /// listen to for connections</param>
 /// <param name="schemaPath">The location of schemas for validating messages</param>
 public static void Initialize(int port, string schemaPath,
                               BecsFecsInputWrapper inputQueue, FecsBecsOutputWrapper outputQueue)
 {
     _port            = new Port(System.Net.IPAddress.Any, port);
     _channelMgr      = new FecsChannelManager();
     _port.ChannelMgr = _channelMgr;
     _port.Open();
     _msgValidator  = new FecsMessageValidator(schemaPath);
     _inputAdapter  = new InputQueueFecsAdapter(inputQueue, _channelMgr);
     _outputAdapter = new OutputQueueFecsAdapter(outputQueue, _msgValidator);
     _inputAdapter.OutputAdapter = _outputAdapter;
     _port.NewConnection        += new ConnectionHandler(OnPortNewConnection);
 }
 /// <summary>
 /// Stops listening to new connections.
 /// Call it to end the functionality of the class.
 /// </summary>
 public void Stop()
 {
     CommObjects.Shutdown();
     if (_fecsBecsOutputQueue != null)
     {
         _fecsBecsOutputQueue.Close();
         _fecsBecsOutputQueue = null;
     }
     if (_becsFecsInputQueue != null)
     {
         _becsFecsInputQueue.Close();
         _becsFecsInputQueue = null;
     }
 }
        /// <summary>
        /// Launches listening to clients and BECS.
        /// Call it to really start the functionality of the class.
        /// </summary>
        public void Start()
        {
            // Create the queue sender to BECS
            _fecsBecsOutputQueue = new FecsBecsOutputWrapper(OUTPUT_QUEUE_PATH);
            // Create the queue receiver from BECS
            _becsFecsInputQueue = new BecsFecsInputWrapper(INPUT_QUEUE_PATH);

            // Determine the IPAddress of this machine
            IPAddress [] aryLocalAddr = null;
            String       strHostName  = "";

            try
            {
                // NOTE: DNS lookups are nice and all but quite time consuming.
                strHostName = Dns.GetHostName();
                IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
                aryLocalAddr = ipEntry.AddressList;
            }
            catch (Exception ex)
            {
                //Logger.WriteLogException(3, "Error trying to get local address", ex);
                FecsMain.Logger.AddLog(ex);
            }

            // Verify we got an IP address. Tell the user if we did
            if (aryLocalAddr == null || aryLocalAddr.Length < 1)
            {
                //Logger.WriteLogMessage(3, "Unable to get local address");
                FecsMain.Logger.AddLog("Unable to get local address", LoggerSeverities.Error);
                return;
            }
            /// JLB: GPRS -> Use second address if available
            /// TODO: Remove when testing base connection
            //int index =(aryLocalAddr.Length > 1) ? 1 : 0;

            // Initialize listener
            try
            {
                CommObjects.Initialize(PORT_NUMBER, XML_SCHEMAS_PATH,
                                       _becsFecsInputQueue, _fecsBecsOutputQueue);
            }
            catch (Exception ex)
            {
                //Logger.WriteLogMessage(3, "Port is busy. Can't create listener on : {0}:{1} - {2}", aryLocalAddr[index], int.Parse(PORT_NUMBER), ex.Message);
                FecsMain.Logger.AddLog("Port is busy. Can't create listener on port : " + PORT_NUMBER + " - " + ex.Message, LoggerSeverities.Error);
                return;
            }

            // Notify about correct working
            //Logger.WriteLogMessage(3, "Listening on : [{0}] {1}:{2}", strHostName, aryLocalAddr[index], int.Parse(PORT_NUMBER));
            FecsMain.Logger.AddLog("Listening on : [" + strHostName + ":" + PORT_NUMBER + "]", LoggerSeverities.Info);

            // Initialize queue
            try
            {
                _becsFecsInputQueue.BeginReceive();
            }
            catch (Exception ex)
            {
                //Logger.WriteLogMessage(3, "Wrong queue path(either input or output) - {0}", ex.Message);
                FecsMain.Logger.AddLog(ex);
                return;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Constructor taking the object to use as interface to an outbound
 /// message queue
 /// </summary>
 /// <param name="queue">The outbound message queue</param>
 /// <param name="validator">The object that knows how to validate
 /// incoming messages</param>
 public OutputQueueFecsAdapter(FecsBecsOutputWrapper queue, IMessageValidator validator)
 {
     _outQueue  = queue;
     _validator = validator;
 }