Thumbnail List Update notifications moved to MediatR
This commit is contained in:
@@ -17,6 +17,11 @@ namespace EveOPreview
|
||||
|
||||
public void SetupExceptionHandlers()
|
||||
{
|
||||
if (System.Diagnostics.Debugger.IsAttached)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
Application.ThreadException += delegate (Object sender, ThreadExceptionEventArgs e)
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace EveOPreview
|
||||
public void Register<TService, TImplementation>()
|
||||
where TImplementation : TService
|
||||
{
|
||||
this._container.Register<TService, TImplementation>(new PerContainerLifetime());
|
||||
this._container.Register<TService, TImplementation>();
|
||||
}
|
||||
|
||||
public void Register<TService>(Expression<Func<TService>> factory)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Presenters;
|
||||
@@ -20,7 +19,17 @@ namespace EveOPreview.Mediator.Handlers.Thumbnails
|
||||
|
||||
public Task Handle(ThumbnailListUpdated notification, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (notification.Added.Count > 0)
|
||||
{
|
||||
this._presenter.AddThumbnails(notification.Added);
|
||||
}
|
||||
|
||||
if (notification.Removed.Count > 0)
|
||||
{
|
||||
this._presenter.RemoveThumbnails(notification.Removed);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using MediatR;
|
||||
|
||||
namespace EveOPreview.Mediator.Messages
|
||||
{
|
||||
sealed class ThumbnailListUpdated : NotificationBase<IList<string>>
|
||||
sealed class ThumbnailListUpdated : INotification
|
||||
{
|
||||
public ThumbnailListUpdated(UpdateKind updateKind, IList<string> list)
|
||||
: base(list)
|
||||
public ThumbnailListUpdated(IList<string> addedThumbnails, IList<string> removedThumbnails)
|
||||
{
|
||||
this.Kind = updateKind;
|
||||
this.Added = addedThumbnails;
|
||||
this.Removed = removedThumbnails;
|
||||
}
|
||||
|
||||
public UpdateKind Kind { get; }
|
||||
|
||||
public enum UpdateKind
|
||||
{
|
||||
Add,
|
||||
Update,
|
||||
Remove
|
||||
}
|
||||
public IList<string> Added { get; }
|
||||
public IList<string> Removed { get; }
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ using System.Drawing;
|
||||
using EveOPreview.Configuration;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Services;
|
||||
using EveOPreview.UI;
|
||||
using EveOPreview.View;
|
||||
using MediatR;
|
||||
|
||||
@@ -23,6 +22,8 @@ namespace EveOPreview.Presenters
|
||||
private readonly IConfigurationStorage _configurationStorage;
|
||||
private readonly IThumbnailManager _thumbnailManager;
|
||||
|
||||
private readonly IDictionary<string, IThumbnailDescription> _descriptionsCache;
|
||||
|
||||
private bool _exitApplication;
|
||||
#endregion
|
||||
|
||||
@@ -33,9 +34,10 @@ namespace EveOPreview.Presenters
|
||||
this._mediator = mediator;
|
||||
this._configuration = configuration;
|
||||
this._configurationStorage = configurationStorage;
|
||||
|
||||
this._thumbnailManager = thumbnailManager;
|
||||
|
||||
this._descriptionsCache = new Dictionary<string, IThumbnailDescription>();
|
||||
|
||||
this._exitApplication = false;
|
||||
|
||||
this.View.FormActivated = this.Activate;
|
||||
@@ -150,70 +152,65 @@ namespace EveOPreview.Presenters
|
||||
this._thumbnailManager.SetupThumbnailFrames();
|
||||
}
|
||||
|
||||
private void ThumbnailsAdded(IList<IThumbnailView> thumbnails)
|
||||
|
||||
public void AddThumbnails(IList<string> thumbnailTitles)
|
||||
{
|
||||
//this.View.AddThumbnails(this.GetThumbnailViews(thumbnails, false));
|
||||
IList<IThumbnailDescription> descriptions = new List<IThumbnailDescription>(thumbnailTitles.Count);
|
||||
|
||||
lock (this._descriptionsCache)
|
||||
{
|
||||
foreach (string title in thumbnailTitles)
|
||||
{
|
||||
IThumbnailDescription description = this.CreateThumbnailDescription(title);
|
||||
this._descriptionsCache[title] = description;
|
||||
|
||||
descriptions.Add(description);
|
||||
}
|
||||
}
|
||||
|
||||
this.View.AddThumbnails(descriptions);
|
||||
}
|
||||
|
||||
private void ThumbnailsUpdated(IList<IThumbnailView> thumbnails)
|
||||
public void RemoveThumbnails(IList<string> thumbnailTitles)
|
||||
{
|
||||
//this.View.UpdateThumbnails(this.GetThumbnailViews(thumbnails, false));
|
||||
IList<IThumbnailDescription> descriptions = new List<IThumbnailDescription>(thumbnailTitles.Count);
|
||||
|
||||
lock (this._descriptionsCache)
|
||||
{
|
||||
foreach (string title in thumbnailTitles)
|
||||
{
|
||||
if (!this._descriptionsCache.TryGetValue(title, out IThumbnailDescription description))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
this._descriptionsCache.Remove(title);
|
||||
descriptions.Add(description);
|
||||
}
|
||||
}
|
||||
|
||||
this.View.RemoveThumbnails(descriptions);
|
||||
}
|
||||
|
||||
private void ThumbnailsRemoved(IList<IThumbnailView> thumbnails)
|
||||
private IThumbnailDescription CreateThumbnailDescription(string title)
|
||||
{
|
||||
//this.View.RemoveThumbnails(this.GetThumbnailViews(thumbnails, true));
|
||||
// TODO Read here persisted value for the IsDisabled parameter
|
||||
return new ThumbnailDescription(title, false);
|
||||
}
|
||||
|
||||
//private IList<IThumbnailDescriptionView> GetThumbnailViews(IList<IThumbnailView> thumbnails, bool removeFromCache)
|
||||
//{
|
||||
// IList<IThumbnailDescriptionView> thumbnailViews = new List<IThumbnailDescriptionView>(thumbnails.Count);
|
||||
|
||||
// // Time for some thread safety
|
||||
// lock (this._thumbnailDescriptionViews)
|
||||
// {
|
||||
// foreach (IThumbnailView thumbnail in thumbnails)
|
||||
// {
|
||||
// IThumbnailDescriptionView thumbnailView;
|
||||
// bool foundInCache = this._thumbnailDescriptionViews.TryGetValue(thumbnail.Id, out thumbnailView);
|
||||
|
||||
// if (!foundInCache)
|
||||
// {
|
||||
// if (removeFromCache)
|
||||
// {
|
||||
// // This item was not even cached
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// thumbnailView = this._thumbnailDescriptionViewFactory.Create(thumbnail.Id, thumbnail.Title, !thumbnail.IsEnabled);
|
||||
// this._thumbnailDescriptionViews.Add(thumbnail.Id, thumbnailView);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (removeFromCache)
|
||||
// {
|
||||
// this._thumbnailDescriptionViews.Remove(thumbnail.Id);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// thumbnailView.Title = thumbnail.Title;
|
||||
// }
|
||||
// }
|
||||
|
||||
// thumbnailViews.Add(thumbnailView);
|
||||
// }
|
||||
// }
|
||||
|
||||
// return thumbnailViews;
|
||||
//}
|
||||
|
||||
private void UpdateThumbnailState(String title)
|
||||
{
|
||||
//this._thumbnailManager.SetThumbnailState(thumbnailId, this._thumbnailDescriptionViews[thumbnailId].IsDisabled);
|
||||
}
|
||||
|
||||
public void UpdateThumbnailSize(Size size)
|
||||
{
|
||||
this.View.ThumbnailSize = size;
|
||||
}
|
||||
|
||||
private void OpenDocumentationLink()
|
||||
{
|
||||
// TODO Move out
|
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(new Uri(MainFormPresenter.ForumUrl).AbsoluteUri);
|
||||
Process.Start(processStartInfo);
|
||||
}
|
||||
@@ -229,10 +226,5 @@ namespace EveOPreview.Presenters
|
||||
this._exitApplication = true;
|
||||
this.View.Close();
|
||||
}
|
||||
|
||||
public void UpdateThumbnailSize(Size size)
|
||||
{
|
||||
this.View.ThumbnailSize = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
using System.Drawing;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace EveOPreview.Presenters
|
||||
{
|
||||
interface IMainFormPresenter
|
||||
{
|
||||
void AddThumbnails(IList<string> thumbnailTitles);
|
||||
void RemoveThumbnails(IList<string> thumbnailTitles);
|
||||
|
||||
void UpdateThumbnailSize(Size size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Drawing;
|
||||
using System.Windows.Threading;
|
||||
using EveOPreview.Configuration;
|
||||
using EveOPreview.Mediator.Messages;
|
||||
using EveOPreview.Services;
|
||||
using EveOPreview.View;
|
||||
using MediatR;
|
||||
|
||||
@@ -71,8 +70,7 @@ namespace EveOPreview.Services
|
||||
|
||||
public void SetThumbnailState(IntPtr thumbnailId, bool hideAlways)
|
||||
{
|
||||
IThumbnailView thumbnail;
|
||||
if (!this._thumbnailViews.TryGetValue(thumbnailId, out thumbnail))
|
||||
if (!this._thumbnailViews.TryGetValue(thumbnailId, out IThumbnailView thumbnail))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +104,7 @@ namespace EveOPreview.Services
|
||||
foreach (KeyValuePair<IntPtr, IThumbnailView> entry in this._thumbnailViews)
|
||||
{
|
||||
IThumbnailView view = entry.Value;
|
||||
|
||||
|
||||
if (hideAllThumbnails || !view.IsEnabled)
|
||||
{
|
||||
if (view.IsActive)
|
||||
@@ -191,7 +189,6 @@ namespace EveOPreview.Services
|
||||
IntPtr foregroundWindowHandle = this._windowManager.GetForegroundWindowHandle();
|
||||
|
||||
List<string> viewsAdded = new List<string>();
|
||||
List<string> viewsUpdated = new List<string>();
|
||||
List<string> viewsRemoved = new List<string>();
|
||||
|
||||
foreach (IProcessInfo process in addedProcesses)
|
||||
@@ -247,15 +244,13 @@ namespace EveOPreview.Services
|
||||
|
||||
if (process.Title != view.Title) // update thumbnail title
|
||||
{
|
||||
viewsRemoved.Add(view.Title);
|
||||
view.Title = process.Title;
|
||||
viewsAdded.Add(view.Title);
|
||||
|
||||
view.RegisterHotkey(this._configuration.GetClientHotkey(process.Title));
|
||||
|
||||
this.ApplyClientLayout(view.Id, view.Title);
|
||||
|
||||
if (view.Title != ThumbnailManager.DefaultClientTitle)
|
||||
{
|
||||
viewsUpdated.Add(view.Title);
|
||||
}
|
||||
}
|
||||
|
||||
if (process.Handle == foregroundWindowHandle)
|
||||
@@ -270,6 +265,10 @@ namespace EveOPreview.Services
|
||||
IThumbnailView view = this._thumbnailViews[process.Handle];
|
||||
|
||||
this._thumbnailViews.Remove(view.Id);
|
||||
if (view.Title != ThumbnailManager.DefaultClientTitle)
|
||||
{
|
||||
viewsRemoved.Add(view.Title);
|
||||
}
|
||||
|
||||
view.UnregisterHotkey();
|
||||
|
||||
@@ -280,26 +279,11 @@ namespace EveOPreview.Services
|
||||
view.ThumbnailActivated = null;
|
||||
|
||||
view.Close();
|
||||
|
||||
if (view.Title != ThumbnailManager.DefaultClientTitle)
|
||||
{
|
||||
viewsRemoved.Add(view.Title);
|
||||
}
|
||||
}
|
||||
|
||||
if (viewsAdded.Count > 0)
|
||||
if ((viewsAdded.Count > 0) || (viewsRemoved.Count > 0))
|
||||
{
|
||||
await this._mediator.Publish(new ThumbnailListUpdated(ThumbnailListUpdated.UpdateKind.Add, viewsAdded));
|
||||
}
|
||||
|
||||
if (viewsUpdated.Count > 0)
|
||||
{
|
||||
await this._mediator.Publish(new ThumbnailListUpdated(ThumbnailListUpdated.UpdateKind.Update, viewsUpdated));
|
||||
}
|
||||
|
||||
if (viewsRemoved.Count > 0)
|
||||
{
|
||||
await this._mediator.Publish(new ThumbnailListUpdated(ThumbnailListUpdated.UpdateKind.Remove, viewsRemoved));
|
||||
await this._mediator.Publish(new ThumbnailListUpdated(viewsAdded, viewsRemoved));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using EveOPreview.UI;
|
||||
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
@@ -208,11 +207,6 @@ namespace EveOPreview.View
|
||||
|
||||
public void AddThumbnails(IList<IThumbnailDescription> thumbnails)
|
||||
{
|
||||
if (thumbnails.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.ThumbnailsList.BeginUpdate();
|
||||
|
||||
foreach (IThumbnailDescription view in thumbnails)
|
||||
@@ -223,22 +217,8 @@ namespace EveOPreview.View
|
||||
this.ThumbnailsList.EndUpdate();
|
||||
}
|
||||
|
||||
public void UpdateThumbnails(IList<IThumbnailDescription> thumbnails)
|
||||
{
|
||||
// Just trigger redraw
|
||||
if (thumbnails.Count > 0)
|
||||
{
|
||||
this.ThumbnailsList.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveThumbnails(IList<IThumbnailDescription> thumbnails)
|
||||
{
|
||||
if (thumbnails.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.ThumbnailsList.BeginUpdate();
|
||||
|
||||
foreach (IThumbnailDescription view in thumbnails)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
sealed class ThumbnailDescription
|
||||
sealed class ThumbnailDescription : IThumbnailDescription
|
||||
{
|
||||
public ThumbnailDescription(string title, bool isDisabled)
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace EveOPreview.UI
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
partial class ThumbnailOverlay
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using System.Windows.Forms;
|
||||
using EveOPreview.Services;
|
||||
|
||||
namespace EveOPreview.UI
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
public partial class ThumbnailOverlay : Form
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace EveOPreview.UI
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
partial class ThumbnailView
|
||||
{
|
||||
|
||||
@@ -4,9 +4,8 @@ using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using EveOPreview.Services;
|
||||
using EveOPreview.UI.Hotkeys;
|
||||
using EveOPreview.View;
|
||||
|
||||
namespace EveOPreview.UI
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
public partial class ThumbnailView : Form, IThumbnailView
|
||||
{
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace EveOPreview.View
|
||||
void Minimize();
|
||||
|
||||
void AddThumbnails(IList<IThumbnailDescription> thumbnails);
|
||||
void UpdateThumbnails(IList<IThumbnailDescription> thumbnails);
|
||||
void RemoveThumbnails(IList<IThumbnailDescription> thumbnails);
|
||||
void RefreshZoomSettings();
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace EveOPreview.View
|
||||
namespace EveOPreview.View
|
||||
{
|
||||
public interface IThumbnailDescription
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user