Exemplo n.º 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));
    }
Exemplo n.º 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));
    }
Exemplo n.º 3
0
    /// \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;
    }