예제 #1
0
        /// <summary>
        /// The init.
        /// </summary>
        private void Init()
        {
            lock (this.lockInit)
            {
                if (this.isInit)
                {
                    return;
                }

                this.isInit = true;

                // starting TCP-Listener to retreive connections
                this.tcpListener = new TcpListener(IPAddress.Any, this.config.TCPPort);
                this.tcpListener.Start();

                // starting a Thread to grab new TCP-Connections and wrap them into a EpicsTCPServerConnection
                this.connectionGrabber = new Thread(this.GrabConnection);
                this.connectionGrabber.IsBackground = true;
                this.connectionGrabber.Start();

                // opening the UDP-Listener
                this.udpConnection = new EpicsServerUDPConnection(this);
                if (this.Config.ProducingBeacon)
                {
                    this.beaconHandler = new Beaconizer(this.udpConnection, this.Config.BeaconPort);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// The dispose.
        /// </summary>
        public void Dispose()
        {
            if (this.notDisposing)
            {
                this.notDisposing = false;
            }
            else
            {
                return;
            }

            this.BeaconHandler.Dispose();
            this.BeaconHandler = null;

            // close Connections
            this.tcpListener.Stop();
            this.tcpListener = null;

            this.UdpConnFrom.Dispose();
            this.UdpConnTo.Dispose();

            // close Connections will close all channels and monitors related to them
            lock (this.TCPConnections)
            {
                foreach (var pair in this.TCPConnections)
                {
                    pair.Value.Dispose();
                }

                this.TCPConnections.Clear();
            }
        }
예제 #3
0
        /// <summary>
        /// The config_ config changed.
        /// </summary>
        /// <param name="propertyName">
        /// The property name.
        /// </param>
        private void config_ConfigChanged(string propertyName)
        {
            lock (this.lockInit)
            {
                if (!this.isInit)
                {
                    return;
                }

                if (propertyName == "UDPPort")
                {
                    this.beaconHandler.Dispose();
                    this.udpConnection.Dispose();

                    this.udpConnection = null;
                    this.udpConnection = new EpicsServerUDPConnection(this);
                    this.beaconHandler = new Beaconizer(this.udpConnection, this.Config.BeaconPort);
                }
                else if (propertyName == "TCPPort")
                {
                    this.tcpListener.Stop();
                    this.tcpListener = new TcpListener(IPAddress.Any, this.config.TCPPort);
                    this.tcpListener.Start();

                    this.connectionGrabber = new Thread(this.GrabConnection);
                    this.connectionGrabber.IsBackground = true;
                    this.connectionGrabber.Start();
                }
                else if (propertyName == "ProducingBeacon")
                {
                    if (this.Config.ProducingBeacon)
                    {
                        this.beaconHandler = new Beaconizer(this.udpConnection, this.Config.BeaconPort);
                    }
                    else
                    {
                        this.beaconHandler.Dispose();
                    }
                }
            }
        }
예제 #4
0
        /// <summary>
        /// The init.
        /// </summary>
        /// <param name="ipFrom">
        /// The ip from.
        /// </param>
        /// <param name="uDPListen">
        /// The u dp listen.
        /// </param>
        /// <param name="beaconPortFrom">
        /// The beacon port from.
        /// </param>
        /// <param name="tCPListen">
        /// The t cp listen.
        /// </param>
        /// <param name="uDPSend">
        /// The u dp send.
        /// </param>
        /// <param name="ipTo">
        /// The ip to.
        /// </param>
        /// <param name="beaconPortTo">
        /// The beacon port to.
        /// </param>
        /// <param name="targetIpList">
        /// The target ip list.
        /// </param>
        /// <param name="rules">
        /// The rules.
        /// </param>
        private void Init(
            string ipFrom,
            int uDPListen,
            int beaconPortFrom,
            int tCPListen,
            int uDPSend,
            string ipTo,
            int beaconPortTo,
            string targetIpList,
            IRuleSet rules)
        {
            this.Rules = rules;

            this.receiverCodec  = new EpicsGateWayReceiverCodec(this);
            this.connectorCodec = new EpicsGateWayConnectorCodec(this);
            this.Statistic      = new EpicsGateWayStatistics();

            // start listening for connection requests on
            this.tcpListener = new TcpListener(new IPEndPoint(IPAddress.Parse(ipFrom), tCPListen));
            this.tcpListener.Start();

            this.Config.BeaconPortFrom = beaconPortFrom;
            this.Config.BeaconPortTo   = beaconPortTo;
            this.Config.TCPListenPort  = tCPListen;
            this.Config.UDPSendPort    = uDPSend;
            this.Config.UDPListenPort  = uDPListen;

            Trace.Write("I" + string.Format("Starting gateway {0}:{1} to ({2}):{3}.", ipFrom, uDPListen, targetIpList, uDPSend));

            this.Config.ServerList.Clear();
            if (targetIpList.Contains(","))
            {
                var ips = targetIpList.Split(',');
                foreach (var ip in ips)
                {
                    this.Config.ServerList.Add(ip + ":" + uDPSend);
                }
            }
            else
            {
                this.Config.ServerList.Add(targetIpList + ":" + uDPSend);
            }

            // starting a Thread to grab new TCP-Connections and wrap them into a EpicsTCPServerConnection
            this.connectionGrabber = new Thread(this.GrabConnection);
            this.connectionGrabber.IsBackground = true;
            this.connectionGrabber.Start();

            this.ChannelSearcher = new Thread(this.HandleChannelSearch);
            this.ChannelSearcher.IsBackground = true;
            this.ChannelSearcher.Start();

            this.UdpConnFrom = new EpicsUDPGWConnection(
                this, this.receiverCodec, new IPEndPoint(IPAddress.Parse(ipFrom), this.Config.UDPListenPort));
            this.UdpConnTo = new EpicsUDPGWConnection(
                this, this.connectorCodec, new IPEndPoint(IPAddress.Parse(ipTo), this.Config.BeaconPortTo));

            this.BeaconHandler = new Beaconizer(this.UdpConnFrom, this.Config.BeaconPortFrom);
            ThreadPool.QueueUserWorkItem(
                delegate
            {
                Thread.Sleep(5 * 60 * 1000);
                this.Inited = true;
                this.CareBeacons();
            });
        }
예제 #5
0
		/// <summary>
		/// The init.
		/// </summary>
		/// <param name="ipFrom">
		/// The ip from.
		/// </param>
		/// <param name="uDPListen">
		/// The u dp listen.
		/// </param>
		/// <param name="beaconPortFrom">
		/// The beacon port from.
		/// </param>
		/// <param name="tCPListen">
		/// The t cp listen.
		/// </param>
		/// <param name="uDPSend">
		/// The u dp send.
		/// </param>
		/// <param name="ipTo">
		/// The ip to.
		/// </param>
		/// <param name="beaconPortTo">
		/// The beacon port to.
		/// </param>
		/// <param name="targetIpList">
		/// The target ip list.
		/// </param>
		/// <param name="rules">
		/// The rules.
		/// </param>
		private void Init(
			string ipFrom, 
			int uDPListen, 
			int beaconPortFrom, 
			int tCPListen, 
			int uDPSend, 
			string ipTo, 
			int beaconPortTo, 
			string targetIpList, 
			IRuleSet rules)
		{
			this.Rules = rules;

			this.receiverCodec = new EpicsGateWayReceiverCodec(this);
			this.connectorCodec = new EpicsGateWayConnectorCodec(this);
			this.Statistic = new EpicsGateWayStatistics();

			// start listening for connection requests on 
			this.tcpListener = new TcpListener(new IPEndPoint(IPAddress.Parse(ipFrom), tCPListen));
			this.tcpListener.Start();

			this.Config.BeaconPortFrom = beaconPortFrom;
			this.Config.BeaconPortTo = beaconPortTo;
			this.Config.TCPListenPort = tCPListen;
			this.Config.UDPSendPort = uDPSend;
			this.Config.UDPListenPort = uDPListen;

			Trace.Write("I" + string.Format("Starting gateway {0}:{1} to ({2}):{3}.", ipFrom, uDPListen, targetIpList, uDPSend));

			this.Config.ServerList.Clear();
			if (targetIpList.Contains(","))
			{
				var ips = targetIpList.Split(',');
				foreach (var ip in ips)
				{
					this.Config.ServerList.Add(ip + ":" + uDPSend);
				}
			}
			else
			{
				this.Config.ServerList.Add(targetIpList + ":" + uDPSend);
			}

			// starting a Thread to grab new TCP-Connections and wrap them into a EpicsTCPServerConnection
			this.connectionGrabber = new Thread(this.GrabConnection);
			this.connectionGrabber.IsBackground = true;
			this.connectionGrabber.Start();

			this.ChannelSearcher = new Thread(this.HandleChannelSearch);
			this.ChannelSearcher.IsBackground = true;
			this.ChannelSearcher.Start();

			this.UdpConnFrom = new EpicsUDPGWConnection(
				this, this.receiverCodec, new IPEndPoint(IPAddress.Parse(ipFrom), this.Config.UDPListenPort));
			this.UdpConnTo = new EpicsUDPGWConnection(
				this, this.connectorCodec, new IPEndPoint(IPAddress.Parse(ipTo), this.Config.BeaconPortTo));

			this.BeaconHandler = new Beaconizer(this.UdpConnFrom, this.Config.BeaconPortFrom);
			ThreadPool.QueueUserWorkItem(
				delegate
					{
						Thread.Sleep(5 * 60 * 1000);
						this.Inited = true;
						this.CareBeacons();
					});
		}
예제 #6
0
		/// <summary>
		/// The dispose.
		/// </summary>
		public void Dispose()
		{
			if (this.notDisposing)
			{
				this.notDisposing = false;
			}
			else
			{
				return;
			}

			this.BeaconHandler.Dispose();
			this.BeaconHandler = null;

			// close Connections
			this.tcpListener.Stop();
			this.tcpListener = null;

			this.UdpConnFrom.Dispose();
			this.UdpConnTo.Dispose();

			// close Connections will close all channels and monitors related to them
			lock (this.TCPConnections)
			{
				foreach (var pair in this.TCPConnections)
				{
					pair.Value.Dispose();
				}

				this.TCPConnections.Clear();
			}
		}