mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Display conditions - Implemented IDisposable
Display conditions - Listen to registration add/remove WIP Data bindings - Implemented IDisposable Data bindings - Listen to registration add/remove
This commit is contained in:
1 parent
11de30318e
commit
1de6fefc2a
17 files changed
+461
-227
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
@@ -7,7 +8,7 @@ namespace Artemis.Core
|
||||
/// <summary>
|
||||
/// An abstract class for display condition parts
|
||||
/// </summary>
|
||||
public abstract class DisplayConditionPart
|
||||
public abstract class DisplayConditionPart : IDisposable
|
||||
{
|
||||
private readonly List<DisplayConditionPart> _children = new List<DisplayConditionPart>();
|
||||
|
||||
@@ -62,5 +63,23 @@ namespace Artemis.Core
|
||||
|
||||
internal abstract void ApplyToEntity();
|
||||
internal abstract DisplayConditionPartEntity GetEntity();
|
||||
|
||||
#region IDisposable
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ namespace Artemis.Core
|
||||
/// </summary>
|
||||
public class DisplayConditionGroup : DisplayConditionPart
|
||||
{
|
||||
private bool _disposed;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="DisplayConditionGroup" /> class
|
||||
/// </summary>
|
||||
@@ -55,6 +57,9 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override bool Evaluate()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DisplayConditionGroup");
|
||||
|
||||
// Empty groups are always true
|
||||
if (Children.Count == 0)
|
||||
return true;
|
||||
@@ -80,6 +85,9 @@ namespace Artemis.Core
|
||||
/// <inheritdoc />
|
||||
public override bool EvaluateObject(object target)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DisplayConditionGroup");
|
||||
|
||||
// Empty groups are always true
|
||||
if (Children.Count == 0)
|
||||
return true;
|
||||
@@ -111,6 +119,19 @@ namespace Artemis.Core
|
||||
{
|
||||
return Entity;
|
||||
}
|
||||
|
||||
#region IDisposable
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
foreach (var child in Children)
|
||||
child.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum BooleanOperator
|
||||
|
||||
@@ -10,6 +10,8 @@ namespace Artemis.Core
|
||||
{
|
||||
public class DisplayConditionList : DisplayConditionPart
|
||||
{
|
||||
private bool _disposed;
|
||||
|
||||
public DisplayConditionList(DisplayConditionPart parent)
|
||||
{
|
||||
Parent = parent;
|
||||
@@ -37,6 +39,9 @@ namespace Artemis.Core
|
||||
|
||||
public override bool Evaluate()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DisplayConditionList");
|
||||
|
||||
if (CompiledListAccessor == null)
|
||||
return false;
|
||||
|
||||
@@ -45,6 +50,9 @@ namespace Artemis.Core
|
||||
|
||||
public override bool EvaluateObject(object target)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DisplayConditionList");
|
||||
|
||||
if (!Children.Any())
|
||||
return false;
|
||||
if (!(target is IList list))
|
||||
@@ -63,6 +71,9 @@ namespace Artemis.Core
|
||||
|
||||
public void UpdateList(DataModel dataModel, string path)
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DisplayConditionList");
|
||||
|
||||
if (dataModel != null && path == null)
|
||||
throw new ArtemisCoreException("If a data model is provided, a path is also required");
|
||||
if (dataModel == null && path != null)
|
||||
@@ -93,6 +104,9 @@ namespace Artemis.Core
|
||||
|
||||
public void CreateExpression()
|
||||
{
|
||||
if (_disposed)
|
||||
throw new ObjectDisposedException("DisplayConditionList");
|
||||
|
||||
var parameter = Expression.Parameter(typeof(object), "listDataModel");
|
||||
var accessor = ListPropertyPath.Split('.').Aggregate<string, Expression>(
|
||||
Expression.Convert(parameter, ListDataModel.GetType()),
|
||||
@@ -101,12 +115,15 @@ namespace Artemis.Core
|
||||
var lambda = Expression.Lambda<Func<object, IList>>(accessor, parameter);
|
||||
CompiledListAccessor = lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
// Target list
|
||||
Entity.ListDataModelGuid = ListDataModel?.PluginInfo?.Guid;
|
||||
Entity.ListPropertyPath = ListPropertyPath;
|
||||
if (ListDataModel != null)
|
||||
{
|
||||
Entity.ListDataModelGuid = ListDataModel.PluginInfo.Guid;
|
||||
Entity.ListPropertyPath = ListPropertyPath;
|
||||
}
|
||||
|
||||
// Operator
|
||||
Entity.ListOperator = (int) ListOperator;
|
||||
@@ -125,6 +142,8 @@ namespace Artemis.Core
|
||||
|
||||
internal void Initialize()
|
||||
{
|
||||
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
|
||||
if (Entity.ListDataModelGuid == null)
|
||||
return;
|
||||
|
||||
@@ -147,6 +166,49 @@ namespace Artemis.Core
|
||||
AddChild(new DisplayConditionGroup(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||
{
|
||||
var dataModel = e.Registration.DataModel;
|
||||
if (dataModel.PluginInfo.Guid == Entity.ListDataModelGuid && dataModel.ContainsPath(Entity.ListPropertyPath))
|
||||
{
|
||||
ListDataModel = dataModel;
|
||||
ListPropertyPath = Entity.ListPropertyPath;
|
||||
CreateExpression();
|
||||
}
|
||||
}
|
||||
|
||||
private void DataModelStoreOnDataModelRemoved(object sender, DataModelStoreEvent e)
|
||||
{
|
||||
if (ListDataModel != e.Registration.DataModel)
|
||||
return;
|
||||
|
||||
ListDataModel = null;
|
||||
CompiledListAccessor = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
_disposed = true;
|
||||
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
foreach (var child in Children)
|
||||
child.Dispose();
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public enum ListOperator
|
||||
|
||||
@@ -248,6 +248,9 @@ namespace Artemis.Core
|
||||
|
||||
internal void Initialize()
|
||||
{
|
||||
DataModelStore.DataModelAdded += DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved += DataModelStoreOnDataModelRemoved;
|
||||
|
||||
// Left side
|
||||
if (Entity.LeftDataModelGuid != null)
|
||||
{
|
||||
@@ -424,5 +427,42 @@ namespace Artemis.Core
|
||||
Expression.Property
|
||||
);
|
||||
}
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void DataModelStoreOnDataModelAdded(object sender, DataModelStoreEvent e)
|
||||
{
|
||||
var dataModel = e.Registration.DataModel;
|
||||
if (dataModel.PluginInfo.Guid == Entity.LeftDataModelGuid && dataModel.ContainsPath(Entity.LeftPropertyPath))
|
||||
UpdateLeftSide(dataModel, Entity.LeftPropertyPath);
|
||||
if (dataModel.PluginInfo.Guid == Entity.RightDataModelGuid && dataModel.ContainsPath(Entity.RightPropertyPath))
|
||||
UpdateRightSide(dataModel, Entity.RightPropertyPath);
|
||||
}
|
||||
|
||||
private void DataModelStoreOnDataModelRemoved(object sender, DataModelStoreEvent e)
|
||||
{
|
||||
if (LeftDataModel == e.Registration.DataModel)
|
||||
{
|
||||
CompiledDynamicPredicate = null;
|
||||
LeftDataModel = null;
|
||||
}
|
||||
|
||||
if (RightDataModel == e.Registration.DataModel)
|
||||
{
|
||||
CompiledDynamicPredicate = null;
|
||||
RightDataModel = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
DataModelStore.DataModelAdded -= DataModelStoreOnDataModelAdded;
|
||||
DataModelStore.DataModelRemoved -= DataModelStoreOnDataModelRemoved;
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user