[MWB][CQ]Refactoring "Common" classes - Common.Log.cs (#35156)

* [MouseWithoutBorders] - split "Common.Log.cs" into "Logger.cs"

* [MouseWithoutBorders] - fix references to Logger

* [MouseWithoutBorders] - add MouseWithoutBorders.UnitTests

* [MouseWithoutBorders] - fixing broken tests

* [MouseWithoutBorders] - fixing spelling

* [MouseWithoutBorders] - fixing spelling

* [MouseWithoutBorders] - fixing resource filename casing

* [MouseWithoutBorders] - fixing resource filename casing

* [MouseWithoutBorders] - fixing resource filename casing

* [MouseWithoutBorders] - fixing resource filename casing

* [MouseWithoutBorders] - fixed compile error

* [MouseWithoutBorders] - fixed failing test

* [MouseWithoutBorders] - fixed failing build

* [MouseWithoutBorders] - ignore flakey test
This commit is contained in:
Michael Clayton
2024-10-18 17:32:08 +01:00
committed by GitHub
parent 37eaf10bf0
commit 5cba82f929
37 changed files with 1965 additions and 839 deletions

View File

@@ -5,7 +5,7 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using MouseWithoutBorders.Core;
using MouseWithoutBorders.Form.Settings;
namespace MouseWithoutBorders
@@ -23,9 +23,9 @@ namespace MouseWithoutBorders
toolTipManual.ToolTipTitle = Application.ProductName;
Text = Application.ProductName;
Common.LogDebug("FIRST RUN, SHOWING THE FIRST SETUP PAGE.");
Logger.LogDebug("FIRST RUN, SHOWING THE FIRST SETUP PAGE.");
Common.LogDebug($"{nameof(Common.RunWithNoAdminRight)} = {Common.RunWithNoAdminRight}");
Logger.LogDebug($"{nameof(Common.RunWithNoAdminRight)} = {Common.RunWithNoAdminRight}");
if (Common.RunWithNoAdminRight)
{
@@ -43,7 +43,7 @@ namespace MouseWithoutBorders
if (_currentPage != null)
{
Common.LogDebug(_currentPage.Name + " closing.");
Logger.LogDebug(_currentPage.Name + " closing.");
_currentPage.OnPageClosing();
}
@@ -67,7 +67,7 @@ namespace MouseWithoutBorders
if (page != null)
{
Common.LogDebug("GOING TO NEXT PAGE: " + page.Name);
Logger.LogDebug("GOING TO NEXT PAGE: " + page.Name);
page.BackColor = Color.Transparent;
page.NextPage += PageNextPage;
page.Location = contentPanel.Location;

View File

@@ -7,6 +7,7 @@ using System.Drawing;
using System.Windows.Forms;
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
using MouseWithoutBorders.Properties;
namespace MouseWithoutBorders
@@ -42,7 +43,7 @@ namespace MouseWithoutBorders
private void ShowStatus(string status)
{
labelStatus.Text = status;
Common.Log(status);
Logger.Log(status);
}
public override void OnPageClosing()

View File

@@ -16,6 +16,7 @@ using System.Windows.Forms;
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
[module: SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions", Scope = "member", Target = "MouseWithoutBorders.frmInputCallback.#InstallKeyboardAndMouseHook()", Justification = "Dotnet port with style preservation")]
@@ -65,7 +66,7 @@ namespace MouseWithoutBorders
Common.Hook.MouseEvent += new InputHook.MouseEvHandler(Common.MouseEvent);
Common.Hook.KeyboardEvent += new InputHook.KeybdEvHandler(Common.KeybdEvent);
Common.Log("(((((Keyboard/Mouse hooks installed/reinstalled!)))))");
Logger.Log("(((((Keyboard/Mouse hooks installed/reinstalled!)))))");
/* The hook is called in the context of the thread that installed it.
* The call is made by sending a message to the thread that installed the hook.
* Therefore, the thread that installed the hook must have a message loop!!!

View File

@@ -21,7 +21,7 @@ using Microsoft.PowerToys.Telemetry;
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
using Timer = System.Windows.Forms.Timer;
[module: SuppressMessage("Microsoft.Globalization", "CA1300:SpecifyMessageBoxOptions", Scope = "member", Target = "MouseWithoutBorders.frmMatrix.#buttonOK_Click(System.Object,System.EventArgs)", Justification = "Dotnet port with style preservation")]
@@ -151,7 +151,7 @@ namespace MouseWithoutBorders
if (Common.MachineMatrix != null && Common.MachineMatrix.Length == Common.MAX_MACHINE)
{
Common.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString);
Logger.LogDebug("LoadMachines: Machine Matrix: " + Setting.Values.MachineMatrixString);
for (int i = 0; i < Common.MAX_MACHINE; i++)
{
@@ -329,8 +329,8 @@ namespace MouseWithoutBorders
}
catch (Exception ee)
{
Common.Log(ee);
Common.Log(rv.ToString(CultureInfo.CurrentCulture));
Logger.Log(ee);
Logger.Log(rv.ToString(CultureInfo.CurrentCulture));
}
}

View File

@@ -22,6 +22,7 @@ using Microsoft.PowerToys.Telemetry;
// 2023- Included in PowerToys.
// </history>
using MouseWithoutBorders.Class;
using MouseWithoutBorders.Core;
using MouseWithoutBorders.Properties;
using Timer = System.Windows.Forms.Timer;
@@ -81,7 +82,7 @@ namespace MouseWithoutBorders
}
catch (Exception e)
{
Common.Log(e);
Logger.Log(e);
}
}
@@ -232,7 +233,7 @@ namespace MouseWithoutBorders
}
catch (Exception e)
{
Common.Log(e);
Logger.Log(e);
}
}
@@ -273,7 +274,7 @@ namespace MouseWithoutBorders
{
BackColor = Color.White;
Opacity = 0.15;
Common.Log(ex);
Logger.Log(ex);
}
helperTimer = new System.Windows.Forms.Timer();
@@ -355,7 +356,7 @@ namespace MouseWithoutBorders
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && !Common.GetUserName())
{
// While Windows 8 is hybrid-shutting down, user name would be empty (as returned from the .Net API), we should not do anything in this case.
Common.LogDebug("No active user.");
Logger.LogDebug("No active user.");
Thread.Sleep(1000);
busy = false;
return;
@@ -432,7 +433,7 @@ namespace MouseWithoutBorders
if (!Common.AtLeastOneSocketEstablished())
{
Common.GetMachineName();
Common.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture));
Logger.LogDebug("Common.pleaseReopenSocket: " + Common.PleaseReopenSocket.ToString(CultureInfo.InvariantCulture));
Common.ReopenSockets(false);
Common.NewDesMachineID = Common.DesMachineID = Common.MachineID;
}
@@ -545,7 +546,7 @@ namespace MouseWithoutBorders
if (count % 20 == 0)
{
Common.LogAll();
Logger.LogAll();
// Need to review this code on why it is needed (moved from MoveToMyNeighbourIfNeeded(...))
for (int i = 0; i < Common.MachineMatrix.Length; i++)
@@ -579,14 +580,14 @@ namespace MouseWithoutBorders
if (!Common.RunOnLogonDesktop && !Common.RunOnScrSaverDesktop && Common.IsMyDesktopActive() && (rv = Common.SendMessageToHelper(0x400, IntPtr.Zero, IntPtr.Zero)) <= 0)
{
Common.TelemetryLogTrace($"{Common.HELPER_FORM_TEXT} not found: {rv}", SeverityLevel.Warning);
Logger.TelemetryLogTrace($"{Common.HELPER_FORM_TEXT} not found: {rv}", SeverityLevel.Warning);
}
}
}
}
catch (Exception ex)
{
Common.Log(ex);
Logger.Log(ex);
}
finally
{
@@ -678,7 +679,7 @@ namespace MouseWithoutBorders
p.Dispose();
#endif
Common.LogDebug($"Changing icon to {iconCode}.");
Logger.LogDebug($"Changing icon to {iconCode}.");
if (NotifyIcon.Icon != null)
{
@@ -690,13 +691,13 @@ namespace MouseWithoutBorders
}
catch (Exception e)
{
Common.Log(e);
Logger.Log(e);
}
}
internal void MenuAllPC_Click(object sender, EventArgs e)
{
Common.LogDebug("menuAllPC_Click");
Logger.LogDebug("menuAllPC_Click");
Common.SwitchToMultipleMode(MenuAllPC.Checked, true);
CurIcon = MenuAllPC.Checked ? Common.ICON_ALL : Common.ICON_ONE;
ChangeIcon(CurIcon);
@@ -801,7 +802,7 @@ namespace MouseWithoutBorders
if (h.ToInt32() > 0)
{
Common.LogDebug("Hide Mouse Without Borders Helper.");
Logger.LogDebug("Hide Mouse Without Borders Helper.");
// Common.ShowWindow(h, 1);
_ = NativeMethods.ShowWindow(h, 0);
@@ -813,7 +814,7 @@ namespace MouseWithoutBorders
break;
case NativeMethods.WM_CHECK_EXPLORER_DRAG_DROP:
Common.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!");
Logger.LogDebug("Got WM_CHECK_EXPLORER_DRAG_DROP!");
Common.DragDropStep04();
break;
@@ -825,7 +826,7 @@ namespace MouseWithoutBorders
break;
case WM_QUERYENDSESSION:
Common.LogDebug("WM_QUERYENDSESSION...");
Logger.LogDebug("WM_QUERYENDSESSION...");
Common.StartServiceAndSendLogoffSignal();
break;
@@ -993,7 +994,7 @@ namespace MouseWithoutBorders
}
catch (Exception e)
{
Common.Log(e);
Logger.Log(e);
}
}
@@ -1210,7 +1211,7 @@ namespace MouseWithoutBorders
private void MenuGenDumpFile_Click(object sender, EventArgs e)
{
Common.GenerateLog();
Logger.GenerateLog();
}
private void MainMenu_Opening(object sender, CancelEventArgs e)