From e45f46804964a3dcf6ec43ac0d95f351e2a5acff Mon Sep 17 00:00:00 2001 From: Brian Pratt Date: Tue, 8 Oct 2024 11:04:44 -0700 Subject: [PATCH 1/2] Transition settings TransitionFilter.Equals was not considering its _smallMoleculeFragmentAdducts member, which caused UI problems when that was the only value being edited (would not save) (#3185) --- pwiz_tools/Skyline/Model/DocSettings/TransitionSettings.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pwiz_tools/Skyline/Model/DocSettings/TransitionSettings.cs b/pwiz_tools/Skyline/Model/DocSettings/TransitionSettings.cs index 80d9c1a0b9..e74e43cdf9 100644 --- a/pwiz_tools/Skyline/Model/DocSettings/TransitionSettings.cs +++ b/pwiz_tools/Skyline/Model/DocSettings/TransitionSettings.cs @@ -1180,6 +1180,7 @@ public bool Equals(TransitionFilter obj) ArrayUtil.EqualsDeep(obj._peptideProductCharges, _peptideProductCharges) && ArrayUtil.EqualsDeep(obj._peptideIonTypes, _peptideIonTypes) && ArrayUtil.EqualsDeep(obj._smallMoleculePrecursorAdducts, _smallMoleculePrecursorAdducts) && + ArrayUtil.EqualsDeep(obj._smallMoleculeFragmentAdducts, _smallMoleculeFragmentAdducts) && ArrayUtil.EqualsDeep(obj._smallMoleculeIonTypes, _smallMoleculeIonTypes) && Equals(obj.FragmentRangeFirst, FragmentRangeFirst) && Equals(obj.FragmentRangeLast, FragmentRangeLast) && @@ -1205,6 +1206,7 @@ public override int GetHashCode() result = (result * 397) ^ _peptideProductCharges.GetHashCodeDeep(); result = (result * 397) ^ _peptideIonTypes.GetHashCodeDeep(); result = (result * 397) ^ _smallMoleculePrecursorAdducts.GetHashCodeDeep(); + result = (result * 397) ^ _smallMoleculeFragmentAdducts.GetHashCodeDeep(); result = (result * 397) ^ _smallMoleculeIonTypes.GetHashCodeDeep(); result = (result * 397) ^ FragmentRangeFirst.GetHashCode(); result = (result*397) ^ FragmentRangeLast.GetHashCode(); From 0f98e37e37d31c1e99c2e6f3dae1b6344da7ee10 Mon Sep 17 00:00:00 2001 From: Brian Pratt Date: Tue, 8 Oct 2024 15:41:16 -0700 Subject: [PATCH 2/2] Replace uses of Trace.Trace* with new wrapper methods Replace most uses of Trace.* with wrapper methods e.g. Messages.WriteAsyncDebugMessage(). Doing this because a bare call to Trace.TraceWarning, Trace.TraceInformation, or Trace.TraceError looks too much like accidentally retained debug code. Added custom code inspections to check for proper use of Trace in Skyline code. --- .../Common/DataBinding/AbstractViewContext.cs | 2 +- .../DataBinding/Controls/Editor/FilterTab.cs | 4 +- .../DataBinding/Internal/BindingListView.cs | 3 +- .../Common/DataBinding/Internal/Pivoter.cs | 4 +- .../Shared/Common/Graph/CurveDataHandler.cs | 4 +- .../Shared/CommonUtil/CommonUtil.csproj | 7 +-- .../CommonUtil/SystemUtil/Caching/Receiver.cs | 3 +- .../CommonUtil/SystemUtil/CommonActionUtil.cs | 3 +- .../Shared/CommonUtil/SystemUtil/Messages.cs | 45 +++++++++++++++++++ .../Shared/ProteomeDb/API/ProteinMatcher.cs | 5 ++- .../zedgraph/ZedGraph/ZedGraphControl.cs | 2 +- .../Skyline/Alerts/ReportShutdownDlg.cs | 4 +- .../Model/Databinding/ReportSpecConverter.cs | 6 +-- .../Model/Lib/ChromLib/ChromatogramLibrary.cs | 5 +-- .../Skyline/Model/Lib/EncylopeDiaLibrary.cs | 3 +- .../Skyline/Model/Results/PeptideChromData.cs | 10 ++--- .../Model/Results/SpectraChromDataProvider.cs | 5 +-- pwiz_tools/Skyline/Program.cs | 6 +-- pwiz_tools/Skyline/Test/CodeInspectionTest.cs | 20 +++++++++ .../Skyline/Util/TraceWarningListener.cs | 3 +- pwiz_tools/Skyline/Util/UtilIO.cs | 4 +- 21 files changed, 106 insertions(+), 42 deletions(-) create mode 100644 pwiz_tools/Shared/CommonUtil/SystemUtil/Messages.cs diff --git a/pwiz_tools/Shared/Common/DataBinding/AbstractViewContext.cs b/pwiz_tools/Shared/Common/DataBinding/AbstractViewContext.cs index 16f55c88c8..07053b529b 100644 --- a/pwiz_tools/Shared/Common/DataBinding/AbstractViewContext.cs +++ b/pwiz_tools/Shared/Common/DataBinding/AbstractViewContext.cs @@ -498,7 +498,7 @@ protected virtual DataGridViewColumn CreateCustomColumn(PropertyDescriptor prope } catch (Exception exception) { - Trace.TraceError(@"Exception constructing column of type {0}:{1}", columnTypeAttribute.ColumnType, exception); + Messages.WriteAsyncDebugMessage(@"Exception constructing column of type {0}:{1}", columnTypeAttribute.ColumnType, exception); return null; } } diff --git a/pwiz_tools/Shared/Common/DataBinding/Controls/Editor/FilterTab.cs b/pwiz_tools/Shared/Common/DataBinding/Controls/Editor/FilterTab.cs index 98ad815d86..9f9561aa14 100644 --- a/pwiz_tools/Shared/Common/DataBinding/Controls/Editor/FilterTab.cs +++ b/pwiz_tools/Shared/Common/DataBinding/Controls/Editor/FilterTab.cs @@ -18,11 +18,11 @@ */ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.Linq; using System.Windows.Forms; using pwiz.Common.Properties; +using pwiz.Common.SystemUtil; namespace pwiz.Common.DataBinding.Controls.Editor { @@ -301,7 +301,7 @@ private void DataGridViewFilterOnCellEnter(object sender, DataGridViewCellEventA private void dataGridViewFilter_DataError(object sender, DataGridViewDataErrorEventArgs e) { - Trace.TraceError(@"DataGridViewFilterOnDataError:{0}", e.Exception); + Messages.WriteAsyncDebugMessage(@"DataGridViewFilterOnDataError:{0}", e.Exception); } protected override void OnLoad(EventArgs e) diff --git a/pwiz_tools/Shared/Common/DataBinding/Internal/BindingListView.cs b/pwiz_tools/Shared/Common/DataBinding/Internal/BindingListView.cs index a30f81396c..149b5fee55 100644 --- a/pwiz_tools/Shared/Common/DataBinding/Internal/BindingListView.cs +++ b/pwiz_tools/Shared/Common/DataBinding/Internal/BindingListView.cs @@ -28,6 +28,7 @@ using pwiz.Common.DataBinding.Clustering; using pwiz.Common.DataBinding.Controls; using pwiz.Common.DataBinding.Layout; +using pwiz.Common.SystemUtil; namespace pwiz.Common.DataBinding.Internal { @@ -533,7 +534,7 @@ public void Dispose() public void OnUnhandledException(Exception exception) { - Trace.TraceError(@"BindingListView unhandled exception {0}", exception); + Messages.WriteAsyncDebugMessage(@"BindingListView unhandled exception {0}", exception); var unhandledExceptionEvent = UnhandledExceptionEvent; if (null != unhandledExceptionEvent) { diff --git a/pwiz_tools/Shared/Common/DataBinding/Internal/Pivoter.cs b/pwiz_tools/Shared/Common/DataBinding/Internal/Pivoter.cs index 807d37178a..04b197f9dd 100644 --- a/pwiz_tools/Shared/Common/DataBinding/Internal/Pivoter.cs +++ b/pwiz_tools/Shared/Common/DataBinding/Internal/Pivoter.cs @@ -19,10 +19,10 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Threading; using pwiz.Common.Collections; +using pwiz.Common.SystemUtil; namespace pwiz.Common.DataBinding.Internal { @@ -261,7 +261,7 @@ IDictionary>, List> allR } else { - Trace.TraceWarning(@"Unable to pivot on column {0} because it is already pivoted.", pivotColumn.PropertyPath); + Messages.WriteAsyncDebugMessage(@"Unable to pivot on column {0} because it is already pivoted.", pivotColumn.PropertyPath); // N.B. see TraceWarningListener for output details } } var pivotOnKey = PivotKey.GetPivotKey(allPivotKeys, pivotOnKeyValues); diff --git a/pwiz_tools/Shared/Common/Graph/CurveDataHandler.cs b/pwiz_tools/Shared/Common/Graph/CurveDataHandler.cs index b6aaead083..5273ef53d6 100644 --- a/pwiz_tools/Shared/Common/Graph/CurveDataHandler.cs +++ b/pwiz_tools/Shared/Common/Graph/CurveDataHandler.cs @@ -18,8 +18,8 @@ */ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; +using pwiz.Common.SystemUtil; using ZedGraph; namespace pwiz.Common.Graph @@ -232,7 +232,7 @@ protected virtual Func ValueOfPointFuncForAxis(DataFrameBuild { return point => point.Y; } - Trace.TraceError(@"Could not determine type of axis {0}", axis); + Messages.WriteAsyncDebugMessage(@"Could not determine type of axis {0}", axis); return null; } diff --git a/pwiz_tools/Shared/CommonUtil/CommonUtil.csproj b/pwiz_tools/Shared/CommonUtil/CommonUtil.csproj index a4599a23b9..ba3dd31c06 100644 --- a/pwiz_tools/Shared/CommonUtil/CommonUtil.csproj +++ b/pwiz_tools/Shared/CommonUtil/CommonUtil.csproj @@ -170,6 +170,7 @@ Form + @@ -270,7 +271,7 @@ Resources.Designer.cs Designer - + GeneralTerms.resx Designer @@ -278,12 +279,12 @@ GeneralTerms.resx Designer - + ResXFileCodeGenerator GeneralTerms.Designer.cs Designer - + Images.resx Designer diff --git a/pwiz_tools/Shared/CommonUtil/SystemUtil/Caching/Receiver.cs b/pwiz_tools/Shared/CommonUtil/SystemUtil/Caching/Receiver.cs index a99cbd7e31..7cde3d76a3 100644 --- a/pwiz_tools/Shared/CommonUtil/SystemUtil/Caching/Receiver.cs +++ b/pwiz_tools/Shared/CommonUtil/SystemUtil/Caching/Receiver.cs @@ -17,7 +17,6 @@ * limitations under the License. */ using System; -using System.Diagnostics; using System.Windows.Forms; namespace pwiz.Common.SystemUtil.Caching @@ -135,7 +134,7 @@ public void Dispose() _workOrder = null; if (OwnerControl != null) { - Trace.TraceInformation("CalculatedValueListener destroyed: {0}", Producer.ValueType); + Messages.WriteAsyncDebugMessage("CalculatedValueListener destroyed: {0}", Producer.ValueType); // N.B. see TraceWarningListener for output details OwnerControl.HandleDestroyed -= OwnerControlHandleDestroyed; OwnerControl = null; } diff --git a/pwiz_tools/Shared/CommonUtil/SystemUtil/CommonActionUtil.cs b/pwiz_tools/Shared/CommonUtil/SystemUtil/CommonActionUtil.cs index a2de073279..feb0476829 100644 --- a/pwiz_tools/Shared/CommonUtil/SystemUtil/CommonActionUtil.cs +++ b/pwiz_tools/Shared/CommonUtil/SystemUtil/CommonActionUtil.cs @@ -17,7 +17,6 @@ * limitations under the License. */ using System; -using System.Diagnostics; using System.Threading; using System.Windows.Forms; @@ -53,7 +52,7 @@ public static void HandleException(Exception exception) { return; } - Trace.TraceWarning(@"Unhandled Exception: {0}", exception); + Messages.WriteAsyncDebugMessage(@"Unhandled Exception: {0}", exception); // N.B. see TraceWarningListener for output details } public static bool SafeBeginInvoke(Control control, Action action) diff --git a/pwiz_tools/Shared/CommonUtil/SystemUtil/Messages.cs b/pwiz_tools/Shared/CommonUtil/SystemUtil/Messages.cs new file mode 100644 index 0000000000..3a5b391774 --- /dev/null +++ b/pwiz_tools/Shared/CommonUtil/SystemUtil/Messages.cs @@ -0,0 +1,45 @@ +/* + * Original author: Brian Pratt , + * MacCoss Lab, Department of Genome Sciences, UW + * + * Copyright 2024 University of Washington - Seattle, WA + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System.Diagnostics; + +namespace pwiz.Common.SystemUtil +{ + /// + /// Provides a mechanism for showing non-blocking messages. + /// + /// Really just a wrapper for Trace, which we don't want to call + /// directly as it looks too much like leftover debug code. + /// + /// + public static class Messages + { + public static void WriteAsyncDebugMessage(string message, params object[] args) + { + Trace.TraceInformation(message, args); + } + + public static void WriteAsyncUserMessage(string message, params object[] args) + { + // For Skyline UI, the TraceWarningListener class causes these messages to appear in the + // Immediate Window, for commandline they appear in the console. + Trace.TraceWarning(message, args); + } + } +} diff --git a/pwiz_tools/Shared/ProteomeDb/API/ProteinMatcher.cs b/pwiz_tools/Shared/ProteomeDb/API/ProteinMatcher.cs index b89cb19da4..8705e073f4 100644 --- a/pwiz_tools/Shared/ProteomeDb/API/ProteinMatcher.cs +++ b/pwiz_tools/Shared/ProteomeDb/API/ProteinMatcher.cs @@ -18,13 +18,14 @@ */ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Threading; using NHibernate; using pwiz.ProteomeDatabase.DataModel; using pwiz.ProteomeDatabase.Util; using pwiz.Common.Collections; +using pwiz.Common.SystemUtil; + namespace pwiz.ProteomeDatabase.API { /// @@ -252,7 +253,7 @@ private void ExecuteBackground() { return; } - Trace.TraceError(@"Unhandled exception: {0}", exception); + Messages.WriteAsyncDebugMessage(@"Unhandled exception: {0}", exception); } } diff --git a/pwiz_tools/Shared/zedgraph/ZedGraph/ZedGraphControl.cs b/pwiz_tools/Shared/zedgraph/ZedGraph/ZedGraphControl.cs index b9a207fa0e..62fd85a016 100644 --- a/pwiz_tools/Shared/zedgraph/ZedGraph/ZedGraphControl.cs +++ b/pwiz_tools/Shared/zedgraph/ZedGraph/ZedGraphControl.cs @@ -622,7 +622,7 @@ protected override void OnPaint( PaintEventArgs e ) } catch (Exception exception) { - Trace.TraceWarning(@"Error when painting a zedGraph:{0}", exception); + Trace.TraceInformation(@"Error when painting a zedGraph:{0}", exception); // N.B. see TraceWarningListener for output details } } diff --git a/pwiz_tools/Skyline/Alerts/ReportShutdownDlg.cs b/pwiz_tools/Skyline/Alerts/ReportShutdownDlg.cs index 965e881b97..0cd45412fa 100644 --- a/pwiz_tools/Skyline/Alerts/ReportShutdownDlg.cs +++ b/pwiz_tools/Skyline/Alerts/ReportShutdownDlg.cs @@ -18,12 +18,12 @@ */ using System; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; +using pwiz.Common.SystemUtil; using pwiz.Skyline.Util; using pwiz.Skyline.Util.Extensions; @@ -75,7 +75,7 @@ public static void SaveExceptionFile(Exception exception, bool forced = false) if (!forced) { - Trace.TraceError(exceptionInfo); + Messages.WriteAsyncDebugMessage(exceptionInfo); Console.WriteLine(exceptionInfo); } diff --git a/pwiz_tools/Skyline/Model/Databinding/ReportSpecConverter.cs b/pwiz_tools/Skyline/Model/Databinding/ReportSpecConverter.cs index 1ba402151e..ab4a70de73 100644 --- a/pwiz_tools/Skyline/Model/Databinding/ReportSpecConverter.cs +++ b/pwiz_tools/Skyline/Model/Databinding/ReportSpecConverter.cs @@ -19,10 +19,10 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.Diagnostics; using System.Linq; using System.Reflection; using pwiz.Common.DataBinding; +using pwiz.Common.SystemUtil; using pwiz.Skyline.Model.DocSettings; using pwiz.Skyline.Model.Hibernate; @@ -270,7 +270,7 @@ private ColumnSpec ConvertReportColumn(ReportColumn reportColumn) oldCaption = null; if (null == propertyPath) { - Trace.TraceWarning(@"Unable to parse ratio property {0}", part); + Messages.WriteAsyncDebugMessage(@"Unable to parse ratio property {0}", part); propertyPath = PropertyPath.Root.Property(part); } } @@ -283,7 +283,7 @@ private ColumnSpec ConvertReportColumn(ReportColumn reportColumn) PropertyInfo property = component.GetProperty(part); if (null == property) { - Trace.TraceWarning(@"Could not find property {0}", part); + Messages.WriteAsyncDebugMessage(@"Could not find property {0}", part); continue; } propertyPath = PropertyPath.Root.Property(part); diff --git a/pwiz_tools/Skyline/Model/Lib/ChromLib/ChromatogramLibrary.cs b/pwiz_tools/Skyline/Model/Lib/ChromLib/ChromatogramLibrary.cs index 0959a07334..3ad4ea7d20 100644 --- a/pwiz_tools/Skyline/Model/Lib/ChromLib/ChromatogramLibrary.cs +++ b/pwiz_tools/Skyline/Model/Lib/ChromLib/ChromatogramLibrary.cs @@ -18,7 +18,6 @@ */ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; @@ -571,7 +570,7 @@ private bool LoadLibraryFromDatabase(ILoadMonitor loader) } catch (Exception e) { - Trace.TraceWarning(ChromLibResources.ChromatogramLibrary_LoadLibraryFromDatabase_Error_loading_chromatogram_library__0_, e); + Messages.WriteAsyncUserMessage(ChromLibResources.ChromatogramLibrary_LoadLibraryFromDatabase_Error_loading_chromatogram_library__0_, e); return false; } } @@ -692,7 +691,7 @@ private bool LoadFromCache(ILoadMonitor loadMonitor, ProgressStatus status) } catch (Exception exception) { - Trace.TraceWarning(ChromLibResources.ChromatogramLibrary_LoadFromCache_Exception_reading_cache__0_, exception); + Messages.WriteAsyncUserMessage(ChromLibResources.ChromatogramLibrary_LoadFromCache_Exception_reading_cache__0_, exception); return false; } } diff --git a/pwiz_tools/Skyline/Model/Lib/EncylopeDiaLibrary.cs b/pwiz_tools/Skyline/Model/Lib/EncylopeDiaLibrary.cs index 9071a2fd9f..a8858f1ecc 100644 --- a/pwiz_tools/Skyline/Model/Lib/EncylopeDiaLibrary.cs +++ b/pwiz_tools/Skyline/Model/Lib/EncylopeDiaLibrary.cs @@ -21,7 +21,6 @@ using System.Data; using System.Data.Common; using System.Data.SQLite; -using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -466,7 +465,7 @@ private bool LoadFromCache(ILoadMonitor loader) } catch (Exception exception) { - Trace.TraceWarning(@"Exception loading cache: {0}", exception); + Messages.WriteAsyncDebugMessage(@"Exception loading cache: {0}", exception); return false; } } diff --git a/pwiz_tools/Skyline/Model/Results/PeptideChromData.cs b/pwiz_tools/Skyline/Model/Results/PeptideChromData.cs index ce445cd124..db41bbc2b6 100644 --- a/pwiz_tools/Skyline/Model/Results/PeptideChromData.cs +++ b/pwiz_tools/Skyline/Model/Results/PeptideChromData.cs @@ -19,11 +19,11 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics; using System.Drawing; using System.Linq; using pwiz.Common.Collections; using pwiz.Common.PeakFinding; +using pwiz.Common.SystemUtil; using pwiz.Skyline.Model.DocSettings; using pwiz.Skyline.Model.Results.Scoring; using pwiz.Skyline.Util; @@ -959,11 +959,11 @@ public bool FilterByRetentionTime() string precursorText = GetTextForNode(NodePep, dataSet.NodeGroup, null); if (dataSet.MinRawTime > dataSet.MaxRawTime) { - Trace.TraceWarning(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_empty_chromatograms_for__0_, precursorText); + Messages.WriteAsyncUserMessage(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_empty_chromatograms_for__0_, precursorText); } else { - Trace.TraceWarning(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_chromatograms_for___0___because_the_explicit_retention_time__1__is_not_between__2__and__3_, + Messages.WriteAsyncUserMessage(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_chromatograms_for___0___because_the_explicit_retention_time__1__is_not_between__2__and__3_, precursorText, explicitRT, dataSet.MinRawTime, dataSet.MaxRawTime); } DataSets.RemoveAt(i); @@ -978,11 +978,11 @@ public bool FilterByRetentionTime() string transitionText = GetTextForNode(NodePep, dataSet.NodeGroup, chrom.DocNode); if (!chrom.Times.Any()) { - Trace.TraceWarning(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_empty_chromatograms_for__0_, transitionText); + Messages.WriteAsyncUserMessage(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_empty_chromatograms_for__0_, transitionText); } else { - Trace.TraceWarning(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_chromatograms_for___0___because_the_explicit_retention_time__1__is_not_between__2__and__3_, + Messages.WriteAsyncUserMessage(ResultsResources.PeptideChromDataSets_FilterByRetentionTime_Discarding_chromatograms_for___0___because_the_explicit_retention_time__1__is_not_between__2__and__3_, transitionText, explicitRT, chrom.Times.First(), chrom.Times.Last()); } dataSet.Chromatograms.RemoveAt(j); diff --git a/pwiz_tools/Skyline/Model/Results/SpectraChromDataProvider.cs b/pwiz_tools/Skyline/Model/Results/SpectraChromDataProvider.cs index 21d4e93cb5..aaf413ace4 100644 --- a/pwiz_tools/Skyline/Model/Results/SpectraChromDataProvider.cs +++ b/pwiz_tools/Skyline/Model/Results/SpectraChromDataProvider.cs @@ -19,7 +19,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; @@ -1597,7 +1596,7 @@ public IonMobilityValue IonMobilityFromCCS(double ccs, double mz, int charge, ob var im = _dataFile.IonMobilityFromCCS(ccs, mz, charge); if (!im.HasValue) { - Trace.TraceWarning(ResultsResources.DataFileInstrumentInfo_IonMobilityFromCCS_no_conversion, obj, ccs, mz, charge); + Messages.WriteAsyncUserMessage(ResultsResources.DataFileInstrumentInfo_IonMobilityFromCCS_no_conversion, obj, ccs, mz, charge); } return im; } @@ -1606,7 +1605,7 @@ public double CCSFromIonMobility(IonMobilityValue im, double mz, int charge, obj var ccs = _dataFile.CCSFromIonMobilityValue(im, mz, charge); if (double.IsNaN(ccs)) { - Trace.TraceWarning(ResultsResources.DataFileInstrumentInfo_CCSFromIonMobility_no_conversion, obj, im, mz, charge); + Messages.WriteAsyncUserMessage(ResultsResources.DataFileInstrumentInfo_CCSFromIonMobility_no_conversion, obj, im, mz, charge); } return ccs; } diff --git a/pwiz_tools/Skyline/Program.cs b/pwiz_tools/Skyline/Program.cs index f72d86b24c..98d6b33bb2 100644 --- a/pwiz_tools/Skyline/Program.cs +++ b/pwiz_tools/Skyline/Program.cs @@ -364,7 +364,7 @@ private static void SendAnalyticsHitAsync() } catch (Exception ex) { - Trace.TraceInformation(@"Exception sending analytics hit {0}", ex); + Messages.WriteAsyncDebugMessage(@"Exception sending analytics hit {0}", ex); } }); } @@ -616,7 +616,7 @@ public static void ReportException(Exception exception) } catch (Exception exception2) { - Trace.TraceError(@"Exception in ReportException: {0}", exception2); + Messages.WriteAsyncDebugMessage(@"Exception in ReportException: {0}", exception2); } } @@ -628,7 +628,7 @@ private static void ThreadExceptionEventHandler(Object sender, ThreadExceptionEv return; } - Trace.TraceError(@"Unhandled exception on UI thread: {0}", e.Exception); + Messages.WriteAsyncDebugMessage(@"Unhandled exception on UI thread: {0}", e.Exception); var stackTrace = new StackTrace(1, true); ReportExceptionUI(e.Exception, stackTrace); } diff --git a/pwiz_tools/Skyline/Test/CodeInspectionTest.cs b/pwiz_tools/Skyline/Test/CodeInspectionTest.cs index ad6b0955ec..721ebdb739 100644 --- a/pwiz_tools/Skyline/Test/CodeInspectionTest.cs +++ b/pwiz_tools/Skyline/Test/CodeInspectionTest.cs @@ -95,6 +95,26 @@ public void CodeInspection() true, // Pattern is a regular expression @"This appears to be temporary debugging code that should not be checked in. Or perhaps you meant to use PauseForManualTutorialStep()?"); // Explanation for prohibition, appears in report + // Looking for forgotten SourceLevel.Information use that writes debug messages to console/ImmediateWindow + AddTextInspection(@"TraceWarningListener.cs", // Examine files with this mask + Inspection.Forbidden, // This is a test for things that should NOT be in such files + Level.Error, // Any failure is treated as an error, and overall test fails + null, // Only these files should contain this + string.Empty, // No file content required for inspection + @"SourceLevels.Information", // Forbidden pattern + false, // Pattern is not a regular expression + @"This appears to be temporary debugging code that should not be checked in. Normally we don't want users to see this level of Trace messages."); // Explanation for prohibition, appears in report + + // Looking for bare use of Trace calls that should be UserMessage or DebugMessage calls + AddTextInspection(@"*.cs", // Examine files with this mask + Inspection.Forbidden, // This is a test for things that should NOT be in such files + Level.Error, // Any failure is treated as an error, and overall test fails + NonSkylineDirectories().Append(@"Messages.cs").ToArray(), // Only these files should contain this + string.Empty, // No file content required for inspection + @"Trace.Trace", // Forbidden pattern + false, // Pattern is not a regular expression + @"Trace should not be used directly. The Messages class is the proper way to produce non-blocking user-facing messages, and permanent dev-facing messages."); // Explanation for prohibition, appears in report + // Looking for forgotten "RunPerfTests=true" statements that will force running possibly unintended tests AddTextInspection(@"*.cs", // Examine files with this mask Inspection.Forbidden, // This is a test for things that should NOT be in such files diff --git a/pwiz_tools/Skyline/Util/TraceWarningListener.cs b/pwiz_tools/Skyline/Util/TraceWarningListener.cs index 329868a4b4..38a1b5c7e6 100644 --- a/pwiz_tools/Skyline/Util/TraceWarningListener.cs +++ b/pwiz_tools/Skyline/Util/TraceWarningListener.cs @@ -26,7 +26,8 @@ public class TraceWarningListener : TraceListener private TextWriter _textWriter; public TraceWarningListener(TextWriter textWriter) { - Filter = new EventTypeFilter(SourceLevels.Warning); + // N.B. if you want to see DebugMessage.AsynchWrite messages too, add .Information to the flags here + Filter = new EventTypeFilter(SourceLevels.Warning); _textWriter = textWriter; } diff --git a/pwiz_tools/Skyline/Util/UtilIO.cs b/pwiz_tools/Skyline/Util/UtilIO.cs index 54cf1ad658..e24e53bf2f 100644 --- a/pwiz_tools/Skyline/Util/UtilIO.cs +++ b/pwiz_tools/Skyline/Util/UtilIO.cs @@ -1365,7 +1365,7 @@ public void Dispose() } catch (Exception e) { - Trace.TraceWarning(@"Exception in FileSaver.Dispose: {0}", e); + Messages.WriteAsyncDebugMessage(@"Exception in FileSaver.Dispose: {0}", e); } _stream = null; } @@ -1381,7 +1381,7 @@ public void Dispose() } catch (Exception e) { - Trace.TraceWarning(@"Exception in FileSaver.Dispose: {0}", e); + Messages.WriteAsyncDebugMessage(@"Exception in FileSaver.Dispose: {0}", e); } // Make sure any further calls to Dispose() do nothing. SafeName = null;