Exemplo n.º 1
0
    public void NewWithLong()
    {
      WorldDateTime wdt = new WorldDateTime("20070323044500 +0200", false);

      Assert.IsTrue(wdt.Year == 2007);
      Assert.IsTrue(wdt.Month == 3);
      Assert.IsTrue(wdt.Day == 23);
      Assert.IsTrue(wdt.Hour == 4);
      Assert.IsTrue(wdt.Minute == 45);


      wdt = new WorldDateTime("20070323044500 +0200", true);

      Assert.IsTrue(wdt.Year == 2007);
      Assert.IsTrue(wdt.Month == 3);
      Assert.IsTrue(wdt.Day == 23);
      Assert.IsTrue(wdt.Hour == 6);
      Assert.IsTrue(wdt.Minute == 45);

      wdt = new WorldDateTime("20070323044500", false);

      Assert.IsTrue(wdt.Year == 2007);
      Assert.IsTrue(wdt.Month == 3);
      Assert.IsTrue(wdt.Day == 23);
      Assert.IsTrue(wdt.Hour == 4);
      Assert.IsTrue(wdt.Minute == 45);

      wdt = new WorldDateTime("20070323044500", true);

      Assert.IsTrue(wdt.Year == 2007);
      Assert.IsTrue(wdt.Month == 3);
      Assert.IsTrue(wdt.Day == 23);
      Assert.IsTrue(wdt.Hour == 4);
      Assert.IsTrue(wdt.Minute == 45);
    }
Exemplo n.º 2
0
 public RequestBuilder(HTTPRequest baseRequest, WorldDateTime startTime, RequestData data)
 {
   _baseRequest = baseRequest;
   _requestTime = startTime;
   _data = data;
   _dayOffset = 0;
   _offset = 0;
 }
Exemplo n.º 3
0
    public void ToLocalTime()
    {
      WorldDateTime wdt = new WorldDateTime(DateTime.Now);

      DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 8:00:00 AM");

      Assert.IsTrue(wdt.DaysSince(dtEpochStartTime) == wdt.ToEpochDate());
      Assert.IsTrue(wdt.SecondsSince(dtEpochStartTime) == wdt.ToEpochTime());
    }
Exemplo n.º 4
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than obj. Zero This instance is equal to obj. Greater than zero This instance is greater than obj.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">obj is not the same type as this instance. </exception>
        public int CompareTo(object obj)
        {
            WorldDateTime compareObj = (WorldDateTime)obj;

            return(DateTime.CompareTo(compareObj.DateTime));
        }
Exemplo n.º 5
0
 public void SetElement(string tag, string element)
 {
   try
   {
     switch (tag)
     {
       case "#STARTXMLTV":
         _startTime = new WorldDateTime(element, false);
         break;
       case "#ENDXMLTV":
         _endTime = new WorldDateTime(element, false);
         break;
       case "#START":
         BasicTime startTime = GetTime(element);
         if (_startTime == null)
         {
           _startTime = new WorldDateTime();
         }
         _startTime.Hour = startTime.Hour;
         _startTime.Minute = startTime.Minute;
         break;
       case "#END":
         BasicTime endTime = GetTime(element);
         if (_endTime == null)
         {
           _endTime = new WorldDateTime();
         }
         _endTime.Hour = endTime.Hour;
         _endTime.Minute = endTime.Minute;
         break;
       case "#DATE":
         GetDate(element);
         break;
       case "#DAY":
         if (_startTime == null)
         {
           _startTime = new WorldDateTime();
         }
         _startTime.Day = int.Parse(element);
         break;
       case "#DESCRIPTION":
         if (_description == string.Empty)
         {
           _description = element.Trim(' ', '\n', '\t');
         }
         else
         {
           _description = _description + "\n" + element.Trim(' ', '\n', '\t');
         }
         break;
       case "#MONTH":
         if (_startTime == null)
         {
           _startTime = new WorldDateTime();
         }
         _startTime.Month = GetMonth(element.Trim(' ', '\n', '\t'));
         break;
       case "#TITLE":
         Title = element.Trim(' ', '\n', '\t');
         break;
       case "#SUBTITLE":
         SubTitle = element.Trim(' ', '\n', '\t');
         break;
       case "#GENRE":
         Genre = element.Trim(' ', '\n', '\t');
         break;
       case "#ACTORS":
         _actors = GetActors(element);
         break;
       case "#EPISODE":
         _episode = GetNumber(element);
         break;
       case "#SEASON":
         _season = GetNumber(element);
         break;
       case "#REPEAT":
         if (element.ToLower().IndexOf("false") == -1)
         {
           _repeat = true;
         }
         break;
       case "#SUBTITLES":
         if (element.ToLower().IndexOf("false") == -1)
         {
           _subtitles = true;
         }
         break;
       default:
         break;
     }
   }
   catch (Exception)
   {
     Log.Error("Parsing error {0} : {1}", tag, element);
   }
 }
Exemplo n.º 6
0
    private void GetDate(string element)
    {
      if (_startTime == null)
      {
        _startTime = new WorldDateTime();
      }

      int pos = 0;
      if ((pos = element.IndexOf("/")) != -1)
      {
        _startTime.Day = Int32.Parse(element.Substring(0, pos));
      }

      int start = pos + 1;
      if ((pos = element.IndexOf("/", start)) != -1)
      {
        _startTime.Month = Int32.Parse(element.Substring(start, pos - start));
      }
    }
Exemplo n.º 7
0
 public void InitFromProgram(Program dbProgram)
 {
   _startTime = new WorldDateTime(dbProgram.StartTime);
   _endTime = new WorldDateTime(dbProgram.EndTime);
   _title = dbProgram.Title;
   _description = dbProgram.Description;
   _genre = dbProgram.Genre;
   _subTitle = dbProgram.EpisodeName;
   int.TryParse(dbProgram.EpisodeNum, out _episode);
   int.TryParse(dbProgram.SeriesNum, out _season);
 }
Exemplo n.º 8
0
 public void AddDays(int days)
 {
   _dayOffset += days;
   _requestTime = _requestTime.AddDays(days);
 }
Exemplo n.º 9
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;
    }