1 //-------------------------------------------------------------
2 // <copyright company=
\92Microsoft Corporation
\92>
3 // Copyright © Microsoft Corporation. All Rights Reserved.
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 // File: FormulaRegistry.cs
10 // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting.Formulas
12 // Classes: FormulaRegistry
14 // Purpose: Keep track of all registered formula module types.
16 // Reviewed: GS - August 6, 2002
17 // AG - August 7, 2002
19 //===================================================================
22 #region Used namespace
25 using System.Collections;
26 using System.ComponentModel;
27 using System.ComponentModel.Design;
34 namespace System.Windows.Forms.DataVisualization.Charting.Formulas
36 namespace System.Web.UI.DataVisualization.Charting.Formulas
40 /// Keep track of all registered formula modules types.
42 internal class FormulaRegistry : IServiceProvider
46 // Storage for all registered formula modules
47 internal Hashtable registeredModules = new Hashtable(StringComparer.OrdinalIgnoreCase);
48 private Hashtable _createdModules = new Hashtable(StringComparer.OrdinalIgnoreCase);
49 private ArrayList _modulesNames = new ArrayList();
56 /// Formula Registry public constructor
58 public FormulaRegistry()
63 /// Adds modules into the registry.
65 /// <param name="name">Module name.</param>
66 /// <param name="moduleType">Module class type.</param>
67 public void Register(string name, Type moduleType)
69 // First check if module with specified name already registered
70 if(registeredModules.Contains(name))
72 // If same type provided - ignore
73 if(registeredModules[name].GetType() == moduleType)
78 // Error - throw exception
79 throw( new ArgumentException( SR.ExceptionFormulaModuleNameIsNotUnique( name ) ) );
83 _modulesNames.Add(name);
85 // Make sure that specified class support IFormula interface
87 Type[] interfaces = moduleType.GetInterfaces();
88 foreach(Type type in interfaces)
90 if(type == typeof(IFormula))
98 throw( new ArgumentException( SR.ExceptionFormulaModuleHasNoInterface));
101 // Add formula module to the hash table
102 registeredModules[name] = moduleType;
106 /// Returns formula module registry service object.
108 /// <param name="serviceType">Service AxisName.</param>
109 /// <returns>Service object.</returns>
110 [EditorBrowsableAttribute(EditorBrowsableState.Never)]
111 object IServiceProvider.GetService(Type serviceType)
113 if(serviceType == typeof(FormulaRegistry))
117 throw (new ArgumentException( SR.ExceptionFormulaModuleRegistryUnsupportedType( serviceType.ToString())));
121 /// Returns formula module object by name.
123 /// <param name="name">Formula Module name.</param>
124 /// <returns>Formula module object derived from IFormula.</returns>
125 public IFormula GetFormulaModule(string name)
127 // First check if formula module with specified name registered
128 if(!registeredModules.Contains(name))
130 throw( new ArgumentException( SR.ExceptionFormulaModuleNameUnknown( name ) ) );
133 // Check if the formula module object is already created
134 if(!_createdModules.Contains(name))
136 // Create formula module object
137 _createdModules[name] =
138 ((Type)registeredModules[name]).Assembly.
139 CreateInstance(((Type)registeredModules[name]).ToString());
142 return (IFormula)_createdModules[name];
146 /// Returns the name of the module.
148 /// <param name="index">Module index.</param>
149 /// <returns>Module Name.</returns>
150 public string GetModuleName( int index )
152 return (string)_modulesNames[index];
160 /// Return the number of registered modules.
166 return _modulesNames.Count;
174 /// Interface which defines the set of standard methods and
175 /// properties for each formula module
177 internal interface IFormula
179 #region IFormula Properties and Methods
182 /// Formula Module name
187 /// The first method in the module, which converts a formula
188 /// name to the corresponding private method.
190 /// <param name="formulaName">String which represent a formula name</param>
191 /// <param name="inputValues">Arrays of doubles - Input values</param>
192 /// <param name="outputValues">Arrays of doubles - Output values</param>
193 /// <param name="parameterList">Array of strings - Formula parameters</param>
194 /// <param name="extraParameterList">Array of strings - Extra Formula parameters from DataManipulator object</param>
195 /// <param name="outLabels">Array of strings - Used for Labels. Description for output results.</param>
196 void Formula(string formulaName, double [][] inputValues, out double [][] outputValues, string [] parameterList, string [] extraParameterList, out string [][] outLabels );