public T getValueInSamples <T>(string paramName, int[] ignoreColumns) { lock (lockParameters) { // try to retrieve the parameter iParam param = getParameter(paramName); if (param == null) { // message and return 0 logger.Error("Could not find parameter '" + paramName + "' in parameter set '" + paramSetName + "', returning 0"); return((T)Convert.ChangeType(Parameters.emptyValue <T>(), typeof(T))); } // if int[][] or double[][] matrix then get values in samples while ignoring columns if (param.GetType() == typeof(ParamDoubleMat) || param.GetType() == typeof(double[][])) { return(((ParamDoubleMat)param).getValueInSamples <T>(ignoreColumns)); } else if (param.GetType() == typeof(ParamIntMat) || param.GetType() == typeof(int[][])) { return(((ParamIntMat)param).getValueInSamples <T>(ignoreColumns)); } else { // message and return 0 logger.Error("Could not retrieve the values (in samples) for parameter '" + paramName + "' (parameter set: '" + paramSetName + "'), the getValueInSamples functionality with ignoreColumns can only be used for matrix parameters (int[][] or double[][]). Returning 0"); return((T)Convert.ChangeType(Parameters.emptyValue <T>(), typeof(T))); } } }
public bool setValue(string paramName, string[][] paramValue) { lock (lockParameters) { iParam param = getParameter(paramName); if (param == null) { logger.Error("Could not find parameter '" + paramName + "' in parameter set '" + paramSetName + "', value not set"); return(false); } // check if the parameter is indeed used to store a string matix if (param.GetType() != typeof(ParamStringMat)) { logger.Error("Could not set parameter '" + paramName + "' in parameter set '" + paramSetName + "', trying to set a matrix of strings in a '" + param.GetType().Name + "' parameter"); return(false); } // set the value if (!((ParamStringMat)param).setValue(paramValue)) { return(false); } // return success return(true); } }
public bool setValue(string paramName, double[] paramValue, Parameters.Units[] paramUnit) { lock (lockParameters) { iParam param = getParameter(paramName); if (param == null) { logger.Error("Could not find parameter '" + paramName + "' in parameter set '" + paramSetName + "', value not set"); return(false); } // check if the parameter is indeed used to store a double array if (param.GetType() != typeof(ParamDoubleArr)) { logger.Error("Could not set parameter '" + paramName + "' in parameter set '" + paramSetName + "', trying to set an array of doubles in a '" + param.GetType().Name + "' parameter"); return(false); } // set the value if (!((ParamDoubleArr)param).setValue(paramValue)) { return(false); } if (!((ParamDoubleArr)param).setUnit(paramUnit)) { return(false); } // return success return(true); } }
public static void setValue <T>(string paramName, string paramValue) { lock (lockParameters) { // retrieve the parameter iParam param = getParameter(paramName); // create the parameter if it does not exist if (param == null) { param = addParameter <T>(paramName); } // if not able to create, return if (param == null) { return; } // call setter of the parameter for further processing if (param.setValue(paramValue)) { // successfully set // also store certain types as evaluable variables if (param.GetType() == typeof(ParamBool)) { evaluableVariables[paramName] = ((ParamBool)param).Value ? 1 : 0; } else if (param.GetType() == typeof(ParamInt)) { evaluableVariables[paramName] = ((ParamInt)param).Value; } else if (param.GetType() == typeof(ParamDouble)) { evaluableVariables[paramName] = ((ParamDouble)param).Value; } } else { // failure to set // message logger.Error("Could not find parameter '" + paramName + "' in globals, discarded"); } } }
public string getType(string paramName) { lock (lockParameters) { iParam param = getParameter(paramName); if (param == null) { // message logger.Error("Could not find parameter '" + paramName + "' in parameter set '" + paramSetName + "', returning 0"); // return "" return(""); } // return the value return(param.GetType().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); } }