Internal code cleanup

This commit is contained in:
Anton Kasyanov
2019-02-25 22:03:11 +02:00
parent a4e46c27bd
commit 7bc2775fb7
9 changed files with 39 additions and 45 deletions

View File

@@ -12,8 +12,8 @@ namespace EveOPreview
// So this dumb and non elegant approach is used // So this dumb and non elegant approach is used
sealed class ExceptionHandler sealed class ExceptionHandler
{ {
private const string ExceptionDumpFileName = "EVE-O Preview.log"; private const string EXCEPTION_DUMP_FILE_NAME = "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_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() public void SetupExceptionHandlers()
{ {
@@ -39,9 +39,9 @@ namespace EveOPreview
try try
{ {
String exceptionMessage = exception.ToString(); 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 catch
{ {

View File

@@ -5,7 +5,7 @@ namespace EveOPreview.Configuration.Implementation
{ {
class ConfigurationStorage : IConfigurationStorage 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 IAppConfig _appConfig;
private readonly IThumbnailConfiguration _thumbnailConfiguration; private readonly IThumbnailConfiguration _thumbnailConfiguration;
@@ -50,7 +50,7 @@ namespace EveOPreview.Configuration.Implementation
private string GetConfigFileName() 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;
} }
} }
} }

View File

@@ -214,7 +214,6 @@
<None Include="packages.config"> <None Include="packages.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</None> </None>
<None Include="Resources\icon.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="FodyWeavers.xml" /> <None Include="FodyWeavers.xml" />

View File

@@ -7,7 +7,7 @@ namespace EveOPreview.UI.Hotkeys
class HotkeyHandler : IMessageFilter, IDisposable class HotkeyHandler : IMessageFilter, IDisposable
{ {
private static int _currentId; private static int _currentId;
private const int MaxId = 0xBFFF; private const int MAX_ID = 0xBFFF;
#region Private fields #region Private fields
private readonly int _hotkeyId; private readonly int _hotkeyId;
@@ -17,7 +17,7 @@ namespace EveOPreview.UI.Hotkeys
public HotkeyHandler(IntPtr target, Keys hotkey) public HotkeyHandler(IntPtr target, Keys hotkey)
{ {
this._hotkeyId = HotkeyHandler._currentId; this._hotkeyId = HotkeyHandler._currentId;
HotkeyHandler._currentId = (HotkeyHandler._currentId + 1) & HotkeyHandler.MaxId; HotkeyHandler._currentId = (HotkeyHandler._currentId + 1) & HotkeyHandler.MAX_ID;
this._hotkeyTarget = target; this._hotkeyTarget = target;
@@ -106,10 +106,7 @@ namespace EveOPreview.UI.Hotkeys
Application.RemoveMessageFilter(this); Application.RemoveMessageFilter(this);
// Clean up after ourselves // Clean up after ourselves
if (!HotkeyHandlerNativeMethods.UnregisterHotKey(this._hotkeyTarget, this._hotkeyId)) HotkeyHandlerNativeMethods.UnregisterHotKey(this._hotkeyTarget, this._hotkeyId);
{
return;
}
} }
#region IMessageFilter #region IMessageFilter

View File

@@ -12,7 +12,7 @@ namespace EveOPreview.Presenters
public class MainFormPresenter : Presenter<IMainFormView>, IMainFormPresenter public class MainFormPresenter : Presenter<IMainFormView>, IMainFormPresenter
{ {
#region Private constants #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 #endregion
#region Private fields #region Private fields
@@ -50,7 +50,7 @@ namespace EveOPreview.Presenters
private void Activate() private void Activate()
{ {
this.LoadApplicationSettings(); this.LoadApplicationSettings();
this.View.SetDocumentationUrl(MainFormPresenter.ForumUrl); this.View.SetDocumentationUrl(MainFormPresenter.FORUM_URL);
this.View.SetVersionInfo(this.GetApplicationVersion()); this.View.SetVersionInfo(this.GetApplicationVersion());
if (this._configuration.MinimizeToTray) if (this._configuration.MinimizeToTray)
{ {
@@ -225,7 +225,7 @@ namespace EveOPreview.Presenters
private void OpenDocumentationLink() private void OpenDocumentationLink()
{ {
// TODO Move out to a separate service / presenter / message handler // 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); Process.Start(processStartInfo);
} }

View File

@@ -7,7 +7,7 @@ namespace EveOPreview.Services.Implementation
sealed class ProcessMonitor : IProcessMonitor sealed class ProcessMonitor : IProcessMonitor
{ {
#region Private constants #region Private constants
private const string DefaultProcessName = "ExeFile"; private const string DEFAULT_PROCESS_NAME = "ExeFile";
#endregion #endregion
#region Private fields #region Private fields
@@ -22,7 +22,7 @@ namespace EveOPreview.Services.Implementation
private bool IsMonitoredProcess(string processName) private bool IsMonitoredProcess(string processName)
{ {
// This is a possible extension point // 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<IProcessInfo> addedProcesses, out ICollection<IProcessInfo> updatedProcesses, out ICollection<IProcessInfo> removedProcesses) public void GetUpdatedProcesses(out ICollection<IProcessInfo> addedProcesses, out ICollection<IProcessInfo> updatedProcesses, out ICollection<IProcessInfo> removedProcesses)
@@ -62,7 +62,7 @@ namespace EveOPreview.Services.Implementation
if (cachedTitle != mainWindowTitle) if (cachedTitle != mainWindowTitle)
{ {
this._processCache[mainWindowHandle] = mainWindowTitle; this._processCache[mainWindowHandle] = mainWindowTitle;
updatedProcesses.Add((IProcessInfo)new ProcessInfo(mainWindowHandle, mainWindowTitle)); updatedProcesses.Add(new ProcessInfo(mainWindowHandle, mainWindowTitle));
} }
knownProcesses.Remove(mainWindowHandle); knownProcesses.Remove(mainWindowHandle);

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Threading; using System.Windows.Threading;
using EveOPreview.Configuration; using EveOPreview.Configuration;
@@ -14,13 +13,13 @@ namespace EveOPreview.Services
class ThumbnailManager : IThumbnailManager class ThumbnailManager : IThumbnailManager
{ {
#region Private constants #region Private constants
private const int WindowPositionThresholdLow = -10_000; private const int WINDOW_POSITION_THRESHOLD_LOW = -10_000;
private const int WindowPositionThresholdHigh = 31_000; private const int WINDOW_POSITION_THRESHOLD_HIGH = 31_000;
private const int WindowSizeThreshold = 10; private const int WINDOW_SIZE_THRESHOLD = 10;
private const int ForcedRefreshCycleThreshold = 2; private const int FORCED_REFRESH_CYCLE_THRESHOLD = 2;
private const int DefaultLocationChangeNotificationDelay = 2; private const int DEFAULT_LOCATION_CHANGE_NOTIFICATION_DELAY = 2;
private const string DefaultClientTitle = "EVE"; private const string DEFAULT_CLIENT_TITLE = "EVE";
#endregion #endregion
#region Private fields #region Private fields
@@ -51,7 +50,7 @@ namespace EveOPreview.Services
this._configuration = configuration; this._configuration = configuration;
this._thumbnailViewFactory = factory; this._thumbnailViewFactory = factory;
this._activeClient = (IntPtr.Zero, ThumbnailManager.DefaultClientTitle); this._activeClient = (IntPtr.Zero, ThumbnailManager.DEFAULT_CLIENT_TITLE);
this.EnableViewEvents(); this.EnableViewEvents();
this._isHoverEffectActive = false; this._isHoverEffectActive = false;
@@ -121,7 +120,7 @@ namespace EveOPreview.Services
this.ApplyClientLayout(view.Id, view.Title); this.ApplyClientLayout(view.Id, view.Title);
// TODO Add extension filter here later // TODO Add extension filter here later
if (view.Title != ThumbnailManager.DefaultClientTitle) if (view.Title != ThumbnailManager.DEFAULT_CLIENT_TITLE)
{ {
viewsAdded.Add(view.Title); viewsAdded.Add(view.Title);
} }
@@ -154,7 +153,7 @@ namespace EveOPreview.Services
IThumbnailView view = this._thumbnailViews[process.Handle]; IThumbnailView view = this._thumbnailViews[process.Handle];
this._thumbnailViews.Remove(view.Id); this._thumbnailViews.Remove(view.Id);
if (view.Title != ThumbnailManager.DefaultClientTitle) if (view.Title != ThumbnailManager.DEFAULT_CLIENT_TITLE)
{ {
viewsRemoved.Add(view.Title); viewsRemoved.Add(view.Title);
} }
@@ -203,7 +202,7 @@ namespace EveOPreview.Services
this._refreshCycleCount++; this._refreshCycleCount++;
bool forceRefresh; bool forceRefresh;
if (this._refreshCycleCount >= ThumbnailManager.ForcedRefreshCycleThreshold) if (this._refreshCycleCount >= ThumbnailManager.FORCED_REFRESH_CYCLE_THRESHOLD)
{ {
this._refreshCycleCount = 0; this._refreshCycleCount = 0;
forceRefresh = true; forceRefresh = true;
@@ -223,11 +222,11 @@ namespace EveOPreview.Services
{ {
this.SnapThumbnailView(view); this.SnapThumbnailView(view);
this.RaiseThumbnailLocationUpdatedNotification(view.Title, this._activeClient.Title, view.ThumbnailLocation); this.RaiseThumbnailLocationUpdatedNotification(view.Title);
} }
else 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) 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; return;
} }
@@ -617,12 +616,12 @@ namespace EveOPreview.Services
if ((this._enqueuedLocationChangeNotification.Handle == view.Id) && if ((this._enqueuedLocationChangeNotification.Handle == view.Id) &&
(this._enqueuedLocationChangeNotification.ActiveClient == activeClientTitle)) (this._enqueuedLocationChangeNotification.ActiveClient == activeClientTitle))
{ {
this._enqueuedLocationChangeNotification.Delay = ThumbnailManager.DefaultLocationChangeNotificationDelay; this._enqueuedLocationChangeNotification.Delay = ThumbnailManager.DEFAULT_LOCATION_CHANGE_NOTIFICATION_DELAY;
return; return;
} }
this.RaiseThumbnailLocationUpdatedNotification(this._enqueuedLocationChangeNotification.Title, activeClientTitle, this._enqueuedLocationChangeNotification.Location); this.RaiseThumbnailLocationUpdatedNotification(this._enqueuedLocationChangeNotification.Title);
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);
} }
} }
@@ -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; return;
} }
@@ -665,15 +664,15 @@ namespace EveOPreview.Services
// TODO Move to a service (?) // TODO Move to a service (?)
private bool IsManageableThumbnail(IThumbnailView view) 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 // Quick sanity check that the window is not minimized
private bool IsValidWindowPosition(int letf, int top, int width, int height) private bool IsValidWindowPosition(int letf, int top, int width, int height)
{ {
return (letf > ThumbnailManager.WindowPositionThresholdLow) && (letf < ThumbnailManager.WindowPositionThresholdHigh) return (letf > ThumbnailManager.WINDOW_POSITION_THRESHOLD_LOW) && (letf < ThumbnailManager.WINDOW_POSITION_THRESHOLD_HIGH)
&& (top > ThumbnailManager.WindowPositionThresholdLow) && (top < ThumbnailManager.WindowPositionThresholdHigh) && (top > ThumbnailManager.WINDOW_POSITION_THRESHOLD_LOW) && (top < ThumbnailManager.WINDOW_POSITION_THRESHOLD_HIGH)
&& (width > ThumbnailManager.WindowSizeThreshold) && (height > ThumbnailManager.WindowSizeThreshold); && (width > ThumbnailManager.WINDOW_SIZE_THRESHOLD) && (height > ThumbnailManager.WINDOW_SIZE_THRESHOLD);
} }
} }
} }

View File

@@ -10,7 +10,7 @@ namespace EveOPreview.View
public partial class ThumbnailView : Form, IThumbnailView public partial class ThumbnailView : Form, IThumbnailView
{ {
#region Private constants #region Private constants
private const int ResizeEventTimeout = 500; private const int RESIZE_EVENT_TIMEOUT = 500;
#endregion #endregion
#region Private fields #region Private fields
@@ -388,7 +388,7 @@ namespace EveOPreview.View
{ {
// Workaround for WinForms issue with the Resize event being fired with inconsistent ClientSize value // Workaround for WinForms issue with the Resize event being fired with inconsistent ClientSize value
// Any Resize events fired before this timestamp will be ignored // 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 #region GUI events

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using EveOPreview.UI;
namespace EveOPreview.View namespace EveOPreview.View
{ {