/// <summary> /// Decompiles an Xml node back into an <see cref="AlgorithmDefinition"/>. /// </summary> /// <param name="algorithmNode">The <see cref="XNode"/> representing the /// <see cref="AlgorithmDefinition"/>.</param> /// <returns>An <see cref="AlgorithmDefinition"/> object represented by /// the provided Xml.</returns> public AlgorithmDefinition DecompileAlgorithm(XNode algorithmNode) { if (algorithmNode.NodeType != System.Xml.XmlNodeType.Element) { throw new ArgumentException("An XElement is required"); } object paramObj = null; XElement element = (XElement)algorithmNode; XAttribute nameAttr = element.Attribute("name"); string name = nameAttr.Value; AlgorithmDefinition d = new AlgorithmDefinition(name, new Property[] { }); XNode propertyNode = element.FirstNode; if (propertyNode != null && propertyNode.NodeType == System.Xml.XmlNodeType.Element) { if (_factories.ContainsKey(name) == false) { throw new ArgumentException("Unknown process provided"); } XElement propElement = (XElement)propertyNode; IPipelineXmlInterpreter factory = _factories[name]; d.ParameterObject = factory.CreateObject(propElement); } return(d); }
/// <summary> /// Fetches the <see cref="IPipelineXmlInterpreter"/> for a given /// process. /// </summary> /// <param name="processName">The name of the process to fetch /// the <see cref="IPipelineXmlInterpreter"/> for.</param> /// <returns>The <see cref="IPipelineXmlInterpreter"/> capable /// of saving or restoring the state of the associated /// process.</returns> public IPipelineXmlInterpreter FetchInterpreter(string processName) { IPipelineXmlInterpreter interpreter = null; if (processName != null && _interpreters.ContainsKey(processName)) { _interpreters.TryGetValue(processName, out interpreter); } return(interpreter); }
/// <summary> /// Registers the incoming valid type in this repo /// </summary> /// <param name="type">The type to register</param> private void _registerType(Type type) { try { PipelineXmlOriginatorAttribute attr = type.GetCustomAttribute( typeof(PipelineXmlOriginatorAttribute)) as PipelineXmlOriginatorAttribute; Type pluginType = attr.PluginType; AlgorithmAttribute pluginAttr = pluginType.GetCustomAttribute(typeof(AlgorithmAttribute)) as AlgorithmAttribute; string pluginID = pluginAttr.PluginName; IPipelineXmlInterpreter interpreter = Activator.CreateInstance(type) as IPipelineXmlInterpreter; _interpreters.Add(pluginID, interpreter); } catch (Exception e) { } }
/// <summary> /// Constructs Xml using the <see cref="AlgorithmDefinition"/>. /// </summary> /// <param name="definition">The <see cref="AlgorithmDefinition"/> /// detailing the process and its properties.</param> /// <returns>An <see cref="XElement"/> representing the /// <see cref="AlgorithmDefinition"/>.</returns> public XElement Build(AlgorithmDefinition definition) { string algName = definition.AlgorithmName; XAttribute name = new XAttribute("name", algName); if (definition.ParameterObject != null) { if (_factories.ContainsKey(algName) == false) { throw new ArgumentException("Unknown algorithm provided"); } IPipelineXmlInterpreter factory = _factories[algName]; var props = factory.CreateXml(definition.ParameterObject); return(new XElement("algorithm", name, props)); } else { return(new XElement("algorithm", name)); } }