Beispiel #1
0
        private void SetCurrentCellValue(DataGridView grid, object value)
        {
            IDataGridViewEditingControl editingControl = null;
            DataGridViewEditingControlShowingEventHandler onEditingControlShowing =
                (sender, args) =>
            {
                Assume.IsNull(editingControl);
                editingControl = args.Control as IDataGridViewEditingControl;
            };

            try
            {
                grid.EditingControlShowing += onEditingControlShowing;
                grid.BeginEdit(true);
                if (null != editingControl)
                {
                    editingControl.EditingControlFormattedValue = value;
                }
                else
                {
                    grid.CurrentCell.Value = value;
                }
            }
            finally
            {
                grid.EditingControlShowing -= onEditingControlShowing;
            }
        }
Beispiel #2
0
 public Target ChangeSequence(string sequence)
 {
     if (Equals(sequence, Sequence))
     {
         return(this);
     }
     Assume.IsNull(Molecule);
     return(new Target(sequence));
 }
Beispiel #3
0
        public bool GetChromatogram(ChromKey chromKey, out float[] times, out int[] scanIds, out float[] intensities, out float[] massErrors)
        {
            int keyIndex = -1;

            if (_chromKeyIndiceses != null)
            {
                var tolerance = (float)ChromTaskList.SrmDocument.Settings.TransitionSettings.Instrument.MzMatchTolerance;
                Assume.IsNull(chromKey.OptionalMinTime);
                Assume.IsNull(chromKey.OptionalMaxTime);
                Assume.IsTrue(0 == chromKey.IonMobilityValue);
                Assume.IsTrue(0 == chromKey.IonMobilityExtractionWidth);
                keyIndex = _chromKeyIndiceses.IndexOf(entry => entry.Key.CompareTolerant(chromKey, tolerance) == 0);
            }
            if (keyIndex == -1 || _chromKeyIndiceses == null)   // Keep ReSharper from complaining
            {
                times       = null;
                scanIds     = null;
                intensities = null;
                massErrors  = null;
                return(false);
            }
            ChromKeyIndices chromKeyIndices = _chromKeyIndiceses[keyIndex];
            var             chromGroupInfo  = _chromatogramCache.LoadChromatogramInfo(chromKeyIndices.GroupIndex);

            chromGroupInfo.ReadChromatogram(_chromatogramCache);
            var tranInfo = chromGroupInfo.GetTransitionInfo(chromKeyIndices.TranIndex);

            times = tranInfo.Times;
            if (times.Length == 0)
            {
                // Chorus returns zero length chromatogram to indicate that no spectra matched
                // the precursor filter.
                times       = null;
                scanIds     = null;
                intensities = null;
                massErrors  = null;
                return(false);
            }
            if (null != tranInfo.ScanIndexes)
            {
                scanIds = tranInfo.ScanIndexes[(short)chromKeyIndices.Key.Source];
            }
            else
            {
                scanIds = null;
            }
            intensities = tranInfo.Intensities;
            massErrors  = null;
            if (tranInfo.MassError10Xs != null)
            {
                massErrors = tranInfo.MassError10Xs.Select(m => m / 10.0f).ToArray();
            }
            CoalesceIntensities(ref times, ref scanIds, ref intensities, ref massErrors);
            return(true);
        }
        private bool TrySetValue(DataGridViewCell cell, string strValue)
        {
            IDataGridViewEditingControl editingControl = null;
            DataGridViewEditingControlShowingEventHandler onEditingControlShowing =
                (sender, args) =>
            {
                Assume.IsNull(editingControl);
                editingControl = args.Control as IDataGridViewEditingControl;
            };

            try
            {
                DataGridView.EditingControlShowing += onEditingControlShowing;
                DataGridView.CurrentCell            = cell;
                DataGridView.BeginEdit(true);
                if (null != editingControl)
                {
                    object convertedValue;
                    if (!TryConvertValue(strValue, DataGridView.CurrentCell.FormattedValueType, out convertedValue))
                    {
                        return(false);
                    }
                    editingControl.EditingControlFormattedValue = convertedValue;
                }
                else
                {
                    object convertedValue;
                    if (!TryConvertValue(strValue, DataGridView.CurrentCell.ValueType, out convertedValue))
                    {
                        return(false);
                    }
                    DataGridView.CurrentCell.Value = convertedValue;
                }
                if (!DataGridView.EndEdit())
                {
                    return(false);
                }
                return(true);
            }
            catch (Exception e)
            {
                Program.ReportException(e);
                return(false);
            }
            finally
            {
                DataGridView.EditingControlShowing -= onEditingControlShowing;
            }
        }
Beispiel #5
0
        private void Validate()
        {
            if (IsCustomIon)
            {
                Assume.IsNull(_fastaSequence);
                Assume.IsNull(Sequence);
                CustomIon.Validate();
            }
            else if (_fastaSequence == null)
            {
                if (Begin.HasValue || End.HasValue)
                {
                    throw new InvalidDataException(Resources.Peptide_Validate_Peptides_without_a_protein_sequence_do_not_support_the_start_and_end_properties);
                }

                // No FastaSequence checked the sequence, so check it here.
                FastaSequence.ValidateSequence(Sequence);
            }
            else
            {
                // Otherwise, validate the peptide sequence against the group sequence
                if (!Begin.HasValue || !End.HasValue)
                {
                    throw new InvalidDataException(Resources.Peptide_Validate_Peptides_from_protein_sequences_must_have_start_and_end_values);
                }
                if (0 > Begin.Value || End.Value > _fastaSequence.Sequence.Length)
                {
                    throw new InvalidDataException(Resources.Peptide_Validate_Peptide_sequence_exceeds_the_bounds_of_the_protein_sequence);
                }

                var j = 0;
                for (var i = Begin.Value; i < End.Value;)
                {
                    if (!Equals(Sequence[j++], _fastaSequence.Sequence[i++]))
                    {
                        string sequenceCheck = _fastaSequence.Sequence.Substring(Begin.Value, End.Value - Begin.Value);
                        throw new InvalidDataException(
                                  string.Format(Resources.Peptide_Validate_The_peptide_sequence__0__does_not_agree_with_the_protein_sequence__1__at__2__3__,
                                                Sequence, sequenceCheck, Begin.Value, End.Value));
                    }
                }
            }
            // CONSIDER: Validate missed cleavages some day?
        }
        public void LibraryBuildCompleteCallback(LibraryManager.BuildState buildState, bool success)
        {
            // Completion needs to happen on a separate thread because of the access to UI elements
            // In order to make sure the thread handle is released, it needs to call Application.ThreadExit()
            var threadComplete = BackgroundEventThreads.CreateThreadForAction(() =>
            {
                if (success && NotificationContainerForm.IsHandleCreated)
                {
                    // Only one form showing at a time
                    lock (this)
                    {
                        RemoveLibraryBuildNotification();

                        var frm                   = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                        frm.Activated            += notification_Activated;
                        frm.Shown                += notification_Shown;
                        frm.ExploreLibrary       += notification_ExploreLibrary;
                        frm.NotificationComplete += notification_NotificationComplete;
                        Point anchor              = NotificationAnchor;
                        frm.Left                  = anchor.X;
                        frm.Top                   = anchor.Y - frm.Height;
                        NotificationContainerForm.BeginInvoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                            {
                                MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                            }
                            if (buildState.IrtStandard != null && !buildState.IrtStandard.Name.Equals(IrtStandard.EMPTY.Name) && AddIrts(buildState))
                            {
                                AddRetentionTimePredictor(buildState);
                            }
                        }));
                        frm.Start();
                        Assume.IsNull(Interlocked.Exchange(ref _notification, frm));
                    }
                }
            });

            threadComplete.Name = @"Library Build Completion";
            threadComplete.Start();
        }
Beispiel #7
0
            public void Load()
            {
                string documentFilePath = _container.DocumentFilePath;

                if (documentFilePath == null)
                {
                    return;
                }

                var results = _docCurrent.Settings.MeasuredResults;

                if (results.IsLoaded)
                {
                    return;
                }

                Assume.IsNull(_loadMonitor);
                _loadMonitor = new MultiFileLoadMonitor(_manager, _container, results)
                {
                    HasUI = _manager.SupportAllGraphs
                };
                results.Load(_docCurrent, documentFilePath, _loadMonitor, _multiFileLoader, FinishLoad);
            }
Beispiel #8
0
        public void LibraryBuildCompleteCallback(LibraryManager.BuildState buildState, bool success)
        {
            // Completion needs to happen on a separate thread because of the access to UI elements
            // In order to make sure the thread handle is released, it needs to call Application.ThreadExit()
            var threadComplete = BackgroundEventThreads.CreateThreadForAction(() =>
            {
                if (success && NotificationContainerForm.IsHandleCreated)
                {
                    // Only one form showing at a time
                    lock (this)
                    {
                        RemoveLibraryBuildNotification();

                        var frm                   = new BuildLibraryNotification(buildState.LibrarySpec.Name);
                        frm.Activated            += notification_Activated;
                        frm.Shown                += notification_Shown;
                        frm.ExploreLibrary       += notification_ExploreLibrary;
                        frm.NotificationComplete += notification_NotificationComplete;
                        Point anchor              = NotificationAnchor;
                        frm.Left                  = anchor.X;
                        frm.Top                   = anchor.Y - frm.Height;
                        NotificationContainerForm.BeginInvoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(buildState.ExtraMessage))
                            {
                                MessageDlg.Show(TopMostApplicationForm, buildState.ExtraMessage);
                            }
                            if (buildState.IrtStandard != null && !buildState.IrtStandard.Name.Equals(IrtStandard.EMPTY.Name))
                            {
                                // Load library
                                Library lib = null;
                                using (var longWait = new LongWaitDlg {
                                    Text = Resources.LibraryBuildNotificationHandler_AddIrts_Loading_library
                                })
                                {
                                    var status = longWait.PerformWork(TopMostApplicationForm, 800, monitor =>
                                    {
                                        lib = NotificationContainer.LibraryManager.TryGetLibrary(buildState.LibrarySpec) ??
                                              NotificationContainer.LibraryManager.LoadLibrary(buildState.LibrarySpec, () => new DefaultFileLoadMonitor(monitor));
                                        foreach (var stream in lib.ReadStreams)
                                        {
                                            stream.CloseStream();
                                        }
                                    });
                                    if (status.IsCanceled)
                                    {
                                        lib = null;
                                    }
                                    if (status.IsError)
                                    {
                                        throw status.ErrorException;
                                    }
                                }
                                // Add iRTs to library
                                if (AddIrts(lib, buildState.LibrarySpec, buildState.IrtStandard, NotificationContainerForm, true))
                                {
                                    AddRetentionTimePredictor(buildState);
                                }
                            }
                        }));
                        frm.Start();
                        Assume.IsNull(Interlocked.Exchange(ref _notification, frm));
                    }
                }
            });

            threadComplete.Name = @"Library Build Completion";
            threadComplete.Start();
        }
Beispiel #9
0
        private void updateCheck_Complete(object sender, RunWorkerCompletedEventArgs e)
        {
            var exTrust = e.Result as TrustNotGrantedException;

            if (exTrust != null)
            {
                if (ShowUpgradeForm(AppDeployment.GetVersionFromUpdateLocation(), false, true))
                {
                    AppDeployment.OpenInstallLink(ParentWindow);
                }
                return;
            }
            var ex = e.Result as Exception;

            if (ex != null)
            {
                // Show an error message box to allow a user to inspect the exception stack trace
                MessageDlg.ShowWithException(ParentWindow,
                                             Resources.UpgradeManager_updateCheck_Complete_Failed_attempting_to_check_for_an_upgrade_, ex);
                // Show no upgrade found message to allow a user to turn off or on this checking
                ShowUpgradeForm(null, false, false);
                return;
            }
            _updateInfo = e.Result as UpdateCheckDetails;
            if (_updateInfo != null && _updateInfo.UpdateAvailable)
            {
                if (!ShowUpgradeForm(_updateInfo.AvailableVersion, true, true))
                {
                    return;
                }

                using (var longWaitUpdate = new LongWaitDlg
                {
                    Text = string.Format(Resources.UpgradeManager_updateCheck_Complete_Upgrading__0_, Program.Name),
                    Message = GetProgressMessage(0, _updateInfo.UpdateSizeBytes ?? 0),
                    ProgressValue = 0
                })
                {
                    AutoResetEvent endUpdateEvent = null;
                    try
                    {
                        lock (this)
                        {
                            Assume.IsNull(_endUpdateEvent);
                            _endUpdateEvent = endUpdateEvent = new AutoResetEvent(false);
                        }

                        longWaitUpdate.PerformWork(ParentWindow, 500, broker =>
                        {
                            BeginUpdate(broker);
                            endUpdateEvent.WaitOne();
                            broker.ProgressValue = 100;
                        });
                    }
                    finally
                    {
                        lock (this)
                        {
                            if (endUpdateEvent != null)
                            {
                                _endUpdateEvent = null;
                            }
                        }
                        endUpdateEvent?.Dispose();
                    }
                }
                if (_completeArgs == null || _completeArgs.Cancelled)
                {
                    return;
                }

                if (_completeArgs.Error != null)
                {
                    MessageDlg.ShowWithException(ParentWindow,
                                                 Resources.UpgradeManager_updateCheck_Complete_Failed_attempting_to_upgrade_, _completeArgs.Error);
                    if (ShowUpgradeForm(null, false, true))
                    {
                        AppDeployment.OpenInstallLink(ParentWindow);
                    }
                    return;
                }

                AppDeployment.Restart();
            }
            else if (!_startup)
            {
                ShowUpgradeForm(null, false, false);
            }
        }
Beispiel #10
0
        public void PerformWork(Control parent, int delayMillis, Action <ILongWaitBroker> performWork)
        {
            _startTime  = DateTime.UtcNow; // Said to be 117x faster than Now and this is for a delta
            _parentForm = parent;
            ManualResetEvent completionEvent = null;

            try
            {
                lock (this)
                {
                    Assume.IsNull(_completionEvent);
                    _completionEvent = completionEvent = new ManualResetEvent(false);
                }
//                Action<Action<ILongWaitBroker>> runner = RunWork;
//                _result = runner.BeginInvoke(performWork, runner.EndInvoke, null);
                ActionUtil.RunAsync(() => RunWork(performWork));

                // Wait as long as the caller wants before showing the progress
                // animation to the user.
//                _result.AsyncWaitHandle.WaitOne(delayMillis);

                // Return without notifying the user, if the operation completed
                // before the wait expired.
//                if (_result.IsCompleted)
                if (completionEvent.WaitOne(delayMillis))
                {
                    return;
                }

                progressBar.Value = Math.Max(0, _progressValue);
                if (_message != null)
                {
                    labelMessage.Text = _message;
                }

                ShowDialog(parent);
            }
            finally
            {
                var x = _exception;

                // Get rid of this window before leaving this function
                Dispose();
                lock (this)
                {
                    if (completionEvent != null)
                    {
                        _completionEvent = null;
                    }
                }
                completionEvent?.Dispose();

                if (IsCanceled && null != x)
                {
                    if (x is OperationCanceledException || x.InnerException is OperationCanceledException)
                    {
                        x = null;
                    }
                }

                if (x != null)
                {
                    Helpers.WrapAndThrowException(x);
                }
            }
        }