Finished transition to MediatR for GUI <-> service interaction
This commit is contained in:
@@ -114,18 +114,21 @@
|
||||
<Compile Include="Configuration\IThumbnailConfiguration.cs" />
|
||||
<Compile Include="Configuration\ZoomAnchor.cs" />
|
||||
<Compile Include="Mediator\Handlers\Configuration\SaveConfigurationHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailFrameSettingsUpdatedHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailConfiguredSizeUpdatedHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailListUpdatedHandler.cs" />
|
||||
<Compile Include="Mediator\Messages\Thumbnails\ThumbnailFrameSettingsUpdated.cs" />
|
||||
<Compile Include="Mediator\Messages\Thumbnails\ThumbnailConfiguredSizeUpdated.cs" />
|
||||
<Compile Include="Mediator\Messages\Thumbnails\ThumbnailListUpdated.cs" />
|
||||
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailLocationUpdatedHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailSizeUpdatedHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Services\StartServiceHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Services\StopServiceHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Thumbnails\ThumbnailActiveSizeUpdatedHandler.cs" />
|
||||
<Compile Include="Mediator\Handlers\Services\StartStopServiceHandler.cs" />
|
||||
<Compile Include="Mediator\Messages\Base\NotificationBase.cs" />
|
||||
<Compile Include="Mediator\Messages\Configuration\SaveConfiguration.cs" />
|
||||
<Compile Include="Mediator\Messages\Services\StartService.cs" />
|
||||
<Compile Include="Mediator\Messages\Services\StopService.cs" />
|
||||
<Compile Include="Mediator\Messages\Thumbnails\ThumbnailLocationUpdated.cs" />
|
||||
<Compile Include="Mediator\Messages\Thumbnails\ThumbnailSizeUpdated.cs" />
|
||||
<Compile Include="Mediator\Messages\Thumbnails\ThumbnailActiveSizeUpdated.cs" />
|
||||
<Compile Include="Presenters\Interface\IMainFormPresenter.cs" />
|
||||
<Compile Include="Services\Implementation\ProcessInfo.cs" />
|
||||
<Compile Include="Services\Implementation\ProcessMonitor.cs" />
|
||||
|
@@ -6,11 +6,11 @@ using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Handlers.Services
|
||||
{
|
||||
sealed class StartServiceHandler : IRequestHandler<StartService>
|
||||
sealed class StartStopServiceHandler : IRequestHandler<StartService>, IRequestHandler<StopService>
|
||||
{
|
||||
private readonly IThumbnailManager _manager;
|
||||
|
||||
public StartServiceHandler(IThumbnailManager manager)
|
||||
public StartStopServiceHandler(IThumbnailManager manager)
|
||||
{
|
||||
this._manager = manager;
|
||||
}
|
||||
@@ -21,5 +21,12 @@ namespace EveOPreview.Mediator.Handlers.Services
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(StopService message, CancellationToken cancellationToken)
|
||||
{
|
||||
this._manager.Stop();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Services;
|
||||
using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Handlers.Services
|
||||
{
|
||||
sealed class StopServiceHandler : IRequestHandler<StopService>
|
||||
{
|
||||
private readonly IThumbnailManager _manager;
|
||||
|
||||
public StopServiceHandler(IThumbnailManager manager)
|
||||
{
|
||||
this._manager = manager;
|
||||
}
|
||||
|
||||
public Task Handle(StopService message, CancellationToken cancellationToken)
|
||||
{
|
||||
this._manager.Stop();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -6,16 +6,16 @@ using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Handlers.Thumbnails
|
||||
{
|
||||
sealed class ThumbnailSizeUpdatedHandler : INotificationHandler<ThumbnailSizeUpdated>
|
||||
sealed class ThumbnailActiveSizeUpdatedHandler : INotificationHandler<ThumbnailActiveSizeUpdated>
|
||||
{
|
||||
private readonly IMainFormPresenter _presenter;
|
||||
|
||||
public ThumbnailSizeUpdatedHandler(MainFormPresenter presenter)
|
||||
public ThumbnailActiveSizeUpdatedHandler(MainFormPresenter presenter)
|
||||
{
|
||||
this._presenter = presenter;
|
||||
}
|
||||
|
||||
public Task Handle(ThumbnailSizeUpdated notification, CancellationToken cancellationToken)
|
||||
public Task Handle(ThumbnailActiveSizeUpdated notification, CancellationToken cancellationToken)
|
||||
{
|
||||
this._presenter.UpdateThumbnailSize(notification.Value);
|
||||
|
@@ -0,0 +1,25 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Services;
|
||||
using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Handlers.Thumbnails
|
||||
{
|
||||
sealed class ThumbnailConfiguredSizeUpdatedHandler : INotificationHandler<ThumbnailConfiguredSizeUpdated>
|
||||
{
|
||||
private readonly IThumbnailManager _manager;
|
||||
|
||||
public ThumbnailConfiguredSizeUpdatedHandler(IThumbnailManager manager)
|
||||
{
|
||||
this._manager = manager;
|
||||
}
|
||||
|
||||
public Task Handle(ThumbnailConfiguredSizeUpdated notification, CancellationToken cancellationToken)
|
||||
{
|
||||
this._manager.UpdateThumbnailsSize();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Services;
|
||||
using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Handlers.Thumbnails
|
||||
{
|
||||
sealed class ThumbnailFrameSettingsUpdatedHandler : INotificationHandler<ThumbnailFrameSettingsUpdated>
|
||||
{
|
||||
private readonly IThumbnailManager _manager;
|
||||
|
||||
public ThumbnailFrameSettingsUpdatedHandler(IThumbnailManager manager)
|
||||
{
|
||||
this._manager = manager;
|
||||
}
|
||||
|
||||
public Task Handle(ThumbnailFrameSettingsUpdated notification, CancellationToken cancellationToken)
|
||||
{
|
||||
this._manager.UpdateThumbnailFrames();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace EveOPreview.Mediator.Messages
|
||||
{
|
||||
sealed class ThumbnailActiveSizeUpdated : NotificationBase<Size>
|
||||
{
|
||||
public ThumbnailActiveSizeUpdated(Size size)
|
||||
: base(size)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Messages
|
||||
{
|
||||
sealed class ThumbnailConfiguredSizeUpdated : INotification
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Messages
|
||||
{
|
||||
sealed class ThumbnailFrameSettingsUpdated : INotification
|
||||
{
|
||||
}
|
||||
}
|
@@ -1,12 +0,0 @@
|
||||
using System.Drawing;
|
||||
|
||||
namespace EveOPreview.Mediator.Messages
|
||||
{
|
||||
sealed class ThumbnailSizeUpdated : NotificationBase<Size>
|
||||
{
|
||||
public ThumbnailSizeUpdated(Size size)
|
||||
: base(size)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -4,7 +4,6 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using EveOPreview.Configuration;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Services;
|
||||
using EveOPreview.View;
|
||||
using MediatR;
|
||||
|
||||
@@ -20,24 +19,22 @@ namespace EveOPreview.Presenters
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IThumbnailConfiguration _configuration;
|
||||
private readonly IConfigurationStorage _configurationStorage;
|
||||
private readonly IThumbnailManager _thumbnailManager;
|
||||
|
||||
private readonly IDictionary<string, IThumbnailDescription> _descriptionsCache;
|
||||
private bool _suppressSizeNotifications;
|
||||
|
||||
private bool _exitApplication;
|
||||
#endregion
|
||||
|
||||
public MainFormPresenter(IApplicationController controller, IMainFormView view, IMediator mediator, IThumbnailConfiguration configuration, IConfigurationStorage configurationStorage,
|
||||
IThumbnailManager thumbnailManager)
|
||||
public MainFormPresenter(IApplicationController controller, IMainFormView view, IMediator mediator, IThumbnailConfiguration configuration, IConfigurationStorage configurationStorage)
|
||||
: base(controller, view)
|
||||
{
|
||||
this._mediator = mediator;
|
||||
this._configuration = configuration;
|
||||
this._configurationStorage = configurationStorage;
|
||||
this._thumbnailManager = thumbnailManager;
|
||||
|
||||
this._descriptionsCache = new Dictionary<string, IThumbnailDescription>();
|
||||
|
||||
this._suppressSizeNotifications = false;
|
||||
this._exitApplication = false;
|
||||
|
||||
this.View.FormActivated = this.Activate;
|
||||
@@ -79,7 +76,6 @@ namespace EveOPreview.Presenters
|
||||
{
|
||||
this._mediator.Send(new StopService()).Wait();
|
||||
|
||||
this._thumbnailManager.Stop();
|
||||
this._configurationStorage.Save();
|
||||
request.Allow = true;
|
||||
return;
|
||||
@@ -89,10 +85,14 @@ namespace EveOPreview.Presenters
|
||||
this.View.Minimize();
|
||||
}
|
||||
|
||||
private void UpdateThumbnailsSize()
|
||||
private async void UpdateThumbnailsSize()
|
||||
{
|
||||
this._thumbnailManager.SetThumbnailsSize(this.View.ThumbnailSize);
|
||||
this.SaveApplicationSettings();
|
||||
|
||||
if (!this._suppressSizeNotifications)
|
||||
{
|
||||
await this._mediator.Publish(new ThumbnailConfiguredSizeUpdated());
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadApplicationSettings()
|
||||
@@ -122,7 +122,7 @@ namespace EveOPreview.Presenters
|
||||
this.View.ActiveClientHighlightColor = this._configuration.ActiveClientHighlightColor;
|
||||
}
|
||||
|
||||
private void SaveApplicationSettings()
|
||||
private async void SaveApplicationSettings()
|
||||
{
|
||||
this._configuration.MinimizeToTray = this.View.MinimizeToTray;
|
||||
|
||||
@@ -141,7 +141,12 @@ namespace EveOPreview.Presenters
|
||||
this._configuration.ThumbnailZoomAnchor = ViewZoomAnchorConverter.Convert(this.View.ThumbnailZoomAnchor);
|
||||
|
||||
this._configuration.ShowThumbnailOverlays = this.View.ShowThumbnailOverlays;
|
||||
if (this._configuration.ShowThumbnailFrames != this.View.ShowThumbnailFrames)
|
||||
{
|
||||
await this._mediator.Publish(new ThumbnailFrameSettingsUpdated());
|
||||
this._configuration.ShowThumbnailFrames = this.View.ShowThumbnailFrames;
|
||||
}
|
||||
|
||||
this._configuration.EnableActiveClientHighlight = this.View.EnableActiveClientHighlight;
|
||||
this._configuration.ActiveClientHighlightColor = this.View.ActiveClientHighlightColor;
|
||||
|
||||
@@ -149,7 +154,7 @@ namespace EveOPreview.Presenters
|
||||
|
||||
this.View.RefreshZoomSettings();
|
||||
|
||||
this._thumbnailManager.SetupThumbnailFrames();
|
||||
await this._mediator.Send(new SaveConfiguration());
|
||||
}
|
||||
|
||||
|
||||
@@ -200,17 +205,20 @@ namespace EveOPreview.Presenters
|
||||
|
||||
private void UpdateThumbnailState(String title)
|
||||
{
|
||||
// TODO This setting doesn't work atm
|
||||
//this._thumbnailManager.SetThumbnailState(thumbnailId, this._thumbnailDescriptionViews[thumbnailId].IsDisabled);
|
||||
}
|
||||
|
||||
public void UpdateThumbnailSize(Size size)
|
||||
{
|
||||
this._suppressSizeNotifications = true;
|
||||
this.View.ThumbnailSize = size;
|
||||
this._suppressSizeNotifications = false;
|
||||
}
|
||||
|
||||
private void OpenDocumentationLink()
|
||||
{
|
||||
// TODO Move out
|
||||
// TODO Move out to a separate service / presenter / message handler
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(new Uri(MainFormPresenter.ForumUrl).AbsoluteUri);
|
||||
Process.Start(processStartInfo);
|
||||
}
|
||||
|
@@ -78,7 +78,19 @@ namespace EveOPreview.Services
|
||||
thumbnail.IsEnabled = !hideAlways;
|
||||
}
|
||||
|
||||
public void UpdateThumbnailsSize()
|
||||
{
|
||||
this.InternalSetThumbnailsSize(this._configuration.ThumbnailSize);
|
||||
}
|
||||
|
||||
public async void SetThumbnailsSize(Size size)
|
||||
{
|
||||
this.InternalSetThumbnailsSize(size);
|
||||
|
||||
await this._mediator.Publish(new ThumbnailActiveSizeUpdated(size));
|
||||
}
|
||||
|
||||
private void InternalSetThumbnailsSize(Size size)
|
||||
{
|
||||
this.DisableViewEvents();
|
||||
|
||||
@@ -88,8 +100,6 @@ namespace EveOPreview.Services
|
||||
entry.Value.Refresh(false);
|
||||
}
|
||||
|
||||
await this._mediator.Publish(new ThumbnailSizeUpdated(size));
|
||||
|
||||
this.EnableViewEvents();
|
||||
}
|
||||
|
||||
@@ -154,7 +164,7 @@ namespace EveOPreview.Services
|
||||
this.EnableViewEvents();
|
||||
}
|
||||
|
||||
public void SetupThumbnailFrames()
|
||||
public void UpdateThumbnailFrames()
|
||||
{
|
||||
this.DisableViewEvents();
|
||||
|
||||
|
@@ -10,6 +10,7 @@ namespace EveOPreview.Services
|
||||
|
||||
void SetThumbnailState(IntPtr thumbnailId, bool hideAlways);
|
||||
void SetThumbnailsSize(Size size);
|
||||
void SetupThumbnailFrames();
|
||||
void UpdateThumbnailsSize();
|
||||
void UpdateThumbnailFrames();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user