mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 18:57:19 +02:00
[fxcop] Fixes for Wox.Plugin (2of3) - Moved logger interface to Wox.Plugin (#7464)
* Moved Logger/Log.cs from Wox.Infrastructure to Wox.Plugin
- Installed Logger dependency in Wox.Plugin: NLog.Extensions.Logging
- Moved file Log.cs from Wox.Infrastructure/Logger/ to Wox.Plugin/Logger
- Moved file Constant.cs from Wox.Infrastructure to Wox.Plugin: This file was moved since Log.cs depends on this class
- Copied Wox.Infrastructure.Helper.NonNull to Wox.Plugin.Constant since Constant.cs depends on this method
- Replaced all "using Wox.Infrastructure.Logger" to "using Wox.Plugin.Logger" in all files as needed
- Replaced Wox.Infrastructure.Constant to Wox.Plugin.Constant in all files as needed
* Removed Nlog.Extensions.Logging from Wox.Infrastructure
* Added logging and suppressed general exceptions (CA1031: Do not catch general exception types)
* Resolved fxcop errors introduced by newly added Log.cs
- CA1307: Specify StringComparison for clarity
- CA2000: Dispose objects before losing scope
- CA1062: Validate arguments of public methods
* Replaced Wox.Infrastructure.Logger with Wox.Plugin.Logger
This commit is contained in:
@@ -4,11 +4,14 @@
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Wox.Plugin.Logger;
|
||||
|
||||
namespace Wox.Plugin.SharedCommands
|
||||
{
|
||||
public static class FilesFolders
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exception has been logged")]
|
||||
public static void Copy(this string sourcePath, string targetPath)
|
||||
{
|
||||
// Get the subdirectories for the specified directory.
|
||||
@@ -50,6 +53,8 @@ namespace Wox.Plugin.SharedCommands
|
||||
catch (Exception e)
|
||||
#pragma warning restore CS0168 // Variable is declared but never used
|
||||
{
|
||||
string error = $"Copying path {targetPath} has failed";
|
||||
Log.Exception(error, e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#if DEBUG
|
||||
throw e;
|
||||
#else
|
||||
@@ -59,6 +64,7 @@ namespace Wox.Plugin.SharedCommands
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exception has been logged")]
|
||||
public static bool VerifyBothFolderFilesEqual(this string fromPath, string toPath)
|
||||
{
|
||||
try
|
||||
@@ -82,15 +88,18 @@ namespace Wox.Plugin.SharedCommands
|
||||
catch (Exception e)
|
||||
#pragma warning restore CS0168 // Variable is declared but never used
|
||||
{
|
||||
string error = $"Unable to verify folders and files between {fromPath} and {toPath}";
|
||||
Log.Exception(error, e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#if DEBUG
|
||||
throw e;
|
||||
#else
|
||||
System.Windows.MessageBox.Show(string.Format("Unable to verify folders and files between {0} and {1}", fromPath, toPath));
|
||||
System.Windows.MessageBox.Show(string.Format(error));
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exception has been logged")]
|
||||
public static void RemoveFolder(this string path)
|
||||
{
|
||||
try
|
||||
@@ -104,10 +113,12 @@ namespace Wox.Plugin.SharedCommands
|
||||
catch (Exception e)
|
||||
#pragma warning restore CS0168 // Variable is declared but never used
|
||||
{
|
||||
string error = $"Not able to delete folder {path}, please go to the location and manually delete it";
|
||||
Log.Exception(error, e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#if DEBUG
|
||||
throw e;
|
||||
#else
|
||||
System.Windows.MessageBox.Show(string.Format("Not able to delete folder {0}, please go to the location and manually delete it", path));
|
||||
System.Windows.MessageBox.Show(string.Format(error));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user