[Analyzers] Update StyleCop and enable SA1200 (#22707)

* update StyleCop and enable SA1200

* Fix merge issues

* fix build and added using rule
This commit is contained in:
Davide Giacometti 2022-12-18 14:27:14 +01:00 committed by GitHub
parent 617150cf50
commit 6d138e80fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 338 additions and 371 deletions

View File

@ -29,14 +29,14 @@
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<Compile Include="$(MSBuildThisFileDirectory)\src\codeAnalysis\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\src\codeAnalysis\StyleCop.json" Link="StyleCop.json" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0-preview1.22464.1">
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

View File

@ -8,7 +8,6 @@ dotnet_diagnostic.CA1303.severity = suggestion
# CA1051: Do not declare visible instance fields
dotnet_code_quality.ca1051.exclude_structs = true
csharp_using_directive_placement = inside_namespace:warning
csharp_prefer_simple_using_statement = true:suggestion
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent

View File

@ -12,7 +12,6 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")]

View File

@ -15,7 +15,8 @@
"newlineAtEndOfFile": "require"
},
"orderingRules": {
"usingDirectivesPlacement": "outsideNamespace"
"usingDirectivesPlacement": "outsideNamespace",
"systemUsingDirectivesFirst": true
}
}
}

View File

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
namespace ManagedCommon
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
public static class ColorFormatHelper
{
/// <summary>
@ -16,7 +16,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The cyan[0..1], magenta[0..1], yellow[0..1] and black key[0..1] of the converted color</returns>
public static (double cyan, double magenta, double yellow, double blackKey) ConvertToCMYKColor(Color color)
public static (double Cyan, double Magenta, double Yellow, double BlackKey) ConvertToCMYKColor(Color color)
{
// special case for black (avoid division by zero)
if (color.R == 0 && color.G == 0 && color.B == 0)
@ -48,7 +48,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and brightness [0..1] of the converted color</returns>
public static (double hue, double saturation, double brightness) ConvertToHSBColor(Color color)
public static (double Hue, double Saturation, double Brightness) ConvertToHSBColor(Color color)
{
// HSB and HSV represents the same color space
return ConvertToHSVColor(color);
@ -59,7 +59,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and value [0..1] of the converted color</returns>
public static (double hue, double saturation, double value) ConvertToHSVColor(Color color)
public static (double Hue, double Saturation, double Value) ConvertToHSVColor(Color color)
{
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
@ -72,7 +72,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and intensity [0..1] of the converted color</returns>
public static (double hue, double saturation, double intensity) ConvertToHSIColor(Color color)
public static (double Hue, double Saturation, double Intensity) ConvertToHSIColor(Color color)
{
// special case for black
if (color.R == 0 && color.G == 0 && color.B == 0)
@ -96,7 +96,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], saturation [0..1] and lightness [0..1] values of the converted color</returns>
public static (double hue, double saturation, double lightness) ConvertToHSLColor(Color color)
public static (double Hue, double Saturation, double Lightness) ConvertToHSLColor(Color color)
{
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
@ -120,7 +120,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue [0°..360°], whiteness [0..1] and blackness [0..1] of the converted color</returns>
public static (double hue, double whiteness, double blackness) ConvertToHWBColor(Color color)
public static (double Hue, double Whiteness, double Blackness) ConvertToHWBColor(Color color)
{
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;
@ -133,10 +133,10 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The lightness [0..100] and two chromaticities [-128..127]</returns>
public static (double lightness, double chromaticityA, double chromaticityB) ConvertToCIELABColor(Color color)
public static (double Lightness, double ChromaticityA, double ChromaticityB) ConvertToCIELABColor(Color color)
{
var xyz = ConvertToCIEXYZColor(color);
var lab = GetCIELABColorFromCIEXYZ(xyz.x, xyz.y, xyz.z);
var lab = GetCIELABColorFromCIEXYZ(xyz.X, xyz.Y, xyz.Z);
return lab;
}
@ -150,7 +150,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The X [0..1], Y [0..1] and Z [0..1]</returns>
public static (double x, double y, double z) ConvertToCIEXYZColor(Color color)
public static (double X, double Y, double Z) ConvertToCIEXYZColor(Color color)
{
double r = color.R / 255d;
double g = color.G / 255d;
@ -177,7 +177,7 @@ namespace ManagedCommon
/// <param name="y">The <see cref="y"/> represents the luminance</param>
/// <param name="z">The <see cref="z"/> is quasi-equal to blue (of CIE RGB)</param>
/// <returns>The lightness [0..100] and two chromaticities [-128..127]</returns>
private static (double lightness, double chromaticityA, double chromaticityB)
private static (double Lightness, double ChromaticityA, double ChromaticityB)
GetCIELABColorFromCIEXYZ(double x, double y, double z)
{
// sRGB reference white (x=0.3127, y=0.3290, Y=1.0), actually CIE Standard Illuminant D65 truncated to 4 decimal places,
@ -215,7 +215,7 @@ namespace ManagedCommon
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The hue, whiteness [0..1] and blackness [0..1] of the converted color</returns>
public static (string hue, double whiteness, double blackness) ConvertToNaturalColor(Color color)
public static (string Hue, double Whiteness, double Blackness) ConvertToNaturalColor(Color color)
{
var min = Math.Min(Math.Min(color.R, color.G), color.B) / 255d;
var max = Math.Max(Math.Max(color.R, color.G), color.B) / 255d;

View File

@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
using System;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml.Data;
public sealed class FileCountConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)

View File

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.IO;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
using System;
using System.IO;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml.Data;
public sealed class FileListToDescriptionConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)

View File

@ -2,16 +2,16 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using System.IO;
using CommunityToolkit.WinUI.UI;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage;
namespace PowerToys.FileLocksmithUI.Converters
{
using System;
using System.Drawing;
using System.IO;
using CommunityToolkit.WinUI.UI;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Media.Imaging;
using Windows.Storage;
public sealed class PidToIconConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)

View File

@ -2,14 +2,14 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
namespace PowerToys.FileLocksmithUI.Converters
{
using System;
using System.Globalization;
using FileLocksmith.Interop;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
public sealed class UserToSystemWarningVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)

View File

@ -2,23 +2,20 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FileLocksmith.Interop;
using global::FileLocksmithUI.Helpers;
namespace PowerToys.FileLocksmithUI.ViewModels
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using FileLocksmith.Interop;
using global::FileLocksmithUI;
using global::FileLocksmithUI.Helpers;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml.Controls;
#pragma warning disable CA1708 // Identifiers should differ by more than case
public partial class MainViewModel : ObservableObject, IDisposable
#pragma warning restore CA1708 // Identifiers should differ by more than case
@ -31,7 +28,7 @@ namespace PowerToys.FileLocksmithUI.ViewModels
private bool _disposed;
private CancellationTokenSource _cancelProcessWatching;
public ObservableCollection<ProcessResult> Processes { get; } = new ();
public ObservableCollection<ProcessResult> Processes { get; } = new();
public bool IsLoading
{

View File

@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Microsoft.UI.Xaml.Controls;
using PowerToys.FileLocksmithUI.ViewModels;
namespace PowerToys.FileLocksmithUI.Views
{
using System;
using Microsoft.UI.Xaml.Controls;
using PowerToys.FileLocksmithUI.ViewModels;
public sealed partial class MainPage : Page
{
public MainViewModel ViewModel { get; private set; }

View File

@ -2,11 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Hosts.Helpers
{
using System;
using System.Runtime.InteropServices;
internal class NativeMethods
{
[DllImport("user32.dll", SetLastError = true)]

View File

@ -13,11 +13,10 @@ using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Windows.Graphics;
using WinUIEx;
using static NativeMethods;
namespace MeasureToolUI
{
using static NativeMethods;
/// <summary>
/// An empty window that can be used on its own or navigated to within a Frame.
/// </summary>

View File

@ -57,7 +57,8 @@ namespace Awake.Core
_log.Error($"An error occurred initializing the tray. {ex.Message}");
_log.Error($"{ex.StackTrace}");
}
}, TrayIcon);
},
TrayIcon);
}
/// <summary>

View File

@ -38,19 +38,21 @@ namespace ColorPicker.Behaviors
{
Task.Run(
new Action(() =>
{
Dispatcher.BeginInvoke(
new Action(() =>
{
if (e.LeftButton == MouseButtonState.Pressed)
{
var data = new DataObject();
data.SetData("Source", (sender as FrameworkElement).DataContext);
DragDrop.DoDragDrop(sender as DependencyObject, data, DragDropEffects.Move);
e.Handled = true;
}
}), null);
}), CancellationToken.None);
{
Dispatcher.BeginInvoke(
new Action(() =>
{
if (e.LeftButton == MouseButtonState.Pressed)
{
var data = new DataObject();
data.SetData("Source", (sender as FrameworkElement).DataContext);
DragDrop.DoDragDrop(sender as DependencyObject, data, DragDropEffects.Move);
e.Handled = true;
}
}),
null);
}),
CancellationToken.None);
}
}

View File

@ -103,28 +103,28 @@ namespace ColorPicker.Controls
HueGradientSlider.Background = gradientBrush;
}
private static void SetColorVariationsForCurrentColor(DependencyObject d, (double hue, double saturation, double value) hsv)
private static void SetColorVariationsForCurrentColor(DependencyObject d, (double Hue, double Saturation, double Value) hsv)
{
var hueCoefficient = 0;
var hueCoefficient2 = 0;
if (1 - hsv.value < 0.15)
if (1 - hsv.Value < 0.15)
{
hueCoefficient = 1;
}
if (hsv.value - 0.3 < 0)
if (hsv.Value - 0.3 < 0)
{
hueCoefficient2 = 1;
}
var s = hsv.saturation;
var s = hsv.Saturation;
var control = (ColorPickerControl)d;
control.colorVariation1Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.hue + (hueCoefficient * 8), 360), s, Math.Min(hsv.value + 0.3, 1)));
control.colorVariation2Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.hue + (hueCoefficient * 4), 360), s, Math.Min(hsv.value + 0.15, 1)));
control.colorVariation1Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.Hue + (hueCoefficient * 8), 360), s, Math.Min(hsv.Value + 0.3, 1)));
control.colorVariation2Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Min(hsv.Hue + (hueCoefficient * 4), 360), s, Math.Min(hsv.Value + 0.15, 1)));
control.colorVariation3Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.hue - (hueCoefficient2 * 4), 0), s, Math.Max(hsv.value - 0.2, 0)));
control.colorVariation4Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.hue - (hueCoefficient2 * 8), 0), s, Math.Max(hsv.value - 0.3, 0)));
control.colorVariation3Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.Hue - (hueCoefficient2 * 4), 0), s, Math.Max(hsv.Value - 0.2, 0)));
control.colorVariation4Button.Background = new SolidColorBrush(HSVColor.RGBFromHSV(Math.Max(hsv.Hue - (hueCoefficient2 * 8), 0), s, Math.Max(hsv.Value - 0.3, 0)));
}
private void UpdateValueColorGradient(double posX)
@ -312,9 +312,9 @@ namespace ColorPicker.Controls
{
var hsv = ColorFormatHelper.ConvertToHSVColor(color);
var huePosition = (hsv.hue / 360) * HueGradientSlider.Maximum;
var saturationPosition = hsv.saturation * SaturationGradientSlider.Maximum;
var valuePosition = hsv.value * ValueGradientSlider.Maximum;
var huePosition = (hsv.Hue / 360) * HueGradientSlider.Maximum;
var saturationPosition = hsv.Saturation * SaturationGradientSlider.Maximum;
var valuePosition = hsv.Value * ValueGradientSlider.Maximum;
UpdateHueColorGradient(huePosition);
UpdateSaturationColorGradient(saturationPosition);
UpdateValueColorGradient(valuePosition);

View File

@ -2,7 +2,6 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
namespace ColorPicker.Helpers
@ -17,7 +16,7 @@ namespace ColorPicker.Helpers
/// </summary>
/// <param name="color">The <see cref="Color"/> to convert</param>
/// <returns>The int / 255d for each value to get value between 0 and 1</returns>
internal static (double red, double green, double blue) ConvertToDouble(Color color)
internal static (double Red, double Green, double Blue) ConvertToDouble(Color color)
=> (color.R / 255d, color.G / 255d, color.B / 255d);
}
}

View File

@ -189,7 +189,7 @@ namespace ColorPicker.ViewModels
{
".TXT" => colors.ToTxt(';'),
".JSON" => colors.ToJson(),
_ => string.Empty
_ => string.Empty,
};
File.WriteAllText(dialog.FileName, contentToWrite);

View File

@ -5,7 +5,6 @@
using System;
using System.Drawing;
using System.Globalization;
using ColorPicker.Helpers;
using ManagedCommon;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -57,13 +56,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSLColor(color);
// hue[0°..360°]
Assert.AreEqual(result.hue, hue, 0.2d);
Assert.AreEqual(result.Hue, hue, 0.2d);
// saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.2d);
Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d);
// lightness[0..1]
Assert.AreEqual(result.lightness * 100d, lightness, 0.2d);
Assert.AreEqual(result.Lightness * 100d, lightness, 0.2d);
}
// test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum
@ -106,13 +105,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSVColor(color);
// hue [0°..360°]
Assert.AreEqual(result.hue, hue, 0.2d);
Assert.AreEqual(result.Hue, hue, 0.2d);
// saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.2d);
Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d);
// value[0..1]
Assert.AreEqual(result.value * 100d, value, 0.2d);
Assert.AreEqual(result.Value * 100d, value, 0.2d);
}
// test values taken from https://de.wikipedia.org/wiki/HSV-Farbraum
@ -155,13 +154,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSBColor(color);
// hue [0°..360°]
Assert.AreEqual(result.hue, hue, 0.2d);
Assert.AreEqual(result.Hue, hue, 0.2d);
// saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.2d);
Assert.AreEqual(result.Saturation * 100d, saturation, 0.2d);
// value[0..1]
Assert.AreEqual(result.brightness * 100d, value, 0.2d);
Assert.AreEqual(result.Brightness * 100d, value, 0.2d);
}
[TestMethod]
@ -199,16 +198,16 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToCMYKColor(color);
// cyan[0..1]
Assert.AreEqual(result.cyan * 100d, cyan, 0.5d);
Assert.AreEqual(result.Cyan * 100d, cyan, 0.5d);
// magenta[0..1]
Assert.AreEqual(result.magenta * 100d, magenta, 0.5d);
Assert.AreEqual(result.Magenta * 100d, magenta, 0.5d);
// yellow[0..1]
Assert.AreEqual(result.yellow * 100d, yellow, 0.5d);
Assert.AreEqual(result.Yellow * 100d, yellow, 0.5d);
// black[0..1]
Assert.AreEqual(result.blackKey * 100d, blackKey, 0.5d);
Assert.AreEqual(result.BlackKey * 100d, blackKey, 0.5d);
}
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
@ -249,13 +248,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHSIColor(color);
// hue[0°..360°]
Assert.AreEqual(result.hue, hue, 0.5d);
Assert.AreEqual(result.Hue, hue, 0.5d);
// saturation[0..1]
Assert.AreEqual(result.saturation * 100d, saturation, 0.5d);
Assert.AreEqual(result.Saturation * 100d, saturation, 0.5d);
// intensity[0..1]
Assert.AreEqual(result.intensity * 100d, intensity, 0.5d);
Assert.AreEqual(result.Intensity * 100d, intensity, 0.5d);
}
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
@ -297,13 +296,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToHWBColor(color);
// hue[0°..360°]
Assert.AreEqual(result.hue, hue, 0.5d);
Assert.AreEqual(result.Hue, hue, 0.5d);
// whiteness[0..1]
Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d);
Assert.AreEqual(result.Whiteness * 100d, whiteness, 0.5d);
// blackness[0..1]
Assert.AreEqual(result.blackness * 100d, blackness, 0.5d);
Assert.AreEqual(result.Blackness * 100d, blackness, 0.5d);
}
// values taken from https://en.wikipedia.org/wiki/HSL_and_HSV#Examples
@ -345,13 +344,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToNaturalColor(color);
// hue
Assert.AreEqual(result.hue, hue);
Assert.AreEqual(result.Hue, hue);
// whiteness[0..1]
Assert.AreEqual(result.whiteness * 100d, whiteness, 0.5d);
Assert.AreEqual(result.Whiteness * 100d, whiteness, 0.5d);
// blackness[0..1]
Assert.AreEqual(result.blackness * 100d, blackness, 0.5d);
Assert.AreEqual(result.Blackness * 100d, blackness, 0.5d);
}
[TestMethod]
@ -401,13 +400,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToCIELABColor(color);
// lightness[0..100]
Assert.AreEqual(Math.Round(result.lightness, 2), lightness);
Assert.AreEqual(Math.Round(result.Lightness, 2), lightness);
// chromaticityA[-128..127]
Assert.AreEqual(Math.Round(result.chromaticityA, 2), chromaticityA);
Assert.AreEqual(Math.Round(result.ChromaticityA, 2), chromaticityA);
// chromaticityB[-128..127]
Assert.AreEqual(Math.Round(result.chromaticityB, 2), chromaticityB);
Assert.AreEqual(Math.Round(result.ChromaticityB, 2), chromaticityB);
}
// The following results are computed using LittleCMS2, an open-source color management engine,
@ -465,13 +464,13 @@ namespace Microsoft.ColorPicker.UnitTests
var result = ColorFormatHelper.ConvertToCIEXYZColor(color);
// x[0..0.95047]
Assert.AreEqual(Math.Round(result.x * 100, 4), x);
Assert.AreEqual(Math.Round(result.X * 100, 4), x);
// y[0..1]
Assert.AreEqual(Math.Round(result.y * 100, 4), y);
Assert.AreEqual(Math.Round(result.Y * 100, 4), y);
// z[0..1.08883]
Assert.AreEqual(Math.Round(result.z * 100, 4), z);
Assert.AreEqual(Math.Round(result.Z * 100, 4), z);
}
[TestMethod]

View File

@ -2,11 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Windows.Automation.Peers;
using System.Windows.Controls;
namespace FancyZonesEditor.Controls
{
using System.Windows.Automation.Peers;
using System.Windows.Controls;
/// <summary>
/// Interaction logic for CustomSlider.xaml
/// </summary>

View File

@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
namespace FancyZonesEditor.Controls
{
using System.Globalization;
using System.Windows.Automation.Peers;
using System.Windows.Controls;
internal class CustomSliderAutomationPeer : SliderAutomationPeer
{
private string name = string.Empty;

View File

@ -86,7 +86,7 @@ namespace ImageResizer.Models
var batch = CreateBatch(_ => { });
batch.Files.Add("Image1.jpg");
batch.Files.Add("Image2.jpg");
var calls = new ConcurrentBag<(int i, double count)>();
var calls = new ConcurrentBag<(int I, double Count)>();
batch.Process(
(i, count) => calls.Add((i, count)),

View File

@ -111,9 +111,9 @@ namespace ImageResizer.Extensions
/// <returns>
/// metadata path and metadata value of all successfully read data items.
/// </returns>
public static List<(string metadataPath, object value)> GetListOfMetadata(this BitmapMetadata metadata)
public static List<(string MetadataPath, object Value)> GetListOfMetadata(this BitmapMetadata metadata)
{
var listOfAllMetadata = new List<(string metadataPath, object value)>();
var listOfAllMetadata = new List<(string MetadataPath, object Value)>();
try
{
@ -196,7 +196,7 @@ namespace ImageResizer.Extensions
foreach (var metadataItem in listOfMetadata)
{
// Debug.WriteLine($"modifiableMetadata.RemoveQuerySafe(\"{metadataItem.metadataPath}\");");
Debug.WriteLine($"{metadataItem.metadataPath} | {metadataItem.value}");
Debug.WriteLine($"{metadataItem.MetadataPath} | {metadataItem.Value}");
}
}
@ -207,9 +207,9 @@ namespace ImageResizer.Extensions
/// <remarks>
/// Intented for debug only!!!
/// </remarks>
public static List<(string metadataPath, object value)> GetListOfMetadataForDebug(this BitmapMetadata metadata)
public static List<(string MetadataPath, object Value)> GetListOfMetadataForDebug(this BitmapMetadata metadata)
{
var listOfAllMetadata = new List<(string metadataPath, object value)>();
var listOfAllMetadata = new List<(string MetadataPath, object Value)>();
try
{

View File

@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Wox.Plugin.Interfaces;
namespace Microsoft.Plugin.Folder
{
using Wox.Plugin.Interfaces;
public class SearchResult : IFileDropResult
{
public string Path { get; set; }

View File

@ -44,7 +44,7 @@ namespace Microsoft.Plugin.Folder.Sources
return query.Any(c => c.Equals('>'));
}
private (string search, string incompleteName) Process(string search)
private (string Search, string IncompleteName) Process(string search)
{
string incompleteName = string.Empty;
if (HasSpecialChars(search) || !_directory.Exists($@"{search}\"))

View File

@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Wox.Plugin.Interfaces;
namespace Microsoft.Plugin.Indexer.SearchHelper
{
using Wox.Plugin.Interfaces;
public class SearchResult : IFileDropResult
{
// Contains the Path of the file or folder

View File

@ -29,8 +29,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
public void ErrorResultOnInvalidKeywordQuery(string typedString, string expectedResult)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "=");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "=");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle;
@ -56,8 +56,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
public void NoResultOnInvalidGlobalQuery(string typedString)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString);
Mock<Main> main = new();
Query expectedQuery = new(typedString);
// Act
var result = main.Object.Query(expectedQuery).Count;
@ -80,9 +80,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
public void NoResultIfQueryEndsWithBinaryOperator(string typedString)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString);
Query expectedQueryWithKeyword = new ("=" + typedString, "=");
Mock<Main> main = new();
Query expectedQuery = new(typedString);
Query expectedQueryWithKeyword = new("=" + typedString, "=");
// Act
var result = main.Object.Query(expectedQuery).Count;
@ -101,9 +101,9 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator.UnitTests
public void NoErrorForDivisionByNumberWithDecimalDigits(string typedString)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString);
Query expectedQueryWithKeyword = new ("=" + typedString, "=");
Mock<Main> main = new();
Query expectedQuery = new(typedString);
Query expectedQueryWithKeyword = new("=" + typedString, "=");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault().SubTitle;

View File

@ -53,7 +53,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
return !trailTest.Any();
}
private static (TrailDirection direction, TrailType type) BracketTrail(char @char)
private static (TrailDirection Direction, TrailType Type) BracketTrail(char @char)
{
switch (@char)
{

View File

@ -19,7 +19,8 @@ namespace Microsoft.PowerToys.Run.Plugin.Calculator
@"pi|" +
@"==|~=|&&|\|\||" +
@"e|[0-9]|0x[0-9a-fA-F]+|0b[01]+|[\+\-\*\/\^\., ""]|[\(\)\|\!\[\]]" +
@")+$", RegexOptions.Compiled);
@")+$",
RegexOptions.Compiled);
public static bool InputValid(string input)
{

View File

@ -42,7 +42,7 @@ namespace Microsoft.PowerToys.Run.Plugin.Registry.Helper
/// </summary>
/// <param name="query">The query to search</param>
/// <returns>A combination of a list of base <see cref="RegistryKey"/> and the sub keys</returns>
internal static (IEnumerable<RegistryKey>? baseKey, string subKey) GetRegistryBaseKey(in string query)
internal static (IEnumerable<RegistryKey>? BaseKey, string SubKey) GetRegistryBaseKey(in string query)
{
if (string.IsNullOrWhiteSpace(query))
{

View File

@ -63,9 +63,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void IconThemeDarkTest(string typedString, string subTitleMatch, string expectedResult)
{
// Setup
Mock<Main> main = new ();
Mock<Main> main = new();
main.Object.IconTheme = "dark";
Query expectedQuery = new ("(" + typedString, "(");
Query expectedQuery = new("(" + typedString, "(");
// Act
string result = main.Object.Query(expectedQuery).FirstOrDefault(predicate: x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath;
@ -108,9 +108,9 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void IconThemeLightTest(string typedString, string subTitleMatch, string expectedResult)
{
// Setup
Mock<Main> main = new ();
Mock<Main> main = new();
main.Object.IconTheme = "light";
Query expectedQuery = new ("(" + typedString, "(");
Query expectedQuery = new("(" + typedString, "(");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(subTitleMatch, System.StringComparison.CurrentCulture)).IcoPath;

View File

@ -41,8 +41,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void CountWithoutPluginKeyword(string typedString, int expectedResultCount)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString);
Mock<Main> main = new();
Query expectedQuery = new(typedString);
// Act
var result = main.Object.Query(expectedQuery).Count;
@ -63,8 +63,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void CountWithPluginKeyword(string typedString, int expectedResultCount)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "(");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "(");
// Act
var result = main.Object.Query(expectedQuery);
@ -87,8 +87,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void ValidateBehaviorOnGlobalQueries(string typedString, int expectedResultCount)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString);
Mock<Main> main = new();
Query expectedQuery = new(typedString);
// Act
var result = main.Object.Query(expectedQuery);
@ -141,8 +141,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void CanFindFormatResult(string typedString, string expectedResult)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "(");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "(");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(expectedResult, StringComparison.CurrentCulture));
@ -160,8 +160,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void DateTimeNumberOnlyInput(string typedString, string expectedResult)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "(");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "(");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault(x => x.SubTitle.StartsWith(expectedResult, StringComparison.CurrentCulture));
@ -188,8 +188,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void InvalidInputNotShowsResults(string typedString)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "(");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "(");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault();
@ -206,8 +206,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void InvalidNumberInputShowsErrorMessage(string typedString)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "(");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "(");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault().Title;
@ -224,8 +224,8 @@ namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests
public void InvalidInputNotShowsErrorMessage(string typedString)
{
// Setup
Mock<Main> main = new ();
Query expectedQuery = new (typedString, "(");
Mock<Main> main = new();
Query expectedQuery = new(typedString, "(");
// Act
var result = main.Object.Query(expectedQuery).FirstOrDefault();

View File

@ -2,15 +2,15 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using DrawingImaging = System.Drawing.Imaging;
using MediaImaging = System.Windows.Media.Imaging;
namespace PowerLauncher.Helper
{
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using DrawingImaging = System.Drawing.Imaging;
using MediaImaging = System.Windows.Media.Imaging;
// based on: https://stackoverflow.com/questions/61041282/showing-image-thumbnail-with-mouse-cursor-while-dragging/61148788#61148788
public static class DragDataObject
{

View File

@ -153,10 +153,11 @@ namespace PowerLauncher.ViewModel
{
Task.Run(
() =>
{
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
UpdateResultView(e.Results, e.Query.RawQuery, _updateToken);
}, _updateToken);
{
PluginManager.UpdatePluginMetadata(e.Results, pair.Metadata, e.Query);
UpdateResultView(e.Results, e.Query.RawQuery, _updateToken);
},
_updateToken);
};
}
}
@ -553,26 +554,47 @@ namespace PowerLauncher.ViewModel
var queryResultsTask = Task.Factory.StartNew(
() =>
{
Thread.Sleep(20);
// Keep track of total number of results for telemetry
var numResults = 0;
// Contains all the plugins for which this raw query is valid
var plugins = pluginQueryPairs.Keys.ToList();
var sw = System.Diagnostics.Stopwatch.StartNew();
try
{
var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary<PluginMetadata, List<Result>>();
Thread.Sleep(20);
if (_settings.PTRunNonDelayedSearchInParallel)
// Keep track of total number of results for telemetry
var numResults = 0;
// Contains all the plugins for which this raw query is valid
var plugins = pluginQueryPairs.Keys.ToList();
var sw = System.Diagnostics.Stopwatch.StartNew();
try
{
Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) =>
var resultPluginPair = new System.Collections.Concurrent.ConcurrentDictionary<PluginMetadata, List<Result>>();
if (_settings.PTRunNonDelayedSearchInParallel)
{
try
Parallel.ForEach(pluginQueryPairs, (pluginQueryItem) =>
{
try
{
var plugin = pluginQueryItem.Key;
var query = pluginQueryItem.Value;
query.SelectedItems = _userSelectedRecord.GetGenericHistory();
var results = PluginManager.QueryForPlugin(plugin, query);
resultPluginPair[plugin.Metadata] = results;
currentCancellationToken.ThrowIfCancellationRequested();
}
catch (OperationCanceledException)
{
// nothing to do here
}
});
sw.Stop();
}
else
{
currentCancellationToken.ThrowIfCancellationRequested();
// To execute a query corresponding to each plugin
foreach (KeyValuePair<PluginPair, Query> pluginQueryItem in pluginQueryPairs)
{
var plugin = pluginQueryItem.Key;
var query = pluginQueryItem.Value;
@ -581,64 +603,43 @@ namespace PowerLauncher.ViewModel
resultPluginPair[plugin.Metadata] = results;
currentCancellationToken.ThrowIfCancellationRequested();
}
catch (OperationCanceledException)
{
// nothing to do here
}
});
sw.Stop();
}
else
{
currentCancellationToken.ThrowIfCancellationRequested();
// To execute a query corresponding to each plugin
foreach (KeyValuePair<PluginPair, Query> pluginQueryItem in pluginQueryPairs)
{
var plugin = pluginQueryItem.Key;
var query = pluginQueryItem.Value;
query.SelectedItems = _userSelectedRecord.GetGenericHistory();
var results = PluginManager.QueryForPlugin(plugin, query);
resultPluginPair[plugin.Metadata] = results;
currentCancellationToken.ThrowIfCancellationRequested();
}
}
lock (_addResultsLock)
{
// Using CurrentCultureIgnoreCase since this is user facing
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
lock (_addResultsLock)
{
Results.Clear();
foreach (var p in resultPluginPair)
// Using CurrentCultureIgnoreCase since this is user facing
if (queryText.Equals(_currentQuery, StringComparison.CurrentCultureIgnoreCase))
{
UpdateResultView(p.Value, queryText, currentCancellationToken);
Results.Clear();
foreach (var p in resultPluginPair)
{
UpdateResultView(p.Value, queryText, currentCancellationToken);
currentCancellationToken.ThrowIfCancellationRequested();
}
currentCancellationToken.ThrowIfCancellationRequested();
numResults = Results.Results.Count;
if (!doFinalSort)
{
Results.Sort(queryTuning);
Results.SelectedItem = Results.Results.FirstOrDefault();
}
}
currentCancellationToken.ThrowIfCancellationRequested();
numResults = Results.Results.Count;
if (!doFinalSort)
{
Results.Sort(queryTuning);
Results.SelectedItem = Results.Results.FirstOrDefault();
UpdateResultsListViewAfterQuery(queryText);
}
}
currentCancellationToken.ThrowIfCancellationRequested();
if (!doFinalSort)
bool noInitialResults = numResults == 0;
if (!delayedExecution.HasValue || delayedExecution.Value)
{
UpdateResultsListViewAfterQuery(queryText);
}
}
bool noInitialResults = numResults == 0;
if (!delayedExecution.HasValue || delayedExecution.Value)
{
// Run the slower query of the DelayedExecution plugins
currentCancellationToken.ThrowIfCancellationRequested();
Parallel.ForEach(plugins, (plugin) =>
// Run the slower query of the DelayedExecution plugins
currentCancellationToken.ThrowIfCancellationRequested();
Parallel.ForEach(plugins, (plugin) =>
{
try
{
@ -683,22 +684,23 @@ namespace PowerLauncher.ViewModel
// nothing to do here
}
});
}
}
catch (OperationCanceledException)
{
// nothing to do here
}
}
catch (OperationCanceledException)
{
// nothing to do here
}
queryTimer.Stop();
var queryEvent = new LauncherQueryEvent()
{
QueryTimeMs = queryTimer.ElapsedMilliseconds,
NumResults = numResults,
QueryLength = queryText.Length,
};
PowerToysTelemetry.Log.WriteEvent(queryEvent);
}, currentCancellationToken);
queryTimer.Stop();
var queryEvent = new LauncherQueryEvent()
{
QueryTimeMs = queryTimer.ElapsedMilliseconds,
NumResults = numResults,
QueryLength = queryText.Length,
};
PowerToysTelemetry.Log.WriteEvent(queryEvent);
},
currentCancellationToken);
if (doFinalSort)
{

View File

@ -2,12 +2,12 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using PowerToys.PowerAccentKeyboardService;
using Windows.Globalization;
namespace PowerAccent.Core
{
using System;
using PowerToys.PowerAccentKeyboardService;
using Windows.Globalization;
public enum Language
{
ALL,

View File

@ -100,7 +100,8 @@ public class PowerAccent : IDisposable
{
OnChangeDisplay?.Invoke(true, _characters);
}
}, TaskScheduler.FromCurrentSynchronizationContext());
},
TaskScheduler.FromCurrentSynchronizationContext());
}
private string GetCharacterDescription(string character)

View File

@ -2,16 +2,14 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace PowerAccent.Core.Services;
using System.IO.Abstractions;
using System.Text.Json;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Enumerations;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
using PowerToys.PowerAccentKeyboardService;
using System.IO.Abstractions;
using System.Text.Json;
using static Vanara.PInvoke.LANGID;
namespace PowerAccent.Core.Services;
public class SettingsService
{
private const string PowerAccentModuleName = "QuickAccent";

View File

@ -41,7 +41,7 @@ internal static class WindowsFunctions
public static Point GetCaretPosition()
{
User32.GUITHREADINFO guiInfo = new ();
User32.GUITHREADINFO guiInfo = default;
guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
User32.GetGUIThreadInfo(0, ref guiInfo);
POINT caretPosition = new POINT(guiInfo.rcCaret.left, guiInfo.rcCaret.top);
@ -59,12 +59,12 @@ internal static class WindowsFunctions
public static (Point Location, Size Size, double Dpi) GetActiveDisplay()
{
User32.GUITHREADINFO guiInfo = new ();
User32.GUITHREADINFO guiInfo = default;
guiInfo.cbSize = (uint)Marshal.SizeOf(guiInfo);
User32.GetGUIThreadInfo(0, ref guiInfo);
var res = User32.MonitorFromWindow(guiInfo.hwndActive, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST);
User32.MONITORINFO monitorInfo = new ();
User32.MONITORINFO monitorInfo = default;
monitorInfo.cbSize = (uint)Marshal.SizeOf(monitorInfo);
User32.GetMonitorInfo(res, ref monitorInfo);

View File

@ -47,7 +47,8 @@ internal static class Program
{
Terminate();
}
}, _tokenSource.Token);
},
_tokenSource.Token);
}
private static void Arguments(string[] args)

View File

@ -13,7 +13,7 @@ namespace PowerAccent.UI;
public partial class Selector : Window, IDisposable, INotifyPropertyChanged
{
private readonly Core.PowerAccent _powerAccent = new ();
private readonly Core.PowerAccent _powerAccent = new();
private Visibility _characterNameVisibility = Visibility.Visible;
@ -84,7 +84,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
private void SetWindowPosition()
{
Size windowSize = new (((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight);
Size windowSize = new(((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualWidth, ((System.Windows.Controls.Panel)Application.Current.MainWindow.Content).ActualHeight);
Point position = _powerAccent.GetDisplayCoordinates(windowSize);
this.Left = position.X;
this.Top = position.Y;
@ -97,7 +97,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
Position.Left or Position.TopLeft or Position.BottomLeft => HorizontalAlignment.Left,
Position.Right or Position.TopRight or Position.BottomRight => HorizontalAlignment.Right,
Position.Center or Position.Top or Position.Bottom => HorizontalAlignment.Center,
_ => HorizontalAlignment.Center
_ => HorizontalAlignment.Center,
};
}

View File

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
namespace Microsoft.PowerToys.PreviewHandler.Gcode
{
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
internal static class Program
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Gcode
{
using System.Globalization;
internal static class Program
{
private static GcodeThumbnailProvider _thumbnailProvider;

View File

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
namespace Microsoft.PowerToys.PreviewHandler.Markdown
{
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
internal static class Program
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text.Json;
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
{
using System.Text.Json;
public class JsonFormatter : IFormatter
{
/// <inheritdoc/>

View File

@ -2,11 +2,11 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Text;
using System.Xml;
namespace Microsoft.PowerToys.PreviewHandler.Monaco.Formatters
{
using System.Text;
using System.Xml;
public class XmlFormatter : IFormatter
{
/// <inheritdoc/>

View File

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
namespace Microsoft.PowerToys.PreviewHandler.Monaco
{
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
internal static class Program
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
namespace Microsoft.PowerToys.PreviewHandler.Pdf
{
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
internal static class Program
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Pdf
{
using System.Globalization;
internal static class Program
{
private static PdfThumbnailProvider _thumbnailProvider;

View File

@ -1,11 +1,10 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Stl
{
using System.Globalization;
internal static class Program
{
private static StlThumbnailProvider _thumbnailProvider;

View File

@ -2,13 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
namespace Microsoft.PowerToys.PreviewHandler.Svg
{
using System.Globalization;
using System.Windows.Threading;
using Common.UI;
using interop;
internal static class Program
{
private static CancellationTokenSource _tokenSource = new CancellationTokenSource();

View File

@ -2,10 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
namespace Microsoft.PowerToys.ThumbnailHandler.Svg
{
using System.Globalization;
internal static class Program
{
private static SvgThumbnailProvider _thumbnailProvider;

View File

@ -22,7 +22,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
public class SettingsBackupAndRestoreUtils
{
private static SettingsBackupAndRestoreUtils instance;
private (bool success, string severity, bool lastBackupExists, DateTime? lastRan) lastBackupSettingsResults;
private (bool Success, string Severity, bool LastBackupExists, DateTime? LastRan) lastBackupSettingsResults;
private static object backupSettingsInternalLock = new object();
private static object removeOldBackupsLock = new object();
@ -262,7 +262,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// A tuple that indicates if the backup was done or not, and a message.
/// The message usually is a localized reference key.
/// </returns>
public (bool success, string message, string severity) RestoreSettings(string appBasePath, string settingsBackupAndRestoreDir)
public (bool Success, string Message, string Severity) RestoreSettings(string appBasePath, string settingsBackupAndRestoreDir)
{
try
{
@ -554,26 +554,26 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <remarks>
/// This is a wrapper for BackupSettingsInternal, so we can check the time to run.
/// </remarks>
public (bool success, string message, string severity, bool lastBackupExists) BackupSettings(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun)
public (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettings(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun)
{
var sw = Stopwatch.StartNew();
var results = BackupSettingsInternal(appBasePath, settingsBackupAndRestoreDir, dryRun);
sw.Stop();
Logger.LogInfo($"BackupSettings took {sw.ElapsedMilliseconds}");
lastBackupSettingsResults = (results.success, results.severity, results.lastBackupExists, DateTime.UtcNow);
lastBackupSettingsResults = (results.Success, results.Severity, results.LastBackupExists, DateTime.UtcNow);
return results;
}
/// <summary>
/// Method <c>DryRunBackup</c> wrapper function to do a dry-run backup
/// </summary>
public (bool success, string message, string severity, bool lastBackupExists) DryRunBackup()
public (bool Success, string Message, string Severity, bool LastBackupExists) DryRunBackup()
{
var settingsUtils = new SettingsUtils();
var appBasePath = Path.GetDirectoryName(settingsUtils.GetSettingsFilePath());
string settingsBackupAndRestoreDir = GetSettingsBackupAndRestoreDir();
var results = BackupSettings(appBasePath, settingsBackupAndRestoreDir, true);
lastBackupSettingsResults = (results.success, results.severity, results.lastBackupExists, DateTime.UtcNow);
lastBackupSettingsResults = (results.Success, results.Severity, results.LastBackupExists, DateTime.UtcNow);
return results;
}
@ -583,9 +583,9 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <returns>
/// A tuple that indicates if the backup was done or not, and other information
/// </returns>
public (bool success, bool hadError, bool lastBackupExists, DateTime? lastRan) GetLastBackupSettingsResults()
public (bool Success, bool HadError, bool LastBackupExists, DateTime? LastRan) GetLastBackupSettingsResults()
{
return (lastBackupSettingsResults.success, lastBackupSettingsResults.severity == "Error", lastBackupSettingsResults.lastBackupExists, lastBackupSettingsResults.lastRan);
return (lastBackupSettingsResults.Success, lastBackupSettingsResults.Severity == "Error", lastBackupSettingsResults.LastBackupExists, lastBackupSettingsResults.LastRan);
}
/// <summary>
@ -595,7 +595,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// A tuple that indicates if the backup was done or not, and a message.
/// The message usually is a localized reference key.
/// </returns>
private (bool success, string message, string severity, bool lastBackupExists) BackupSettingsInternal(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun)
private (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettingsInternal(string appBasePath, string settingsBackupAndRestoreDir, bool dryRun)
{
var lastBackupExists = false;
@ -650,7 +650,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
}
var anyFileBackedUp = false;
var skippedSettingsFiles = new Dictionary<string, (string path, string settings)>();
var skippedSettingsFiles = new Dictionary<string, (string Path, string Settings)>();
var updatedSettingsFiles = new Dictionary<string, string>();
foreach (var currentFile in currentSettingsFiles)
@ -717,7 +717,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
{
// if we did do a backup, we need to copy in all the settings files we skipped so the backup is complete.
// this is needed since we might use the backup on another machine/
var relativePath = currentFile.Value.path.Substring(appBasePath.Length + 1);
var relativePath = currentFile.Value.Path.Substring(appBasePath.Length + 1);
var backupFullPath = Path.Combine(fullBackupDir, relativePath);
Logger.LogInfo($"BackupSettings writing, {backupFullPath}, dryRun:{dryRun}");
@ -726,7 +726,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
TryCreateDirectory(fullBackupDir);
TryCreateDirectory(Path.GetDirectoryName(backupFullPath));
File.WriteAllText(backupFullPath, currentFile.Value.settings);
File.WriteAllText(backupFullPath, currentFile.Value.Settings);
}
}

View File

@ -189,7 +189,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <summary>
/// Method <c>BackupSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.BackupSettings
/// </summary>
public static (bool success, string message, string severity, bool lastBackupExists) BackupSettings()
public static (bool Success, string Message, string Severity, bool LastBackupExists) BackupSettings()
{
var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance;
var settingsUtils = new SettingsUtils();
@ -202,7 +202,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
/// <summary>
/// Method <c>RestoreSettings</c> Mostly a wrapper for SettingsBackupAndRestoreUtils.RestoreSettings
/// </summary>
public static (bool success, string message, string severity) RestoreSettings()
public static (bool Success, string Message, string Severity) RestoreSettings()
{
var settingsBackupAndRestoreUtilsX = SettingsBackupAndRestoreUtils.Instance;
var settingsUtils = new SettingsUtils();

View File

@ -1,30 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("StyleCop.CSharp.SpacingRules", "SA1009:ClosingParenthesisMustBeSpacedCorrectly", Justification = "All current violations are due to Tuple shorthand and so valid.")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1101:PrefixLocalCallsWithThis", Justification = "We follow the C# Core Coding Style which avoids using `this` unless absolutely necessary.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1200:UsingDirectivesMustBePlacedWithinNamespace", Justification = "We follow the C# Core Coding Style which puts using statements outside the namespace.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1201:ElementsMustAppearInTheCorrectOrder", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1203:ConstantsMustAppearBeforeFields", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1204:StaticElementsMustAppearBeforeInstanceElements", Justification = "It is not a priority and have hight impact in code changes.")]
[assembly: SuppressMessage("StyleCop.CSharp.NamingRules", "SA1309:FieldNamesMustNotBeginWithUnderscore", Justification = "We follow the C# Core Coding Style which uses underscores as prefixes rather than using `this.`.")]
[assembly: SuppressMessage("StyleCop.CSharp.SpecialRules", "SA0001:XmlCommentAnalysisDisabled", Justification = "Not enabled as we don't want or need XML documentation.")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1629:DocumentationTextMustEndWithAPeriod", Justification = "Not enabled as we don't want or need XML documentation.")]
// Non general suppressions
[assembly: SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Used in a lot of places for meaningful method names")]
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Static methods may improve performance but decrease maintainability")]
[assembly: SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "Renaming everything would be a lot of work. It does not do any harm if an EventHandler delegate ends with the suffix EventHandler. Besides this, the Rule causes some false positives.")]
[assembly: SuppressMessage("Performance", "CA1838:Avoid 'StringBuilder' parameters for P/Invokes", Justification = "We are not concerned about the performance impact of marshaling a StringBuilder")]

View File

@ -418,16 +418,16 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var resultText = string.Empty;
if (!results.lastRan.HasValue)
if (!results.LastRan.HasValue)
{
// not ran since started.
return GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsNoChecked"); // "Current Settings Unknown";
}
else
{
if (results.success)
if (results.Success)
{
if (results.lastBackupExists)
if (results.LastBackupExists)
{
// if true, it means a backup would have been made
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsDiffer"); // "Current Settings Differ";
@ -440,7 +440,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
else
{
if (results.hadError)
if (results.HadError)
{
// if false and error we don't really know
resultText = GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsUnknown"); // "Current Settings Unknown";
@ -452,7 +452,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
}
return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.lastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}";
return $"{resultText} {GetResourceString("General_SettingsBackupAndRestore_CurrentSettingsStatusAt")} {results.LastRan.Value.ToLocalTime().ToString("G", CultureInfo.CurrentCulture)}";
}
}
catch (Exception e)
@ -683,13 +683,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
}
var results = SettingsUtils.RestoreSettings();
_backupRestoreMessageSeverity = results.severity;
_backupRestoreMessageSeverity = results.Severity;
if (!results.success)
if (!results.Success)
{
_settingsBackupRestoreMessageVisible = true;
_settingsBackupMessage = GetResourceString(results.message);
_settingsBackupMessage = GetResourceString(results.Message);
NotifyAllBackupAndRestoreProperties();
@ -720,8 +720,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
var results = SettingsUtils.BackupSettings();
_settingsBackupRestoreMessageVisible = true;
_backupRestoreMessageSeverity = results.severity;
_settingsBackupMessage = GetResourceString(results.message);
_backupRestoreMessageSeverity = results.Severity;
_settingsBackupMessage = GetResourceString(results.Message);
// now we do a dry run to get the results for "setting match"
var settingsUtils = new SettingsUtils();