private bool RemoveStreamListenerIfFinishedProcessing(IResourceFacade resource)
        {
            var listener = _listeners[resource.Id];

            if (listener.IsFixtureEnded || resource.IsMatchOver)
            {
                _logger.DebugFormat("{0} is marked as ended - checking for stopping streaming", resource);

                var currentState = EventState.GetFixtureState(resource.Id);

                if (currentState != null && currentState.MatchStatus != MatchStatus.MatchOver)
                {
                    _logger.DebugFormat("{0} is over but the MatchOver update has not been processed yet", resource);
                    return(false);
                }

                _logger.InfoFormat("{0} is over. Listener will be removed", resource);

                if (RemoveStreamListener(resource.Id))
                {
                    EventState.RemoveFixture(resource.Id);
                }
                else
                {
                    _logger.WarnFormat("Couldn't remove listener for matchOver fixture {0}", resource);
                }

                return(true);
            }

            return(false);
        }
        public bool ShouldProcessResource(IResourceFacade resource)
        {
            if (HasStreamListener(resource.Id))
            {
                _logger.DebugFormat("Listener already exists for {0}", resource);

                IListener listener = _listeners[resource.Id];

                var shouldAdapterProcessResource = false;

                if (listener.IsFixtureDeleted)
                {
                    _logger.DebugFormat("{0} was deleted and republished. Listener wil be removed", resource);
                    RemoveStreamListener(resource.Id);
                }
                else if (listener.IsIgnored)
                {
                    _logger.DebugFormat("{0} is marked as ignored. Listener wil be removed", resource);
                    RemoveStreamListener(resource.Id);
                }
                //Disconnected from the stream - this fixture should be reconnected ASAP
                else if (listener.IsDisconnected && (resource.MatchStatus == MatchStatus.Prematch || resource.MatchStatus == MatchStatus.InRunning))
                {
                    _logger.WarnFormat("{0} was disconnected from stream {1}", resource, resource.MatchStatus);
                    RemoveStreamListener(resource.Id);

                    shouldAdapterProcessResource = true;
                }
                else
                {
                    if (!RemoveStreamListenerIfFinishedProcessing(resource))
                    {
                        _listeners[resource.Id].UpdateResourceState(resource);
                    }
                }
                return(shouldAdapterProcessResource);
            }
            else
            {
                // Check fixture is not yet over, ignore if over
                var fixtureState = EventState.GetFixtureState(resource.Id);
                if (resource.IsMatchOver && (fixtureState == null || fixtureState.MatchStatus == resource.MatchStatus))
                {
                    _logger.InfoFormat("{0} is over. Adapter will not process the resource", resource);
                    return(false);
                }

                if (_createListener.ContainsKey(resource.Id))
                {
                    _logger.DebugFormat("Listener for {0} is not created yet. It is creating right now.", resource);
                    return(false);
                }

                _logger.DebugFormat("Listener for {0} is not created yet. Adapter will add resource to the creation queue", resource);
                //the resource will added to the queue
                return(true);
            }
        }
        private void CleanUpFixtureData(string fixtureId)
        {
            var fixtureState = EventState.GetFixtureState(fixtureId);

            FixtureOverview tempObj = null;

            _fixtures.TryRemove(fixtureId, out tempObj);

            if (fixtureState != null && fixtureState.MatchStatus == MatchStatus.MatchOver)
            {
                SaveState();
            }
        }