//------------------------------------------------------------- // // Copyright © Microsoft Corporation. All Rights Reserved. // //------------------------------------------------------------- // @owner=alexgor, deliant //================================================================= // File: FormulaRegistry.cs // // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting.Formulas // // Classes: FormulaRegistry // // Purpose: Keep track of all registered formula module types. // // Reviewed: GS - August 6, 2002 // AG - August 7, 2002 // //=================================================================== #region Used namespace using System; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; #endregion #if Microsoft_CONTROL namespace System.Windows.Forms.DataVisualization.Charting.Formulas #else namespace System.Web.UI.DataVisualization.Charting.Formulas #endif { /// /// Keep track of all registered formula modules types. /// internal class FormulaRegistry : IServiceProvider { #region Fields // Storage for all registered formula modules internal Hashtable registeredModules = new Hashtable(StringComparer.OrdinalIgnoreCase); private Hashtable _createdModules = new Hashtable(StringComparer.OrdinalIgnoreCase); private ArrayList _modulesNames = new ArrayList(); #endregion #region Methods /// /// Formula Registry public constructor /// public FormulaRegistry() { } /// /// Adds modules into the registry. /// /// Module name. /// Module class type. public void Register(string name, Type moduleType) { // First check if module with specified name already registered if(registeredModules.Contains(name)) { // If same type provided - ignore if(registeredModules[name].GetType() == moduleType) { return; } // Error - throw exception throw( new ArgumentException( SR.ExceptionFormulaModuleNameIsNotUnique( name ) ) ); } // Add Module Name _modulesNames.Add(name); // Make sure that specified class support IFormula interface bool found = false; Type[] interfaces = moduleType.GetInterfaces(); foreach(Type type in interfaces) { if(type == typeof(IFormula)) { found = true; break; } } if(!found) { throw( new ArgumentException( SR.ExceptionFormulaModuleHasNoInterface)); } // Add formula module to the hash table registeredModules[name] = moduleType; } /// /// Returns formula module registry service object. /// /// Service AxisName. /// Service object. [EditorBrowsableAttribute(EditorBrowsableState.Never)] object IServiceProvider.GetService(Type serviceType) { if(serviceType == typeof(FormulaRegistry)) { return this; } throw (new ArgumentException( SR.ExceptionFormulaModuleRegistryUnsupportedType( serviceType.ToString()))); } /// /// Returns formula module object by name. /// /// Formula Module name. /// Formula module object derived from IFormula. public IFormula GetFormulaModule(string name) { // First check if formula module with specified name registered if(!registeredModules.Contains(name)) { throw( new ArgumentException( SR.ExceptionFormulaModuleNameUnknown( name ) ) ); } // Check if the formula module object is already created if(!_createdModules.Contains(name)) { // Create formula module object _createdModules[name] = ((Type)registeredModules[name]).Assembly. CreateInstance(((Type)registeredModules[name]).ToString()); } return (IFormula)_createdModules[name]; } /// /// Returns the name of the module. /// /// Module index. /// Module Name. public string GetModuleName( int index ) { return (string)_modulesNames[index]; } #endregion #region Properties /// /// Return the number of registered modules. /// public int Count { get { return _modulesNames.Count; } } #endregion } /// /// Interface which defines the set of standard methods and /// properties for each formula module /// internal interface IFormula { #region IFormula Properties and Methods /// /// Formula Module name /// string Name { get; } /// /// The first method in the module, which converts a formula /// name to the corresponding private method. /// /// String which represent a formula name /// Arrays of doubles - Input values /// Arrays of doubles - Output values /// Array of strings - Formula parameters /// Array of strings - Extra Formula parameters from DataManipulator object /// Array of strings - Used for Labels. Description for output results. void Formula(string formulaName, double [][] inputValues, out double [][] outputValues, string [] parameterList, string [] extraParameterList, out string [][] outLabels ); #endregion } }