private bool ShouldSuspendOnDisconnection()
        {
            var state = _eventState.GetFixtureState(this.FixtureId);

            if (state == null || !_fixtureStartTime.HasValue)
            {
                return(true);
            }

            var spanBetweenNowAndStartTime = _fixtureStartTime.Value - DateTime.UtcNow;
            var doNotSuspend = _settings.DisablePrematchSuspensionOnDisconnection && spanBetweenNowAndStartTime.TotalMinutes > _settings.PreMatchSuspensionBeforeStartTimeInMins;

            return(!doNotSuspend);
        }
        public StreamListener(IResourceFacade resource, IAdapterPlugin platformConnector, IEventState eventState, IStateManager stateManager, ISettings settings)
        {
            if (resource == null)
            {
                throw new ArgumentException("Resource information cannot be null");
            }

            if (resource.Content == null)
            {
                throw new Exception("Resource does not contain any content");
            }


            _logger.DebugFormat("Instantiating listener for {0} with sequence={1}", resource, resource.Content.Sequence);

            _lockTimeout       = settings.ProcessingLockTimeOutInSecs;
            _resource          = resource;
            _platformConnector = platformConnector;
            _eventState        = eventState;
            _stateManager      = stateManager;
            _settings          = settings;

            _currentSequence = resource.Content.Sequence;
            _lastSequenceProcessedInSnapshot = -1;

            _hasRecoveredFromError     = true;
            _isFirstSnapshotProcessed  = false;
            _isProcessingFirstSnapshot = false;
            _performingDelayedStop     = false;

            _marketsRuleManager = stateManager.CreateNewMarketRuleManager(resource.Id);

            FixtureId = resource.Id;
            Sport     = resource.Sport;
            SequenceOnStreamingAvailable = _currentSequence;

            IsStreaming  = false;
            IsConnecting = false;
            IsDisposing  = false;
            IsErrored    = false;
            IsIgnored    = false;
            IsStopping   = false;

            var fixtureState = _eventState.GetFixtureState(resource.Id);

            IsFixtureEnded   = fixtureState != null ? fixtureState.MatchStatus == MatchStatus.MatchOver : _resource.IsMatchOver;
            IsFixtureSetup   = (_resource.MatchStatus == MatchStatus.Setup || _resource.MatchStatus == MatchStatus.Ready);
            IsFixtureDeleted = false;
            IsInPlay         = fixtureState != null ? fixtureState.MatchStatus == MatchStatus.InRunning : _resource.MatchStatus == MatchStatus.InRunning;
            _currentEpoch    = fixtureState != null ? fixtureState.Epoch : -1;

            _Stats = StatsManager.Instance[string.Concat("adapter.core.sport.", resource.Sport)].GetHandle();

            SetupListener();
            _logger.DebugFormat("Listener instantiated for {0}", resource);
        }
        public StreamListener(IResourceFacade resource, IAdapterPlugin platformConnector, IEventState eventState, IStateManager stateManager,ISettings settings)
        {
            if (resource == null)
                throw new ArgumentException("Resource information cannot be null");

            if (resource.Content == null)
                throw new Exception("Resource does not contain any content");


            _logger.DebugFormat("Instantiating listener for {0} with sequence={1}", resource, resource.Content.Sequence);

            _lockTimeout = settings.ProcessingLockTimeOutInSecs;
            _resource = resource;
            _platformConnector = platformConnector;
            _eventState = eventState;
            _stateManager = stateManager;
            _settings = settings;

            _currentSequence = resource.Content.Sequence;
            _lastSequenceProcessedInSnapshot = -1;
            
            _hasRecoveredFromError = true;
            _isFirstSnapshotProcessed = false;
            _isProcessingFirstSnapshot = false;
            _performingDelayedStop = false;

            _marketsRuleManager = stateManager.CreateNewMarketRuleManager(resource.Id);

            FixtureId = resource.Id;
            Sport = resource.Sport;
            SequenceOnStreamingAvailable = _currentSequence;

            IsStreaming = false;
            IsConnecting = false;
            IsDisposing = false;
            IsErrored = false;
            IsIgnored = false;
            IsStopping = false;

            var fixtureState = _eventState.GetFixtureState(resource.Id);

            IsFixtureEnded = fixtureState != null ? fixtureState.MatchStatus == MatchStatus.MatchOver : _resource.IsMatchOver;
            IsFixtureSetup = (_resource.MatchStatus == MatchStatus.Setup || _resource.MatchStatus == MatchStatus.Ready);
            IsFixtureDeleted = false;
            IsInPlay = fixtureState != null ? fixtureState.MatchStatus == MatchStatus.InRunning : _resource.MatchStatus == MatchStatus.InRunning;
            _currentEpoch = fixtureState != null ? fixtureState.Epoch : -1;
            
            _Stats = StatsManager.Instance[string.Concat("adapter.core.sport.", resource.Sport)].GetHandle();

            SetupListener();
            _logger.DebugFormat("Listener instantiated for {0}", resource);

        }