Core - Added stores for the different register-able types

Profiles - Refactored large parts of the profile structure to use these stores
This commit is contained in:
Robert authored and SpoinkyNL committed 2020-09-09 19:56:06 +02:00
1 parent 4cfe71796c
commit 11de30318e
75 files changed
+1526 -934

No files matched your search

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Artemis.Core.Services
{
internal class ConditionOperatorService : IConditionOperatorService
{
public ConditionOperatorService()
{
RegisterBuiltInConditionOperators();
}
public ConditionOperatorRegistration RegisterConditionOperator(PluginInfo pluginInfo, ConditionOperator conditionOperator)
{
if (pluginInfo == null)
throw new ArgumentNullException(nameof(pluginInfo));
if (conditionOperator == null)
throw new ArgumentNullException(nameof(conditionOperator));
conditionOperator.PluginInfo = pluginInfo;
return ConditionOperatorStore.Add(conditionOperator);
}
public void RemoveConditionOperator(ConditionOperatorRegistration registration)
{
if (registration == null)
throw new ArgumentNullException(nameof(registration));
ConditionOperatorStore.Remove(registration);
}
public List<ConditionOperator> GetConditionOperatorsForType(Type type)
{
return ConditionOperatorStore.GetForType(type).Select(r => r.ConditionOperator).ToList();
}
public ConditionOperator GetConditionOperator(Guid operatorPluginGuid, string operatorType)
{
return ConditionOperatorStore.Get(operatorPluginGuid, operatorType)?.ConditionOperator;
}
private void RegisterBuiltInConditionOperators()
{
// General usage for any type
RegisterConditionOperator(Constants.CorePluginInfo, new EqualsConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new NotEqualConditionOperator());
// Numeric operators
RegisterConditionOperator(Constants.CorePluginInfo, new LessThanConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new GreaterThanConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new LessThanOrEqualConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new GreaterThanOrEqualConditionOperator());
// String operators
RegisterConditionOperator(Constants.CorePluginInfo, new StringEqualsConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringNotEqualConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringContainsConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringNotContainsConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringStartsWithConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringEndsWithConditionOperator());
RegisterConditionOperator(Constants.CorePluginInfo, new StringNullConditionOperator());
}
}
}
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Artemis.Core.Services
{
internal class DataBindingService : IDataBindingService
{
public DataBindingService()
{
RegisterBuiltInModifiers();
}
public DataBindingModifierTypeRegistration RegisterModifierType(PluginInfo pluginInfo, DataBindingModifierType dataBindingModifierType)
{
if (pluginInfo == null)
throw new ArgumentNullException(nameof(pluginInfo));
if (dataBindingModifierType == null)
throw new ArgumentNullException(nameof(dataBindingModifierType));
dataBindingModifierType.PluginInfo = pluginInfo;
return DataBindingModifierTypeStore.Add(dataBindingModifierType);
}
public void RemoveModifierType(DataBindingModifierTypeRegistration registration)
{
if (registration == null)
throw new ArgumentNullException(nameof(registration));
DataBindingModifierTypeStore.Remove(registration);
}
public List<DataBindingModifierType> GetCompatibleModifierTypes(Type type)
{
return DataBindingModifierTypeStore.GetForType(type).Select(r => r.DataBindingModifierType).ToList();
}
public DataBindingModifierType GetModifierType(Guid modifierTypePluginGuid, string modifierType)
{
return DataBindingModifierTypeStore.Get(modifierTypePluginGuid, modifierType)?.DataBindingModifierType;
}
private void RegisterBuiltInModifiers()
{
RegisterModifierType(Constants.CorePluginInfo, new MultiplicationModifierType());
RegisterModifierType(Constants.CorePluginInfo, new DivideModifierType());
RegisterModifierType(Constants.CorePluginInfo, new FloorModifierType());
}
}
}
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.DataModelExpansions;
using Artemis.Core.Modules;
namespace Artemis.Core.Services
{
internal class DataModelService : IDataModelService
{
public DataModelService(IPluginService pluginService)
{
// Add data models of already loaded plugins
foreach (var module in pluginService.GetPluginsOfType<Module>())
AddModuleDataModel(module);
foreach (var dataModelExpansion in pluginService.GetPluginsOfType<BaseDataModelExpansion>())
AddDataModelExpansionDataModel(dataModelExpansion);
// Add data models of new plugins when they get enabled
pluginService.PluginEnabled += PluginServiceOnPluginEnabled;
}
public DataModelRegistration RegisterDataModel(DataModel dataModel)
{
if (dataModel == null)
throw new ArgumentNullException(nameof(dataModel));
return DataModelStore.Add(dataModel);
}
public void RemoveDataModel(DataModelRegistration registration)
{
if (registration == null)
throw new ArgumentNullException(nameof(registration));
DataModelStore.Remove(registration);
}
public List<DataModel> GetDataModels()
{
return DataModelStore.GetAll().Select(d => d.DataModel).ToList();
}
public T GetDataModel<T>() where T : DataModel
{
return (T) DataModelStore.GetAll().FirstOrDefault(d => d.DataModel is T)?.DataModel;
}
public DataModel GetPluginDataModel(Plugin plugin)
{
return DataModelStore.Get(plugin.PluginInfo.Guid)?.DataModel;
}
public DataModel GetPluginDataModel(Guid pluginGuid)
{
return DataModelStore.Get(pluginGuid)?.DataModel;
}
private void PluginServiceOnPluginEnabled(object sender, PluginEventArgs e)
{
if (e.PluginInfo.Instance is Module module)
AddModuleDataModel(module);
else if (e.PluginInfo.Instance is BaseDataModelExpansion dataModelExpansion)
AddDataModelExpansionDataModel(dataModelExpansion);
}
private void AddModuleDataModel(Module module)
{
if (module.InternalDataModel == null)
return;
if (module.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(module.PluginInfo, "Module overrides GetDataModelDescription but returned null");
module.InternalDataModel.IsExpansion = module.InternalExpandsMainDataModel;
RegisterDataModel(module.InternalDataModel);
}
private void AddDataModelExpansionDataModel(BaseDataModelExpansion dataModelExpansion)
{
if (dataModelExpansion.InternalDataModel.DataModelDescription == null)
throw new ArtemisPluginException(dataModelExpansion.PluginInfo, "Data model expansion overrides GetDataModelDescription but returned null");
dataModelExpansion.InternalDataModel.IsExpansion = true;
RegisterDataModel(dataModelExpansion.InternalDataModel);
}
}
}
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Properties;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to register and retrieve conditions operators used by display conditions
/// </summary>
public interface IConditionOperatorService : IArtemisService
{
/// <summary>
/// Registers a new condition operator for use in layer conditions
/// </summary>
/// <param name="pluginInfo">The PluginInfo of the plugin this condition operator belongs to</param>
/// <param name="conditionOperator">The condition operator to register</param>
ConditionOperatorRegistration RegisterConditionOperator([NotNull] PluginInfo pluginInfo, [NotNull] ConditionOperator conditionOperator);
/// <summary>
/// Removes a condition operator so it is no longer available for use in layer conditions
/// </summary>
/// <param name="registration">The registration of the condition operator to remove</param>
void RemoveConditionOperator([NotNull] ConditionOperatorRegistration registration);
/// <summary>
/// Returns all the condition operators compatible with the provided type
/// </summary>
List<ConditionOperator> GetConditionOperatorsForType(Type type);
/// <summary>
/// Gets a condition operator by its plugin GUID and type name
/// </summary>
/// <param name="operatorPluginGuid">The operator's plugin GUID</param>
/// <param name="operatorType">The type name of the operator</param>
ConditionOperator GetConditionOperator(Guid operatorPluginGuid, string operatorType);
}
}
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using Artemis.Core.Properties;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to register and retrieve data binding modifiers used by the data bindings system
/// </summary>
public interface IDataBindingService : IArtemisService
{
/// <summary>
/// Registers a new modifier type for use in data bindings
/// </summary>
/// <param name="pluginInfo">The PluginInfo of the plugin this modifier type belongs to</param>
/// <param name="dataBindingModifierType">The modifier type to register</param>
DataBindingModifierTypeRegistration RegisterModifierType([NotNull] PluginInfo pluginInfo, [NotNull] DataBindingModifierType dataBindingModifierType);
/// <summary>
/// Removes a modifier type so it is no longer available for use in data bindings
/// </summary>
/// <param name="dataBindingModifierType">The registration of the modifier type to remove</param>
void RemoveModifierType([NotNull] DataBindingModifierTypeRegistration dataBindingModifierType);
/// <summary>
/// Returns all the data binding modifier types compatible with the provided type
/// </summary>
List<DataBindingModifierType> GetCompatibleModifierTypes(Type type);
/// <summary>
/// Gets a modifier type by its plugin GUID and type name
/// </summary>
/// <param name="modifierTypePluginGuid">The modifier type's plugin GUID</param>
/// <param name="modifierType">The type name of the modifier type</param>
/// <returns></returns>
DataBindingModifierType GetModifierType(Guid modifierTypePluginGuid, string modifierType);
}
}
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using Artemis.Core.DataModelExpansions;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to register and retrieve data models
/// </summary>
public interface IDataModelService : IArtemisService
{
/// <summary>
/// Add a data model to so that it is available to conditions and data bindings
/// </summary>
/// <param name="dataModel"></param>
DataModelRegistration RegisterDataModel(DataModel dataModel);
/// <summary>
/// Remove a previously added data model so that it is no longer available
/// </summary>
void RemoveDataModel(DataModelRegistration registration);
/// <summary>
/// Returns a list of all registered data models
/// </summary>
List<DataModel> GetDataModels();
/// <summary>
/// If found, returns the registered data model of type <typeparamref name="T" />
/// </summary>
/// <typeparam name="T">The type of the data model to find</typeparam>
T GetDataModel<T>() where T : DataModel;
/// <summary>
/// If found, returns the data model of the provided plugin
/// </summary>
/// <param name="plugin">The plugin to find the data model of</param>
DataModel GetPluginDataModel(Plugin plugin);
/// <summary>
/// If found, returns the data model of the provided plugin GUID
/// </summary>
/// <param name="pluginGuid">The GUID of the plugin to find the data model of</param>
DataModel GetPluginDataModel(Guid pluginGuid);
}
}
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using Artemis.Core.LayerBrushes;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to register and retrieve layer brushes
/// </summary>
public interface ILayerBrushService : IArtemisService
{
/// <summary>
/// Add a layer brush descriptor so that it is available to layers
/// </summary>
LayerBrushRegistration RegisterLayerBrush(LayerBrushDescriptor descriptor);
/// <summary>
/// Remove a previously added layer brush descriptor so that it is no longer available
/// </summary>
void RemoveLayerBrush(LayerBrushRegistration registration);
/// <summary>
/// Returns a list of all registered layer brush descriptors
/// </summary>
List<LayerBrushDescriptor> GetLayerBrushes();
}
}
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using Artemis.Core.LayerBrushes;
using Artemis.Core.LayerEffects;
namespace Artemis.Core.Services
{
/// <summary>
/// A service that allows you to register and retrieve layer brushes
/// </summary>
public interface ILayerEffectService : IArtemisService
{
/// <summary>
/// Add an effect descriptor so that it is available to profile elements
/// </summary>
LayerEffectRegistration RegisterLayerEffect(LayerEffectDescriptor descriptor);
/// <summary>
/// Remove a previously added layer effect descriptor so that it is no longer available
/// </summary>
void RemoveLayerEffect(LayerEffectRegistration registration);
/// <summary>
/// Returns a list of all registered layer effect descriptors
/// </summary>
List<LayerEffectDescriptor> GetLayerEffects();
}
}
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.LayerBrushes;
using Ninject;
namespace Artemis.Core.Services
{
internal class LayerBrushService : ILayerBrushService
{
private readonly IKernel _kernel;
public LayerBrushService(IKernel kernel)
{
_kernel = kernel;
}
public LayerBrushRegistration RegisterLayerBrush(LayerBrushDescriptor descriptor)
{
if (descriptor == null)
throw new ArgumentNullException(nameof(descriptor));
descriptor.Kernel = _kernel;
return LayerBrushStore.Add(descriptor);
}
public void RemoveLayerBrush(LayerBrushRegistration registration)
{
if (registration == null)
throw new ArgumentNullException(nameof(registration));
LayerBrushStore.Remove(registration);
}
public List<LayerBrushDescriptor> GetLayerBrushes()
{
return LayerBrushStore.GetAll().Select(r => r.LayerBrushDescriptor).ToList();
}
}
}
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Artemis.Core.LayerEffects;
using Ninject;
namespace Artemis.Core.Services
{
internal class LayerEffectService : ILayerEffectService
{
private readonly IKernel _kernel;
public LayerEffectService(IKernel kernel)
{
_kernel = kernel;
}
public LayerEffectRegistration RegisterLayerEffect(LayerEffectDescriptor descriptor)
{
if (descriptor == null)
throw new ArgumentNullException(nameof(descriptor));
descriptor.Kernel = _kernel;
return LayerEffectStore.Add(descriptor);
}
public void RemoveLayerEffect(LayerEffectRegistration registration)
{
if (registration == null)
throw new ArgumentNullException(nameof(registration));
LayerEffectStore.Remove(registration);
}
public List<LayerEffectDescriptor> GetLayerEffects()
{
return LayerEffectStore.GetAll().Select(r => r.LayerEffectDescriptor).ToList();
}
}
}