Esempio n. 1
0
        /// <summary>
        /// Gets the guide for a given channel.
        /// </summary>
        /// <param name="strChannelID">The channel ID.</param>
        /// <param name="Linked">if set to <c>true</c> get [linked] pages.</param>
        /// <param name="linkStart">The start time to get link pages.</param>
        /// <param name="linkEnd">The end time to get linked pages.</param>
        /// <param name="startDateTime">The start date time for grabbing.</param>
        /// <returns>list of programs</returns>
        public List <ProgramData> GetGuide(string strChannelID, string displayName, bool Linked, TimeRange linkTime,
                                           DateTime startDateTime)
        {
            _strID         = strChannelID;
            _grabLinked    = Linked;
            _linkTimeRange = linkTime;
            //int offset = 0;

            _reqData.ChannelId = _grabber.GetChannel(strChannelID);
            if (_reqData.ChannelId == null)
            {
                Log.Error("WebEPG: ChannelId: {0} not found!", strChannelID);
                return(null);
            }

            //_removeProgramsList = _grabber.GetRemoveProgramList(strChannelID); // <--- !!!

            _programs = new List <ProgramData>();

            Log.Info("WebEPG: ChannelId: {0}", strChannelID);

            //_GrabDay = 0;

            // sets a minimum delay for the programlist Site page grabbing
            // why? likely not needed. to be tested.
            // possible reason: 'relaxing' webservers
            if (_grabber.Listing.Request.Delay < 500)
            {
                _grabber.Listing.Request.Delay = 500;
            }
            WorldDateTime reqStartTime = new WorldDateTime(_siteTimeZone.FromLocalTime(startDateTime), _siteTimeZone);

            _reqBuilder = new RequestBuilder(_grabber.Listing.Request, reqStartTime, _reqData);
            _grabStart  = startDateTime;

            Log.Debug("WebEPG: Grab Start {0} {1}", startDateTime.ToShortTimeString(),
                      startDateTime.ToShortDateString());
            int requestedStartDay = startDateTime.Subtract(DateTime.Now).Days;

            if (requestedStartDay > 0)
            {
                if (requestedStartDay > _grabber.Info.GrabDays)
                {
                    Log.Error("WebEPG: Trying to grab past guide days");
                    return(null);
                }

                if (requestedStartDay + _maxGrabDays > _grabber.Info.GrabDays)
                {
                    _maxGrabDays = _grabber.Info.GrabDays - requestedStartDay;
                    Log.Info("WebEPG: Grab days more than Guide days, limiting to {0}", _maxGrabDays);
                }

                //_GrabDay = requestedStartDay;
                _reqBuilder.DayOffset = requestedStartDay;
                if (_reqBuilder.DayOffset > _maxGrabDays)                //_GrabDay > _maxGrabDays)
                {
                    _maxGrabDays = _reqBuilder.DayOffset + _maxGrabDays; // _GrabDay + _maxGrabDays;
                }
            }

            //TVDatabase.BeginTransaction();
            //TVDatabase.ClearCache();
            //TVDatabase.RemoveOldPrograms();

            _dbPrograms = new List <Program>();
            _dbLastProg = 0;

            try
            {
                Key             epgMapKey   = new Key(false, "displayName", displayName);
                IList <Channel> epgChannels = Broker.RetrieveList <Channel>(epgMapKey);
                if (epgChannels.Count > 0)
                {
                    _dbPrograms = epgChannels[0].ReferringProgram();
                }
            }
            catch (Exception)
            {
                Log.Error("WebEPG: Database failed, disabling db lookup");
                _dblookup = false;
            }

            _timeControl = new ListingTimeControl(_siteTimeZone.FromLocalTime(startDateTime));
            while (_reqBuilder.DayOffset < _maxGrabDays)
            {
                _reqBuilder.Offset = 0;

                bool error;
                while (GetListing(out error))
                {
                    //if (_grabber.Listing.SearchParameters.MaxListingCount == 0)
                    //  break;
                    _reqBuilder.Offset++;
                }

                if (error)
                {
                    if (!_grabber.Info.TreatErrorAsWarning)
                    {
                        Log.Error("WebEPG: ChannelId: {0} grabber error - stopping", strChannelID);
                        break;
                    }
                    Log.Info("WebEPG: ChannelId: {0} grabber error - continuing", strChannelID);
                }

                //_GrabDay++;
                if (_reqBuilder.HasDate()) // < here
                {
                    _reqBuilder.AddDays(1);
                    _timeControl.NewDay();
                }
                else
                {
                    //if (_reqBuilder.HasList()) // < here
                    break;
                    //_reqBuilder.AddDays(_timeControl.GrabDay);
                }
            }

            return(_programs);
        }
Esempio n. 2
0
    /// <summary>
    /// Gets the guide for a given channel.
    /// </summary>
    /// <param name="strChannelID">The channel ID.</param>
    /// <param name="Linked">if set to <c>true</c> get [linked] pages.</param>
    /// <param name="linkStart">The start time to get link pages.</param>
    /// <param name="linkEnd">The end time to get linked pages.</param>
    /// <param name="startDateTime">The start date time for grabbing.</param>
    /// <returns>list of programs</returns>
    public List<ProgramData> GetGuide(string strChannelID, string displayName, bool Linked, TimeRange linkTime,
                                      DateTime startDateTime)
    {
      _strID = strChannelID;
      _grabLinked = Linked;
      _linkTimeRange = linkTime;
      //int offset = 0;

      _reqData.ChannelId = _grabber.GetChannel(strChannelID);
      if (_reqData.ChannelId == null)
      {
        Log.Error("WebEPG: ChannelId: {0} not found!", strChannelID);
        return null;
      }

      //_removeProgramsList = _grabber.GetRemoveProgramList(strChannelID); // <--- !!!

      _programs = new List<ProgramData>();

      Log.Info("WebEPG: ChannelId: {0}", strChannelID);

      //_GrabDay = 0;

      // sets a minimum delay for the programlist Site page grabbing
      // why? likely not needed. to be tested.
      // possible reason: 'relaxing' webservers
      if (_grabber.Listing.Request.Delay < 500)
      {
        _grabber.Listing.Request.Delay = 500;
      }
      WorldDateTime reqStartTime = new WorldDateTime(_siteTimeZone.FromLocalTime(startDateTime), _siteTimeZone);
      _reqBuilder = new RequestBuilder(_grabber.Listing.Request, reqStartTime, _reqData);
      _grabStart = startDateTime;

      Log.Debug("WebEPG: Grab Start {0} {1}", startDateTime.ToShortTimeString(),
                startDateTime.ToShortDateString());
      int requestedStartDay = startDateTime.Subtract(DateTime.Now).Days;
      if (requestedStartDay > 0)
      {
        if (requestedStartDay > _grabber.Info.GrabDays)
        {
          Log.Error("WebEPG: Trying to grab past guide days");
          return null;
        }

        if (requestedStartDay + _maxGrabDays > _grabber.Info.GrabDays)
        {
          _maxGrabDays = _grabber.Info.GrabDays - requestedStartDay;
          Log.Info("WebEPG: Grab days more than Guide days, limiting to {0}", _maxGrabDays);
        }

        //_GrabDay = requestedStartDay;
        _reqBuilder.DayOffset = requestedStartDay;
        if (_reqBuilder.DayOffset > _maxGrabDays) //_GrabDay > _maxGrabDays)
        {
          _maxGrabDays = _reqBuilder.DayOffset + _maxGrabDays; // _GrabDay + _maxGrabDays;
        }
      }

      //TVDatabase.BeginTransaction();
      //TVDatabase.ClearCache();
      //TVDatabase.RemoveOldPrograms();

      _dbPrograms = new List<Program>();
      _dbLastProg = 0;

      try
      {
        Key epgMapKey = new Key(false, "displayName", displayName);
        IList<Channel> epgChannels = Broker.RetrieveList<Channel>(epgMapKey);
        if (epgChannels.Count > 0)
        {
          _dbPrograms = epgChannels[0].ReferringProgram();
        }
      }
      catch (Exception)
      {
        Log.Error("WebEPG: Database failed, disabling db lookup");
        _dblookup = false;
      }

      _timeControl = new ListingTimeControl(_siteTimeZone.FromLocalTime(startDateTime));
      while (_reqBuilder.DayOffset < _maxGrabDays)
      {
        _reqBuilder.Offset = 0;

        bool error;
        while (GetListing(out error))
        {
          //if (_grabber.Listing.SearchParameters.MaxListingCount == 0)
          //  break;
          _reqBuilder.Offset++;
        }

        if (error)
        {
          if (!_grabber.Info.TreatErrorAsWarning)
          {
            Log.Error("WebEPG: ChannelId: {0} grabber error - stopping", strChannelID);
            break;
          }
          Log.Info("WebEPG: ChannelId: {0} grabber error - continuing", strChannelID);
        }

        //_GrabDay++;
        if (_reqBuilder.HasDate()) // < here
        {
          _reqBuilder.AddDays(1);
          _timeControl.NewDay();
        }
        else
        {
          //if (_reqBuilder.HasList()) // < here
          break;
          //_reqBuilder.AddDays(_timeControl.GrabDay);
        }
      }

      return _programs;
    }