RulesManager for WinForms
ルールのロードと保存

Rules Manager supports loading and saving rules to an XML file. It allows you to load rules definition using LoadRules method of the C1RulesManager class. The LoadRules method provides three overloads to load rules definition from an XML file, XMLReader or a stream. Similarly, RulesManager lets you save the rules definition using SaveRules method of the C1RulesManager class. The SaveRules method provides three overloads which can be used to save rules definition to an XML file, XMLWriter or a stream.

The following example demonstrates the use of the LoadRules to load the rules definition from an XML file and the SaveRules methods to save the rules definition in an XML file when any rule is changed in the Rules Manager. This example uses the same data source which is configured in Quick Start.

C#
コードのコピー
private const string xmlFileName = "LoadRules.xml";
private string pathToXmlFile = null;
private void ApplyRules()
{
    pathToXmlFile = Path.Combine(Directory.GetCurrentDirectory(), xmlFileName);

    if (!File.Exists(pathToXmlFile))
    {
        ApplyPredefinedRules();
    }
    else
    {
        // XMLファイルからルール定義をロードします
        rulesManager.LoadRules(pathToXmlFile);
    }
}
private void RulesManager_RulesChanged(object sender, ListChangedEventArgs e)
{
    // ルール定義をXMLファイルに保存します
    rulesManager.SaveRules(pathToXmlFile);
}