/// <summary> /// Export to a isolation scheme to a file or to memory. /// </summary> /// <param name="fileName">A file on disk to export to, or null to export to memory.</param> /// <param name="progressMonitor">progress monitor</param> public void Export(string fileName, IProgressMonitor progressMonitor) { if (ExportString == null) { StringWriter writer = new StringWriter(); if (HasHeaders) { WriteHeaders(writer); } if (IsolationScheme.WindowsPerScan.HasValue) { WriteMultiplexedWindows(writer, IsolationScheme.WindowsPerScan.Value, progressMonitor); } else { WriteWindows(writer); } ExportString = writer.ToString(); } if (fileName != null) { var saver = new FileSaver(fileName); if (!saver.CanSave()) { throw new IOException(string.Format(Resources.AbstractDiaExporter_Export_Cannot_save_to__0__, fileName)); } var writer = new StreamWriter(saver.SafeName); writer.Write(ExportString); writer.Close(); saver.Commit(); } }
/// <summary> /// Save the report to a temp file /// </summary> /// <returns>The path to the saved temp file.</returns> private static string GetReportTempPath(ToolMacroInfo toolMacroInfo) { SrmDocument doc = toolMacroInfo.Doc; string reportName = toolMacroInfo.ReportName; string toolTitle = toolMacroInfo.ToolTitle; if (String.IsNullOrEmpty(reportName)) { throw new Exception(string.Format(Resources.ToolMacros_GetReportTempPath_The_selected_tool_0_requires_a_selected_report_Please_select_a_report_for_this_tool_, toolTitle)); } var tempFilePath = GetReportTempPath(reportName, toolTitle); try { using (var saver = new FileSaver(tempFilePath)) { if (!saver.CanSave()) { throw new IOException(); } using (var writer = new StreamWriter(saver.SafeName)) { ToolDescriptionHelpers.GetReport(doc, reportName, toolTitle, toolMacroInfo.ProgressMonitor, writer); } saver.Commit(); return(tempFilePath); } } catch (Exception) { throw new IOException(Resources.ToolMacros_GetReportTempPath_Error_exporting_the_report__tool_execution_canceled_); } }
protected override bool SafeWriteToFile(Control owner, string fileName, Func <Stream, bool> writeFunc) { using (var fileSaver = new FileSaver(fileName, true)) { if (!fileSaver.CanSave(owner)) { return(false); } if (writeFunc(fileSaver.Stream)) { fileSaver.Commit(); return(true); } } return(false); }
private void btnExport_Click(object sender, EventArgs e) { string strReferenceFile = (string)comboBoxReferenceFile.SelectedItem; string strSaveFileName = string.Empty; if (!string.IsNullOrEmpty(_documentFilePath)) { strSaveFileName = Path.GetFileNameWithoutExtension(_documentFilePath); } if (!string.IsNullOrEmpty(strReferenceFile)) { strSaveFileName += Path.GetFileNameWithoutExtension(strReferenceFile); } strSaveFileName += ".ChorusRequest.xml"; // Not L10N strSaveFileName = strSaveFileName.Replace(' ', '_'); using (var saveFileDialog = new SaveFileDialog { FileName = strSaveFileName }) { if (saveFileDialog.ShowDialog(this) != DialogResult.OK || string.IsNullOrEmpty(saveFileDialog.FileName)) { return; } SpectrumFilter spectrumFilterData = new SpectrumFilter(Document, MsDataFileUri.Parse(strReferenceFile), null); using (var saver = new FileSaver(saveFileDialog.FileName)) { if (!saver.CanSave(this)) { return; } using (var stream = new StreamWriter(saver.SafeName)) { var xmlSerializer = new XmlSerializer(typeof(Model.Results.RemoteApi.GeneratedCode.ChromatogramRequestDocument)); xmlSerializer.Serialize(stream, spectrumFilterData.ToChromatogramRequestDocument()); } saver.Commit(); } } Close(); }
public void Init() { if (_single) { if (FileName != null) { _saver = new FileSaver(FileName); if (!_saver.CanSave()) { throw new IOException(string.Format(Resources.FileIterator_Init_Cannot_save_to__0__, FileName)); } _writer = new StreamWriter(_saver.SafeName); } else { StringBuilder sb = new StringBuilder(); MemoryOutput[BaseName] = sb; _writer = new StringWriter(sb); } _writeHeaders(_writer); } }
private bool ExportReport(string fileName, char separator) { try { using (var saver = new FileSaver(fileName)) { if (!saver.CanSave(this)) { return(false); } using (var writer = new StreamWriter(saver.SafeName)) { Report report = GetReport(); bool success = false; using (var longWait = new LongWaitDlg { Text = Resources.ExportReportDlg_ExportReport_Generating_Report }) { longWait.PerformWork(this, 1500, broker => { var status = new ProgressStatus(Resources.ExportReportDlg_GetDatabase_Analyzing_document); broker.UpdateProgress(status); Database database = EnsureDatabase(broker, 80, ref status); if (broker.IsCanceled) { return; } broker.UpdateProgress(status = status.ChangeMessage(Resources.ExportReportDlg_ExportReport_Building_report)); ResultSet resultSet = report.Execute(database); if (broker.IsCanceled) { return; } broker.UpdateProgress(status = status.ChangePercentComplete(95) .ChangeMessage(Resources.ExportReportDlg_ExportReport_Writing_report)); ResultSet.WriteReportHelper(resultSet, separator, writer, CultureInfo); writer.Flush(); writer.Close(); if (broker.IsCanceled) { return; } broker.UpdateProgress(status.Complete()); saver.Commit(); success = true; }); } return(success); } } } catch (Exception x) { MessageDlg.ShowWithException(this, string.Format(Resources.ExportReportDlg_ExportReport_Failed_exporting_to, fileName, GetExceptionDisplayMessage(x)), x); return(false); } }
private bool ValidateBuilder(bool validateInputFiles) { string name; if (!_helper.ValidateNameTextBox(textName, out name)) { return(false); } string outputPath = textPath.Text; if (string.IsNullOrEmpty(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath); return(false); } if (Directory.Exists(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath); return(false); } string outputDir = Path.GetDirectoryName(outputPath); if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir); return(false); } if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT)) { outputPath += BiblioSpecLiteSpec.EXT; } try { using (var sfLib = new FileSaver(outputPath)) { if (!sfLib.CanSave(this)) { textPath.Focus(); textPath.SelectAll(); return(false); } } } catch (UnauthorizedAccessException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return(false); } catch (IOException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return(false); } double cutOffScore; if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore)) { return(false); } Settings.Default.LibraryResultCutOff = cutOffScore; var libraryBuildAction = LibraryBuildAction; if (validateInputFiles) { var inputFilesChosen = new List <string>(); foreach (int i in listInputFiles.CheckedIndices) { inputFilesChosen.Add(_inputFileNames[i]); } List <Target> targetPeptidesChosen = null; if (cbFilter.Checked) { targetPeptidesChosen = new List <Target>(); var doc = _documentUiContainer.Document; foreach (PeptideDocNode nodePep in doc.Peptides) { // Add light modified sequences targetPeptidesChosen.Add(nodePep.ModifiedTarget); // Add heavy modified sequences foreach (var nodeGroup in nodePep.TransitionGroups) { if (nodeGroup.TransitionGroup.LabelType.IsLight) { continue; } targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Target, nodeGroup.TransitionGroup.LabelType, nodePep.ExplicitMods)); } } } if (prositDataSourceRadioButton.Checked) { // TODO: Need to figure out a better way to do this, use PrositPeptidePrecursorPair? var doc = _documentUiContainer.DocumentUI; var peptides = doc.Peptides.ToArray(); var precursorCount = doc.PeptideTransitionGroupCount; var peptidesPerPrecursor = new PeptideDocNode[precursorCount]; var precursors = new TransitionGroupDocNode[precursorCount]; int index = 0; for (var i = 0; i < peptides.Length; ++i) { var groups = peptides[i].TransitionGroups.ToArray(); Array.Copy(Enumerable.Repeat(peptides[i], groups.Length).ToArray(), 0, peptidesPerPrecursor, index, groups.Length); Array.Copy(groups, 0, precursors, index, groups.Length); index += groups.Length; } try { PrositUIHelpers.CheckPrositSettings(this, _skylineWindow); // Still construct the library builder, otherwise a user might configure Prosit // incorrectly, causing the build to silently fail Builder = new PrositLibraryBuilder(doc, name, outputPath, () => true, IrtStandard, peptidesPerPrecursor, precursors, NCE); } catch (Exception ex) { _helper.ShowTextBoxError(this, ex.Message); return(false); } } else { Builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen) { Action = libraryBuildAction, IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked, KeepRedundant = LibraryKeepRedundant, CutOffScore = cutOffScore, Id = Helpers.MakeId(textName.Text), IrtStandard = _driverStandards.SelectedItem, PreferEmbeddedSpectra = PreferEmbeddedSpectra }; } } return(true); }
private void ExportLiveReport(string reportName, string reportFile, char reportColSeparator, bool reportInvariant) { var viewContext = DocumentGridViewContext.CreateDocumentGridViewContext(_doc, reportInvariant ? DataSchemaLocalizer.INVARIANT : SkylineDataSchema.GetLocalizedSchemaLocalizer()); var viewInfo = viewContext.GetViewInfo(PersistedViews.MainGroup.Id.ViewName(reportName)); if (null == viewInfo) { _out.WriteLine(Resources.CommandLine_ExportLiveReport_Error__The_report__0__does_not_exist__If_it_has_spaces_in_its_name__use__double_quotes__around_the_entire_list_of_command_parameters_, reportName); return; } _out.WriteLine(Resources.CommandLine_ExportLiveReport_Exporting_report__0____, reportName); try { using (var saver = new FileSaver(reportFile)) { if (!saver.CanSave()) { _out.WriteLine(Resources.CommandLine_ExportLiveReport_Error__The_report__0__could_not_be_saved_to__1__, reportName, reportFile); _out.WriteLine(Resources.CommandLine_ExportLiveReport_Check_to_make_sure_it_is_not_read_only_); } var status = new ProgressStatus(string.Empty); IProgressMonitor broker = new CommandProgressMonitor(_out, status); using (var writer = new StreamWriter(saver.SafeName)) { viewContext.Export(broker, ref status, viewInfo, writer, new DsvWriter(reportInvariant ? CultureInfo.InvariantCulture : LocalizationHelper.CurrentCulture, reportColSeparator)); } broker.UpdateProgress(status.Complete()); saver.Commit(); _out.WriteLine(Resources.CommandLine_ExportLiveReport_Report__0__exported_successfully_to__1__, reportName, reportFile); } } catch (Exception x) { _out.WriteLine(Resources.CommandLine_ExportLiveReport_Error__Failure_attempting_to_save__0__report_to__1__, reportName, reportFile); _out.WriteLine(x.Message); } }
private bool ValidateBuilder(bool validateInputFiles) { string name; if (!_helper.ValidateNameTextBox(textName, out name)) { return(false); } string outputPath = textPath.Text; if (string.IsNullOrEmpty(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath); return(false); } if (Directory.Exists(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath); return(false); } string outputDir = Path.GetDirectoryName(outputPath); if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir); return(false); } if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT)) { outputPath += BiblioSpecLiteSpec.EXT; } try { using (var sfLib = new FileSaver(outputPath)) { if (!sfLib.CanSave(this)) { textPath.Focus(); textPath.SelectAll(); return(false); } } } catch (UnauthorizedAccessException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return(false); } catch (IOException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return(false); } double cutOffScore; if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore)) { return(false); } Settings.Default.LibraryResultCutOff = cutOffScore; var libraryBuildAction = LibraryBuildAction; string authority = null; string id = null; if (libraryBuildAction == LibraryBuildAction.Create) { authority = LibraryAuthority; if (Uri.CheckHostName(authority) != UriHostNameType.Dns) { _helper.ShowTextBoxError(textAuthority, Resources.BuildLibraryDlg_ValidateBuilder_The_lab_authority_name__0__is_not_valid_This_should_look_like_an_internet_server_address_e_g_mylab_myu_edu_and_be_unlikely_to_be_used_by_any_other_lab_but_need_not_refer_to_an_actual_server, authority); return(false); } Settings.Default.LibraryAuthority = authority; id = textID.Text; if (!Regex.IsMatch(id, @"\w[0-9A-Za-z_\-]*")) // Not L10N: Easier to keep IDs restricted to these values. { _helper.ShowTextBoxError(textID, Resources.BuildLibraryDlg_ValidateBuilder_The_library_identifier__0__is_not_valid_Identifiers_start_with_a_letter_number_or_underscore_and_contain_only_letters_numbers_underscores_and_dashes, id); return(false); } } if (validateInputFiles) { var inputFilesChosen = new List <string>(); foreach (int i in listInputFiles.CheckedIndices) { inputFilesChosen.Add(_inputFileNames[i]); } List <string> targetPeptidesChosen = null; if (cbFilter.Checked) { targetPeptidesChosen = new List <string>(); var doc = _documentUiContainer.Document; foreach (PeptideDocNode nodePep in doc.Peptides) { // Add light modified sequences targetPeptidesChosen.Add(nodePep.ModifiedSequence); // Add heavy modified sequences foreach (var nodeGroup in nodePep.TransitionGroups) { if (nodeGroup.TransitionGroup.LabelType.IsLight) { continue; } targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Sequence, nodeGroup.TransitionGroup.LabelType, nodePep.ExplicitMods)); } } } _builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen) { Action = libraryBuildAction, IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked, KeepRedundant = LibraryKeepRedundant, CutOffScore = cutOffScore, Authority = authority, Id = id }; } return(true); }
private bool ValidateBuilder(bool validateInputFiles) { string name; if (!_helper.ValidateNameTextBox(textName, out name)) { return(false); } string outputPath = textPath.Text; if (string.IsNullOrEmpty(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath); return(false); } if (Directory.Exists(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath); return(false); } string outputDir = Path.GetDirectoryName(outputPath); if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir); return(false); } if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT)) { outputPath += BiblioSpecLiteSpec.EXT; } try { using (var sfLib = new FileSaver(outputPath)) { if (!sfLib.CanSave(this)) { textPath.Focus(); textPath.SelectAll(); return(false); } } } catch (UnauthorizedAccessException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return(false); } catch (IOException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return(false); } double cutOffScore; if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore)) { return(false); } Settings.Default.LibraryResultCutOff = cutOffScore; var libraryBuildAction = LibraryBuildAction; if (validateInputFiles) { var inputFilesChosen = new List <string>(); foreach (int i in listInputFiles.CheckedIndices) { inputFilesChosen.Add(_inputFileNames[i]); } List <Target> targetPeptidesChosen = null; if (cbFilter.Checked) { targetPeptidesChosen = new List <Target>(); var doc = _documentUiContainer.Document; foreach (PeptideDocNode nodePep in doc.Peptides) { // Add light modified sequences targetPeptidesChosen.Add(nodePep.ModifiedTarget); // Add heavy modified sequences foreach (var nodeGroup in nodePep.TransitionGroups) { if (nodeGroup.TransitionGroup.LabelType.IsLight) { continue; } targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Target, nodeGroup.TransitionGroup.LabelType, nodePep.ExplicitMods)); } } } _builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen) { Action = libraryBuildAction, IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked, KeepRedundant = LibraryKeepRedundant, CutOffScore = cutOffScore, Id = Helpers.MakeId(textName.Text), IrtStandard = comboStandards.SelectedItem as IrtStandard }; } return(true); }
private bool ExportReport(string fileName, char separator) { try { using (var saver = new FileSaver(fileName)) { if (!saver.CanSave(this)) return false; using (var writer = new StreamWriter(saver.SafeName)) { Report report = GetReport(); bool success = false; using (var longWait = new LongWaitDlg { Text = Resources.ExportReportDlg_ExportReport_Generating_Report }) { longWait.PerformWork(this, 1500, broker => { var status = new ProgressStatus(Resources.ExportReportDlg_GetDatabase_Analyzing_document); broker.UpdateProgress(status); Database database = EnsureDatabase(broker, 80, ref status); if (broker.IsCanceled) return; broker.UpdateProgress(status = status.ChangeMessage(Resources.ExportReportDlg_ExportReport_Building_report)); ResultSet resultSet = report.Execute(database); if (broker.IsCanceled) return; broker.UpdateProgress(status = status.ChangePercentComplete(95) .ChangeMessage(Resources.ExportReportDlg_ExportReport_Writing_report)); ResultSet.WriteReportHelper(resultSet, separator, writer, CultureInfo); writer.Flush(); writer.Close(); if (broker.IsCanceled) return; broker.UpdateProgress(status.Complete()); saver.Commit(); success = true; }); } return success; } } } catch (Exception x) { MessageDlg.ShowWithException(this, string.Format(Resources.ExportReportDlg_ExportReport_Failed_exporting_to, fileName, GetExceptionDisplayMessage(x)), x); return false; } }
private void SaveLayout(string fileName) { using (var saverUser = new FileSaver(GetViewFile(fileName))) { if (saverUser.CanSave()) { dockPanel.SaveAsXml(saverUser.SafeName); saverUser.Commit(); } } }
private bool ValidateBuilder(bool validateInputFiles) { string name; if (!_helper.ValidateNameTextBox(textName, out name)) return false; string outputPath = textPath.Text; if (string.IsNullOrEmpty(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_You_must_specify_an_output_file_path, outputPath); return false; } if (Directory.Exists(outputPath)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_output_path__0__is_a_directory_You_must_specify_a_file_path, outputPath); return false; } string outputDir = Path.GetDirectoryName(outputPath); if (string.IsNullOrEmpty(outputDir) || !Directory.Exists(outputDir)) { _helper.ShowTextBoxError(textPath, Resources.BuildLibraryDlg_ValidateBuilder_The_directory__0__does_not_exist, outputDir); return false; } if (!outputPath.EndsWith(BiblioSpecLiteSpec.EXT)) outputPath += BiblioSpecLiteSpec.EXT; try { using (var sfLib = new FileSaver(outputPath)) { if (!sfLib.CanSave(this)) { textPath.Focus(); textPath.SelectAll(); return false; } } } catch (UnauthorizedAccessException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Access_violation_attempting_to_write_to__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return false; } catch (IOException) { _helper.ShowTextBoxError(textPath, TextUtil.LineSeparate(Resources.BuildLibraryDlg_ValidateBuilder_Failure_attempting_to_create_a_file_in__0__, Resources.BuildLibraryDlg_ValidateBuilder_Please_check_that_you_have_write_access_to_this_folder_), outputDir); return false; } double cutOffScore; if (!_helper.ValidateDecimalTextBox(textCutoff, 0, 1.0, out cutOffScore)) return false; Settings.Default.LibraryResultCutOff = cutOffScore; var libraryBuildAction = LibraryBuildAction; string authority = null; string id = null; if (libraryBuildAction == LibraryBuildAction.Create) { authority = LibraryAuthority; if (Uri.CheckHostName(authority) != UriHostNameType.Dns) { _helper.ShowTextBoxError(textAuthority, Resources.BuildLibraryDlg_ValidateBuilder_The_lab_authority_name__0__is_not_valid_This_should_look_like_an_internet_server_address_e_g_mylab_myu_edu_and_be_unlikely_to_be_used_by_any_other_lab_but_need_not_refer_to_an_actual_server, authority); return false; } Settings.Default.LibraryAuthority = authority; id = textID.Text; if (!Regex.IsMatch(id, @"\w[0-9A-Za-z_\-]*")) // Not L10N: Easier to keep IDs restricted to these values. { _helper.ShowTextBoxError(textID, Resources.BuildLibraryDlg_ValidateBuilder_The_library_identifier__0__is_not_valid_Identifiers_start_with_a_letter_number_or_underscore_and_contain_only_letters_numbers_underscores_and_dashes, id); return false; } } if (validateInputFiles) { var inputFilesChosen = new List<string>(); foreach (int i in listInputFiles.CheckedIndices) { inputFilesChosen.Add(_inputFileNames[i]); } List<string> targetPeptidesChosen = null; if (cbFilter.Checked) { targetPeptidesChosen = new List<string>(); var doc = _documentUiContainer.Document; foreach (PeptideDocNode nodePep in doc.Peptides) { // Add light modified sequences targetPeptidesChosen.Add(nodePep.ModifiedSequence); // Add heavy modified sequences foreach (var nodeGroup in nodePep.TransitionGroups) { if (nodeGroup.TransitionGroup.LabelType.IsLight) continue; targetPeptidesChosen.Add(doc.Settings.GetModifiedSequence(nodePep.Peptide.Sequence, nodeGroup.TransitionGroup.LabelType, nodePep.ExplicitMods)); } } } _builder = new BiblioSpecLiteBuilder(name, outputPath, inputFilesChosen, targetPeptidesChosen) { Action = libraryBuildAction, IncludeAmbiguousMatches = cbIncludeAmbiguousMatches.Checked, KeepRedundant = LibraryKeepRedundant, CutOffScore = cutOffScore, Authority = authority, Id = id }; } return true; }
private void btnExport_Click(object sender, EventArgs e) { string strReferenceFile = (string) comboBoxReferenceFile.SelectedItem; string strSaveFileName = string.Empty; if (!string.IsNullOrEmpty(_documentFilePath)) { strSaveFileName = Path.GetFileNameWithoutExtension(_documentFilePath); } if (!string.IsNullOrEmpty(strReferenceFile)) { strSaveFileName += Path.GetFileNameWithoutExtension(strReferenceFile); } strSaveFileName += ".ChorusRequest.xml"; // Not L10N strSaveFileName = strSaveFileName.Replace(' ', '_'); using (var saveFileDialog = new SaveFileDialog { FileName = strSaveFileName}) { if (saveFileDialog.ShowDialog(this) != DialogResult.OK || string.IsNullOrEmpty(saveFileDialog.FileName)) { return; } SpectrumFilter spectrumFilterData = new SpectrumFilter(Document, MsDataFileUri.Parse(strReferenceFile), null); using (var saver = new FileSaver(saveFileDialog.FileName)) { if (!saver.CanSave(this)) { return; } using (var stream = new StreamWriter(saver.SafeName)) { var xmlSerializer = new XmlSerializer(typeof(Model.Results.RemoteApi.GeneratedCode.ChromatogramRequestDocument)); xmlSerializer.Serialize(stream, spectrumFilterData.ToChromatogramRequestDocument()); } saver.Commit(); } } Close(); }
/// <summary> /// Export to a isolation scheme to a file or to memory. /// </summary> /// <param name="fileName">A file on disk to export to, or null to export to memory.</param> /// <param name="progressMonitor">progress monitor</param> public void Export(string fileName, IProgressMonitor progressMonitor) { if (ExportString == null) { StringWriter writer = new StringWriter(); if (HasHeaders) WriteHeaders(writer); if (IsolationScheme.WindowsPerScan.HasValue) WriteMultiplexedWindows(writer, IsolationScheme.WindowsPerScan.Value, progressMonitor); else WriteWindows(writer); ExportString = writer.ToString(); } if (fileName != null) { var saver = new FileSaver(fileName); if (!saver.CanSave()) throw new IOException(string.Format(Resources.AbstractDiaExporter_Export_Cannot_save_to__0__, fileName)); var writer = new StreamWriter(saver.SafeName); writer.Write(ExportString); writer.Close(); saver.Commit(); } }