From c1cf87df21f5a118d9e4af02d8cdd939897620a7 Mon Sep 17 00:00:00 2001 From: Stefan Kert Date: Sat, 27 Apr 2019 07:54:55 +0200 Subject: [PATCH] Fixed many compilation warnings --- src/BuildVision.Common/AppVersionInfo.cs | 2 + src/BuildVision.Common/BindableBase.cs | 8 +- .../CustomStringFormatProvider.cs | 2 + .../Diagnostics/DiagnosticsClient.cs | 27 ++++-- .../Extensions/DateTimeExtensions.cs | 3 + src/BuildVision.Common/FilePathHelper.cs | 2 +- src/BuildVision.Common/GithubHelper.cs | 11 +-- .../PropertyColumnSorter.cs | 6 ++ src/BuildVision.Common/RelayCommand.cs | 5 +- src/BuildVision.Common/SettingsBase.cs | 2 + src/BuildVision.Common/VSVersion.cs | 2 + .../Enums/BuildActions.cs | 10 +-- .../Enums/BuildScopes.cs | 8 +- .../Exceptions/PropertyNotFoundException.cs | 15 ++-- .../Models/BuildProjectContextEntry.cs | 4 +- src/BuildVision.Contracts/Models/ErrorItem.cs | 4 + .../Models/IBuildInformationModel.cs | 4 +- .../Models/IProjectItem.cs | 6 +- .../Providers/IBuildInformationProvider.cs | 6 +- .../Sevices/ITaskBarInfoService.cs | 2 +- .../Attributes/DisplayStringAttribute.cs | 2 + .../Components/ErrorsGrid.xaml.cs | 2 + .../Components/ProjectGrid.xaml.cs | 4 + .../Components/SpinnerControl.xaml.cs | 4 + .../AlternatingRowBackgroundConverter.cs | 24 +++-- .../Converters/BooleanToHiddenConverter.cs | 10 +-- .../Converters/ColumnWidthConverter.cs | 13 +-- .../DataGridLengthStringConverter.cs | 13 +-- .../Converters/ExpanderIsExpandedConverter.cs | 19 ++-- ...mnSettingsToColumnExampleValueConverter.cs | 8 ++ .../MultiBindingStringFormatConverter.cs | 4 +- .../Converters/NumberToIsPositiveConverter.cs | 2 + .../ObjectsReferencesEqualsConverter.cs | 6 +- .../Converters/SubtractConstantConverter.cs | 4 +- src/BuildVision.UI/DataGrid/ColumnsManager.cs | 33 +++++++ .../Extensions/EnumerationExtension.cs | 6 ++ .../Extensions/TextBlockUtils.cs | 2 + src/BuildVision.UI/Extensions/VisualHelper.cs | 8 ++ .../Helpers/BuildMessagesFactory.cs | 34 +++---- .../Models/BuildInformationModel.cs | 90 ++++++++++++++----- src/BuildVision.UI/Models/ProjectItem.cs | 4 + .../Settings/GridSettingsControl.xaml.cs | 20 +++++ .../Settings/Models/BuildMessagesSettings.cs | 6 ++ .../Settings/Models/ControlSettings.cs | 10 +++ .../Settings/Models/GridSettings.cs | 4 + .../Commands/ShowToolWindowCommand.cs | 2 + src/BuildVision/Core/BuildVisionPane.cs | 7 ++ src/BuildVision/Core/Services.cs | 9 ++ src/BuildVision/Core/SolutionBuildEvents.cs | 4 +- .../Extensions/BuildActionsExtensions.cs | 10 +-- .../Extensions/BuildStateExtensions.cs | 4 +- src/BuildVision/Helpers/ProjectExtensions.cs | 70 +++++++++++++++ .../Helpers/PropertiesExtensions.cs | 2 + .../Helpers/SolutionProjectsExtensions.cs | 14 +++ .../Helpers/StateConverterHelper.cs | 10 +-- .../Services/BuildInformationProvider.cs | 26 +++--- src/BuildVision/Services/BuildOutputLogger.cs | 2 + src/BuildVision/Services/BuildService.cs | 13 ++- .../Services/ErrorNavigationService.cs | 14 +++ .../Services/PackageSettingsProvider.cs | 2 + src/BuildVision/Services/SolutionProvider.cs | 5 ++ .../Services/StatusBarNotificationService.cs | 4 + .../Services/TaskBarInfoService.cs | 2 +- .../Services/WindowStateService.cs | 7 ++ .../Views/Settings/SettingsDialogPage.cs | 7 ++ .../BuildInformationModelTests.cs | 52 +++++------ 66 files changed, 549 insertions(+), 178 deletions(-) diff --git a/src/BuildVision.Common/AppVersionInfo.cs b/src/BuildVision.Common/AppVersionInfo.cs index 42517575..c993da81 100644 --- a/src/BuildVision.Common/AppVersionInfo.cs +++ b/src/BuildVision.Common/AppVersionInfo.cs @@ -40,7 +40,9 @@ private static DateTime RetrieveLinkerTimestamp(Assembly assembly) finally { if (stream != null) + { stream.Close(); + } } int i = BitConverter.ToInt32(buffer, PeHeaderOffset); diff --git a/src/BuildVision.Common/BindableBase.cs b/src/BuildVision.Common/BindableBase.cs index 5efa5848..5d2ecec8 100644 --- a/src/BuildVision.Common/BindableBase.cs +++ b/src/BuildVision.Common/BindableBase.cs @@ -11,7 +11,9 @@ public abstract class BindableBase : INotifyPropertyChanged public virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) { if (Equals(storage, value)) + { return false; + } storage = value; OnPropertyChanged(propertyName); @@ -19,12 +21,14 @@ public virtual bool SetProperty(ref T storage, T value, [CallerMemberName] st return true; } - public virtual bool SetProperty(Func storage, Action set, T value, [CallerMemberName] string propertyName = null) + public virtual bool SetProperty(Func storage, Action setAction, T value, [CallerMemberName] string propertyName = null) { if (Equals(storage(), value)) + { return false; + } - set(value); + setAction(value); OnPropertyChanged(propertyName); return true; diff --git a/src/BuildVision.Common/CustomStringFormatProvider.cs b/src/BuildVision.Common/CustomStringFormatProvider.cs index d343b0fa..0703ede6 100644 --- a/src/BuildVision.Common/CustomStringFormatProvider.cs +++ b/src/BuildVision.Common/CustomStringFormatProvider.cs @@ -19,7 +19,9 @@ public object GetFormat(Type formatType) public string Format(string format, object arg, IFormatProvider formatProvider) { if (arg == null) + { return null; + } if (format != null && arg is string) { diff --git a/src/BuildVision.Common/Diagnostics/DiagnosticsClient.cs b/src/BuildVision.Common/Diagnostics/DiagnosticsClient.cs index cd976446..62006f2b 100644 --- a/src/BuildVision.Common/Diagnostics/DiagnosticsClient.cs +++ b/src/BuildVision.Common/Diagnostics/DiagnosticsClient.cs @@ -29,7 +29,10 @@ public static void Initialize(string apiKey) public static void OnExit() { - if (!_initialized) return; + if (!_initialized) + { + return; + } _client.Flush(); // Allow time for flushing: @@ -38,26 +41,40 @@ public static void OnExit() public static void TrackEvent(string eventName, IDictionary properties = null, IDictionary metrics = null) { - if (!_initialized) return; + if (!_initialized) + { + return; + } + _client.TrackEvent(eventName, properties, metrics); } public static void TrackTrace(string evt) { - if (!_initialized) return; + if (!_initialized) + { + return; + } + _client.TrackTrace(evt); } public static void Notify(Exception exception) { - if (!_initialized) return; + if (!_initialized) + { + return; + } _client.TrackException(exception); } public static void TrackPageView(string pageName) { - if (!_initialized) return; + if (!_initialized) + { + return; + } _client.TrackPageView(pageName); } diff --git a/src/BuildVision.Common/Extensions/DateTimeExtensions.cs b/src/BuildVision.Common/Extensions/DateTimeExtensions.cs index c2cffa78..62aa887b 100644 --- a/src/BuildVision.Common/Extensions/DateTimeExtensions.cs +++ b/src/BuildVision.Common/Extensions/DateTimeExtensions.cs @@ -7,7 +7,10 @@ public static class DateTimeExtensions public static DateTime Truncate(this DateTime dateTime, TimeSpan timeSpan) { if (timeSpan <= TimeSpan.Zero) + { return dateTime; + } + return dateTime.AddTicks(-(dateTime.Ticks % timeSpan.Ticks)); } } diff --git a/src/BuildVision.Common/FilePathHelper.cs b/src/BuildVision.Common/FilePathHelper.cs index d7c52811..12e72f8c 100644 --- a/src/BuildVision.Common/FilePathHelper.cs +++ b/src/BuildVision.Common/FilePathHelper.cs @@ -120,7 +120,7 @@ public static string ShortenPath(string path, int maxLength) } } - if (lastPart == "") + if (string.IsNullOrEmpty(lastPart)) { //the filename (and root path) in itself was longer than maxLength, shorten it lastPart = pathParts[pathParts.Length - 1];//"pathParts[pathParts.Length -1]" is the equivalent of "Path.GetFileName(pathToShorten)" diff --git a/src/BuildVision.Common/GithubHelper.cs b/src/BuildVision.Common/GithubHelper.cs index d05914c3..b6679ac6 100644 --- a/src/BuildVision.Common/GithubHelper.cs +++ b/src/BuildVision.Common/GithubHelper.cs @@ -1,11 +1,12 @@ using System; using System.Diagnostics; +using System.Globalization; using System.Net; using BuildVision.Common; namespace BuildVision.Helpers { - public class GithubHelper + public static class GithubHelper { const string ASSIGNEE = "stefankert"; const string URL_TEMPLATE = "https://github.com/StefanKert/BuildVision/issues/new?labels={0}&title={1}&assignee={2}&body={3}"; @@ -24,13 +25,13 @@ public static void OpenBrowserWithPrefilledIssue() { var appVersion = new AppVersionInfo(); - var url = GetUrlForNewBug(string.Format(template, VsVersion.FullVersion, appVersion.BuildVersion, Environment.OSVersion)); - Process.Start(new ProcessStartInfo(url)); + var url = GetUrlForNewBug(string.Format(CultureInfo.CurrentCulture, template, VsVersion.FullVersion, appVersion.BuildVersion, Environment.OSVersion)); + Process.Start(new ProcessStartInfo(url.ToString())); } - public static string GetUrlForNewBug(string body) + public static Uri GetUrlForNewBug(string body) { - return string.Format(URL_TEMPLATE, "Bug", "", ASSIGNEE, WebUtility.UrlEncode(body)); + return new Uri(string.Format(CultureInfo.CurrentCulture, URL_TEMPLATE, "Bug", "", ASSIGNEE, WebUtility.UrlEncode(body))); } } } diff --git a/src/BuildVision.Common/PropertyColumnSorter.cs b/src/BuildVision.Common/PropertyColumnSorter.cs index e1f5d14c..849ab477 100644 --- a/src/BuildVision.Common/PropertyColumnSorter.cs +++ b/src/BuildVision.Common/PropertyColumnSorter.cs @@ -18,7 +18,9 @@ public PropertyColumnSorter(ListSortDirection direction, string propertyName) _propertyInfo = typeof(T).GetProperty(propertyName); if (_propertyInfo == null) + { throw new PropertyNotFoundException(propertyName, typeof(T)); + } } int IComparer.Compare(object x, object y) @@ -32,10 +34,14 @@ protected int Compare(T x, T y) var y1 = _propertyInfo.GetValue(y, null) as IComparable; if (x1 != null && y1 != null) + { return x1.CompareTo(y1) * _direction; + } if (x1 == null && y1 == null) + { return 0; + } // Null values always in the bottom. return (x1 == null) ? 1 : -1; diff --git a/src/BuildVision.Common/RelayCommand.cs b/src/BuildVision.Common/RelayCommand.cs index cec77435..3d8c3080 100644 --- a/src/BuildVision.Common/RelayCommand.cs +++ b/src/BuildVision.Common/RelayCommand.cs @@ -32,10 +32,7 @@ public RelayCommand(Action execute) /// The execution status logic. public RelayCommand(Action execute, Predicate canExecute) { - if (execute == null) - throw new ArgumentNullException("execute"); - - _execute = execute; + _execute = execute ?? throw new ArgumentNullException(nameof(execute)); _canExecute = canExecute; } diff --git a/src/BuildVision.Common/SettingsBase.cs b/src/BuildVision.Common/SettingsBase.cs index da0a4cb9..ec4f5e96 100644 --- a/src/BuildVision.Common/SettingsBase.cs +++ b/src/BuildVision.Common/SettingsBase.cs @@ -14,7 +14,9 @@ public void InitFrom(T source) where T : SettingsBase { PropertyInfo[] properties = typeof(T).GetProperties(); foreach (var property in properties) + { property.SetValue(this, property.GetValue(source, null), null); + } } } } diff --git a/src/BuildVision.Common/VSVersion.cs b/src/BuildVision.Common/VSVersion.cs index 33539271..47bd2d92 100644 --- a/src/BuildVision.Common/VSVersion.cs +++ b/src/BuildVision.Common/VSVersion.cs @@ -36,7 +36,9 @@ public static Version FullVersion mVsVersion = new Version(verName); } else + { mVsVersion = new Version(0, 0); // Not running inside Visual Studio! + } } } diff --git a/src/BuildVision.Contracts/Enums/BuildActions.cs b/src/BuildVision.Contracts/Enums/BuildActions.cs index 48a92cce..b1078a2e 100644 --- a/src/BuildVision.Contracts/Enums/BuildActions.cs +++ b/src/BuildVision.Contracts/Enums/BuildActions.cs @@ -1,11 +1,11 @@ namespace BuildVision.Contracts { - public enum BuildActions + public enum BuildAction { - BuildActionBuild = 1, - BuildActionRebuildAll = 2, - BuildActionClean = 3, - BuildActionDeploy = 4, + Build = 1, + RebuildAll = 2, + Clean = 3, + Deploy = 4, Unknown = 5 } } diff --git a/src/BuildVision.Contracts/Enums/BuildScopes.cs b/src/BuildVision.Contracts/Enums/BuildScopes.cs index 416b1f00..0a762b7f 100644 --- a/src/BuildVision.Contracts/Enums/BuildScopes.cs +++ b/src/BuildVision.Contracts/Enums/BuildScopes.cs @@ -1,10 +1,10 @@ namespace BuildVision.Contracts { - public enum BuildScopes + public enum BuildScope { - BuildScopeSolution = 1, - BuildScopeBatch = 2, - BuildScopeProject = 3, + Solution = 1, + Batch = 2, + Project = 3, Unknown = 4 } } diff --git a/src/BuildVision.Contracts/Exceptions/PropertyNotFoundException.cs b/src/BuildVision.Contracts/Exceptions/PropertyNotFoundException.cs index 527c0ef8..0420d0d5 100644 --- a/src/BuildVision.Contracts/Exceptions/PropertyNotFoundException.cs +++ b/src/BuildVision.Contracts/Exceptions/PropertyNotFoundException.cs @@ -2,18 +2,19 @@ namespace BuildVision.Contracts.Exceptions { + [Serializable] public class PropertyNotFoundException : Exception { + public string PropertyName { get; } + + public Type PropertyType { get; } + + public override string Message => string.Format("Property '{0}' not found in '{1}' type.", PropertyName, PropertyType); + public PropertyNotFoundException(string propertyName, Type type) { PropertyName = propertyName; - Type = type; + PropertyType = type; } - - public string PropertyName { get; } - - public Type Type { get; } - - public override string Message => string.Format("Property '{0}' not found in '{1}' type.", PropertyName, Type); } } diff --git a/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs b/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs index 8862f0e7..41b5a3c6 100644 --- a/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs +++ b/src/BuildVision.Contracts/Models/BuildProjectContextEntry.cs @@ -1,4 +1,4 @@ -using BuildVision.UI.Models; +using BuildVision.UI.Models; using System.Collections.Generic; namespace BuildVision.UI.Contracts @@ -11,7 +11,7 @@ public class BuildProjectContextEntry public string FileName { get; set; } - public IDictionary Properties { get; set; } + public IDictionary Properties { get; } public IProjectItem ProjectItem { get; set; } diff --git a/src/BuildVision.Contracts/Models/ErrorItem.cs b/src/BuildVision.Contracts/Models/ErrorItem.cs index 75e67afe..1b320c2b 100644 --- a/src/BuildVision.Contracts/Models/ErrorItem.cs +++ b/src/BuildVision.Contracts/Models/ErrorItem.cs @@ -107,10 +107,14 @@ public void VerifyValues() } if (LineNumber < 1) + { LineNumber = 1; + } if (ColumnNumber < 1) + { ColumnNumber = 1; + } if (EndLineNumber == 0 && EndColumnNumber == 0) { diff --git a/src/BuildVision.Contracts/Models/IBuildInformationModel.cs b/src/BuildVision.Contracts/Models/IBuildInformationModel.cs index 7e1f9d31..8ed56319 100644 --- a/src/BuildVision.Contracts/Models/IBuildInformationModel.cs +++ b/src/BuildVision.Contracts/Models/IBuildInformationModel.cs @@ -7,9 +7,9 @@ namespace BuildVision.Contracts.Models { public interface IBuildInformationModel : INotifyPropertyChanged { - BuildActions BuildAction { get; set; } + BuildAction BuildAction { get; set; } DateTime? BuildFinishTime { get; set; } - BuildScopes BuildScope { get; set; } + BuildScope BuildScope { get; set; } DateTime? BuildStartTime { get; set; } BuildState CurrentBuildState { get; set; } int ErrorCount { get; set; } diff --git a/src/BuildVision.Contracts/Models/IProjectItem.cs b/src/BuildVision.Contracts/Models/IProjectItem.cs index 369474e4..1b28cbf7 100644 --- a/src/BuildVision.Contracts/Models/IProjectItem.cs +++ b/src/BuildVision.Contracts/Models/IProjectItem.cs @@ -33,9 +33,9 @@ public interface IProjectItem int MessagesCount { get; set; } int ErrorsCount { get; set; } int WarningsCount { get; set; } - ObservableCollection Errors { get; set; } - ObservableCollection Warnings { get; set; } - ObservableCollection Messages { get; set; } + ObservableCollection Errors { get; } + ObservableCollection Warnings { get; } + ObservableCollection Messages { get; } void RaiseBuildElapsedTimeChanged(); void AddErrorItem(ErrorItem errorItem); diff --git a/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs b/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs index e5dc7e5d..f3316d36 100644 --- a/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs +++ b/src/BuildVision.Exports/Providers/IBuildInformationProvider.cs @@ -11,12 +11,12 @@ public interface IBuildInformationProvider IBuildInformationModel BuildInformationModel { get; } ObservableCollection Projects { get; } - void ProjectBuildStarted(IProjectItem projectItem, BuildActions buildAction); - void ProjectBuildFinished(BuildActions buildAction, string projectIdentifier, bool succeess, bool canceled); + void ProjectBuildStarted(IProjectItem projectItem, BuildAction buildAction); + void ProjectBuildFinished(BuildAction buildAction, string projectIdentifier, bool succeess, bool canceled); void ReloadCurrentProjects(); void ResetCurrentProjects(); void BuildFinished(bool success, bool canceled); - void BuildStarted(BuildActions currentBuildAction, BuildScopes scope); + void BuildStarted(BuildAction currentBuildAction, BuildScope scope); void BuildUpdate(); void ResetBuildInformationModel(); } diff --git a/src/BuildVision.Exports/Sevices/ITaskBarInfoService.cs b/src/BuildVision.Exports/Sevices/ITaskBarInfoService.cs index 58f39b8e..d46ca586 100644 --- a/src/BuildVision.Exports/Sevices/ITaskBarInfoService.cs +++ b/src/BuildVision.Exports/Sevices/ITaskBarInfoService.cs @@ -5,6 +5,6 @@ namespace BuildVision.Exports.Services public interface ITaskBarInfoService { void ResetTaskBarInfo(bool ifTaskBarProgressEnabled = true); - void UpdateTaskBarInfo(BuildState buildState, BuildScopes buildScope, int projectsCount, int finishedProjects); + void UpdateTaskBarInfo(BuildState buildState, BuildScope buildScope, int projectsCount, int finishedProjects); } } diff --git a/src/BuildVision.UI/Attributes/DisplayStringAttribute.cs b/src/BuildVision.UI/Attributes/DisplayStringAttribute.cs index ddb5a0e3..348e512a 100644 --- a/src/BuildVision.UI/Attributes/DisplayStringAttribute.cs +++ b/src/BuildVision.UI/Attributes/DisplayStringAttribute.cs @@ -66,7 +66,9 @@ public override bool Equals(object obj) { var dsaObj = obj as DisplayStringAttribute; if (dsaObj == null) + { return false; + } return DisplayString.Equals(dsaObj.DisplayString); } diff --git a/src/BuildVision.UI/Components/ErrorsGrid.xaml.cs b/src/BuildVision.UI/Components/ErrorsGrid.xaml.cs index c6c74857..ed4074c4 100644 --- a/src/BuildVision.UI/Components/ErrorsGrid.xaml.cs +++ b/src/BuildVision.UI/Components/ErrorsGrid.xaml.cs @@ -58,7 +58,9 @@ private void ErrorsGridRowOnMouseLeftButtonUp(object sender, MouseButtonEventArg private void ErrorsGridOnPreviewMouseWheel(object sender, MouseWheelEventArgs e) { if (_errorsGridScrollViewer.ComputedVerticalScrollBarVisibility == Visibility.Visible) + { return; + } e.Handled = true; var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta) diff --git a/src/BuildVision.UI/Components/ProjectGrid.xaml.cs b/src/BuildVision.UI/Components/ProjectGrid.xaml.cs index d01e33f3..823dc06c 100644 --- a/src/BuildVision.UI/Components/ProjectGrid.xaml.cs +++ b/src/BuildVision.UI/Components/ProjectGrid.xaml.cs @@ -76,7 +76,9 @@ private void ViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs Grid.SelectedIndex = -1; if (Grid.SelectedIndex == -1) + { Grid.ScrollIntoView(ViewModel.BuildInformationModel.CurrentProject); + } } } @@ -110,7 +112,9 @@ private void DataGridRowDetailsOnMouseLeftButtonDown(object sender, MouseButtonE { // http://stackoverflow.com/questions/6279724/mousedoubleclick-events-dont-bubble/6326181#6326181) if (e.ClickCount == 2) + { e.Handled = true; + } } // Autofocus for RowDetails (without extra mouse click). diff --git a/src/BuildVision.UI/Components/SpinnerControl.xaml.cs b/src/BuildVision.UI/Components/SpinnerControl.xaml.cs index b33786ae..839a2888 100644 --- a/src/BuildVision.UI/Components/SpinnerControl.xaml.cs +++ b/src/BuildVision.UI/Components/SpinnerControl.xaml.cs @@ -240,7 +240,9 @@ protected static void OnIncreaseCommand(Object sender, ExecutedRoutedEventArgs e { var control = sender as SpinnerControl; if (control != null) + { control.OnIncrease(); + } } protected void OnIncrease() @@ -256,7 +258,9 @@ protected static void OnDecreaseCommand(Object sender, ExecutedRoutedEventArgs e { var control = sender as SpinnerControl; if (control != null) + { control.OnDecrease(); + } } protected void OnDecrease() diff --git a/src/BuildVision.UI/Converters/AlternatingRowBackgroundConverter.cs b/src/BuildVision.UI/Converters/AlternatingRowBackgroundConverter.cs index 5af63cd9..86fd46ad 100644 --- a/src/BuildVision.UI/Converters/AlternatingRowBackgroundConverter.cs +++ b/src/BuildVision.UI/Converters/AlternatingRowBackgroundConverter.cs @@ -13,11 +13,12 @@ public class AlternatingRowBackgroundConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - var backg = value as SolidColorBrush; - if (backg == null) + if (!(value is SolidColorBrush backg)) + { return value; + } - Color color = backg.Color; + var color = backg.Color; int darkerDelta = -15; int r = color.R + darkerDelta; @@ -51,9 +52,20 @@ public object Convert(object value, Type targetType, object parameter, CultureIn g = color.G + lighterDelta; b = color.B + lighterDelta; - if (r > 255) r = 255; - if (g > 255) g = 255; - if (b > 255) b = 255; + if (r > 255) + { + r = 255; + } + + if (g > 255) + { + g = 255; + } + + if (b > 255) + { + b = 255; + } } var newColor = Color.FromArgb(255, (byte)r, (byte)g, (byte)b); diff --git a/src/BuildVision.UI/Converters/BooleanToHiddenConverter.cs b/src/BuildVision.UI/Converters/BooleanToHiddenConverter.cs index f567f678..8b920a78 100644 --- a/src/BuildVision.UI/Converters/BooleanToHiddenConverter.cs +++ b/src/BuildVision.UI/Converters/BooleanToHiddenConverter.cs @@ -17,19 +17,15 @@ public object Convert(object value, Type targetType, object parameter, CultureIn } else if (value is bool?) { - bool? nullable = (bool?)value; - flag = (nullable.HasValue && nullable.Value); + var nullable = (bool?)value; + flag = nullable.HasValue && nullable.Value; } return flag ? Visibility.Hidden : Visibility.Visible; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is Visibility) - { - return (Visibility)value == Visibility.Hidden; - } - return false; + return value is Visibility ? (Visibility)value == Visibility.Hidden : (object)false; } } } diff --git a/src/BuildVision.UI/Converters/ColumnWidthConverter.cs b/src/BuildVision.UI/Converters/ColumnWidthConverter.cs index 559bda2e..be9d2595 100644 --- a/src/BuildVision.UI/Converters/ColumnWidthConverter.cs +++ b/src/BuildVision.UI/Converters/ColumnWidthConverter.cs @@ -9,20 +9,13 @@ public class ColumnWidthConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - double val = (double)value; - - if (double.IsNaN(val)) - return "auto"; - - return val; + var val = (double)value; + return double.IsNaN(val) ? "auto" : (object)val; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { - if (value as string == "auto") - return double.NaN; - - return value; + return value as string == "auto" ? double.NaN : value; } } } diff --git a/src/BuildVision.UI/Converters/DataGridLengthStringConverter.cs b/src/BuildVision.UI/Converters/DataGridLengthStringConverter.cs index 34265bf9..0dfa6aee 100644 --- a/src/BuildVision.UI/Converters/DataGridLengthStringConverter.cs +++ b/src/BuildVision.UI/Converters/DataGridLengthStringConverter.cs @@ -13,12 +13,11 @@ public object Convert(object value, Type targetType, object parameter, CultureIn var val = (DataGridLength)value; if (val.IsAuto) + { return "auto"; + } - if (val.IsStar) - return val.DisplayValue.ToString("0.0") + "*"; - - return val.Value.ToString("0.0"); + return val.IsStar ? val.DisplayValue.ToString("0.0") + "*" : val.Value.ToString("0.0"); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) @@ -28,10 +27,14 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu var val = ((string)value).Trim().ToLower(); if (val == "auto") + { return new DataGridLength(1.0, DataGridLengthUnitType.Auto); + } - if (val.EndsWith("*")) + if (val.EndsWith("*", StringComparison.InvariantCulture)) + { return new DataGridLength(double.Parse(val.TrimEnd('*')), DataGridLengthUnitType.Star); + } return new DataGridLength(double.Parse(val)); } diff --git a/src/BuildVision.UI/Converters/ExpanderIsExpandedConverter.cs b/src/BuildVision.UI/Converters/ExpanderIsExpandedConverter.cs index 91f6f032..14e823db 100644 --- a/src/BuildVision.UI/Converters/ExpanderIsExpandedConverter.cs +++ b/src/BuildVision.UI/Converters/ExpanderIsExpandedConverter.cs @@ -11,10 +11,11 @@ public class ExpanderIsExpandedConverter : IMultiValueConverter public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { var collectionViewGroup = (CollectionViewGroup)values[0]; - var collapsedGroups = values[1] as IList; - if (collapsedGroups == null || collapsedGroups.Count == 0) + if (!(values[1] is IList collapsedGroups) || collapsedGroups.Count == 0) + { return true; + } string groupId = GetGroupIdentifier(collectionViewGroup); bool collapsed = collapsedGroups.Contains(groupId); @@ -28,15 +29,18 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, public static void SaveState(Expander exp, bool collapsed, IList collapsedGroups) { - var collectionViewGroup = exp.DataContext as CollectionViewGroup; - if (collectionViewGroup == null) + if (!(exp.DataContext is CollectionViewGroup collectionViewGroup)) + { return; + } string groupId = GetGroupIdentifier(collectionViewGroup); if (collapsed) { if (!collapsedGroups.Contains(groupId)) + { collapsedGroups.Add(groupId); + } } else { @@ -48,12 +52,11 @@ private static string GetGroupIdentifier(CollectionViewGroup collectionViewGroup { object groupId = collectionViewGroup.Name; if (groupId == null) + { return null; + } - if (groupId is string) - return (string)groupId; - - return groupId.ToString(); + return groupId is string ? (string)groupId : groupId.ToString(); } } } diff --git a/src/BuildVision.UI/Converters/GridColumnSettingsToColumnExampleValueConverter.cs b/src/BuildVision.UI/Converters/GridColumnSettingsToColumnExampleValueConverter.cs index 0be9b2ad..ffbd26da 100644 --- a/src/BuildVision.UI/Converters/GridColumnSettingsToColumnExampleValueConverter.cs +++ b/src/BuildVision.UI/Converters/GridColumnSettingsToColumnExampleValueConverter.cs @@ -21,18 +21,26 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur private static string FormatExample(object example, string stringFormat) { if (example == null) + { return Resources.GridCellNoneTextInBrackets; + } try { if (string.IsNullOrWhiteSpace(stringFormat)) + { return example.ToString(); + } if (example is DateTime) + { return ((DateTime)example).ToString(stringFormat); + } if (example is TimeSpan) + { return ((TimeSpan)example).ToString(stringFormat); + } return string.Format(stringFormat, example); } diff --git a/src/BuildVision.UI/Converters/MultiBindingStringFormatConverter.cs b/src/BuildVision.UI/Converters/MultiBindingStringFormatConverter.cs index aedbb977..1280542b 100644 --- a/src/BuildVision.UI/Converters/MultiBindingStringFormatConverter.cs +++ b/src/BuildVision.UI/Converters/MultiBindingStringFormatConverter.cs @@ -16,7 +16,9 @@ public class MultiBindingStringFormatConverter : IMultiValueConverter public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values == null || values.Length < 2) + { return string.Empty; + } try { @@ -25,7 +27,7 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur } catch (Exception ex) { - LogManager.ForContext< MultiBindingStringFormatConverter>().Error(ex, "Error during MultiBindingStringFormatConverter."); + LogManager.ForContext().Error(ex, "Error during MultiBindingStringFormatConverter."); return string.Format("", ex.Message); } } diff --git a/src/BuildVision.UI/Converters/NumberToIsPositiveConverter.cs b/src/BuildVision.UI/Converters/NumberToIsPositiveConverter.cs index 076e6aed..46f83c87 100644 --- a/src/BuildVision.UI/Converters/NumberToIsPositiveConverter.cs +++ b/src/BuildVision.UI/Converters/NumberToIsPositiveConverter.cs @@ -10,7 +10,9 @@ public class NumberToIsPositiveConverter : IValueConverter public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && double.TryParse(value.ToString(), out var val)) + { return val > 0; + } return false; } diff --git a/src/BuildVision.UI/Converters/ObjectsReferencesEqualsConverter.cs b/src/BuildVision.UI/Converters/ObjectsReferencesEqualsConverter.cs index e34707c3..d12cf1b2 100644 --- a/src/BuildVision.UI/Converters/ObjectsReferencesEqualsConverter.cs +++ b/src/BuildVision.UI/Converters/ObjectsReferencesEqualsConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Windows.Data; @@ -12,7 +12,9 @@ public object Convert(object[] values, Type targetType, object parameter, Cultur for (int i = 0; i < values.Length - 1; i++) { if (!ReferenceEquals(values[i], values[i + 1])) + { return false; + } } return true; @@ -23,4 +25,4 @@ public object[] ConvertBack(object value, Type[] targetTypes, object parameter, throw new InvalidOperationException(); } } -} \ No newline at end of file +} diff --git a/src/BuildVision.UI/Converters/SubtractConstantConverter.cs b/src/BuildVision.UI/Converters/SubtractConstantConverter.cs index 94f1e477..6873b0b4 100644 --- a/src/BuildVision.UI/Converters/SubtractConstantConverter.cs +++ b/src/BuildVision.UI/Converters/SubtractConstantConverter.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Windows.Data; @@ -19,4 +19,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu return null; } } -} \ No newline at end of file +} diff --git a/src/BuildVision.UI/DataGrid/ColumnsManager.cs b/src/BuildVision.UI/DataGrid/ColumnsManager.cs index 2d4811ec..ffde95f2 100644 --- a/src/BuildVision.UI/DataGrid/ColumnsManager.cs +++ b/src/BuildVision.UI/DataGrid/ColumnsManager.cs @@ -68,14 +68,20 @@ public static object GetColumnExampleValue(GridColumnSettings gridColumnSettings public static bool ColumnIsSortable(string propertyName) { if (_nonSortableColumns.Contains(propertyName)) + { return false; + } + return true; } public static bool ColumnIsGroupable(GridColumnSettings gridColumnSettings) { if (_nonGroupableColumns.Contains(gridColumnSettings.PropertyNameId)) + { return false; + } + return true; } @@ -101,7 +107,9 @@ public static void GenerateColumns(ObservableCollection columns, { GridColumnAttribute columnConfiguration = property.GetCustomAttribute(); if (columnConfiguration == null) + { continue; + } string propertyName = property.Name; GridColumnSettings columnSettings; @@ -152,7 +160,9 @@ public static void SyncColumnSettings(ObservableCollection colum string propertyName = column.GetBindedProperty(); var columnSettings = gridSettings.Columns[propertyName]; if (columnSettings == null) + { continue; + } columnSettings.Visible = (column.Visibility == Visibility.Visible); columnSettings.DisplayIndex = column.DisplayIndex; @@ -169,11 +179,15 @@ public static string GetBindedProperty(this DataGridColumn column) { var boundColumn = column as DataGridBoundColumn; if (boundColumn == null) + { return string.Empty; + } var binding = boundColumn.Binding as Binding; if (binding == null) + { return string.Empty; + } return binding.Path.Path; } @@ -211,13 +225,22 @@ private static DataGridBoundColumn CreateColumnForProperty(PropertyInfo property { DataGridBoundColumn column; if (property.PropertyType == typeof(BitmapSource) || property.PropertyType == typeof(ImageSource)) + { column = new DataGridImageColumn(); + } else if (property.PropertyType == typeof(ControlTemplate)) + { column = new DataGridContentControlColumn(); + } else if (property.PropertyType == typeof(bool)) + { column = new DataGridCheckBoxColumn(); + } else + { column = new DataGridTextColumn(); + } + return column; } @@ -266,20 +289,30 @@ private static void InitColumn(DataGridBoundColumn column, GridColumnAttribute c column.Visibility = columnSettings.Visible ? Visibility.Visible : Visibility.Collapsed; if (columnSettings.DisplayIndex != -1) + { column.DisplayIndex = columnSettings.DisplayIndex; + } if (!double.IsNaN(columnSettings.Width)) + { column.Width = new DataGridLength(columnSettings.Width); + } if (columnSettings.ValueStringFormat != null) + { column.Binding.StringFormat = columnSettings.ValueStringFormat; + } if (column.GetBindedProperty() == sortDescription.Property) + { column.SortDirection = sortDescription.Order.ToSystem(); + } string columnName = columnSettings.Header; if (string.IsNullOrEmpty(columnName)) + { columnName = columnConfiguration.Header; + } column.SetValue(DataGridColumnExtensions.NameProperty, columnName); } diff --git a/src/BuildVision.UI/Extensions/EnumerationExtension.cs b/src/BuildVision.UI/Extensions/EnumerationExtension.cs index 26112ff6..bf5ff149 100644 --- a/src/BuildVision.UI/Extensions/EnumerationExtension.cs +++ b/src/BuildVision.UI/Extensions/EnumerationExtension.cs @@ -12,7 +12,9 @@ public class EnumerationExtension : MarkupExtension public EnumerationExtension(Type enumType) { if (enumType == null) + { throw new ArgumentNullException("enumType"); + } SetEnumType(enumType); } @@ -20,12 +22,16 @@ public EnumerationExtension(Type enumType) private void SetEnumType(Type value) { if (_enumType == value) + { return; + } var enumType = Nullable.GetUnderlyingType(value) ?? value; if (enumType.IsEnum == false) + { throw new ArgumentException("Type must be an Enum."); + } _enumType = value; } diff --git a/src/BuildVision.UI/Extensions/TextBlockUtils.cs b/src/BuildVision.UI/Extensions/TextBlockUtils.cs index 7b7bbd96..62713946 100644 --- a/src/BuildVision.UI/Extensions/TextBlockUtils.cs +++ b/src/BuildVision.UI/Extensions/TextBlockUtils.cs @@ -25,7 +25,9 @@ private static void OnAutoTooltipPropertyChanged(DependencyObject obj, Dependenc { var textBlock = obj as TextBlock; if (textBlock == null) + { return; + } if (e.NewValue.Equals(true)) { diff --git a/src/BuildVision.UI/Extensions/VisualHelper.cs b/src/BuildVision.UI/Extensions/VisualHelper.cs index e91ca506..53a97057 100644 --- a/src/BuildVision.UI/Extensions/VisualHelper.cs +++ b/src/BuildVision.UI/Extensions/VisualHelper.cs @@ -19,11 +19,15 @@ public static T FindVisualChild(DependencyObject obj) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child is T) + { return (T)child; + } var childOfChild = FindVisualChild(child); if (childOfChild != null) + { return childOfChild; + } } return null; @@ -41,10 +45,14 @@ public static IEnumerable FindVisualChildren(DependencyObject obj) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child is T) + { yield return (T)child; + } foreach (T childOfChild in FindVisualChildren(child)) + { yield return childOfChild; + } } } } diff --git a/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs b/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs index ca7fdc36..9139e68c 100644 --- a/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs +++ b/src/BuildVision.UI/Helpers/BuildMessagesFactory.cs @@ -58,56 +58,56 @@ private string GetTimeString(DateTime? startTime) } } - private string GetBeginAtString(BuildActions? buildAction) + private string GetBeginAtString(BuildAction? buildAction) { switch (buildAction.Value) { - case BuildActions.BuildActionRebuildAll: + case BuildAction.RebuildAll: return Resources.BuildActionRebuildAll_BeginAtString; - case BuildActions.BuildActionBuild: + case BuildAction.Build: return Resources.BuildActionBuild_BeginAtString; - case BuildActions.BuildActionClean: + case BuildAction.Clean: return Resources.BuildActionClean_BeginAtString; default: throw new ArgumentOutOfRangeException(nameof(buildAction)); } } - private string GetActionName(BuildActions buildAction) + private string GetActionName(BuildAction buildAction) { switch (buildAction) { - case BuildActions.BuildActionRebuildAll: + case BuildAction.RebuildAll: return Resources.BuildActionRebuildAll; - case BuildActions.BuildActionBuild: + case BuildAction.Build: return Resources.BuildActionBuild; - case BuildActions.BuildActionClean: + case BuildAction.Clean: return Resources.BuildActionClean; default: throw new ArgumentOutOfRangeException(nameof(buildAction)); } } - private string GetUnitName(BuildScopes buildScope) + private string GetUnitName(BuildScope buildScope) { string unitName = ""; switch (buildScope) { - case BuildScopes.BuildScopeSolution: + case BuildScope.Solution: unitName = Resources.BuildScopeSolution_UnitName; //if (_labelSettings.ShowSolutionName) //unitName += string.Format(Resources.BuildScopeSolution_SolutionNameTemplate, solutionItem.Name); break; - case BuildScopes.BuildScopeBatch: + case BuildScope.Batch: unitName = Resources.BuildScopeBatch_UnitName; break; - case BuildScopes.BuildScopeProject: + case BuildScope.Project: unitName = Resources.BuildScopeProject_UnitName; // TODO specify name for project? break; @@ -146,7 +146,9 @@ private string GetBuildDoneMajorMessage(IBuildInformationModel buildInformationM var buildScope = buildInformationModel.BuildScope; if (buildInformationModel.BuildFinishTime == null) + { throw new InvalidOperationException(); + } string timeString; try @@ -161,17 +163,17 @@ private string GetBuildDoneMajorMessage(IBuildInformationModel buildInformationM string unitName; switch (buildScope) { - case BuildScopes.BuildScopeSolution: + case BuildScope.Solution: unitName = Resources.BuildScopeSolution_UnitName; //if (_labelSettings.ShowSolutionName) //unitName += string.Format(Resources.BuildScopeSolution_SolutionNameTemplate, solutionItem.Name); break; - case BuildScopes.BuildScopeBatch: + case BuildScope.Batch: unitName = Resources.BuildScopeBatch_UnitName; break; - case BuildScopes.BuildScopeProject: + case BuildScope.Project: unitName = Resources.BuildScopeProject_UnitName; if (_packageSettingsProvider.Settings.BuildMessagesSettings.ShowProjectName) { @@ -237,7 +239,9 @@ private string GetResultName(BuildResultState resultState) private string GetBuildDoneExtraMessage(IBuildInformationModel buildInformationModel) { if (buildInformationModel.BuildStartTime == null || buildInformationModel.BuildFinishTime == null || !_packageSettingsProvider.Settings.BuildMessagesSettings.ShowExtraMessage) + { return string.Empty; + } TimeSpan timeSpan = buildInformationModel.BuildFinishTime.Value.Subtract(buildInformationModel.BuildStartTime.Value); string extraTimePartString = GetExtraTimePartString(timeSpan); diff --git a/src/BuildVision.UI/Models/BuildInformationModel.cs b/src/BuildVision.UI/Models/BuildInformationModel.cs index 1c88d094..3df365a3 100644 --- a/src/BuildVision.UI/Models/BuildInformationModel.cs +++ b/src/BuildVision.UI/Models/BuildInformationModel.cs @@ -78,8 +78,8 @@ public BuildState CurrentBuildState public BuildResultState ResultState => GetBuildResultState(); - private BuildActions _buildAction = BuildActions.Unknown; - public BuildActions BuildAction + private BuildAction _buildAction = BuildAction.Unknown; + public BuildAction BuildAction { get => _buildAction; set @@ -89,8 +89,8 @@ public BuildActions BuildAction } } - private BuildScopes _buildScope = BuildScopes.Unknown; - public BuildScopes BuildScope + private BuildScope _buildScope = BuildScope.Unknown; + public BuildScope BuildScope { get => _buildScope; set => SetProperty(ref _buildScope, value); @@ -132,12 +132,20 @@ private string GetStateIconKey() var resultState = GetBuildResultState(); if (CurrentBuildState == BuildState.InProgress && resultState == BuildResultState.Unknown) { - if (BuildAction == BuildActions.BuildActionRebuildAll) + if (BuildAction == BuildAction.RebuildAll) + { return "Rebuild"; - if (BuildAction == BuildActions.BuildActionClean) + } + + if (BuildAction == BuildAction.Clean) + { return "Clean"; - if (BuildAction == BuildActions.BuildActionBuild) + } + + if (BuildAction == BuildAction.Build) + { return "Build"; + } } if (resultState == BuildResultState.Unknown) @@ -155,47 +163,87 @@ private BuildResultState GetBuildResultState() } else if (CurrentBuildState == BuildState.Cancelled) { - if (BuildAction == BuildActions.BuildActionRebuildAll) + if (BuildAction == BuildAction.RebuildAll) + { return BuildResultState.RebuildCancelled; - if (BuildAction == BuildActions.BuildActionClean) + } + + if (BuildAction == BuildAction.Clean) + { return BuildResultState.CleanCancelled; - if (BuildAction == BuildActions.BuildActionBuild) + } + + if (BuildAction == BuildAction.Build) + { return BuildResultState.BuildCancelled; + } else + { return BuildResultState.Unknown; + } } else if (CurrentBuildState == BuildState.Failed) { - if (BuildAction == BuildActions.BuildActionRebuildAll) + if (BuildAction == BuildAction.RebuildAll) + { return BuildResultState.RebuildFailed; - if (BuildAction == BuildActions.BuildActionClean) + } + + if (BuildAction == BuildAction.Clean) + { return BuildResultState.CleanFailed; - if (BuildAction == BuildActions.BuildActionBuild) + } + + if (BuildAction == BuildAction.Build) + { return BuildResultState.BuildFailed; + } else + { return BuildResultState.Unknown; + } } else if (CurrentBuildState == BuildState.ErrorDone) { - if (BuildAction == BuildActions.BuildActionRebuildAll) + if (BuildAction == BuildAction.RebuildAll) + { return BuildResultState.RebuildErrorDone; - if (BuildAction == BuildActions.BuildActionClean) + } + + if (BuildAction == BuildAction.Clean) + { return BuildResultState.CleanErrorDone; - if (BuildAction == BuildActions.BuildActionBuild) + } + + if (BuildAction == BuildAction.Build) + { return BuildResultState.BuildErrorDone; + } else + { return BuildResultState.Unknown; + } } else if (CurrentBuildState == BuildState.Done) { - if (BuildAction == BuildActions.BuildActionRebuildAll) + if (BuildAction == BuildAction.RebuildAll) + { return BuildResultState.RebuildDone; - if (BuildAction == BuildActions.BuildActionClean) + } + + if (BuildAction == BuildAction.Clean) + { return BuildResultState.CleanDone; - if (BuildAction == BuildActions.BuildActionBuild) + } + + if (BuildAction == BuildAction.Build) + { return BuildResultState.BuildDone; + } else + { return BuildResultState.Unknown; + } } else { @@ -214,8 +262,8 @@ public void ResetState() WarnedProjectsCount = 0; StateMessage = Resources.BuildDoneText_BuildNotStarted; CurrentBuildState = BuildState.NotStarted; - BuildAction = BuildActions.Unknown; - BuildScope = BuildScopes.Unknown; + BuildAction = BuildAction.Unknown; + BuildScope = BuildScope.Unknown; BuildStartTime = null; BuildFinishTime = null; } diff --git a/src/BuildVision.UI/Models/ProjectItem.cs b/src/BuildVision.UI/Models/ProjectItem.cs index d2bcb3fe..7062551a 100644 --- a/src/BuildVision.UI/Models/ProjectItem.cs +++ b/src/BuildVision.UI/Models/ProjectItem.cs @@ -140,10 +140,14 @@ public TimeSpan? BuildElapsedTime get { if (_buildStartTime == null) + { return null; + } if (_buildFinishTime == null) + { return DateTime.Now.Subtract(_buildStartTime.Value); + } return _buildFinishTime.Value.Truncate(TimeSpan.FromSeconds(1)) .Subtract(_buildStartTime.Value.Truncate(TimeSpan.FromSeconds(1))); diff --git a/src/BuildVision.UI/Settings/GridSettingsControl.xaml.cs b/src/BuildVision.UI/Settings/GridSettingsControl.xaml.cs index 603b3833..0b3d31d7 100644 --- a/src/BuildVision.UI/Settings/GridSettingsControl.xaml.cs +++ b/src/BuildVision.UI/Settings/GridSettingsControl.xaml.cs @@ -31,7 +31,9 @@ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventA { // http://stackoverflow.com/questions/15025865/wpf-datagrid-not-exiting-edit-mode if (e.NewValue == null) + { Grid.CommitEdit(); + } } private void OnDialogKeyPendingEvent(object sender, RoutedEventArgs e) @@ -56,20 +58,28 @@ private void GridOnCurrentCellChanged(object sender, EventArgs e) private void GridOnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { if (_displayIndexCommiting) + { return; + } if (!ReferenceEquals(e.Column, ColumnDisplayIndex)) + { return; + } if (e.EditAction != DataGridEditAction.Commit) + { return; + } _displayIndexCommiting = true; bool commited = Grid.CommitEdit(DataGridEditingUnit.Row, true); _displayIndexCommiting = false; if (!commited) + { return; + } var editedItem = (GridColumnSettings)e.Row.Item; _newDisplayIndex = editedItem.DisplayIndex; @@ -90,10 +100,14 @@ private void GridOnCellEditEnding(object sender, DataGridCellEditEndingEventArgs foreach (GridColumnSettings item in Grid.Items) { if (ReferenceEquals(item, editedItem)) + { continue; + } if (item.DisplayIndex >= _oldDisplayIndex + 1 && item.DisplayIndex <= _newDisplayIndex) + { item.DisplayIndex -= 1; + } } } else @@ -101,10 +115,14 @@ private void GridOnCellEditEnding(object sender, DataGridCellEditEndingEventArgs foreach (GridColumnSettings item in Grid.Items) { if (ReferenceEquals(item, editedItem)) + { continue; + } if (item.DisplayIndex >= _newDisplayIndex && item.DisplayIndex <= _oldDisplayIndex - 1) + { item.DisplayIndex += 1; + } } } @@ -117,7 +135,9 @@ private void GridOnTargetUpdated(object sender, DataTransferEventArgs e) { var grid = (System.Windows.Controls.DataGrid)sender; if (grid.ItemsSource == null) + { return; + } grid.Items.SortDescriptions.Add(new SortDescription("DisplayIndex", ListSortDirection.Ascending)); diff --git a/src/BuildVision.UI/Settings/Models/BuildMessagesSettings.cs b/src/BuildVision.UI/Settings/Models/BuildMessagesSettings.cs index 0026b644..fb1cbea9 100644 --- a/src/BuildVision.UI/Settings/Models/BuildMessagesSettings.cs +++ b/src/BuildVision.UI/Settings/Models/BuildMessagesSettings.cs @@ -65,7 +65,9 @@ public string BuildBeginMajorMessageStringFormat OnPropertyChanged(nameof(BuildBeginMajorMessageStringFormat)); if (!value.Contains("{0}")) + { throw new FormatException("Format must contain '{0}' argument."); + } string tmp = string.Format(value, "test"); } @@ -83,7 +85,9 @@ public string BuildDoneMajorMessageStringFormat OnPropertyChanged(nameof(BuildDoneMajorMessageStringFormat)); if (!value.Contains("{0}")) + { throw new FormatException("Format must contain '{0}' argument."); + } string tmp = string.Format(value, "test"); } @@ -131,7 +135,9 @@ public string ExtraMessageStringFormat OnPropertyChanged(nameof(ExtraMessageStringFormat)); if (!value.Contains("{0}")) + { throw new FormatException("Format must contain '{0}' argument."); + } var tmp = string.Format(value, "test"); } diff --git a/src/BuildVision.UI/Settings/Models/ControlSettings.cs b/src/BuildVision.UI/Settings/Models/ControlSettings.cs index 0753314a..f73528cf 100644 --- a/src/BuildVision.UI/Settings/Models/ControlSettings.cs +++ b/src/BuildVision.UI/Settings/Models/ControlSettings.cs @@ -28,19 +28,29 @@ private void OnDeserialized(StreamingContext context) private void Init() { if (GeneralSettings == null) + { GeneralSettings = new GeneralSettings(); + } if (WindowSettings == null) + { WindowSettings = new WindowSettings(); + } if (GridSettings == null) + { GridSettings = new GridSettings(); + } if (BuildMessagesSettings == null) + { BuildMessagesSettings = new BuildMessagesSettings(); + } if (ProjectItemSettings == null) + { ProjectItemSettings = new ProjectItemSettings(); + } } } } diff --git a/src/BuildVision.UI/Settings/Models/GridSettings.cs b/src/BuildVision.UI/Settings/Models/GridSettings.cs index b936ffa2..a762410c 100644 --- a/src/BuildVision.UI/Settings/Models/GridSettings.cs +++ b/src/BuildVision.UI/Settings/Models/GridSettings.cs @@ -30,7 +30,9 @@ public IEnumerable SortableColumnsUIList { yield return GridColumnSettings.Empty; foreach (GridColumnSettings column in Columns.Where(x => ColumnsManager.ColumnIsSortable(x.PropertyNameId))) + { yield return column; + } } } @@ -40,7 +42,9 @@ public IEnumerable GroupableColumnsUIList { yield return GridColumnSettings.Empty; foreach (GridColumnSettings column in Columns.Where(ColumnsManager.ColumnIsGroupable)) + { yield return column; + } } } diff --git a/src/BuildVision/Commands/ShowToolWindowCommand.cs b/src/BuildVision/Commands/ShowToolWindowCommand.cs index 691f602e..071dd3e4 100644 --- a/src/BuildVision/Commands/ShowToolWindowCommand.cs +++ b/src/BuildVision/Commands/ShowToolWindowCommand.cs @@ -35,7 +35,9 @@ private static ToolWindowPane ShowToolWindow(AsyncPackage package) // The last flag is set to true so that if the tool window does not exists it will be created. var window = package.FindToolWindow(typeof(BuildVisionPane), 0, true); if (window == null || window.Frame == null) + { throw new InvalidOperationException(Resources.CanNotCreateWindow); + } var windowFrame = (IVsWindowFrame)window.Frame; ErrorHandler.ThrowOnFailure(windowFrame.Show()); diff --git a/src/BuildVision/Core/BuildVisionPane.cs b/src/BuildVision/Core/BuildVisionPane.cs index 5a0ce02e..2002f1f8 100644 --- a/src/BuildVision/Core/BuildVisionPane.cs +++ b/src/BuildVision/Core/BuildVisionPane.cs @@ -102,15 +102,22 @@ private void ViewModel_ShowOptionPage(Type obj) { var asyncPackage = (AsyncPackage)Package; if (obj == typeof(GeneralSettings)) + { asyncPackage.ShowOptionPage(typeof(GeneralSettingsDialogPage)); + } + if (obj == typeof(GridColumnSettings)) + { asyncPackage.ShowOptionPage(typeof(GridSettingsDialogPage)); + } } protected override void OnClose() { if (_controlCreatedSuccessfully) + { _packageSettingsProvider.Save(); + } base.OnClose(); } diff --git a/src/BuildVision/Core/Services.cs b/src/BuildVision/Core/Services.cs index 37efa8b8..8ed77ae0 100644 --- a/src/BuildVision/Core/Services.cs +++ b/src/BuildVision/Core/Services.cs @@ -16,11 +16,20 @@ static Ret GetGlobalService(IServiceProvider provider = null) where T : { Ret ret = null; if (provider != null) + { ret = provider.GetService(typeof(T)) as Ret; + } + if (ret != null) + { return ret; + } + if (UnitTestServiceProvider != null) + { return UnitTestServiceProvider.GetService(typeof(T)) as Ret; + } + return Package.GetGlobalService(typeof(T)) as Ret; } diff --git a/src/BuildVision/Core/SolutionBuildEvents.cs b/src/BuildVision/Core/SolutionBuildEvents.cs index 50804eae..9be3860f 100644 --- a/src/BuildVision/Core/SolutionBuildEvents.cs +++ b/src/BuildVision/Core/SolutionBuildEvents.cs @@ -15,7 +15,7 @@ public class SolutionBuildEvents : IVsUpdateSolutionEvents2, IVsUpdateSolutionEv private readonly ISolutionProvider _solutionProvider; private readonly IBuildInformationProvider _buildInformationProvider; private readonly BuildEvents _buildEvents; - private BuildActions _currentBuildAction; + private BuildAction _currentBuildAction; public SolutionBuildEvents( ISolutionProvider solutionProvider, @@ -38,7 +38,7 @@ public void UpdateSolution_BeginUpdateAction(uint dwAction) private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action) { // We use the action from UpdateSolution_BeginUpdateAction here because it givs closer details on the current action - _buildInformationProvider.BuildStarted(_currentBuildAction, (BuildScopes)scope); + _buildInformationProvider.BuildStarted(_currentBuildAction, (BuildScope)scope); } public int UpdateProjectCfg_Begin(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, ref int pfCancel) diff --git a/src/BuildVision/Extensions/BuildActionsExtensions.cs b/src/BuildVision/Extensions/BuildActionsExtensions.cs index f5346f22..311c2cac 100644 --- a/src/BuildVision/Extensions/BuildActionsExtensions.cs +++ b/src/BuildVision/Extensions/BuildActionsExtensions.cs @@ -5,18 +5,18 @@ namespace BuildVision.Extensions { public static class BuildActionsExtensions { - public static ProjectState GetProjectState(this BuildActions buildAction) + public static ProjectState GetProjectState(this BuildAction buildAction) { switch (buildAction) { - case BuildActions.BuildActionBuild: - case BuildActions.BuildActionRebuildAll: + case BuildAction.Build: + case BuildAction.RebuildAll: return ProjectState.Building; - case BuildActions.BuildActionClean: + case BuildAction.Clean: return ProjectState.Cleaning; - case BuildActions.BuildActionDeploy: + case BuildAction.Deploy: throw new InvalidOperationException("vsBuildActionDeploy not supported"); default: diff --git a/src/BuildVision/Extensions/BuildStateExtensions.cs b/src/BuildVision/Extensions/BuildStateExtensions.cs index 9d57c88f..a0bf0c95 100644 --- a/src/BuildVision/Extensions/BuildStateExtensions.cs +++ b/src/BuildVision/Extensions/BuildStateExtensions.cs @@ -5,7 +5,7 @@ namespace BuildVision.Extensions { public static class BuildStateExtensions { - public static TaskbarItemProgressState ToTaskBarItemProgressState(this BuildState buildState, BuildScopes buildScope) + public static TaskbarItemProgressState ToTaskBarItemProgressState(this BuildState buildState, BuildScope buildScope) { var progressState = TaskbarItemProgressState.Normal; if (buildState == BuildState.Cancelled) @@ -20,7 +20,7 @@ public static TaskbarItemProgressState ToTaskBarItemProgressState(this BuildStat { progressState = TaskbarItemProgressState.None; } - else if (buildScope != BuildScopes.BuildScopeSolution) + else if (buildScope != BuildScope.Solution) { progressState = TaskbarItemProgressState.Indeterminate; } diff --git a/src/BuildVision/Helpers/ProjectExtensions.cs b/src/BuildVision/Helpers/ProjectExtensions.cs index c70f1374..2139453d 100644 --- a/src/BuildVision/Helpers/ProjectExtensions.cs +++ b/src/BuildVision/Helpers/ProjectExtensions.cs @@ -102,25 +102,49 @@ public static IEnumerable GetBuildOutputFilePaths(this Project project, { Configuration targetConfig; if (configuration != null && platform != null) + { targetConfig = project.ConfigurationManager.Item(configuration, platform); + } else + { targetConfig = project.ConfigurationManager.ActiveConfiguration; + } var groups = new List(); if (fileTypes.LocalizedResourceDlls) + { groups.Add(BuildOutputGroup.LocalizedResourceDlls); + } + if (fileTypes.XmlSerializer) + { groups.Add("XmlSerializer"); + } + if (fileTypes.ContentFiles) + { groups.Add(BuildOutputGroup.ContentFiles); + } + if (fileTypes.Built) + { groups.Add(BuildOutputGroup.Built); + } + if (fileTypes.SourceFiles) + { groups.Add(BuildOutputGroup.SourceFiles); + } + if (fileTypes.Symbols) + { groups.Add(BuildOutputGroup.Symbols); + } + if (fileTypes.Documentation) + { groups.Add(BuildOutputGroup.Documentation); + } var filePaths = new List(); foreach (string groupName in groups) @@ -161,7 +185,9 @@ public static string GetFrameworkString(this Project project) { var framMonikerValue = (string)framMonikerProperty.Value; if (string.IsNullOrWhiteSpace(framMonikerValue)) + { return Resources.GridCellNoneText; + } framMonikerValue = framMonikerValue.Replace(",Version=v", " "); return framMonikerValue; @@ -171,7 +197,9 @@ public static string GetFrameworkString(this Project project) var framVersionProperty = project.GetPropertyOrDefault("TargetFrameworkVersion") ?? project.GetPropertyOrDefault("TargetFramework"); if (framVersionProperty == null || framVersionProperty.Value == null) + { return Resources.GridCellNoneText; + } var version = Convert.ToInt32(framVersionProperty.Value); string versionStr; @@ -302,11 +330,15 @@ public static IEnumerable GetFlavourTypes(this Project project) var myType = project.TryGetPropertyValueOrDefault("MyType"); // for VB.NET projects if (myType != null && myType.ToString() != "Empty") + { flavourTypes.Add(myType.ToString()); + } var keyword = project.TryGetPropertyValueOrDefault("keyword"); // for C++ projects if (keyword != null) + { flavourTypes.Add(keyword.ToString()); + } var filteredValues = flavourTypes.Where(str => !string.IsNullOrWhiteSpace(str)).Distinct(); return filteredValues; @@ -350,7 +382,9 @@ public static string GetOutputType(this Project project) { var property = project.GetPropertyOrDefault("OutputType"); if (property == null || property.Value == null) + { return Resources.GridCellNoneText; + } if (!Enum.TryParse(property.Value.ToString(), out prjOutputType outputType)) { @@ -382,7 +416,9 @@ public static string GetExtenderNames(this Project project) { var extenderNames = (object[])project.ExtenderNames; if (extenderNames == null || extenderNames.Length == 0) + { return Resources.GridCellNoneText; + } return string.Join("; ", extenderNames); } @@ -436,7 +472,9 @@ private static string GetProjectTypeFromRegistry(string projectKind, string vers LogManager.ForContext().Warning("Project type is taken from the registry: Kind={ProjectKind}, DTEVersion={Version}, Type={Type}", projectKind, version, type); if (string.IsNullOrWhiteSpace(type)) + { return null; + } _knownProjectTypes[projectKind] = type; return type; @@ -460,10 +498,14 @@ public static string GetRootNamespace(this Project project) public static bool IsDirty(this Project project) { if (project.IsDirty) + { return true; + } if (project.ProjectItems != null && project.ProjectItems.Cast().Any(x => x.ProjectItemIsDirty())) + { return true; + } return false; } @@ -476,17 +518,23 @@ public static string GetTreePath(this Project project, bool includeSelfProjectNa try { if (includeSelfProjectName) + { path.Append(project.Name); + } var parent = project; while (true) { parent = TryGetParentProject(parent); if (parent == null || parent == project) + { break; + } if (path.Length != 0) + { path.Insert(0, '\\'); + } path.Insert(0, parent.Name); } @@ -519,19 +567,25 @@ public static Project GetSubProject(this Project solutionFolder, Func GetSubProjects(this Project solutionFolder) { Project subProject = solutionFolder.ProjectItems.Item(i).SubProject; if (subProject == null) + { continue; + } // If this is another solution folder, do a recursive call, otherwise add if (subProject.Kind == EnvDTEProjectKinds.ProjectKindSolutionFolder) + { list.AddRange(GetSubProjects(subProject)); + } else if (!subProject.IsHidden()) + { list.Add(subProject); + } } return list; @@ -562,17 +622,23 @@ public static bool IsHidden(this Project project) try { if (_hiddenProjectsUniqueNames.Contains(project.UniqueName)) + { return true; + } // Solution Folder. if (project.Kind == EnvDTE.Constants.vsProjectKindSolutionItems) + { return true; + } // If projectIsInitialized == false then NotImplementedException will be occured // in project.FullName or project.FileName getters. bool projectIsInitialized = (project.Object != null); if (projectIsInitialized && project.FullName.EndsWith(".tmp_proj")) + { return true; + } return false; } @@ -588,10 +654,14 @@ public static bool IsProjectHidden(string projectFileName) try { if (_hiddenProjectsUniqueNames.Contains(projectFileName)) + { return true; + } if (projectFileName.EndsWith(".tmp_proj")) + { return true; + } return false; } diff --git a/src/BuildVision/Helpers/PropertiesExtensions.cs b/src/BuildVision/Helpers/PropertiesExtensions.cs index 1f16c172..600c1bba 100644 --- a/src/BuildVision/Helpers/PropertiesExtensions.cs +++ b/src/BuildVision/Helpers/PropertiesExtensions.cs @@ -23,7 +23,9 @@ public static T GetPropertyOrDefault(this Properties properties, string prope { var property = GetPropertyOrDefault(properties, propertyName); if (property == null) + { return null; + } return (T)property.Value; } diff --git a/src/BuildVision/Helpers/SolutionProjectsExtensions.cs b/src/BuildVision/Helpers/SolutionProjectsExtensions.cs index 409e46e0..e6ca27a3 100644 --- a/src/BuildVision/Helpers/SolutionProjectsExtensions.cs +++ b/src/BuildVision/Helpers/SolutionProjectsExtensions.cs @@ -64,12 +64,18 @@ public static IList GetProjects(this Solution solution) { var project = proj as Project; if (project == null) + { continue; + } if (project.Kind == EnvDTEProjectKinds.ProjectKindSolutionFolder) + { list.AddRange(project.GetSubProjects()); + } else if (!project.IsHidden()) + { list.Add(project); + } } return list; } @@ -82,18 +88,24 @@ public static Project GetProject(this Solution solution, Func con { var project = item.Current as Project; if (project == null) + { continue; + } if (project.Kind == EnvDTEProjectKinds.ProjectKindSolutionFolder) { var sub = project.GetSubProject(cond); if (sub != null) + { return sub; + } } else if (!project.IsHidden()) { if (cond(project)) + { return project; + } } } @@ -228,7 +240,9 @@ private static void UpdateNameProperties(Project project, ProjectItem projectIte projectItem.FullName = project.FullName; if (IsIntegrationServicesProject(project, projectItem)) + { AdjustUniqueNameForExtensionProjects(project, projectItem); + } try { diff --git a/src/BuildVision/Helpers/StateConverterHelper.cs b/src/BuildVision/Helpers/StateConverterHelper.cs index 6a942a9c..898e6f21 100644 --- a/src/BuildVision/Helpers/StateConverterHelper.cs +++ b/src/BuildVision/Helpers/StateConverterHelper.cs @@ -5,23 +5,23 @@ namespace BuildVision.Tool.Models { public class StateConverterHelper { - public static BuildActions ConvertSolutionBuildFlagsToBuildAction(uint dwAction, VSSOLNBUILDUPDATEFLAGS solutionFlags) + public static BuildAction ConvertSolutionBuildFlagsToBuildAction(uint dwAction, VSSOLNBUILDUPDATEFLAGS solutionFlags) { if (solutionFlags == (VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_FORCE_UPDATE)) { - return BuildActions.BuildActionRebuildAll; + return BuildAction.RebuildAll; } else if (solutionFlags == (VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_CLEAN)) { - return BuildActions.BuildActionClean; + return BuildAction.Clean; } else if (solutionFlags == (VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_NONE | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD)) { - return BuildActions.BuildActionBuild; + return BuildAction.Build; } else { - return BuildActions.Unknown; + return BuildAction.Unknown; } } } diff --git a/src/BuildVision/Services/BuildInformationProvider.cs b/src/BuildVision/Services/BuildInformationProvider.cs index 96531b42..025261cb 100644 --- a/src/BuildVision/Services/BuildInformationProvider.cs +++ b/src/BuildVision/Services/BuildInformationProvider.cs @@ -192,7 +192,7 @@ public void Run(CancellationToken cancellationToken) } } - public void BuildStarted(BuildActions buildAction, BuildScopes buildScope) + public void BuildStarted(BuildAction buildAction, BuildScope buildScope) { _currentQueuePosOfBuildingProject = 0; ErrorNavigationService.BuildErrorNavigated = false; @@ -218,9 +218,9 @@ public void BuildStarted(BuildActions buildAction, BuildScopes buildScope) _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, GetFinishedProjectsCount()); } - public void ProjectBuildStarted(IProjectItem projectItem, BuildActions buildAction) + public void ProjectBuildStarted(IProjectItem projectItem, BuildAction buildAction) { - if (BuildInformationModel.BuildAction == BuildActions.BuildActionDeploy) + if (BuildInformationModel.BuildAction == BuildAction.Deploy) { return; } @@ -240,9 +240,9 @@ public void ProjectBuildStarted(IProjectItem projectItem, BuildActions buildActi _taskBarInfoService.UpdateTaskBarInfo(BuildInformationModel.CurrentBuildState, BuildInformationModel.BuildScope, Projects.Count, GetFinishedProjectsCount()); _currentQueuePosOfBuildingProject++; - if (BuildInformationModel.BuildScope == BuildScopes.BuildScopeSolution && - (BuildInformationModel.BuildAction == BuildActions.BuildActionBuild || - BuildInformationModel.BuildAction == BuildActions.BuildActionRebuildAll)) + if (BuildInformationModel.BuildScope == BuildScope.Solution && + (BuildInformationModel.BuildAction == BuildAction.Build || + BuildInformationModel.BuildAction == BuildAction.RebuildAll)) { projInCollection.BuildOrder = _currentQueuePosOfBuildingProject; } @@ -259,9 +259,9 @@ private int GetFinishedProjectsCount() return BuildInformationModel.SucceededProjectsCount + BuildInformationModel.UpToDateProjectsCount + BuildInformationModel.WarnedProjectsCount + BuildInformationModel.FailedProjectsCount; } - public void ProjectBuildFinished(BuildActions buildAction, string projectIdentifier, bool success, bool canceled) + public void ProjectBuildFinished(BuildAction buildAction, string projectIdentifier, bool success, bool canceled) { - if (BuildInformationModel.BuildAction == BuildActions.BuildActionDeploy) + if (BuildInformationModel.BuildAction == BuildAction.Deploy) { return; } @@ -297,8 +297,8 @@ private ProjectState GetProjectState(bool success, bool canceled, IProjectItem c ProjectState projectState; switch (BuildInformationModel.BuildAction) { - case BuildActions.BuildActionBuild: - case BuildActions.BuildActionRebuildAll: + case BuildAction.Build: + case BuildAction.RebuildAll: if (success) { if (_packageSettingsProvider.Settings.GeneralSettings.ShowWarningSignForBuilds && currentProject.WarningsCount > 0) @@ -317,7 +317,7 @@ private ProjectState GetProjectState(bool success, bool canceled, IProjectItem c } break; - case BuildActions.BuildActionClean: + case BuildAction.Clean: projectState = success ? ProjectState.CleanDone : ProjectState.CleanError; break; @@ -341,12 +341,12 @@ public void BuildUpdate() public void BuildFinished(bool success, bool canceled) { - if (BuildInformationModel.BuildAction == BuildActions.BuildActionDeploy) + if (BuildInformationModel.BuildAction == BuildAction.Deploy) { return; } - if (BuildInformationModel.BuildScope == BuildScopes.BuildScopeSolution) + if (BuildInformationModel.BuildScope == BuildScope.Solution) { foreach (var projectItem in Projects) { diff --git a/src/BuildVision/Services/BuildOutputLogger.cs b/src/BuildVision/Services/BuildOutputLogger.cs index 96fb9904..fdc015b7 100644 --- a/src/BuildVision/Services/BuildOutputLogger.cs +++ b/src/BuildVision/Services/BuildOutputLogger.cs @@ -103,7 +103,9 @@ private void EventSource_ErrorRaised(BuildEventArgs e, ErrorLevel errorLevel) try { if (e.BuildEventContext.IsBuildEventContextInvalid()) + { return; + } int projectInstanceId = e.BuildEventContext.ProjectInstanceId; int projectContextId = e.BuildEventContext.ProjectContextId; diff --git a/src/BuildVision/Services/BuildService.cs b/src/BuildVision/Services/BuildService.cs index b47c6efd..a9a5aa3a 100644 --- a/src/BuildVision/Services/BuildService.cs +++ b/src/BuildVision/Services/BuildService.cs @@ -65,10 +65,15 @@ public void BuildSolution() public async System.Threading.Tasks.Task CancelBuildAsync(IBuildInformationModel buildInformationModel) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); - if (buildInformationModel.BuildAction == BuildActions.BuildActionClean) + if (buildInformationModel.BuildAction == BuildAction.Clean) + { return; + } + if (buildInformationModel.CurrentBuildState != BuildState.InProgress || _buildCancelled || _buildCancelledInternally) + { return; + } try { @@ -104,7 +109,10 @@ private void SelectProjectInSolutionExplorer(IProjectItem projectItem) var project = Core.Services.Dte2.Solution.GetProject(x => x.UniqueName == projectItem.UniqueName); var item = solutionExplorer.FindHierarchyItem(project); if (item == null) + { throw new ProjectNotFoundException($"Project '{projectItem.UniqueName}' not found in SolutionExplorer."); + } + solutionExplorer.Parent.Activate(); item.Select(vsUISelectionType.vsUISelectionTypeSelect); } @@ -189,8 +197,7 @@ private string GetCopyBuildOutputFilesToClipboardActionMessage(string template, filesListArg = "."; } - string msg = string.Format(template, filesCountArg, filesListArg); - return msg; + return string.Format(template, filesCountArg, filesListArg); } private void RaiseCommand(VSConstants.VSStd97CmdID command) diff --git a/src/BuildVision/Services/ErrorNavigationService.cs b/src/BuildVision/Services/ErrorNavigationService.cs index 6aaa9fc0..22c8151e 100644 --- a/src/BuildVision/Services/ErrorNavigationService.cs +++ b/src/BuildVision/Services/ErrorNavigationService.cs @@ -34,16 +34,24 @@ public void NavigateToErrorItem(ErrorItem errorItem) var project = dte.Solution.GetProject(x => x.FileName == errorItem.ProjectFile); if (project == null) + { throw new ArgumentNullException("project"); + } if (errorItem == null) + { throw new ArgumentNullException("errorItem"); + } if (!errorItem.CanNavigateTo) + { return; + } if (string.IsNullOrEmpty(errorItem.File)) + { return; + } string fullPath; @@ -57,18 +65,24 @@ public void NavigateToErrorItem(ErrorItem errorItem) { var projectItemFile = project.FindProjectItem(errorItem.File); if (projectItemFile == null) + { return; + } fullPath = projectItemFile.Properties.GetPropertyOrDefault("FullPath"); if (fullPath == null) + { throw new KeyNotFoundException("FullPath property not found."); + } } try { var window = project.DTE.ItemOperations.OpenFile(fullPath, EnvDTE.Constants.vsViewKindAny); if (window == null) + { throw new NullReferenceException("Associated window is null reference."); + } window.Activate(); diff --git a/src/BuildVision/Services/PackageSettingsProvider.cs b/src/BuildVision/Services/PackageSettingsProvider.cs index 3b5c1fd0..62e988c1 100644 --- a/src/BuildVision/Services/PackageSettingsProvider.cs +++ b/src/BuildVision/Services/PackageSettingsProvider.cs @@ -36,7 +36,9 @@ public void Save() private void SaveSettings() { if (!_settingsStore.CollectionExists(settingsCategoryName)) + { _settingsStore.CreateCollection(settingsCategoryName); + } var legacySerializer = new LegacyConfigurationSerializer(); var value = legacySerializer.Serialize(Settings); diff --git a/src/BuildVision/Services/SolutionProvider.cs b/src/BuildVision/Services/SolutionProvider.cs index 7dee7e07..25a37df8 100644 --- a/src/BuildVision/Services/SolutionProvider.cs +++ b/src/BuildVision/Services/SolutionProvider.cs @@ -50,7 +50,9 @@ public ISolutionModel GetSolutionModel() private void RefrehSolutionModel() { if (_solutionModel == null) + { _solutionModel = new SolutionModel(); + } try { @@ -95,7 +97,10 @@ private void RefrehSolutionModel() public IEnumerable GetProjects() { if (_solution == null) + { ReloadSolution(); + } + return _solution.GetProjectItems(); } } diff --git a/src/BuildVision/Services/StatusBarNotificationService.cs b/src/BuildVision/Services/StatusBarNotificationService.cs index 346fbf3b..84685775 100644 --- a/src/BuildVision/Services/StatusBarNotificationService.cs +++ b/src/BuildVision/Services/StatusBarNotificationService.cs @@ -27,7 +27,9 @@ public StatusBarNotificationService( public void ShowText(string str) { if (!_packageSettingsProvider.Settings.GeneralSettings.EnableStatusBarOutput) + { return; + } var statusBar = _serviceProvider.GetService(typeof(IVsStatusbar)) as IVsStatusbar; statusBar.FreezeOutput(0); @@ -37,7 +39,9 @@ public void ShowText(string str) public void ShowTextWithFreeze(string str) { if (!_packageSettingsProvider.Settings.GeneralSettings.EnableStatusBarOutput) + { return; + } var statusBar = _serviceProvider.GetService(); statusBar.FreezeOutput(0); diff --git a/src/BuildVision/Services/TaskBarInfoService.cs b/src/BuildVision/Services/TaskBarInfoService.cs index 99105d68..4587ca9d 100644 --- a/src/BuildVision/Services/TaskBarInfoService.cs +++ b/src/BuildVision/Services/TaskBarInfoService.cs @@ -28,7 +28,7 @@ public TaskBarInfoService(IPackageSettingsProvider packageSettingsProvider) _packageSettingsProvider = packageSettingsProvider; } - public void UpdateTaskBarInfo(BuildState buildState, BuildScopes buildScope, int projectsCount, int finishedProjects) + public void UpdateTaskBarInfo(BuildState buildState, BuildScope buildScope, int projectsCount, int finishedProjects) { if (_resetTaskBarInfoCts != null && !_resetTaskBarInfoCts.IsCancellationRequested) { diff --git a/src/BuildVision/Services/WindowStateService.cs b/src/BuildVision/Services/WindowStateService.cs index a84dfdbe..e27fdf5d 100644 --- a/src/BuildVision/Services/WindowStateService.cs +++ b/src/BuildVision/Services/WindowStateService.cs @@ -85,7 +85,9 @@ private void MinimizeToolWindow() var doc = _dte.ActiveDocument; if (doc != null) + { doc.Activate(); + } } private static Window GetWindowInstance(DTE dte, Guid windowGuid) @@ -129,7 +131,10 @@ private void ApplyToolWindowStateAction(WindowState windowState) public void Initialize(ToolWindowPane toolWindowPane) { if (toolWindowPane == null) + { return; + } + if (_window == null || _windowFrame == null) { ThreadHelper.ThrowIfNotOnUIThread(); @@ -138,7 +143,9 @@ public void Initialize(ToolWindowPane toolWindowPane) _windowFrame = (IVsWindowFrame)toolWindowPane.Frame; _window = GetWindowInstance(_dte, typeof(BuildVisionPane).GUID); if (_window == null) + { throw new InvalidOperationException("Unable to get Window instance."); + } } } diff --git a/src/BuildVision/Views/Settings/SettingsDialogPage.cs b/src/BuildVision/Views/Settings/SettingsDialogPage.cs index 700f3999..38c95de6 100644 --- a/src/BuildVision/Views/Settings/SettingsDialogPage.cs +++ b/src/BuildVision/Views/Settings/SettingsDialogPage.cs @@ -36,10 +36,15 @@ protected override void OnActivate(CancelEventArgs e) _packageSettingsProvider = Package.GetGlobalService(typeof(IPackageSettingsProvider)) as IPackageSettingsProvider; Assumes.Present(_packageSettingsProvider); if (_editSettings == null) + { _editSettings = Settings.Clone(); + } if (_ctrl.DataContext == null) + { _ctrl.DataContext = _editSettings; + } + base.OnActivate(e); } @@ -59,7 +64,9 @@ protected override void OnClosed(EventArgs e) { _editSettings = null; if (_ctrl != null) + { _ctrl.DataContext = null; + } if (_notifySettingsChangedOnce) { diff --git a/test/BuildVision.UnitTests/BuildInformationModelTests.cs b/test/BuildVision.UnitTests/BuildInformationModelTests.cs index abcb0a46..47c444e0 100644 --- a/test/BuildVision.UnitTests/BuildInformationModelTests.cs +++ b/test/BuildVision.UnitTests/BuildInformationModelTests.cs @@ -26,7 +26,7 @@ public void SetBuildAction_ShouldTrigger_PropertyChanged_ForStateIconKey() var sut = new BuildInformationModel(); using (var monitoredSut = sut.Monitor()) { - sut.BuildAction = BuildActions.BuildActionBuild; + sut.BuildAction = BuildAction.Build; monitoredSut.Should().RaisePropertyChangeFor(x => x.BuildAction); monitoredSut.Should().RaisePropertyChangeFor(x => x.StateIconKey); @@ -54,11 +54,11 @@ public void StateIconKey_ForNonStartedProject_ShouldBe_StandBy() } [Theory] - [InlineData(BuildActions.BuildActionRebuildAll, "Rebuild")] - [InlineData(BuildActions.BuildActionBuild, "Build")] - [InlineData(BuildActions.BuildActionClean, "Clean")] - [InlineData(BuildActions.BuildActionDeploy, "StandBy")] - public void StateIconKey_For_InProgressState_ShouldBe_RightStateDependingOnAction(BuildActions buildAction, string expectedStateKey) + [InlineData(BuildAction.RebuildAll, "Rebuild")] + [InlineData(BuildAction.Build, "Build")] + [InlineData(BuildAction.Clean, "Clean")] + [InlineData(BuildAction.Deploy, "StandBy")] + public void StateIconKey_For_InProgressState_ShouldBe_RightStateDependingOnAction(BuildAction buildAction, string expectedStateKey) { var buildInformationModel = new BuildInformationModel(); buildInformationModel.CurrentBuildState = BuildState.InProgress; @@ -67,11 +67,11 @@ public void StateIconKey_For_InProgressState_ShouldBe_RightStateDependingOnActio } [Theory] - [InlineData(BuildActions.BuildActionRebuildAll, "RebuildDone")] - [InlineData(BuildActions.BuildActionBuild, "BuildDone")] - [InlineData(BuildActions.BuildActionClean, "CleanDone")] - [InlineData(BuildActions.BuildActionDeploy, "StandBy")] - public void StateIconKey_For_InDoneState_ShouldBe_RightStateDependingOnAction(BuildActions buildAction, string expectedStateKey) + [InlineData(BuildAction.RebuildAll, "RebuildDone")] + [InlineData(BuildAction.Build, "BuildDone")] + [InlineData(BuildAction.Clean, "CleanDone")] + [InlineData(BuildAction.Deploy, "StandBy")] + public void StateIconKey_For_InDoneState_ShouldBe_RightStateDependingOnAction(BuildAction buildAction, string expectedStateKey) { var buildInformationModel = new BuildInformationModel(); buildInformationModel.CurrentBuildState = BuildState.Done; @@ -80,11 +80,11 @@ public void StateIconKey_For_InDoneState_ShouldBe_RightStateDependingOnAction(Bu } [Theory] - [InlineData(BuildActions.BuildActionRebuildAll, "RebuildFailed")] - [InlineData(BuildActions.BuildActionBuild, "BuildFailed")] - [InlineData(BuildActions.BuildActionClean, "CleanFailed")] - [InlineData(BuildActions.BuildActionDeploy, "StandBy")] - public void StateIconKey_For_InFailedState_ShouldBe_RightStateDependingOnAction(BuildActions buildAction, string expectedStateKey) + [InlineData(BuildAction.RebuildAll, "RebuildFailed")] + [InlineData(BuildAction.Build, "BuildFailed")] + [InlineData(BuildAction.Clean, "CleanFailed")] + [InlineData(BuildAction.Deploy, "StandBy")] + public void StateIconKey_For_InFailedState_ShouldBe_RightStateDependingOnAction(BuildAction buildAction, string expectedStateKey) { var buildInformationModel = new BuildInformationModel(); buildInformationModel.CurrentBuildState = BuildState.Failed; @@ -93,11 +93,11 @@ public void StateIconKey_For_InFailedState_ShouldBe_RightStateDependingOnAction( } [Theory] - [InlineData(BuildActions.BuildActionRebuildAll, "RebuildErrorDone")] - [InlineData(BuildActions.BuildActionBuild, "BuildErrorDone")] - [InlineData(BuildActions.BuildActionClean, "CleanErrorDone")] - [InlineData(BuildActions.BuildActionDeploy, "StandBy")] - public void StateIconKey_For_InErrorDoneState_ShouldBe_RightStateDependingOnAction(BuildActions buildAction, string expectedStateKey) + [InlineData(BuildAction.RebuildAll, "RebuildErrorDone")] + [InlineData(BuildAction.Build, "BuildErrorDone")] + [InlineData(BuildAction.Clean, "CleanErrorDone")] + [InlineData(BuildAction.Deploy, "StandBy")] + public void StateIconKey_For_InErrorDoneState_ShouldBe_RightStateDependingOnAction(BuildAction buildAction, string expectedStateKey) { var buildInformationModel = new BuildInformationModel(); buildInformationModel.CurrentBuildState = BuildState.ErrorDone; @@ -106,11 +106,11 @@ public void StateIconKey_For_InErrorDoneState_ShouldBe_RightStateDependingOnActi } [Theory] - [InlineData(BuildActions.BuildActionRebuildAll, "RebuildCancelled")] - [InlineData(BuildActions.BuildActionBuild, "BuildCancelled")] - [InlineData(BuildActions.BuildActionClean, "CleanCancelled")] - [InlineData(BuildActions.BuildActionDeploy, "StandBy")] - public void StateIconKey_For_InCancelledState_ShouldBe_RightStateDependingOnAction(BuildActions buildAction, string expectedStateKey) + [InlineData(BuildAction.RebuildAll, "RebuildCancelled")] + [InlineData(BuildAction.Build, "BuildCancelled")] + [InlineData(BuildAction.Clean, "CleanCancelled")] + [InlineData(BuildAction.Deploy, "StandBy")] + public void StateIconKey_For_InCancelledState_ShouldBe_RightStateDependingOnAction(BuildAction buildAction, string expectedStateKey) { var buildInformationModel = new BuildInformationModel(); buildInformationModel.CurrentBuildState = BuildState.Cancelled;