Nun habe ich schon gezeigt wie man ein Seitenfilter Schema aktiv schalten kann… Und hier seht ihr wie man einzelnen Filtereinstellungen hinzufügen kann.
In diesem Beispiel wird der Filter neu erstellt und eine Filtereinstellung hinzugefügt:

  • Kriterium: Seitenbeschreibung
  • Wert: Test
public class PageFilterExample
{
  private const string SCHEME_NAME = "MyFilter";
  private const string SETTINGS_PATH = "USER.PageBrowserGui.PageFilterScheme";

  [DeclareAction("PageFilterExample")]
  public void Action()
  {
    try
    {
      // Remove filter if exists
      SchemeSetting schemeSetting = new SchemeSetting();
      schemeSetting.Init(SETTINGS_PATH);
      if (schemeSetting.CheckIfSchemeExists(SCHEME_NAME))
      {
        schemeSetting.RemoveScheme(SCHEME_NAME);
      }

      // Create filter
      MultiLangString mlName = new MultiLangString();
      mlName.AddString(ISOCode.Language.L___, SCHEME_NAME);

      MultiLangString mlDescription = new MultiLangString();
      mlDescription.AddString(ISOCode.Language.L___, "My Description");
      schemeSetting.CreateScheme(SCHEME_NAME, mlName, mlDescription);

      SetSchemeSettings();

      // Update page filter
      schemeSetting.SetLastUsed(SCHEME_NAME);
      new Settings().SetBoolSetting("USER.PageBrowserGui.PageFilterScheme.ApplyCheckBox", true, 0);
      EventParameterString eventParameterString = new EventParameterString();
      eventParameterString.String = "RefreshPageFilter";
      new EventManager().Send("RefreshPageFilter", eventParameterString);
    }
    catch (Exception exception)
    {
      var baseException = new BaseException("PageFilterExample: " + exception, MessageLevel.Error);
      baseException.FixMessage();
      new Decider().Decide(EnumDecisionType.eOkDecision, exception.ToString(), "SetPageFilter",
        EnumDecisionReturn.eOK, EnumDecisionReturn.eOK, null, false, EnumDecisionIcon.eFATALERROR);
    }
  }

  private void SetSchemeSettings(int index = 0)
  {
    // Setup path: < is in the default schemes also, don't know why
    const string SETTINGS_PATH_SCHEME_SETTINGS = SETTINGS_PATH + "." + SCHEME_NAME + ".Data<.";

    // Set single (needed) settings
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "Value", "Test", index); // Search value
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "PropDescr", "11011;0", index); // page property id & index
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "Activ", true, index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "CriteriaType", 0, index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "IgnoreCase", false, index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "Negation", false, index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "Operator", 0, index);      
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "QuickFilter", false, index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "RelationDescr", "0;0", index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "SingleValue", false, index);
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "UseWildcards", true, index);      
    SetSchemeSetting(SETTINGS_PATH_SCHEME_SETTINGS + "WholeText", true, index);
  }

  public void SetSchemeSetting(string settingsPath, object value, int index = 0)
  {
    // Add settings nodes (needed because SchemeSetting.Set don't create Settings) & Set filter entries
    var settings = new Settings();
    if (value is bool)
    {
      settings.AddBoolSetting(settingsPath, new[] { (bool)value }, ISettings.CreationFlag.Insert);
      settings.SetBoolSetting(settingsPath, (bool)value, index);

    }
    else if (value is int)
    {
      var range = new[] { new Range { FromValue = 0, ToValue = 32768 } };
      settings.AddNumericSetting(settingsPath, new[] { (int)value }, range, ISettings.CreationFlag.Insert);
      settings.SetNumericSetting(settingsPath, (int)value, 0);

    }
    else if (value is string)
    {
      settings.AddStringSetting(settingsPath, new string[] { }, new string[] { }, ISettings.CreationFlag.Insert);
      settings.SetStringSetting(settingsPath, value.ToString(), 0);
    }
    else if (value is MultiLangString)
    {
      settings.AddMultiLangStringDefault(settingsPath, new MultiLangString[] { }, new MultiLangString[] { }, ISettings.CreationFlag.Insert);
      settings.SetMultiLangStringSetting(settingsPath, (MultiLangString) value, 0);
    }
    else
    {
      throw new NotImplementedException("SetSchemeSetting: Unknow type --> " + value.GetType());
    }
  }

}