Ejemplo n.º 1
0
 private void StartStreamingMsgHandler(StartStreamingMsg msg)
 {
     if (!_isStreamConnected)
     {
         //StartStreaming will trigger Resource_StreamConnected
         _resource.StartStreaming();
     }
 }
        private void ConnectToStreamServer()
        {
            int sequence = -1;

            // even if each property used within this block is thread-safe
            // we need to use a lock block because we want to do a check-set operation
            lock (this)
            {
                if (IsFixtureEnded)
                {
                    _logger.WarnFormat("Listener will not start for {0} as the resource is marked as ended", _resource);
                    return;
                }

                // do not start streaming twice
                if (IsStreaming || IsConnecting)
                {
                    _logger.DebugFormat("Listener will not start for {0} as it is already streaming/connecting", _resource);
                    return;
                }

                IsErrored    = false;
                IsStreaming  = false;
                IsStopping   = false;
                IsDisposing  = false;
                IsConnecting = true;
                sequence     = SequenceOnStreamingAvailable;
            }

            try
            {
                // The current UDAPI SDK, before consuming events from the queue raises
                // a "connected" event. We are sure that no updates are pushed
                // before our "connected" event handler terminates because
                // updates are pushed using the same thread the SDK uses to
                // push updates.
                //
                // If the SDK's threading model changes, this
                // class must be revisited

                _logger.DebugFormat("Starting streaming for {0} - resource has sequence={1}", _resource, sequence);
                _resource.StartStreaming();
            }
            catch (Exception ex)
            {
                IsConnecting = false;
                IsStreaming  = false;
                IsErrored    = true;

                _logger.Error(string.Format("Error connecting to stream server for {0}", _resource), ex);
                RaiseEvent(OnError);
            }
        }