public string ToString(string paramName) { lock (lockParameters) { iParam param = getParameter(paramName); if (param == null) { logger.Error("Could not find parameter '" + paramName + "' in parameter set '" + paramSetName + "', returning null"); return(null); } return(param.ToString()); } }
// TODO: max: toch in ParameterManager (static hier om de source, filter en app references op te halen?) public static void saveParameterFile(string xmlFile, Dictionary <string, Parameters> parameterSets) { if (parameterSets == null) { return; } // check if the filename is not empty if (string.IsNullOrEmpty(xmlFile)) { // message logger.Error("Save parameter file called with invalid filename"); // return return; } // TODO: indent with tabs // create parameter XML file with encoding declaration XmlDocument paramFile = new XmlDocument(); XmlNode paramFileNode = paramFile.CreateXmlDeclaration("1.0", "UTF-8", null); paramFile.AppendChild(paramFileNode); // add root node XmlNode rootNode = paramFile.CreateElement("root"); paramFile.AppendChild(rootNode); // VERSION NODES // create versions node and add to root node XmlNode versionsNode = paramFile.CreateElement("versions"); rootNode.AppendChild(versionsNode); // get data name and version value, and create data version node int dataVersionValue = Data.getClassVersion(); string dataVersionName = Data.getClassName(); XmlNode dataVersionNode = paramFile.CreateElement("version"); // add name attribute XmlAttribute dataNameAttr = paramFile.CreateAttribute("name"); dataNameAttr.Value = dataVersionName; dataVersionNode.Attributes.Append(dataNameAttr); // add type attribute XmlAttribute dataTypeAttr = paramFile.CreateAttribute("type"); dataTypeAttr.Value = "data"; dataVersionNode.Attributes.Append(dataTypeAttr); // add value attribute XmlAttribute dataValueAttr = paramFile.CreateAttribute("value"); dataValueAttr.Value = dataVersionValue.ToString(); dataVersionNode.Attributes.Append(dataValueAttr); // add data version node to versions node versionsNode.AppendChild(dataVersionNode); // get source name and version value, and create source version node ISource source = MainThread.getSource(); int sourceVersionValue = source.getClassVersion(); string sourceVersionName = source.getClassName(); XmlNode sourceVersionNode = paramFile.CreateElement("version"); // add name attribute XmlAttribute sourceNameAttr = paramFile.CreateAttribute("name"); sourceNameAttr.Value = sourceVersionName; sourceVersionNode.Attributes.Append(sourceNameAttr); // add type attribute XmlAttribute sourceTypeAttr = paramFile.CreateAttribute("type"); sourceTypeAttr.Value = "source"; sourceVersionNode.Attributes.Append(sourceTypeAttr); // add value attribute XmlAttribute sourceValueAttr = paramFile.CreateAttribute("value"); sourceValueAttr.Value = sourceVersionValue.ToString(); sourceVersionNode.Attributes.Append(sourceValueAttr); // add source version node to versions node versionsNode.AppendChild(sourceVersionNode); // loop through the filters List <IFilter> filters = MainThread.getFilters(); for (int i = 0; i < filters.Count; i++) { // create filter version node XmlNode filterVersionNode = paramFile.CreateElement("version"); // add name attribute XmlAttribute filterNameAttr = paramFile.CreateAttribute("name"); filterNameAttr.Value = filters[i].getName(); filterVersionNode.Attributes.Append(filterNameAttr); // add type attribute XmlAttribute filterTypeAttr = paramFile.CreateAttribute("type"); filterTypeAttr.Value = "filter"; filterVersionNode.Attributes.Append(filterTypeAttr); // add value attribute XmlAttribute fillterValueAttr = paramFile.CreateAttribute("value"); fillterValueAttr.Value = filters[i].getClassVersion().ToString(); filterVersionNode.Attributes.Append(fillterValueAttr); // add filter version node to versions node versionsNode.AppendChild(filterVersionNode); } // get application version and create application version node IApplication application = MainThread.getApplication(); int applicationVersionValue = application.getClassVersion(); string applicationVersionName = application.getClassName(); XmlNode applicationVersionNode = paramFile.CreateElement("version"); // add name attribute XmlAttribute applicationNameAttr = paramFile.CreateAttribute("name"); applicationNameAttr.Value = applicationVersionName; applicationVersionNode.Attributes.Append(applicationNameAttr); // add type attribute XmlAttribute applicationTypeAttr = paramFile.CreateAttribute("type"); applicationTypeAttr.Value = "application"; applicationVersionNode.Attributes.Append(applicationTypeAttr); // add value attribute XmlAttribute applicationValueAttr = paramFile.CreateAttribute("value"); applicationValueAttr.Value = applicationVersionValue.ToString(); applicationVersionNode.Attributes.Append(applicationValueAttr); // add application version node to versions node versionsNode.AppendChild(applicationVersionNode); // cycle through parameter sets foreach (KeyValuePair <string, Parameters> entry in parameterSets) { // create parameterSet node XmlNode parameterSetNode = paramFile.CreateElement("parameterSet"); // add name attribute to parameterSet node and set equal to set name XmlAttribute parameterSetName = paramFile.CreateAttribute("name"); parameterSetName.Value = entry.Key; parameterSetNode.Attributes.Append(parameterSetName); // add parameterSet node to root node rootNode.AppendChild(parameterSetNode); // get Parameter object and iParams contained within Parameters parameterSet = entry.Value; List <iParam> parameters = parameterSet.getParameters(); // loop throug the parameters in the set for (int p = 0; p < parameters.Count; p++) { iParam parameter = parameters[p]; // create param node XmlNode paramNode = paramFile.CreateElement("param"); // add name attribute XmlAttribute paramNameAttr = paramFile.CreateAttribute("name"); paramNameAttr.Value = parameter.Name; paramNode.Attributes.Append(paramNameAttr); // add type attribute XmlAttribute paramTypeAttr = paramFile.CreateAttribute("type"); paramTypeAttr.Value = parameter.GetType().ToString(); paramNode.Attributes.Append(paramTypeAttr); // add value attribute XmlAttribute paramValueAttr = paramFile.CreateAttribute("value"); paramValueAttr.Value = parameter.ToString(); paramNode.Attributes.Append(paramValueAttr); // add param node to parameterSet node parameterSetNode.AppendChild(paramNode); } } try { // save xml string to file paramFile.Save(xmlFile); // message logger.Info("Saved parameter file: " + xmlFile); } catch (Exception e) { // message error logger.Error("Unable to save parameter file (" + xmlFile + "). " + e.Message); } }