Example #1
0
    public void InRangeOverMidnight()
    {
      TimeRange rt = new TimeRange("23:00", "06:00");

      DateTime dt = new DateTime(2009, 3, 5, 23, 30, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 0, 10, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 3, 0, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 5, 59, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));
    }
Example #2
0
    public void InRange()
    {
      TimeRange rt = new TimeRange("06:00", "18:00");

      DateTime dt = new DateTime(2009, 3, 5, 6, 0, 0, 0);
      Assert.IsFalse(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 6, 1, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 12, 0, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 18, 0, 0, 0);
      Assert.IsFalse(rt.IsInRange(dt));

      dt = new DateTime(2009, 3, 5, 17, 59, 0, 0);
      Assert.IsTrue(rt.IsInRange(dt));
    }
    /// \brief Examines the multi information sent and returns true or false accordingly.
    private static bool GetMultiInfoBool(GUIInfo info, int dwContextWindow)
    {
      bool bReturn = false;
      if (IsCachedMultiInfoBoolResult(info, out bReturn))
      {
        return bReturn;
      }

      int condition = Math.Abs(info.m_info);
      switch (condition)
      {
        case SKIN_BOOL:
          bReturn = SkinSettings.GetSkinBool(info.m_data1);
          break;
        case STRING_EQUALS:
        case STRING_STARTS:
        case STRING_CONTAINS:
        case SKIN_STRING:
          if (info.m_data2 != 0)
          {
            string prop1 = "";
            string prop1Name = GetMultiBoolInfoProperty(info.m_data1);
            if (string.IsNullOrEmpty(prop1Name))
            {
              prop1Name = SkinSettings.GetSkinName(info.m_data1);
              prop1 = SkinSettings.GetSkinString(info.m_data1);
            }
            else
            {
              prop1 = GUIPropertyManager.GetProperty(prop1Name);
            }

            string prop2 = m_stringParameters[info.m_data2];
            string value1 = GUIPropertyManager.Parse(prop1).Trim().ToLowerInvariant();
            string value2 = GUIPropertyManager.Parse(prop2).Trim().ToLowerInvariant();

            if ((condition == STRING_EQUALS) || (condition == SKIN_STRING))
            {
              bReturn = (value1 == value2);
            }
            else if (condition == STRING_STARTS)
            {
              bReturn = value1.StartsWith(value2);
            }
            else
            {
              bReturn = value1.Contains(value2);
            }

            bReturn = (info.m_info < 0) ? !bReturn : bReturn;
            AddMultiBoolInfoProperty(info, prop1Name);
            AddMultiBoolInfoProperty(info, prop2);

            // Do not cache the result for skin settings.  The results change based on user interactions.
            if (condition != SKIN_STRING)
            {
              AddMultiInfoBoolResult(info, bReturn);
            }
          }
          else
          {
            string skinProperty = "";
            string skinPropertyName = GetMultiBoolInfoProperty(info.m_data1);
            if (string.IsNullOrEmpty(skinPropertyName))
            {
              skinPropertyName = SkinSettings.GetSkinName(info.m_data1);
              skinProperty = SkinSettings.GetSkinString(info.m_data1);
            }
            else
            {
              skinProperty = GUIPropertyManager.GetProperty(skinPropertyName);
            }

            bReturn = (GUIPropertyManager.Parse(skinProperty).Length != 0);
            bReturn = (info.m_info < 0) ? !bReturn : bReturn;
            AddMultiBoolInfoProperty(info, skinPropertyName);
            AddMultiInfoBoolResult(info, bReturn);
          }
          return bReturn;
        case SKIN_THEME:
          if (info.m_data2 != 0)
          {
            string prop1 = GUIThemeManager.CurrentTheme;
            string prop2 = m_stringParameters[info.m_data2];

            string value1 = GUIPropertyManager.Parse(prop1).Trim().ToLowerInvariant();
            string value2 = GUIPropertyManager.Parse(prop2).Trim().ToLowerInvariant();

            bReturn = (value1 == value2);
          }
          break;
        case CONTROL_GROUP_HAS_FOCUS:
          //  GUIWindow win = GUIWindowManager.GetWindow(dwContextWindow);
          //  if (win == null) win = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);
          //  if (win != null)
          //    bReturn = win.ControlGroupHasFocus(info.m_data1, info.m_data2);
          bReturn = false;

          break;
        case PLUGIN_IS_ENABLED:
          bReturn = PluginManager.IsPluginNameEnabled2(info.m_stringData);
          break;
        case CONTROL_HAS_TEXT:
          GUIWindow pWindow = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);
          if (pWindow != null)
          {
            // Note: This'll only work for unique id's
            GUILabelControl control = pWindow.GetControl(info.m_data1) as GUILabelControl;
            if (control != null)
            {
              bReturn = (control.TextWidth > 0);
            }
            else
            {
              GUIFadeLabel control2 = pWindow.GetControl(info.m_data1) as GUIFadeLabel;
              if (control2 != null)
              {
                bReturn = control2.HasText;
              }
              else
              {
                GUITextControl control3 = pWindow.GetControl(info.m_data1) as GUITextControl;
                if (control3 != null)
                {
                  bReturn = control3.HasText;
                }
                else
                {
                  GUITextScrollUpControl control4 = pWindow.GetControl(info.m_data1) as GUITextScrollUpControl;
                  if (control4 != null)
                  {
                    // SE - does not work
                    //bReturn = control4.SubItemCount > 0;
                    bReturn = control4.HasText;
                  }
                }
              }
            }
          }
          break;
        case CONTROL_HAS_THUMB:
          GUIWindow tWindow = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);
          if (tWindow != null)
          {
            // Note: This'll only work for unique id's
            GUIImage control = tWindow.GetControl(info.m_data1) as GUIImage;
            if (control != null)
            {
              bReturn = (control.TextureHeight > 0 && control.TextureWidth > 0);
            }
          }
          break;
        case CONTROL_IS_VISIBLE:
          GUIWindow vWindow = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);
          if (vWindow != null)
          {
            // Note: This'll only work for unique id's
            GUIControl control = vWindow.GetControl(info.m_data1);
            if (control != null)
            {
              bReturn = control.Visible;
            }
          }
          break;
        case CONTROL_HAS_FOCUS:
          GUIWindow fWindow = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);
          if (fWindow != null)
          {
            bReturn = (fWindow.GetFocusControlId() == info.m_data1);
          }
          break;
        case BUTTON_SCROLLER_HAS_ICON:
          /*
          GUIWindow pWindow = GUIWindowManager.GetWindow(dwContextWindow);
          if (null==pWindow) pWindow = GUIWindowManager.GetWindow(GUIWindowManager.ActiveWindow);
          if (pWindow!=null)
          {
            GUIControl *pControl = (GUIControl *)pWindow.GetControl(pWindow.GetFocusedControl());
            if (pControl && pControl.GetControlType() == GUIControl::GUIControl_BUTTONBAR)
              bReturn = ((CGUIButtonScroller *)pControl).GetActiveButtonID() == info.m_data1;
          }
           */
          return false;
        case SYSTEM_DATE_IS_BETWEEN:
          {
            if (IsTimeForRefresh())
            {
              string startDate = SkinSettings.GetSkinString(info.m_data1);
              string endDate = SkinSettings.GetSkinString(info.m_data2);
              var dateRange = new DateRange(startDate, endDate);
              bReturn = dateRange.IsInRange(DateTime.Now);
              LastReturnValues[info] = bReturn;
              break;
            }
            LastReturnValues.TryGetValue(info, out bReturn);
            break;
          }
        case SYSTEM_TIME_IS_BETWEEN:
          {
            if (IsTimeForRefresh())
            {
              string startDate = SkinSettings.GetSkinString(info.m_data1);
              string endDate = SkinSettings.GetSkinString(info.m_data2);
              var timeRange = new TimeRange(startDate, endDate);
              bReturn = timeRange.IsInRange(DateTime.Now);
              LastReturnValues[info] = bReturn;
              break;
            }
            LastReturnValues.TryGetValue(info, out bReturn);
            break;
          }
        case WINDOW_NEXT:
          bReturn = (info.m_data1 == m_nextWindowID);
          break;
        case WINDOW_PREVIOUS:
          bReturn = (info.m_data1 == m_prevWindowID);
          break;
        case WINDOW_IS_VISIBLE:
          bReturn = GUIWindowManager.ActiveWindow == (info.m_data1);
          break;
        case WINDOW_IS_TOPMOST:
          bReturn = GUIWindowManager.ActiveWindow == (info.m_data1);
          break;
        case SYSTEM_HAS_ALARM:
          bReturn = false; //g_alarmClock.hasAlarm(m_stringParameters[info.m_data1]);
          break;
      }
      return (info.m_info < 0) ? !bReturn : bReturn;
    }
 void IEpgDataSink.SetTimeWindow(TimeRange window)
 {
   _timeWindow = window;
 }
    bool IEpgDataSink.StartChannelPrograms(string id, string name)
    {
      string channelKey = name + "-" + id;

      _timeWindow = null;

      if (_channels.TryGetValue(channelKey, out _currentChannels))
      {
        _channelPrograms = new ProgramList();
        _channelPrograms.AlreadySorted = false;
        return true;
      }
      else
      {
        _currentChannels = null;
        Log.Info("WebEPG: Unknown channel (display name = {0}, channel id = {1}) - skipping...", name, id);
        return false;
      }
    }
    /// <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;
    }
 /// <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>
 /// <returns>list of programs</returns>
 public List<ProgramData> GetGuide(string strChannelID, string displayName, bool Linked, TimeRange linkTime)
 {
   // Grab with start time Now
   return GetGuide(strChannelID, displayName, Linked, linkTime, DateTime.Now);
 }