Esempio n. 1
0
        private void AddRetentionTimePredictor(LibraryManager.BuildState buildState)
        {
            var predictorName = Helpers.GetUniqueName(buildState.LibrarySpec.Name, Settings.Default.RetentionTimeList.Select(rt => rt.Name).ToArray());

            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(predictorName, buildState.LibrarySpec.FilePath, false))
            {
                if (addPredictorDlg.ShowDialog(TopMostApplicationForm) == DialogResult.OK)
                {
                    Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                    Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                    NotificationContainer.ModifyDocument(Resources.LibraryBuildNotificationHandler_AddRetentionTimePredictor_Add_retention_time_predictor,
                                                         doc => doc.ChangeSettings(doc.Settings.ChangePeptidePrediction(predict =>
                                                                                                                        predict.ChangeRetentionTime(addPredictorDlg.Regression))));
                }
            }
        }
Esempio n. 2
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            // Allow updating the original modification
            if (LibrarySpec == null || !Equals(name, LibrarySpec.Name))
            {
                // But not any other existing modification
                foreach (LibrarySpec mod in _existing)
                {
                    if (Equals(name, mod.Name))
                    {
                        helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name);
                        return;
                    }
                }
            }

            String path = textPath.Text;

            if (!File.Exists(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__does_not_exist, path), Program.Name);
                textPath.Focus();
                return;
            }
            if (FileEx.IsDirectory(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_path__0__is_a_directory, path), Program.Name);
                textPath.Focus();
                return;
            }

            // Display an error message if the user is trying to add a BiblioSpec library,
            // and the library has the text "redundant" in the file name.
            if (path.EndsWith(BiblioSpecLiteSpec.EXT_REDUNDANT))
            {
                var message = TextUtil.LineSeparate(string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__appears_to_be_a_redundant_library, path),
                                                    Resources.EditLibraryDlg_OkDialog_Please_choose_a_non_redundant_library);
                MessageDlg.Show(this, string.Format(message, path));
                textPath.Focus();
                return;
            }

            var librarySpec = LibrarySpec.CreateFromPath(name, path);

            if (librarySpec == null)
            {
                MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path));
                textPath.Focus();
                return;
            }
            if (librarySpec is ChromatogramLibrarySpec)
            {
                using (var longWait = new LongWaitDlg {
                    Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library
                })
                {
                    Library lib = null;
                    try
                    {
                        try
                        {
                            longWait.PerformWork(this, 800,
                                                 monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor)));
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                            // Library failed to load
                        }
                        LibraryRetentionTimes libRts;
                        if (lib != null && lib.TryGetIrts(out libRts) &&
                            Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path))
                        {
                            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path))
                            {
                                switch (addPredictorDlg.ShowDialog(this))
                                {
                                case DialogResult.OK:
                                    Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                                    Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                                    Settings.Default.Save();
                                    break;

                                case DialogResult.No:
                                    break;

                                default:
                                    return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (null != lib)
                        {
                            foreach (var pooledStream in lib.ReadStreams)
                            {
                                pooledStream.CloseStream();
                            }
                        }
                    }
                }
            }

            _librarySpec = librarySpec;
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 3
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;

            if (!helper.ValidateNameTextBox(textName, out name))
            {
                return;
            }

            // Allow updating the original modification
            if (LibrarySpec == null || !Equals(name, LibrarySpec.Name))
            {
                // But not any other existing modification
                foreach (LibrarySpec mod in _existing)
                {
                    if (Equals(name, mod.Name))
                    {
                        helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name);
                        return;
                    }
                }
            }

            String path = textPath.Text;

            if (!ValidateLibraryPath(this, path))
            {
                textPath.Focus();
                return;
            }

            var librarySpec = LibrarySpec.CreateFromPath(name, path);

            if (librarySpec == null)
            {
                MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path));
                textPath.Focus();
                return;
            }
            librarySpec = librarySpec.ChangeUseExplicitPeakBounds(cbxUseExplicitPeakBounds.Checked);
            if (librarySpec is ChromatogramLibrarySpec)
            {
                using (var longWait = new LongWaitDlg {
                    Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library
                })
                {
                    Library lib = null;
                    try
                    {
                        try
                        {
                            longWait.PerformWork(this, 800,
                                                 monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor)));
                        }
// ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                            // Library failed to load
                        }
                        LibraryRetentionTimes libRts;
                        if (lib != null && lib.TryGetIrts(out libRts) &&
                            Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path))
                        {
                            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path, true))
                            {
                                switch (addPredictorDlg.ShowDialog(this))
                                {
                                case DialogResult.OK:
                                    Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                                    Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                                    break;

                                case DialogResult.No:
                                    break;

                                default:
                                    return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (null != lib)
                        {
                            foreach (var pooledStream in lib.ReadStreams)
                            {
                                pooledStream.CloseStream();
                            }
                        }
                    }
                }
            }

            _librarySpec = librarySpec;
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 4
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;
            if (!helper.ValidateNameTextBox(textName, out name))
                return;

            // Allow updating the original modification
            if (LibrarySpec == null || !Equals(name, LibrarySpec.Name))
            {
                // But not any other existing modification
                foreach (LibrarySpec mod in _existing)
                {
                    if (Equals(name, mod.Name))
                    {
                        helper.ShowTextBoxError(textName, Resources.EditLibraryDlg_OkDialog_The_library__0__already_exists, name);
                        return;
                    }
                }
            }

            String path = textPath.Text;

            if (!File.Exists(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__does_not_exist, path), Program.Name);
                textPath.Focus();
                return;
            }
            if (FileEx.IsDirectory(path))
            {
                MessageBox.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_path__0__is_a_directory, path), Program.Name);
                textPath.Focus();
                return;
            }

            // Display an error message if the user is trying to add a BiblioSpec library,
            // and the library has the text "redundant" in the file name.
            if (path.EndsWith(BiblioSpecLiteSpec.EXT_REDUNDANT))
            {
                var message = TextUtil.LineSeparate(string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__appears_to_be_a_redundant_library, path),
                                                    Resources.EditLibraryDlg_OkDialog_Please_choose_a_non_redundant_library);
                MessageDlg.Show(this, string.Format(message, path));
                textPath.Focus();
                return;
            }

            var librarySpec = LibrarySpec.CreateFromPath(name, path);
            if (librarySpec == null)
            {
                MessageDlg.Show(this, string.Format(Resources.EditLibraryDlg_OkDialog_The_file__0__is_not_a_supported_spectral_library_file_format, path));
                textPath.Focus();
                return;
            }
            if (librarySpec is ChromatogramLibrarySpec)
            {
                using (var longWait = new LongWaitDlg{ Text = Resources.EditLibraryDlg_OkDialog_Loading_chromatogram_library })
                {
                    Library lib = null;
                    try
                    {
                        try
                        {
                            longWait.PerformWork(this, 800,
                                monitor => lib = librarySpec.LoadLibrary(new DefaultFileLoadMonitor(monitor)));
                        }
            // ReSharper disable once EmptyGeneralCatchClause
                        catch
                        {
                            // Library failed to load
                        }
                        LibraryRetentionTimes libRts;
                        if (lib != null && lib.TryGetIrts(out libRts) &&
                            Settings.Default.RTScoreCalculatorList.All(calc => calc.PersistencePath != path))
                        {
                            using (var addPredictorDlg = new AddRetentionTimePredictorDlg(name, path))
                            {
                                switch (addPredictorDlg.ShowDialog(this))
                                {
                                    case DialogResult.OK:
                                        Settings.Default.RTScoreCalculatorList.Add(addPredictorDlg.Calculator);
                                        Settings.Default.RetentionTimeList.Add(addPredictorDlg.Regression);
                                        Settings.Default.Save();
                                        break;
                                    case DialogResult.No:
                                        break;
                                    default:
                                        return;
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (null != lib)
                        {
                            foreach (var pooledStream in lib.ReadStreams)
                            {
                                pooledStream.CloseStream();
                            }
                        }
                    }
                }
            }

            _librarySpec = librarySpec;
            DialogResult = DialogResult.OK;
            Close();
        }