Пример #1
0
    private void Start()
    {
        DataPublisher publisher = GetComponent <DataPublisher>();

        m_temperaturePort = new DataPublisher.DataPort("Temperature");
        publisher.SetPort(m_temperaturePort);
    }
Пример #2
0
    private void Update()
    {
        if (IsActive && m_mouseEventReady)
        {
            Vector2       mousePos  = TileUtils.NormalizedMousePosition();
            GameObject    obj       = TileManagerScript.TileManager.GetGameObject(mousePos);
            DataPublisher publisher = obj?.GetComponent <DataPublisher>();

            if (m_state == State.WirePlacing)
            {
                DrawLine(mousePos);

                if (m_mouseEventReady && Input.GetMouseButtonUp(MouseUtils.PRIMARY_MOUSE_BUTTON) && publisher != null && m_publisherFrom != publisher)
                {
                    m_state             = State.SelectPortTo;
                    m_selectedPortIndex = -1;
                    ShowPortList(mousePos, publisher.PortList);
                }
            }
            else if (m_state == State.Idle)
            {
                if (Input.GetMouseButtonUp(MouseUtils.PRIMARY_MOUSE_BUTTON) && publisher != null)
                {
                    m_fromPosition  = mousePos;
                    m_state         = State.SelectPortFrom;
                    m_publisherFrom = publisher;
                    ShowPortList(mousePos, publisher.PortList);
                }
            }
        }

        m_mouseEventReady = true;
    }
Пример #3
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="UnsynchronizedClientSubscription"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        // Remove reference to parent
                        m_parent = null;

                        // Dispose base time rotation timer
                        if ((object)m_baseTimeRotationTimer != null)
                        {
                            m_baseTimeRotationTimer.Dispose();
                            m_baseTimeRotationTimer = null;
                        }

                        if ((object)m_workingBuffer != null)
                        {
                            m_workingBuffer.Dispose();
                        }

                        // Dispose Iaon session
                        this.DisposeTemporalSession(ref m_iaonSession);
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
Пример #4
0
    private void Start()
    {
        DataPublisher publisher = GetComponent <DataPublisher>();

        m_presencePort = new DataPublisher.DataPort("IsDetected");
        publisher.SetPort(m_presencePort);
    }
Пример #5
0
        public BAMPublisherInterceptor()
        {
            RestApiConf restApiConf = new RestApiConf();
            set_conf(restApiConf);
            dataPublisher = new DataPublisher(restApiConf);
            string streamDef =
                "{" +
                    "'name':'BAM_WCF_MESSAGE_TRACE'," +
                    "'version':'1.0.0'," +
                    "'nickName':'MessageTracerAgent'," +
                    "'correlationData':[" +
                        "{" +
                            "'name':'activity_id'," +
                            "'type':'STRING'" +
                        "}"+
                    "]," +
                    "'payloadData':[" +
                        "{" +
                            "'name':'message'," +
                            "'type':'STRING'" +
                        "}" +
                    "]" +
                "}";

            dataPublisher.defineStream(streamDef);
        }
Пример #6
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="ClientConnection"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_pingTimer != null)
                        {
                            m_pingTimer.Elapsed -= m_pingTimer_Elapsed;
                            m_pingTimer.Dispose();
                            m_pingTimer = null;
                        }

                        if ((object)m_reconnectTimer != null)
                        {
                            m_reconnectTimer.Elapsed -= m_reconnectTimer_Elapsed;
                            m_reconnectTimer.Dispose();
                            m_reconnectTimer = null;
                        }

                        DataChannel      = null;
                        m_commandChannel = null;
                        m_ipAddress      = null;
                        m_subscription   = null;
                        m_parent         = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
Пример #7
0
    // IMover end

    private void Start()
    {
        m_tileComponent = GetComponent <TileObject>();
        m_direction     = m_tileComponent.Direction;

        m_consumerComponent = GetComponent <EnergyConsumer>();

        m_animator = GetComponent <Animator>();
        if (m_animator != null)
        {
            m_animator.enabled = false;
            m_animationEnabled = false;
        }
        else
        {
            Debug.LogError("Animator is not found for conveyer.");
        }

        DataPublisher publisher = GetComponent <DataPublisher>();

        if (publisher == null)
        {
            Debug.LogWarning("There is no publisher attached to conveyer object!");
            return;
        }

        m_directionPort = new DataPublisher.DataPort("IsReversed");
        m_speedPort     = new DataPublisher.DataPort("Speed");

        publisher.SetPort(m_directionPort);
        publisher.SetPort(m_speedPort);
    }
Пример #8
0
        /// <summary>
        /// Creates a new <see cref="SubscriberConnection"/> instance.
        /// </summary>
        /// <param name="parent">Parent data publisher.</param>
        /// <param name="clientID">Client ID of associated connection.</param>
        /// <param name="serverCommandChannel"><see cref="TcpServer"/> command channel used to lookup connection information.</param>
        /// <param name="clientCommandChannel"><see cref="TcpClient"/> command channel used to lookup connection information.</param>
        public SubscriberConnection(DataPublisher parent, Guid clientID, IServer serverCommandChannel, IClient clientCommandChannel)
        {
            m_parent               = parent;
            ClientID               = clientID;
            ServerCommandChannel   = serverCommandChannel;
            ClientCommandChannel   = clientCommandChannel;
            m_subscriberID         = clientID;
            m_keyIVs               = null;
            m_cipherIndex          = 0;
            CacheUpdateLock        = new();
            PendingCacheUpdateLock = new();

            // Setup ping timer
            m_pingTimer           = Common.TimerScheduler.CreateTimer(5000);
            m_pingTimer.AutoReset = true;
            m_pingTimer.Elapsed  += PingTimer_Elapsed;
            m_pingTimer.Start();

            // Setup reconnect timer
            m_reconnectTimer           = Common.TimerScheduler.CreateTimer(1000);
            m_reconnectTimer.AutoReset = false;
            m_reconnectTimer.Elapsed  += ReconnectTimer_Elapsed;

            LookupEndPointInfo(clientID, GetCommandChannelSocket().RemoteEndPoint as IPEndPoint, ref m_ipAddress, ref m_hostName, ref m_connectionID);
        }
Пример #9
0
        private static double GetPublisherStatistic_ProcessedMeasurements(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = s_statisticValueCache.GetDifference(publisher, publisher.ProcessedMeasurements, "ProcessedMeasurements");
            }

            return(statistic);
        }
Пример #10
0
        private static double GetPublisherStatistic_ConnectedClientCount(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = publisher.Count;
            }

            return(statistic);
        }
Пример #11
0
    public void OnDataPublisher(MessageArgument <T> arguments)
    {
        // Old way
        //var handler = DataPublisher;
        //if (handler != null)
        //{
        //    handler(this, arguments);
        //}

        // C# 6 way
        DataPublisher?.Invoke(this, arguments);
    }
Пример #12
0
        private static double GetPublisherStatistic_UpTime(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = publisher.RunTime;
            }

            return(statistic);
        }
Пример #13
0
        private static double GetPublisherStatistic_LifetimeBytesSent(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = publisher.TotalBytesSent;
            }

            return(statistic);
        }
Пример #14
0
        /// <summary>
        /// Handles the confirmation message received from the
        /// subscriber to indicate that a buffer block was received.
        /// </summary>
        /// <param name="sequenceNumber">The sequence number of the buffer block.</param>
        /// <returns>A list of buffer block sequence numbers for blocks that need to be retransmitted.</returns>
        public void ConfirmBufferBlock(uint sequenceNumber)
        {
            DataPublisher parent = m_parent;
            int           sequenceIndex;
            int           removalCount;

            // We are still receiving confirmations,
            // so stop the retransmission timer
            m_bufferBlockRetransmissionTimer.Stop();

            lock (m_bufferBlockCacheLock)
            {
                // Find the buffer block's location in the cache
                sequenceIndex = (int)(sequenceNumber - m_expectedBufferBlockConfirmationNumber);

                if (sequenceIndex >= 0 && sequenceIndex < m_bufferBlockCache.Count && (object)m_bufferBlockCache[sequenceIndex] != null)
                {
                    // Remove the confirmed block from the cache
                    m_bufferBlockCache[sequenceIndex] = null;

                    if (sequenceNumber == m_expectedBufferBlockConfirmationNumber)
                    {
                        // Get the number of elements to trim from the start of the cache
                        removalCount = m_bufferBlockCache.TakeWhile(m => (object)m == null).Count();

                        // Trim the cache
                        m_bufferBlockCache.RemoveRange(0, removalCount);

                        // Increase the expected confirmation number
                        m_expectedBufferBlockConfirmationNumber += (uint)removalCount;
                    }
                    else
                    {
                        // Retransmit if confirmations are received out of order
                        for (int i = 0; i < sequenceIndex; i++)
                        {
                            if ((object)m_bufferBlockCache[i] != null)
                            {
                                parent?.SendClientResponse(m_clientID, ServerResponse.BufferBlock, ServerCommand.Subscribe, m_bufferBlockCache[i]);
                                OnBufferBlockRetransmission();
                            }
                        }
                    }
                }

                // If there are any objects lingering in the
                // cache, start the retransmission timer
                if (m_bufferBlockCache.Count > 0)
                {
                    m_bufferBlockRetransmissionTimer.Start();
                }
            }
        }
Пример #15
0
        private static double GetPublisherStatistic_LifetimeAverageLatency(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = publisher.LifetimeAverageLatency;
            }

            return(statistic);
        }
Пример #16
0
        private static double GetPublisherStatistic_AverageMeasurementsPerSecond(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = publisher.AverageMeasurementsPerSecond;
            }

            return(statistic);
        }
Пример #17
0
        private static double GetPublisherStatistic_BufferBlockRetransmissions(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = s_statisticValueCache.GetDifference(publisher, publisher.BufferBlockRetransmissions, "BufferBlockRetransmissions");
            }

            return(statistic);
        }
Пример #18
0
    private void Start()
    {
        m_logger = new LogUtils.DebugLogger("Press");

        m_state    = PressState.Up;
        m_consumer = GetComponent <EnergyConsumer>();
        m_animator = GetComponent <Animator>();

        DataPublisher publisher = GetComponent <DataPublisher>();

        m_pressPort = new DataPublisher.DataPort("IsPressed");
        publisher.SetPort(m_pressPort);
    }
Пример #19
0
        /// <summary>
        /// Creates a new <see cref="SynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        public SynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID)
        {
            // Pass parent reference into base class
            AssignParentCollection(parent);

            m_parent           = parent;
            m_clientID         = clientID;
            m_subscriberID     = subscriberID;
            m_signalIndexCache = new SignalIndexCache()
            {
                SubscriberID = subscriberID
            };
        }
Пример #20
0
        /// <summary>
        /// Creates a new <see cref="SynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        public SynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID)
        {
            // Pass parent reference into base class
            AssignParentCollection(parent);

            m_parent = parent;
            m_clientID = clientID;
            m_subscriberID = subscriberID;
            m_signalIndexCache = new SignalIndexCache()
            {
                SubscriberID = subscriberID
            };
        }
Пример #21
0
        /// <summary>
        /// Creates a new <see cref="UnsynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        public UnsynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID)
        {
            m_parent       = parent;
            m_clientID     = clientID;
            m_subscriberID = subscriberID;

            m_signalIndexCache = new SignalIndexCache();
            m_signalIndexCache.SubscriberID = subscriberID;

            m_workingBuffer        = new BlockAllocatedMemoryStream();
            m_bufferBlockCache     = new List <byte[]>();
            m_bufferBlockCacheLock = new object();
        }
Пример #22
0
        /// <summary>
        /// Creates a new <see cref="SynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        /// <param name="compressionModes"><see cref="CompressionModes"/> requested by client.</param>
        public SynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID, CompressionModes compressionModes)
        {
            m_parent           = parent;
            m_clientID         = clientID;
            m_subscriberID     = subscriberID;
            m_compressionModes = compressionModes;

            m_signalIndexCache = new SignalIndexCache();
            m_signalIndexCache.SubscriberID = subscriberID;

            m_bufferBlockCache     = new List <byte[]>();
            m_bufferBlockCacheLock = new object();
        }
Пример #23
0
        public DataPublisherTests(ITestOutputHelper output)
            : base(output)
        {
            // Fixture Setup
            var container = TestComponentryContainer.Create(output);

            this.barSerializer        = new BarSerializer();
            this.instrumentSerializer = new InstrumentSerializer();

            this.publisher = new DataPublisher(
                container,
                DataBusFactory.Create(container),
                this.instrumentSerializer,
                new BypassCompressor(),
                EncryptionSettings.None(),
                new Port(55511));
        }
Пример #24
0
        private static double GetPublisherStatistic_TotalBytesSent(object source, string arguments)
        {
            double        statistic = 0.0D;
            DataPublisher publisher = source as DataPublisher;

            if ((object)publisher != null)
            {
                statistic = s_statisticValueCache.GetDifference(publisher, publisher.TotalBytesSent, "TotalBytesSent");

                if (statistic < 0.0D)
                {
                    statistic = publisher.TotalBytesSent;
                }
            }

            return(statistic);
        }
Пример #25
0
        public void RaiseDataProcessingExceptionOccurred()
        {
            var    exception = new Exception();
            string message   = Guid.NewGuid().ToString();
            EventHandler <ExceptionEventArgs> handler = null;

            handler = (s, e) =>
            {
                DataPublisher.DataProcessingExceptionOccurred -= handler;
                Assert.AreSame(exception, e.Exception);
                Assert.AreEqual(message, e.Message);
                eventRaised = true;
            };
            DataPublisher.DataProcessingExceptionOccurred += handler;
            DataPublisher.RaiseDataProcessExceptionOccurred(this, exception, message);
            EnqueueConditional(() => eventRaised);
            EnqueueTestComplete();
        }
Пример #26
0
        /// <summary>
        /// Creates a new <see cref="SubscriberAdapter"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        /// <param name="compressionModes"><see cref="CompressionModes"/> requested by client.</param>
        public SubscriberAdapter(DataPublisher parent, Guid clientID, Guid subscriberID, CompressionModes compressionModes)
        {
            m_parent               = parent;
            ClientID               = clientID;
            SubscriberID           = subscriberID;
            m_compressionModes     = compressionModes;
            m_bufferBlockCache     = new();
            m_bufferBlockCacheLock = new();
            m_tsscSyncLock         = new();
            m_parent.ClientConnections.TryGetValue(ClientID, out m_connection);

            if (m_connection is null)
            {
                throw new NullReferenceException("Subscriber adapter failed to find associated connection");
            }

            m_connection.SignalIndexCache = new() { SubscriberID = subscriberID };
        }
Пример #27
0
        /// <summary>
        /// Creates a new <see cref="UnsynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        public UnsynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID)
        {
            // Pass parent reference into base class
            AssignParentCollection(parent);

            m_parent       = parent;
            m_clientID     = clientID;
            m_subscriberID = subscriberID;

            m_signalIndexCache = new SignalIndexCache()
            {
                SubscriberID = subscriberID
            };

            m_processQueue = new AsyncQueue <IEnumerable <IMeasurement> >()
            {
                ProcessItemFunction = ProcessMeasurements
            };

            m_processQueue.ProcessException += m_processQueue_ProcessException;
        }
Пример #28
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="SynchronizedClientSubscription"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        // Remove reference to parent
                        m_parent = null;

                        // Dispose Iaon session
                        this.DisposeTemporalSession(ref m_iaonSession);
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
Пример #29
0
        /// <summary>
        /// Creates a new <see cref="ClientConnection"/> instance.
        /// </summary>
        /// <param name="parent">Parent data publisher.</param>
        /// <param name="clientID">Client ID of associated connection.</param>
        /// <param name="commandChannel"><see cref="TcpServer"/> command channel used to lookup connection information.</param>
        public ClientConnection(DataPublisher parent, Guid clientID, TcpServer commandChannel)
        {
            m_parent = parent;
            m_clientID = clientID;
            m_commandChannel = commandChannel;
            m_subscriberID = clientID;
            m_keyIVs = null;
            m_cipherIndex = 0;

            // Setup ping timer
            m_pingTimer = new System.Timers.Timer();
            m_pingTimer.Interval = 5000.0D;
            m_pingTimer.AutoReset = true;
            m_pingTimer.Elapsed += m_pingTimer_Elapsed;
            m_pingTimer.Start();

            // Setup reconnect timer
            m_reconnectTimer = new System.Timers.Timer();
            m_reconnectTimer.Interval = 1000.0D;
            m_reconnectTimer.AutoReset = false;
            m_reconnectTimer.Elapsed += m_reconnectTimer_Elapsed;

            // Attempt to lookup remote connection identification for logging purposes
            try
            {
                TransportProvider<Socket> client;
                IPEndPoint remoteEndPoint = null;

                if ((object)commandChannel != null && commandChannel.TryGetClient(clientID, out client))
                    remoteEndPoint = client.Provider.RemoteEndPoint as IPEndPoint;

                if ((object)remoteEndPoint != null)
                {
                    m_ipAddress = remoteEndPoint.Address;

                    if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6)
                        m_connectionID = "[" + m_ipAddress + "]:" + remoteEndPoint.Port;
                    else
                        m_connectionID = m_ipAddress + ":" + remoteEndPoint.Port;

                    try
                    {
                        IPHostEntry ipHost = Dns.GetHostEntry(remoteEndPoint.Address);

                        if (!string.IsNullOrWhiteSpace(ipHost.HostName))
                        {
                            m_hostName = ipHost.HostName;
                            m_connectionID = m_hostName + " (" + m_connectionID + ")";
                        }
                    }
                    catch
                    {
                        // Just ignoring possible DNS lookup failures...
                    }
                }
            }
            catch
            {
                // At worst we'll just use the client GUID for identification
                m_connectionID = (m_subscriberID == Guid.Empty ? clientID.ToString() : m_subscriberID.ToString());
            }

            if (string.IsNullOrWhiteSpace(m_connectionID))
                m_connectionID = "unavailable";

            if (string.IsNullOrWhiteSpace(m_hostName))
            {
                if (m_ipAddress != null)
                    m_hostName = m_ipAddress.ToString();
                else
                    m_hostName = m_connectionID;
            }

            if (m_ipAddress == null)
                m_ipAddress = System.Net.IPAddress.None;
        }
Пример #30
0
 private void OnDataPublisher(string args)
 {
     DataPublisher?.Invoke(this, args);
 }
Пример #31
0
        /// <summary>
        /// Creates a new <see cref="ClientConnection"/> instance.
        /// </summary>
        /// <param name="parent">Parent data publisher.</param>
        /// <param name="clientID">Client ID of associated connection.</param>
        /// <param name="commandChannel"><see cref="TcpServer"/> command channel used to lookup connection information.</param>
        public ClientConnection(DataPublisher parent, Guid clientID, IServer commandChannel)
        {
            m_parent = parent;
            m_clientID = clientID;
            m_commandChannel = commandChannel;
            m_subscriberID = clientID;
            m_keyIVs = null;
            m_cipherIndex = 0;

            // Setup ping timer
            m_pingTimer = new Timer();
            m_pingTimer.Interval = 5000.0D;
            m_pingTimer.AutoReset = true;
            m_pingTimer.Elapsed += m_pingTimer_Elapsed;
            m_pingTimer.Start();

            // Setup reconnect timer
            m_reconnectTimer = new Timer();
            m_reconnectTimer.Interval = 1000.0D;
            m_reconnectTimer.AutoReset = false;
            m_reconnectTimer.Elapsed += m_reconnectTimer_Elapsed;

            // Attempt to lookup remote connection identification for logging purposes
            try
            {
                Socket commandChannelSocket = GetCommandChannelSocket();
                IPEndPoint remoteEndPoint = null;

                if ((object)commandChannel != null)
                    remoteEndPoint = commandChannelSocket.RemoteEndPoint as IPEndPoint;

                if ((object)remoteEndPoint != null)
                {
                    m_ipAddress = remoteEndPoint.Address;

                    if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6)
                        m_connectionID = "[" + m_ipAddress + "]:" + remoteEndPoint.Port;
                    else
                        m_connectionID = m_ipAddress + ":" + remoteEndPoint.Port;

                    try
                    {
                        IPHostEntry ipHost = Dns.GetHostEntry(remoteEndPoint.Address);

                        if (!string.IsNullOrWhiteSpace(ipHost.HostName))
                        {
                            m_hostName = ipHost.HostName;
                            m_connectionID = m_hostName + " (" + m_connectionID + ")";
                        }
                    }

                    // Just ignoring possible DNS lookup failures...
                    catch (ArgumentNullException)
                    {
                        // The hostNameOrAddress parameter is null. 
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        // The length of hostNameOrAddress parameter is greater than 255 characters. 
                    }
                    catch (ArgumentException)
                    {
                        // The hostNameOrAddress parameter is an invalid IP address. 
                    }
                    catch (SocketException)
                    {
                        // An error was encountered when resolving the hostNameOrAddress parameter.    
                    }
                }
            }
            catch
            {
                // At worst we'll just use the client GUID for identification
                m_connectionID = (m_subscriberID == Guid.Empty ? clientID.ToString() : m_subscriberID.ToString());
            }

            if (string.IsNullOrWhiteSpace(m_connectionID))
                m_connectionID = "unavailable";

            if (string.IsNullOrWhiteSpace(m_hostName))
            {
                if ((object)m_ipAddress != null)
                    m_hostName = m_ipAddress.ToString();
                else
                    m_hostName = m_connectionID;
            }

            if ((object)m_ipAddress == null)
                m_ipAddress = IPAddress.None;
        }
Пример #32
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="ClientConnection"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        if ((object)m_pingTimer != null)
                        {
                            m_pingTimer.Elapsed -= m_pingTimer_Elapsed;
                            m_pingTimer.Dispose();
                            m_pingTimer = null;
                        }

                        if ((object)m_reconnectTimer != null)
                        {
                            m_reconnectTimer.Elapsed -= m_reconnectTimer_Elapsed;
                            m_reconnectTimer.Dispose();
                            m_reconnectTimer = null;
                        }

                        DataChannel = null;
                        m_commandChannel = null;
                        m_ipAddress = null;
                        m_subscription = null;
                        m_parent = null;
                    }
                }
                finally
                {
                    m_disposed = true;  // Prevent duplicate dispose.
                }
            }
        }
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="UnsynchronizedClientSubscription"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        m_parent = null;

                        // Dispose base time rotation timer
                        if ((object)m_baseTimeRotationTimer != null)
                        {
                            m_baseTimeRotationTimer.Dispose();
                            m_baseTimeRotationTimer = null;
                        }

                        // Dispose Iaon session
                        this.DisposeTemporalSession(ref m_iaonSession);
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
Пример #34
0
        /// <summary>
        /// Releases the unmanaged resources used by the <see cref="SynchronizedClientSubscription"/> object and optionally releases the managed resources.
        /// </summary>
        /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
        protected override void Dispose(bool disposing)
        {
            if (!m_disposed)
            {
                try
                {
                    if (disposing)
                    {
                        // Remove reference to parent
                        m_parent = null;

                        // Dispose Iaon session
                        this.DisposeTemporalSession(ref m_iaonSession);
                    }
                }
                finally
                {
                    m_disposed = true;          // Prevent duplicate dispose.
                    base.Dispose(disposing);    // Call base class Dispose().
                }
            }
        }
Пример #35
0
        /// <summary>
        /// Creates a new <see cref="SynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        /// <param name="compressionModes"><see cref="CompressionModes"/> requested by client.</param>
        public SynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID, CompressionModes compressionModes)
        {
            m_parent = parent;
            m_clientID = clientID;
            m_subscriberID = subscriberID;
            m_compressionModes = compressionModes;

            m_signalIndexCache = new SignalIndexCache();
            m_signalIndexCache.SubscriberID = subscriberID;

            m_bufferBlockCache = new List<byte[]>();
            m_bufferBlockCacheLock = new object();
        }
Пример #36
0
        /// <summary>
        /// Creates a new <see cref="UnsynchronizedClientSubscription"/>.
        /// </summary>
        /// <param name="parent">Reference to parent.</param>
        /// <param name="clientID"><see cref="Guid"/> based client connection ID.</param>
        /// <param name="subscriberID"><see cref="Guid"/> based subscriber ID.</param>
        public UnsynchronizedClientSubscription(DataPublisher parent, Guid clientID, Guid subscriberID)
        {
            // Pass parent reference into base class
            AssignParentCollection(parent);

            m_parent = parent;
            m_clientID = clientID;
            m_subscriberID = subscriberID;

            m_signalIndexCache = new SignalIndexCache()
            {
                SubscriberID = subscriberID
            };

            m_processQueue = new AsyncQueue<IEnumerable<IMeasurement>>()
            {
                ProcessItemFunction = ProcessMeasurements
            };

            m_processQueue.ProcessException += m_processQueue_ProcessException;
        }
Пример #37
0
        /// <summary>
        /// Creates a new <see cref="ClientConnection"/> instance.
        /// </summary>
        /// <param name="parent">Parent data publisher.</param>
        /// <param name="clientID">Client ID of associated connection.</param>
        /// <param name="commandChannel"><see cref="TcpServer"/> command channel used to lookup connection information.</param>
        public ClientConnection(DataPublisher parent, Guid clientID, IServer commandChannel)
        {
            m_parent         = parent;
            m_clientID       = clientID;
            m_commandChannel = commandChannel;
            m_subscriberID   = clientID;
            m_keyIVs         = null;
            m_cipherIndex    = 0;

            // Setup ping timer
            m_pingTimer           = Common.TimerScheduler.CreateTimer(5000);
            m_pingTimer.AutoReset = true;
            m_pingTimer.Elapsed  += m_pingTimer_Elapsed;
            m_pingTimer.Start();

            // Setup reconnect timer
            m_reconnectTimer           = Common.TimerScheduler.CreateTimer(1000);
            m_reconnectTimer.AutoReset = false;
            m_reconnectTimer.Elapsed  += m_reconnectTimer_Elapsed;

            // Attempt to lookup remote connection identification for logging purposes
            try
            {
                Socket     commandChannelSocket = GetCommandChannelSocket();
                IPEndPoint remoteEndPoint       = null;

                if ((object)commandChannel != null)
                {
                    remoteEndPoint = commandChannelSocket.RemoteEndPoint as IPEndPoint;
                }

                if ((object)remoteEndPoint != null)
                {
                    m_ipAddress = remoteEndPoint.Address;

                    if (remoteEndPoint.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        m_connectionID = "[" + m_ipAddress + "]:" + remoteEndPoint.Port;
                    }
                    else
                    {
                        m_connectionID = m_ipAddress + ":" + remoteEndPoint.Port;
                    }

                    try
                    {
                        IPHostEntry ipHost = Dns.GetHostEntry(remoteEndPoint.Address);

                        if (!string.IsNullOrWhiteSpace(ipHost.HostName))
                        {
                            m_hostName     = ipHost.HostName;
                            m_connectionID = m_hostName + " (" + m_connectionID + ")";
                        }
                    }

                    // Just ignoring possible DNS lookup failures...
                    catch (ArgumentNullException)
                    {
                        // The hostNameOrAddress parameter is null.
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        // The length of hostNameOrAddress parameter is greater than 255 characters.
                    }
                    catch (ArgumentException)
                    {
                        // The hostNameOrAddress parameter is an invalid IP address.
                    }
                    catch (SocketException)
                    {
                        // An error was encountered when resolving the hostNameOrAddress parameter.
                    }
                }
            }
            catch
            {
                // At worst we'll just use the client GUID for identification
                m_connectionID = m_subscriberID == Guid.Empty ? clientID.ToString() : m_subscriberID.ToString();
            }

            if (string.IsNullOrWhiteSpace(m_connectionID))
            {
                m_connectionID = "unavailable";
            }

            if (string.IsNullOrWhiteSpace(m_hostName))
            {
                if ((object)m_ipAddress != null)
                {
                    m_hostName = m_ipAddress.ToString();
                }
                else
                {
                    m_hostName = m_connectionID;
                }
            }

            if ((object)m_ipAddress == null)
            {
                m_ipAddress = IPAddress.None;
            }
        }
Пример #38
0
 /// <summary>
 /// Handles publish data, if the handler is not null
 /// </summary>
 /// <param name="args"></param>
 private void OnDataPublisher(MessageArgument <T> args)
 {
     DataPublisher?.Invoke(this, args);
 }