RuleTemplate.cs :  » Development » devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Development » devAdvantage 
devAdvantage » AnticipatingMinds » Genesis » KnowledgeManagement » RuleTemplate.cs
using System;
using System.Diagnostics;
using System.Collections;
using System.Xml;
using System.Windows.Forms;
using System.ComponentModel;
using AnticipatingMinds.CommonUIControls;

namespace AnticipatingMinds.Genesis.KnowledgeManagement{
  /// <summary>
  /// Represents a base class for rule templates.
  /// </summary>
  /// <remarks>
  /// RuleTemplate defines an interface and a set of basic functionality for rule template.
  /// Rule template can be viewed as rule factory. It is instantiated dynamicly and than is requested
  /// to create rules by providing rule properties. If the same template creates more than one type of rules
  /// template can add that specifies rule type to the rule properties and than read it durring rule 
  /// instantiation.
  /// </remarks>
  public abstract class RuleTemplate
  {
    /// <summary>
    /// Defines string keys for property names in IDictionary
    /// </summary>
    public class PropertyName
    {
      public const string Name = "Name";
      public const string Description = "Description";
      public const string HelpUrl = "HelpUrl";
    }

    /// <summary>
    /// Represents a handler for event raised when one of the template properties has changed.
    /// </summary>
    public event PropertyChangedEventHandler PropertyChanged;

    /// <summary>
    /// Instantiates a new instance of the <see cref="RuleTemplate"/> class.
    /// </summary>
    /// <param name="templateId">Template id</param>
    /// <param name="templateProperties">Template properties.</param>
    protected RuleTemplate(string templateId, IDictionary templateProperties)
    {
      this.templateId = templateId;
      properties = new Hashtable(templateProperties);
    }

    
    /// <summary>
    /// Gets template id.
    /// </summary>
    public string Id
    {
      get
      {
        return templateId;
      }
    }

    /// <summary>
    /// Gets template name.
    /// </summary>
    /// <remarks>
    /// Template name is read from properties dictionary. Property name is 'Name'
    /// </remarks>
    public virtual string Name
    {
      get
      {
        return GetProperty(PropertyName.Name) as String;
      }
    }
    
    /// <summary>
    /// Gets template description.
    /// </summary>
    /// <remarks>
    /// Template description is read from properties dictionary. Property name is 'Description'
    /// </remarks>
    public virtual string Description
    {
      get
      {
        return GetProperty(PropertyName.Description) as String;
      }
    }

    /// <summary>
    /// Gets or sets template hel url.
    /// </summary>
    /// <remarks>
    /// Template help url is read from properties dictionary. Property name is 'HelpUrl'
    /// </remarks>
    public virtual string HelpUrl
    {
      get
      {
        return GetProperty(PropertyName.HelpUrl) as String;
      }
      set
      {
        SetProperty(PropertyName.HelpUrl,value == null ? String.Empty:value);
      }
    }

    /// <summary>
    /// Sets property value.
    /// </summary>
    /// <param name="propertyName">Property name.</param>
    /// <param name="value">Property value.</param>
    protected void SetProperty(string propertyName, object value)
    {
      if(properties.Contains(propertyName))
        if(properties[propertyName].Equals(value))
          return;

      properties[propertyName] = value;
      OnPropertyChanged(propertyName);
    }

    /// <summary>
    /// Gets property value.
    /// </summary>
    /// <param name="propertyName">Property name.</param>
    /// <returns>Property value if property is found, null otherwise.</returns>
    protected object GetProperty(string propertyName)
    {
      if(properties.Contains(propertyName))
        return properties[propertyName];
      else
        return null;
    }


    /// <summary>
    /// create a rule with property values as found in ruleProperties.
    /// </summary>
    /// <param name="ruleId">An id of new rule.</param>
    /// <param name="ruleProperties">Properties of the rule to create.</param>
    /// <returns>Returns an instance of the created rule.</returns>
    public abstract Rule CreateRule(string ruleId, IDictionary ruleProperties);
    
    /// <summary>
    /// Return current state of passed rule as rule XML.
    /// </summary>
    /// <param name="rule"></param>
    /// <returns>Return an xml elemtn that contains all of the rule properties including name and id</returns>
    public virtual IDictionary GetRuleProperties(Rule rule)
    {
      return rule.GetProperties();
    }

    /// <summary>
    /// Sets rule properties from properties dictionary.
    /// </summary>
    /// <param name="rule">Rule whose properties shall be set.</param>
    /// <param name="ruleProperties">New set of rule properties.</param>
    public virtual void SetRuleProperties(Rule rule,IDictionary ruleProperties)
    {
      rule.SetProperties(ruleProperties);
    }
    
    /// <summary>
    /// Get appropriate rule property pages pre-populated from rule properties
    /// </summary>
    /// <param name="ruleProperties"></param>
    /// <returns></returns>
    public virtual PropertyPage[] GetRulePropertiesUI(IDictionary ruleProperties)
    {
      return noPropertyPages;
    }

    
    /// <summary>
    /// Get Current state of template, returned as xml
    /// </summary>
    /// <returns></returns>
    public virtual IDictionary GetTemplateProperties()
    {
      return properties;
    }
    
    
    /// <summary>
    /// Set current state of template from xml.  This method is called as soon
    /// as the template is instantiated (as templates are loaded from Knowledge Base).
    /// </summary>
    /// <param name="templateProperties"></param>
    public virtual void  SetTemplateProperties(IDictionary templateProperties)
    {
      foreach(string key in templateProperties.Keys)
        SetProperty(key,templateProperties[key]);
    }
    
    /// <summary>
    /// Gets a UI for changing template properties.
    /// </summary>
    /// <returns>Returns an array of pages to display.</returns>
    public virtual PropertyPage[] GetTemplatePropertiesUI()
    {
      return noPropertyPages;
    }

    /// <summary>
    /// This function raises <see cref="PropertyChanged"/> event.
    /// </summary>
    /// <param name="propertyName">Name of the changed property.</param>
    /// <remarks>Do not call this function directly, use 
    /// <see cref="SetProperty"/> function to set property value and raise this event.
    /// </remarks>
    protected virtual void OnPropertyChanged(string propertyName)
    {
      if(PropertyChanged != null)
        PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
    }

    private Hashtable properties;
    private string templateId;
    private static PropertyPage[] noPropertyPages = new PropertyPage[0];
  }

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.