/// <summary> /// Converts a parameter object into a string. /// </summary> /// <param name="o"></param> /// <returns></returns> public static List<ParameterHibernateMapping> ExtractParameterMapObjects(object o, string optionGroup) { List<ParameterHibernateMapping> values = new List<ParameterHibernateMapping>(); if (o != null) { foreach (PropertyInfo prop in o.GetType().GetProperties()) { // Recurse to get parameters. if (prop.CanRead) { object[] customAttributes = prop.GetCustomAttributes(typeof(ParameterFileAttribute), true); object potential = null; if (customAttributes.Length > 0) potential = prop.GetValue(o, BindingFlags.GetProperty, null, null, null); for (int i = 0; i < customAttributes.Length; i++) { ParameterFileAttribute attr = customAttributes[i] as ParameterFileAttribute; if (potential != null && attr != null && attr.Name != "") { ParameterHibernateMapping map = new ParameterHibernateMapping(); map.OptionGroup = optionGroup; map.Parameter = attr.Name; map.Value = potential.ToString(); values.Add(map); } } } } foreach (FieldInfo field in o.GetType().GetFields()) { object[] customAttributes = field.GetCustomAttributes(typeof(ParameterFileAttribute), true); object objectValue = null; if (customAttributes.Length > 0) objectValue = field.GetValue(o); for (int i = 0; i < customAttributes.Length; i++) { ParameterFileAttribute attr = customAttributes[i] as ParameterFileAttribute; if (objectValue != null && attr != null) { ParameterHibernateMapping map = new ParameterHibernateMapping(); map.OptionGroup = optionGroup; map.Parameter = attr.Name; map.Value = objectValue.ToString(); values.Add(map); } } } } return values; }
/// <summary> /// Writes the parameters to the log file and database. /// </summary> private void PrintParameters(MultiAlignAnalysis analysis, bool insertIntoDatabase) { Logger.PrintMessage("Parameters Loaded"); var options = new Dictionary<string, object> { {"Instrument Tolerances", analysis.Options.InstrumentTolerances}, {"Ms Feature Filtering Options", analysis.Options.MsFilteringOptions}, {"Feature Filtering Options", analysis.Options.LcmsFilteringOptions}, {"Mass Tag Database Options", analysis.Options.MassTagDatabaseOptions}, {"Alignment Options", analysis.Options.AlignmentOptions}, {"Clustering Options", analysis.Options.LcmsClusteringOptions}, {"STAC Options", analysis.Options.StacOptions} }; var allmappings = new List<ParameterHibernateMapping>(); foreach (var key in options.Keys) { //var o = options[key]; Logger.PrintMessage(key, true); //var parameters = ParameterUtility.ConvertParameterObjectToStrings(o); //foreach (var parameter in parameters) //{ // Logger.PrintMessage("\t" + parameter, true); //} //var mappings = ParameterUtility.ExtractParameterMapObjects(o, key); //allmappings.AddRange(mappings); } var assemblyData = ApplicationUtility.GetAssemblyData(); var assemblyMap = new ParameterHibernateMapping { OptionGroup = "Assembly Info", Parameter = "Version", Value = assemblyData }; allmappings.Add(assemblyMap); var systemData = ApplicationUtility.GetSystemData(); var systemMap = new ParameterHibernateMapping { OptionGroup = "Assembly Info", Parameter = "System Info", Value = systemData }; allmappings.Add(systemMap); if (insertIntoDatabase) { Logger.PrintMessage("Writing parameters to the analysis database."); var parameterCache = new GenericDAOHibernate<ParameterHibernateMapping>(); parameterCache.AddAll(allmappings); } }