/// <summary> /// Helper function to get the MethodXMLContext /// </summary> /// <param name="model">The instrument model</param> /// <param name="version">The instrument version</param> /// <returns></returns> public static IMethodXMLContext CreateContext(string model = "", string version = "") { if (string.IsNullOrEmpty(model)) { model = MethodXMLFactory.GetInstalledServerModel(); } if (string.IsNullOrEmpty(version)) { version = MethodXMLFactory.GetLatestInstalledVersion(model); } if (!MethodXMLFactory.GetInstalledInstrumentModels().Contains(model)) { throw new ArgumentException("Cannot create method context for non-installed instrument model: " + model); } return(MethodXMLFactory.CreateContext(model, version)); }
/// <summary> /// Prints information about the executing computer's TNG status /// </summary> public static IEnumerable <string> PrintInformation() { // Get all installed instruments for executing computer // Searches the registry for installed TNG instruments. // HKEY_LOCAL_MACHINE\SOFTWARE\Thermo Instruments\TNG // or // HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Thermo Instruments\TNG var instruments = MethodXMLFactory.GetInstalledInstrumentModels(); yield return("== Configured Instruments =="); int i = 1; foreach (string instrument in instruments) { Console.WriteLine("{0,2}: {1}", i++, instrument); // Get all installed instrument versions for this particular instrument (i.e., Fusion 1.1, 1.2, etc...) var versions = MethodXMLFactory.GetInstalledVersions(instrument); // TNG can be installed as Full (connected to instrument) or Workstation (just MethodEditor) mode. var fullInstalledVersions = new HashSet <string>(MethodXMLFactory.GetFullInstalledVersions(instrument)); // The most recently installed version for this instrument model var lastInstalledVersion = MethodXMLFactory.GetLatestInstalledVersion(instrument); foreach (string version in versions) { yield return(string.Format("{0,8} ({1}){2}", version, fullInstalledVersions.Contains(version) ? "Full" : "WorkStation", version == lastInstalledVersion ? " Latest Installed" : "")); } } yield return("============================"); yield return(string.Format("Installed Server Model: {0}", MethodXMLFactory.GetInstalledServerModel())); yield return(string.Format("Installed Server Version: {0}", MethodXMLFactory.GetInstalledServerVersion())); }
/// <summary> /// Get all the installed instrument model names /// </summary> /// <returns>The installed instrument names</returns> public static IEnumerable <string> GetInstalledInstrumentModels() { return(MethodXMLFactory.GetInstalledInstrumentModels()); }
/// <summary> /// Applies the modification XML file to the method template, to produce a modified method file /// </summary> /// <param name="methodTemplate">The method to base off of</param> /// <param name="methodModXML">The modifications to be applied to the template method</param> /// <param name="outputMethod">The file path for the generated method</param> /// <param name="model">The instrument model</param> /// <param name="version">The instrument version</param> /// <param name="enableValidation">Enable automatic validation on saving</param> public static void ModifyMethod(string methodTemplate, string methodModXML, string outputMethod = "", string model = "", string version = "", bool enableValidation = true) { if (string.IsNullOrEmpty(methodTemplate)) { throw new ArgumentException("A method file path must be specified", "Method Template"); } if (string.IsNullOrEmpty(methodModXML)) { throw new ArgumentException("A method modification path must be specified", "Method Modification"); } // Handle relative/absolute paths methodTemplate = Path.GetFullPath(methodTemplate); methodModXML = Path.GetFullPath(methodModXML); // These files are required if (!File.Exists(methodTemplate)) { throw new IOException("File Not Found: " + methodTemplate); } if (!File.Exists(methodModXML)) { throw new IOException("File Not Found: " + methodModXML); } // Create output file path if not specified if (string.IsNullOrEmpty(outputMethod)) { outputMethod = methodTemplate.Replace(".meth", "_modified.meth"); } outputMethod = Path.GetFullPath(outputMethod); // Create output directory if doesn't exist if (!Directory.Exists(Path.GetDirectoryName(outputMethod))) { Directory.CreateDirectory(Path.GetDirectoryName(outputMethod)); } // If the instrument model is not specified, get the default installed one. (might not be the best) if (string.IsNullOrEmpty(model)) { model = MethodXMLFactory.GetInstalledServerModel(); if (string.IsNullOrEmpty(model)) { var instruments = MethodXMLFactory.GetInstalledInstrumentModels(); if (instruments.Count > 1) { throw new Exception(string.Format("Unable to find default installed instrument, you have {0} instruments registered", instruments.Count)); } else if (instruments.Count == 0) { throw new Exception("Unable to find any installed instruments!"); } else { model = instruments[0]; } } } // Get the type of instrument based on its name InstrumentFamily instrumentFamily = GetInstrumentFamilyFromModel(model); // Get the type of instrument modification based on the xml file InstrumentFamily xmlInstrumentFamily = GetInstrumentFamilyFromXml(methodModXML); // These two need to be equivalent to correctly apply the modifications if (instrumentFamily != xmlInstrumentFamily) { throw new ArgumentException(string.Format("The specified xml ({0}) is not compatible with the instrument model ({1}, {2})", xmlInstrumentFamily, instrumentFamily, model)); } using (IMethodXMLContext mxc = CreateContext(model, version)) using (IMethodXML xmlMeth = mxc.Create()) { // Open the template method xmlMeth.Open(methodTemplate); // Set the validation flag xmlMeth.EnableValidation(enableValidation); // Call the correct modification method based on the instrument type switch (instrumentFamily) { case InstrumentFamily.OrbitrapFusion: xmlMeth.ApplyMethodModificationsFromXMLFile(methodModXML); break; case InstrumentFamily.TSQ: xmlMeth.ImportMassListFromXMLFile(methodModXML); break; default: throw new ArgumentException("Unsupported instrument model:" + model); } // Save the in memory method to the output file xmlMeth.SaveAs(outputMethod); } }