Exemplo n.º 1
0
        /// <summary>
        /// Callback fired by the tvcontroller when EPG data has been received
        /// The method checks if epg grabbing was in progress and ifso creates a new workerthread
        /// to update the database with the new epg data
        /// </summary>
        public override int OnEpgReceived()
        {
            try
            {
                //is epg grabbing in progress?

                /*if (_state == EpgState.Idle)
                 * {
                 * Log.Epg("Epg: card:{0} OnEpgReceived while idle", _user.CardId);
                 * return 0;
                 * }*/
                //is epg grabber already updating the database?

                if (_state == EpgState.Updating)
                {
                    Log.Epg("Epg: card:{0} OnEpgReceived while updating", _user.CardId);
                    return(0);
                }

                //is the card still idle?
                if (IsCardIdle(_user) == false)
                {
                    Log.Epg("Epg: card:{0} OnEpgReceived but card is not idle", _user.CardId);
                    _state = EpgState.Idle;
                    _tvController.StopGrabbingEpg(_user);
                    _user.CardId = -1;
                    _currentTransponder.InUse = false;
                    return(0);
                }

                List <EpgChannel> epg = _tvController.Epg(_user.CardId) ?? new List <EpgChannel>();
                //did we receive epg info?
                if (epg.Count == 0)
                {
                    //no epg found for this transponder
                    Log.Epg("Epg: card:{0} no epg found", _user.CardId);
                    _currentTransponder.InUse = false;
                    _currentTransponder.OnTimeOut();

                    _state = EpgState.Idle;
                    _tvController.StopGrabbingEpg(_user);
                    _tvController.PauseCard(_user);
                    _user.CardId = -1;
                    _currentTransponder.InUse = false;
                    return(0);
                }

                //create worker thread to update the database
                Log.Epg("Epg: card:{0} received epg for {1} channels", _user.CardId, epg.Count);
                _state = EpgState.Updating;
                _epg   = epg;
                Thread workerThread = new Thread(UpdateDatabaseThread);
                workerThread.IsBackground = true;
                workerThread.Name         = "EPG Update thread";
                workerThread.Start();
            }
            catch (Exception ex)
            {
                Log.Write(ex);
            }
            return(0);
        }