From 7bc2775fb79669c2cc9865a0ce32d17ccf118f91 Mon Sep 17 00:00:00 2001 From: Anton Kasyanov Date: Mon, 25 Feb 2019 22:03:11 +0200 Subject: [PATCH] Internal code cleanup --- .../ApplicationBase/ExceptionHandler.cs | 8 ++-- .../Implementation/ConfigurationStorage.cs | 4 +- Eve-O-Preview/Eve-O-Preview.csproj | 1 - Eve-O-Preview/Hotkeys/HotkeyHandler.cs | 9 ++-- .../Implementation/MainFormPresenter.cs | 6 +-- .../Services/Implementation/ProcessMonitor.cs | 6 +-- .../Implementation/ThumbnailManager.cs | 45 +++++++++---------- .../View/Implementation/ThumbnailView.cs | 4 +- Eve-O-Preview/View/Interface/IMainFormView.cs | 1 - 9 files changed, 39 insertions(+), 45 deletions(-) diff --git a/Eve-O-Preview/ApplicationBase/ExceptionHandler.cs b/Eve-O-Preview/ApplicationBase/ExceptionHandler.cs index 461370e..f1669b6 100644 --- a/Eve-O-Preview/ApplicationBase/ExceptionHandler.cs +++ b/Eve-O-Preview/ApplicationBase/ExceptionHandler.cs @@ -12,8 +12,8 @@ namespace EveOPreview // So this dumb and non elegant approach is used sealed class ExceptionHandler { - private const string ExceptionDumpFileName = "EVE-O Preview.log"; - private const string ExceptionMessage = "EVE-O Preview has encountered a problem and needs to close. Additional information has been saved in the crash log file."; + private const string EXCEPTION_DUMP_FILE_NAME = "EVE-O Preview.log"; + private const string EXCEPTION_MESSAGE = "EVE-O Preview has encountered a problem and needs to close. Additional information has been saved in the crash log file."; public void SetupExceptionHandlers() { @@ -39,9 +39,9 @@ namespace EveOPreview try { String exceptionMessage = exception.ToString(); - File.WriteAllText(ExceptionHandler.ExceptionDumpFileName, exceptionMessage); + File.WriteAllText(ExceptionHandler.EXCEPTION_DUMP_FILE_NAME, exceptionMessage); - MessageBox.Show(ExceptionHandler.ExceptionMessage, @"EVE-O Preview", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ExceptionHandler.EXCEPTION_MESSAGE, @"EVE-O Preview", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch { diff --git a/Eve-O-Preview/Configuration/Implementation/ConfigurationStorage.cs b/Eve-O-Preview/Configuration/Implementation/ConfigurationStorage.cs index e07ec8f..3419b74 100644 --- a/Eve-O-Preview/Configuration/Implementation/ConfigurationStorage.cs +++ b/Eve-O-Preview/Configuration/Implementation/ConfigurationStorage.cs @@ -5,7 +5,7 @@ namespace EveOPreview.Configuration.Implementation { class ConfigurationStorage : IConfigurationStorage { - private const string ConfigurationFileName = "EVE-O Preview.json"; + private const string CONFIGURATION_FILE_NAME = "EVE-O Preview.json"; private readonly IAppConfig _appConfig; private readonly IThumbnailConfiguration _thumbnailConfiguration; @@ -50,7 +50,7 @@ namespace EveOPreview.Configuration.Implementation private string GetConfigFileName() { - return string.IsNullOrEmpty(this._appConfig.ConfigFileName) ? ConfigurationStorage.ConfigurationFileName : this._appConfig.ConfigFileName; + return string.IsNullOrEmpty(this._appConfig.ConfigFileName) ? ConfigurationStorage.CONFIGURATION_FILE_NAME : this._appConfig.ConfigFileName; } } } \ No newline at end of file diff --git a/Eve-O-Preview/Eve-O-Preview.csproj b/Eve-O-Preview/Eve-O-Preview.csproj index abdecee..30d8b89 100644 --- a/Eve-O-Preview/Eve-O-Preview.csproj +++ b/Eve-O-Preview/Eve-O-Preview.csproj @@ -214,7 +214,6 @@ Designer - diff --git a/Eve-O-Preview/Hotkeys/HotkeyHandler.cs b/Eve-O-Preview/Hotkeys/HotkeyHandler.cs index 4b95cf2..bb95186 100644 --- a/Eve-O-Preview/Hotkeys/HotkeyHandler.cs +++ b/Eve-O-Preview/Hotkeys/HotkeyHandler.cs @@ -7,7 +7,7 @@ namespace EveOPreview.UI.Hotkeys class HotkeyHandler : IMessageFilter, IDisposable { private static int _currentId; - private const int MaxId = 0xBFFF; + private const int MAX_ID = 0xBFFF; #region Private fields private readonly int _hotkeyId; @@ -17,7 +17,7 @@ namespace EveOPreview.UI.Hotkeys public HotkeyHandler(IntPtr target, Keys hotkey) { this._hotkeyId = HotkeyHandler._currentId; - HotkeyHandler._currentId = (HotkeyHandler._currentId + 1) & HotkeyHandler.MaxId; + HotkeyHandler._currentId = (HotkeyHandler._currentId + 1) & HotkeyHandler.MAX_ID; this._hotkeyTarget = target; @@ -106,10 +106,7 @@ namespace EveOPreview.UI.Hotkeys Application.RemoveMessageFilter(this); // Clean up after ourselves - if (!HotkeyHandlerNativeMethods.UnregisterHotKey(this._hotkeyTarget, this._hotkeyId)) - { - return; - } + HotkeyHandlerNativeMethods.UnregisterHotKey(this._hotkeyTarget, this._hotkeyId); } #region IMessageFilter diff --git a/Eve-O-Preview/Presenters/Implementation/MainFormPresenter.cs b/Eve-O-Preview/Presenters/Implementation/MainFormPresenter.cs index 8d35104..57b82ea 100644 --- a/Eve-O-Preview/Presenters/Implementation/MainFormPresenter.cs +++ b/Eve-O-Preview/Presenters/Implementation/MainFormPresenter.cs @@ -12,7 +12,7 @@ namespace EveOPreview.Presenters public class MainFormPresenter : Presenter, IMainFormPresenter { #region Private constants - private const string ForumUrl = @"https://forum.eveonline.com/t/4202"; + private const string FORUM_URL = @"https://forum.eveonline.com/t/4202"; #endregion #region Private fields @@ -50,7 +50,7 @@ namespace EveOPreview.Presenters private void Activate() { this.LoadApplicationSettings(); - this.View.SetDocumentationUrl(MainFormPresenter.ForumUrl); + this.View.SetDocumentationUrl(MainFormPresenter.FORUM_URL); this.View.SetVersionInfo(this.GetApplicationVersion()); if (this._configuration.MinimizeToTray) { @@ -225,7 +225,7 @@ namespace EveOPreview.Presenters private void OpenDocumentationLink() { // TODO Move out to a separate service / presenter / message handler - ProcessStartInfo processStartInfo = new ProcessStartInfo(new Uri(MainFormPresenter.ForumUrl).AbsoluteUri); + ProcessStartInfo processStartInfo = new ProcessStartInfo(new Uri(MainFormPresenter.FORUM_URL).AbsoluteUri); Process.Start(processStartInfo); } diff --git a/Eve-O-Preview/Services/Implementation/ProcessMonitor.cs b/Eve-O-Preview/Services/Implementation/ProcessMonitor.cs index 3f53e87..5c5e057 100644 --- a/Eve-O-Preview/Services/Implementation/ProcessMonitor.cs +++ b/Eve-O-Preview/Services/Implementation/ProcessMonitor.cs @@ -7,7 +7,7 @@ namespace EveOPreview.Services.Implementation sealed class ProcessMonitor : IProcessMonitor { #region Private constants - private const string DefaultProcessName = "ExeFile"; + private const string DEFAULT_PROCESS_NAME = "ExeFile"; #endregion #region Private fields @@ -22,7 +22,7 @@ namespace EveOPreview.Services.Implementation private bool IsMonitoredProcess(string processName) { // This is a possible extension point - return String.Equals(processName, ProcessMonitor.DefaultProcessName, StringComparison.OrdinalIgnoreCase); + return String.Equals(processName, ProcessMonitor.DEFAULT_PROCESS_NAME, StringComparison.OrdinalIgnoreCase); } public void GetUpdatedProcesses(out ICollection addedProcesses, out ICollection updatedProcesses, out ICollection removedProcesses) @@ -62,7 +62,7 @@ namespace EveOPreview.Services.Implementation if (cachedTitle != mainWindowTitle) { this._processCache[mainWindowHandle] = mainWindowTitle; - updatedProcesses.Add((IProcessInfo)new ProcessInfo(mainWindowHandle, mainWindowTitle)); + updatedProcesses.Add(new ProcessInfo(mainWindowHandle, mainWindowTitle)); } knownProcesses.Remove(mainWindowHandle); diff --git a/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs b/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs index e4c2a99..58a562f 100644 --- a/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs +++ b/Eve-O-Preview/Services/Implementation/ThumbnailManager.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows.Threading; using EveOPreview.Configuration; @@ -14,13 +13,13 @@ namespace EveOPreview.Services class ThumbnailManager : IThumbnailManager { #region Private constants - private const int WindowPositionThresholdLow = -10_000; - private const int WindowPositionThresholdHigh = 31_000; - private const int WindowSizeThreshold = 10; - private const int ForcedRefreshCycleThreshold = 2; - private const int DefaultLocationChangeNotificationDelay = 2; + private const int WINDOW_POSITION_THRESHOLD_LOW = -10_000; + private const int WINDOW_POSITION_THRESHOLD_HIGH = 31_000; + private const int WINDOW_SIZE_THRESHOLD = 10; + private const int FORCED_REFRESH_CYCLE_THRESHOLD = 2; + private const int DEFAULT_LOCATION_CHANGE_NOTIFICATION_DELAY = 2; - private const string DefaultClientTitle = "EVE"; + private const string DEFAULT_CLIENT_TITLE = "EVE"; #endregion #region Private fields @@ -51,7 +50,7 @@ namespace EveOPreview.Services this._configuration = configuration; this._thumbnailViewFactory = factory; - this._activeClient = (IntPtr.Zero, ThumbnailManager.DefaultClientTitle); + this._activeClient = (IntPtr.Zero, ThumbnailManager.DEFAULT_CLIENT_TITLE); this.EnableViewEvents(); this._isHoverEffectActive = false; @@ -121,7 +120,7 @@ namespace EveOPreview.Services this.ApplyClientLayout(view.Id, view.Title); // TODO Add extension filter here later - if (view.Title != ThumbnailManager.DefaultClientTitle) + if (view.Title != ThumbnailManager.DEFAULT_CLIENT_TITLE) { viewsAdded.Add(view.Title); } @@ -154,7 +153,7 @@ namespace EveOPreview.Services IThumbnailView view = this._thumbnailViews[process.Handle]; this._thumbnailViews.Remove(view.Id); - if (view.Title != ThumbnailManager.DefaultClientTitle) + if (view.Title != ThumbnailManager.DEFAULT_CLIENT_TITLE) { viewsRemoved.Add(view.Title); } @@ -203,7 +202,7 @@ namespace EveOPreview.Services this._refreshCycleCount++; bool forceRefresh; - if (this._refreshCycleCount >= ThumbnailManager.ForcedRefreshCycleThreshold) + if (this._refreshCycleCount >= ThumbnailManager.FORCED_REFRESH_CYCLE_THRESHOLD) { this._refreshCycleCount = 0; forceRefresh = true; @@ -223,11 +222,11 @@ namespace EveOPreview.Services { this.SnapThumbnailView(view); - this.RaiseThumbnailLocationUpdatedNotification(view.Title, this._activeClient.Title, view.ThumbnailLocation); + this.RaiseThumbnailLocationUpdatedNotification(view.Title); } else { - this.RaiseThumbnailLocationUpdatedNotification(locationChange.Title, locationChange.ActiveClient, locationChange.Location); + this.RaiseThumbnailLocationUpdatedNotification(locationChange.Title); } } @@ -609,7 +608,7 @@ namespace EveOPreview.Services { if (this._enqueuedLocationChangeNotification.Handle == IntPtr.Zero) { - this._enqueuedLocationChangeNotification = (view.Id, view.Title, activeClientTitle, view.ThumbnailLocation, ThumbnailManager.DefaultLocationChangeNotificationDelay); + this._enqueuedLocationChangeNotification = (view.Id, view.Title, activeClientTitle, view.ThumbnailLocation, ThumbnailManager.DEFAULT_LOCATION_CHANGE_NOTIFICATION_DELAY); return; } @@ -617,12 +616,12 @@ namespace EveOPreview.Services if ((this._enqueuedLocationChangeNotification.Handle == view.Id) && (this._enqueuedLocationChangeNotification.ActiveClient == activeClientTitle)) { - this._enqueuedLocationChangeNotification.Delay = ThumbnailManager.DefaultLocationChangeNotificationDelay; + this._enqueuedLocationChangeNotification.Delay = ThumbnailManager.DEFAULT_LOCATION_CHANGE_NOTIFICATION_DELAY; return; } - this.RaiseThumbnailLocationUpdatedNotification(this._enqueuedLocationChangeNotification.Title, activeClientTitle, this._enqueuedLocationChangeNotification.Location); - this._enqueuedLocationChangeNotification = (view.Id, view.Title, activeClientTitle, view.ThumbnailLocation, ThumbnailManager.DefaultLocationChangeNotificationDelay); + this.RaiseThumbnailLocationUpdatedNotification(this._enqueuedLocationChangeNotification.Title); + this._enqueuedLocationChangeNotification = (view.Id, view.Title, activeClientTitle, view.ThumbnailLocation, ThumbnailManager.DEFAULT_LOCATION_CHANGE_NOTIFICATION_DELAY); } } @@ -651,9 +650,9 @@ namespace EveOPreview.Services } } - private async void RaiseThumbnailLocationUpdatedNotification(string title, string activeClient, Point location) + private async void RaiseThumbnailLocationUpdatedNotification(string title) { - if (string.IsNullOrEmpty(title) || (title == ThumbnailManager.DefaultClientTitle)) + if (string.IsNullOrEmpty(title) || (title == ThumbnailManager.DEFAULT_CLIENT_TITLE)) { return; } @@ -665,15 +664,15 @@ namespace EveOPreview.Services // TODO Move to a service (?) private bool IsManageableThumbnail(IThumbnailView view) { - return view.Title != ThumbnailManager.DefaultClientTitle; + return view.Title != ThumbnailManager.DEFAULT_CLIENT_TITLE; } // Quick sanity check that the window is not minimized private bool IsValidWindowPosition(int letf, int top, int width, int height) { - return (letf > ThumbnailManager.WindowPositionThresholdLow) && (letf < ThumbnailManager.WindowPositionThresholdHigh) - && (top > ThumbnailManager.WindowPositionThresholdLow) && (top < ThumbnailManager.WindowPositionThresholdHigh) - && (width > ThumbnailManager.WindowSizeThreshold) && (height > ThumbnailManager.WindowSizeThreshold); + return (letf > ThumbnailManager.WINDOW_POSITION_THRESHOLD_LOW) && (letf < ThumbnailManager.WINDOW_POSITION_THRESHOLD_HIGH) + && (top > ThumbnailManager.WINDOW_POSITION_THRESHOLD_LOW) && (top < ThumbnailManager.WINDOW_POSITION_THRESHOLD_HIGH) + && (width > ThumbnailManager.WINDOW_SIZE_THRESHOLD) && (height > ThumbnailManager.WINDOW_SIZE_THRESHOLD); } } } \ No newline at end of file diff --git a/Eve-O-Preview/View/Implementation/ThumbnailView.cs b/Eve-O-Preview/View/Implementation/ThumbnailView.cs index 7c386ca..94b1f72 100644 --- a/Eve-O-Preview/View/Implementation/ThumbnailView.cs +++ b/Eve-O-Preview/View/Implementation/ThumbnailView.cs @@ -10,7 +10,7 @@ namespace EveOPreview.View public partial class ThumbnailView : Form, IThumbnailView { #region Private constants - private const int ResizeEventTimeout = 500; + private const int RESIZE_EVENT_TIMEOUT = 500; #endregion #region Private fields @@ -388,7 +388,7 @@ namespace EveOPreview.View { // Workaround for WinForms issue with the Resize event being fired with inconsistent ClientSize value // Any Resize events fired before this timestamp will be ignored - this._suppressResizeEventsTimestamp = DateTime.UtcNow.AddMilliseconds(ThumbnailView.ResizeEventTimeout); + this._suppressResizeEventsTimestamp = DateTime.UtcNow.AddMilliseconds(ThumbnailView.RESIZE_EVENT_TIMEOUT); } #region GUI events diff --git a/Eve-O-Preview/View/Interface/IMainFormView.cs b/Eve-O-Preview/View/Interface/IMainFormView.cs index 1c4ad32..cc727ef 100644 --- a/Eve-O-Preview/View/Interface/IMainFormView.cs +++ b/Eve-O-Preview/View/Interface/IMainFormView.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Drawing; -using EveOPreview.UI; namespace EveOPreview.View {