Skip to content

Commit

Permalink
Revert "chore: removes the Behaviour, Manager and Factory interfaces"
Browse files Browse the repository at this point in the history
This reverts commit 4292e54.
  • Loading branch information
pudding committed Jul 12, 2024
1 parent 4292e54 commit ea07af0
Show file tree
Hide file tree
Showing 128 changed files with 271 additions and 284 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class SystemMediaTransportControlsBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class SystemMediaTransportControlsBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const int UPDATE_INTERVAL = 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class ToastNotificationManagerBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class ToastNotificationManagerBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const string GROUP = "87854E64-DD46-4C8C-8E29-B97FBF5265BD";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class ExecutionStateBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class ExecutionStateBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const int UPDATE_INTERVAL = 10000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
[PlatformDependency(Major = 6, Minor = 1)]
public class TaskbarButtonsBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class TaskbarButtonsBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const int UPDATE_INTERVAL = 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
[PlatformDependency(Major = 6, Minor = 1)]
public class TaskbarProgressBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class TaskbarProgressBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const int UPDATE_INTERVAL = 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
[PlatformDependency(Major = 6, Minor = 1)]
public class TaskbarThumbnailBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class TaskbarThumbnailBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const int UPDATE_INTERVAL = 1000;

Expand Down
37 changes: 4 additions & 33 deletions FoxTunes.Core.Windows/Managers/WindowsInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class WindowsInputManager : InputManager, IStandardComponent
public class WindowsInputManager : InputManager, IStandardManager
{
const int WH_KEYBOARD_LL = 13;

Expand Down Expand Up @@ -126,40 +127,10 @@ protected virtual void Disable()
}
}

public bool IsDisposed { get; private set; }

public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (this.IsDisposed || !disposing)
{
return;
}
this.OnDisposing();
this.IsDisposed = true;
}

protected virtual void OnDisposing()
protected override void OnDisposing()
{
this.Disable();
}

~WindowsInputManager()
{
//Logger.Write(this, LogLevel.Error, "Component was not disposed: {0}", this.GetType().Name);
try
{
this.Dispose(true);
}
catch
{
//Nothing can be done, never throw on GC thread.
}
base.OnDisposing();
}

public delegate IntPtr KeyboardProc(int code, IntPtr input, ref KeyboardInput keys);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class WindowsMessageSinkFactory : MessageSinkFactory, IStandardComponent
public class WindowsMessageSinkFactory : MessageSinkFactory, IStandardFactory
{
public override IMessageSink Create(uint id)
{
Expand Down
9 changes: 9 additions & 0 deletions FoxTunes.Core/BaseBehaviour.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using FoxTunes.Interfaces;

namespace FoxTunes
{
public abstract class BaseBehaviour : BaseComponent, IBaseBehaviour
{

}
}
8 changes: 8 additions & 0 deletions FoxTunes.Core/BaseFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using FoxTunes.Interfaces;

namespace FoxTunes
{
public abstract class BaseFactory : BaseComponent, IBaseFactory
{
}
}
44 changes: 44 additions & 0 deletions FoxTunes.Core/BaseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using FoxTunes.Interfaces;
using System;

namespace FoxTunes
{
public abstract class BaseManager : BaseComponent, IBaseManager
{
public bool IsDisposed { get; private set; }

public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (this.IsDisposed || !disposing)
{
return;
}
this.OnDisposing();
this.IsDisposed = true;
}

protected virtual void OnDisposing()
{
//Nothing to do.
}

~BaseManager()
{
//Logger.Write(this, LogLevel.Error, "Component was not disposed: {0}", this.GetType().Name);
try
{
this.Dispose(true);
}
catch
{
//Nothing can be done, never throw on GC thread.
}
}
}
}
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/EnqueueNextItemBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Output)]
public class EnqueueNextItemsBehaviour : StandardComponent, IConfigurableComponent, IDisposable
public class EnqueueNextItemsBehaviour : StandardBehaviour, IConfigurableComponent, IDisposable
{
const int TIMEOUT = 1000;

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/ExternalPlaylistBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Database)]
public class ExternalPlaylistBehaviour : StandardComponent, IInvocableComponent, IConfigurableComponent, IFileActionHandler
public class ExternalPlaylistBehaviour : StandardBehaviour, IInvocableComponent, IConfigurableComponent, IFileActionHandler
{
public const string LOAD_PLAYLIST = "YYYZ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Database)]
public class LibraryHierarchyNodeRefreshBehaviour : StandardComponent, IDisposable
public class LibraryHierarchyNodeRefreshBehaviour : StandardBehaviour, IDisposable
{
public ISignalEmitter SignalEmitter { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/MetaDataBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Database)]
public class MetaDataBehaviour : StandardComponent, IConfigurableComponent
public class MetaDataBehaviour : StandardBehaviour, IConfigurableComponent
{
public IEnumerable<ConfigurationSection> GetConfigurationSections()
{
Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/MetaDataRefreshBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class MetaDataRefreshBehaviour : StandardComponent, IDisposable
public class MetaDataRefreshBehaviour : StandardBehaviour, IDisposable
{
public MetaDataRefreshBehaviour()
{
Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PlayNextItemBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Output)]
public class PlayNextItemBehaviour : StandardComponent, IDisposable
public class PlayNextItemBehaviour : StandardBehaviour, IDisposable
{
public IPlaybackManager PlaybackManager { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PlaybackBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Output)]
public class PlaybackBehaviour : StandardComponent, IConfigurableComponent
public class PlaybackBehaviour : StandardBehaviour, IConfigurableComponent
{
public IEnumerable<ConfigurationSection> GetConfigurationSections()
{
Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PlaylistActionsBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class PlaylistActionsBehaviour : StandardComponent, IInvocableComponent
public class PlaylistActionsBehaviour : StandardBehaviour, IInvocableComponent
{
public const string REMOVE_PLAYLIST_ITEMS = "AAAA";

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PlaylistBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Output)]
public class PlaylistBehaviour : StandardComponent, IInvocableComponent, IConfigurableComponent
public class PlaylistBehaviour : StandardBehaviour, IInvocableComponent, IConfigurableComponent
{
public IConfiguration Configuration { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PlaylistBehaviourBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace FoxTunes
{
public abstract class PlaylistBehaviourBase : StandardComponent, IDisposable
public abstract class PlaylistBehaviourBase : StandardBehaviour, IDisposable
{
public abstract Func<Playlist, bool> Predicate { get; }

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PlaylistSearchBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Database)]
public class PlaylistSearchBehaviour : StandardComponent
public class PlaylistSearchBehaviour : StandardBehaviour
{
public IPlaylistManager PlaylistManager { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/PreemptNextItemBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Output)]
public class PreemptNextItemBehaviour : StandardComponent, IDisposable
public class PreemptNextItemBehaviour : StandardBehaviour, IDisposable
{
public IOutput Output { get; private set; }

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Behaviours/SearchBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.UserInterface)]
public class SearchBehaviour : StandardComponent, IConfigurableComponent
public class SearchBehaviour : StandardBehaviour, IConfigurableComponent
{
public IEnumerable<ConfigurationSection> GetConfigurationSections()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace FoxTunes
{
[ComponentDependency(Slot = ComponentSlots.Database)]
public class SelectionFollowsPlaybackBehaviour : StandardComponent, IInvocableComponent, IConfigurableComponent
public class SelectionFollowsPlaybackBehaviour : StandardBehaviour, IInvocableComponent, IConfigurableComponent
{
public IPlaylistManager PlaylistManager { get; private set; }

Expand Down
24 changes: 21 additions & 3 deletions FoxTunes.Core/ComponentScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public class ComponentScanner : IComponentScanner

private static Type[] STANDARD_COMPONENT_TYPES = new[]
{
typeof(IStandardComponent)
typeof(IStandardComponent),
typeof(IStandardManager),
typeof(IStandardFactory),
typeof(IStandardBehaviour)
};

public static string Location
public static string Location
{
get
{
Expand Down Expand Up @@ -69,7 +72,7 @@ private static IEnumerable<Type> GetTypes(string fileName)
//Logger.Write(typeof(ComponentScanner), LogLevel.Trace, "Error was handled while getting exported types for assembly {0}: {1}", fileName, e.Message);
return e.Types;
}
catch
catch
{
//Logger.Write(typeof(ComponentScanner), LogLevel.Warn, "Failed to get exported types for assembly {0}: {1}", fileName, e.Message);
return Enumerable.Empty<Type>();
Expand Down Expand Up @@ -302,13 +305,28 @@ private static class ComponentSorter
{
public static byte Type(Type type)
{
//TODO: This is awful, basically all component loading goes through this ordering before any other sorting strategies (e.g priority)
//TODO: The load order is always: Components, Factories, Managers, Behaviours.
//TODO: I don't have the energy to fix it, removing this code causes issues with component inter-dependency during start up.
var interfaces = type.GetInterfaces().Select(
@interface => @interface.FullName
).ToArray();
if (interfaces.Contains(typeof(IStandardComponent).FullName, StringComparer.OrdinalIgnoreCase))
{
return 0;
}
if (interfaces.Contains(typeof(IStandardFactory).FullName, StringComparer.OrdinalIgnoreCase))
{
return 1;
}
if (interfaces.Contains(typeof(IStandardManager).FullName, StringComparer.OrdinalIgnoreCase))
{
return 2;
}
if (interfaces.Contains(typeof(IStandardBehaviour).FullName, StringComparer.OrdinalIgnoreCase))
{
return 3;
}
return byte.MaxValue;
}

Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Interfaces/Factories/IDatabaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FoxTunes.Interfaces
{
public interface IDatabaseFactory : IStandardComponent
public interface IDatabaseFactory : IStandardFactory
{
string Id { get; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace FoxTunes.Interfaces
{
public interface IFFTDataTransformerFactory : IStandardComponent
public interface IFFTDataTransformerFactory : IStandardFactory
{
IFFTDataTransformer Create(int[] bands);
}
Expand Down
2 changes: 1 addition & 1 deletion FoxTunes.Core/Interfaces/Factories/IMessageSinkFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace FoxTunes.Interfaces
{
public interface IMessageSinkFactory : IBaseComponent
public interface IMessageSinkFactory : IBaseFactory
{
IMessageSink Create(uint id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FoxTunes.Interfaces
{
public interface IMetaDataDecoratorFactory : IStandardComponent
public interface IMetaDataDecoratorFactory : IStandardFactory
{
IEnumerable<KeyValuePair<string, MetaDataItemType>> Supported { get; }

Expand Down
Loading

0 comments on commit ea07af0

Please sign in to comment.