mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Core - Renamed LayerService to RenderElementService
Display conditions - Implemented persistent storage
This commit is contained in:
1 parent
16c2b7f7fd
commit
0e873a48cf
32 files changed
+209
-111
No files matched your search
@@ -1,13 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
{
|
||||
public abstract class DisplayConditionPart
|
||||
{
|
||||
public Guid EntityId { get; internal set; }
|
||||
|
||||
private readonly List<DisplayConditionPart> _children;
|
||||
|
||||
protected DisplayConditionPart()
|
||||
@@ -36,6 +34,9 @@ namespace Artemis.Core.Models.Profile.Conditions.Abstract
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void ApplyToEntity();
|
||||
public abstract DisplayConditionPartEntity GetEntity();
|
||||
|
||||
internal abstract void ApplyToEntity();
|
||||
internal abstract void Initialize(IDataModelService dataModelService);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
@@ -9,7 +12,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
public DisplayConditionGroup(DisplayConditionPart parent)
|
||||
{
|
||||
Parent = parent;
|
||||
EntityId = Guid.NewGuid();
|
||||
DisplayConditionGroupEntity = new DisplayConditionGroupEntity();
|
||||
}
|
||||
|
||||
@@ -17,7 +19,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
Parent = parent;
|
||||
DisplayConditionGroupEntity = entity;
|
||||
EntityId = DisplayConditionGroupEntity.Id;
|
||||
BooleanOperator = (BooleanOperator) DisplayConditionGroupEntity.BooleanOperator;
|
||||
|
||||
foreach (var childEntity in DisplayConditionGroupEntity.Children)
|
||||
@@ -32,15 +33,26 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
public BooleanOperator BooleanOperator { get; set; }
|
||||
public DisplayConditionGroupEntity DisplayConditionGroupEntity { get; set; }
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
DisplayConditionGroupEntity.Id = EntityId;
|
||||
DisplayConditionGroupEntity.ParentId = Parent?.EntityId ?? Guid.Empty;
|
||||
DisplayConditionGroupEntity.BooleanOperator = (int) BooleanOperator;
|
||||
|
||||
DisplayConditionGroupEntity.Children.Clear();
|
||||
DisplayConditionGroupEntity.Children.AddRange(Children.Select(c => c.GetEntity()));
|
||||
foreach (var child in Children)
|
||||
child.ApplyToEntity();
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
foreach (var child in Children)
|
||||
child.Initialize(dataModelService);
|
||||
}
|
||||
|
||||
public override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return DisplayConditionGroupEntity;
|
||||
}
|
||||
}
|
||||
|
||||
public enum BooleanOperator
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
@@ -6,9 +8,17 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
public ListOperator ListOperator { get; set; }
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
}
|
||||
|
||||
public override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,10 @@ using Artemis.Core.Exceptions;
|
||||
using Artemis.Core.Extensions;
|
||||
using Artemis.Core.Models.Profile.Conditions.Abstract;
|
||||
using Artemis.Core.Plugins.Abstract.DataModels;
|
||||
using Artemis.Core.Services.Interfaces;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Entities.Profile.Abstract;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
@@ -22,10 +25,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
{
|
||||
Parent = parent;
|
||||
DisplayConditionPredicateEntity = entity;
|
||||
|
||||
// TODO: This has to be done from somewhere
|
||||
// LeftDataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.LeftDataModelGuid);
|
||||
// RightDataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.RightDataModelGuid);
|
||||
}
|
||||
|
||||
public DisplayConditionPredicateEntity DisplayConditionPredicateEntity { get; set; }
|
||||
@@ -122,13 +121,77 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
CreateStaticExpression();
|
||||
}
|
||||
|
||||
public override void ApplyToEntity()
|
||||
internal override void ApplyToEntity()
|
||||
{
|
||||
DisplayConditionPredicateEntity.LeftDataModelGuid = LeftDataModel?.PluginInfo?.Guid;
|
||||
DisplayConditionPredicateEntity.LeftPropertyPath = LeftPropertyPath;
|
||||
|
||||
DisplayConditionPredicateEntity.RightDataModelGuid = RightDataModel?.PluginInfo?.Guid;
|
||||
DisplayConditionPredicateEntity.RightPropertyPath = RightPropertyPath;
|
||||
DisplayConditionPredicateEntity.RightStaticValue = JsonConvert.SerializeObject(RightStaticValue);
|
||||
|
||||
DisplayConditionPredicateEntity.OperatorPluginGuid = Operator?.PluginInfo?.Guid;
|
||||
DisplayConditionPredicateEntity.OperatorType = Operator?.GetType().Name;
|
||||
}
|
||||
|
||||
internal override void Initialize(IDataModelService dataModelService)
|
||||
{
|
||||
// Left side
|
||||
if (DisplayConditionPredicateEntity.LeftDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.LeftDataModelGuid.Value);
|
||||
if (dataModel != null)
|
||||
UpdateLeftSide(dataModel, DisplayConditionPredicateEntity.LeftPropertyPath);
|
||||
}
|
||||
|
||||
// Operator
|
||||
if (DisplayConditionPredicateEntity.OperatorPluginGuid != null)
|
||||
{
|
||||
var conditionOperator = dataModelService.GetConditionOperator(DisplayConditionPredicateEntity.OperatorPluginGuid.Value, DisplayConditionPredicateEntity.OperatorType);
|
||||
if (conditionOperator != null)
|
||||
UpdateOperator(conditionOperator);
|
||||
}
|
||||
|
||||
// Right side dynamic
|
||||
if (DisplayConditionPredicateEntity.RightDataModelGuid != null)
|
||||
{
|
||||
var dataModel = dataModelService.GetPluginDataModelByGuid(DisplayConditionPredicateEntity.RightDataModelGuid.Value);
|
||||
if (dataModel != null)
|
||||
UpdateRightSide(dataModel, DisplayConditionPredicateEntity.RightPropertyPath);
|
||||
}
|
||||
// Right side static
|
||||
else if (DisplayConditionPredicateEntity.RightStaticValue != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (LeftDataModel != null)
|
||||
{
|
||||
// Use the left side type so JSON.NET has a better idea what to do
|
||||
var leftSideType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
|
||||
UpdateRightSide(JsonConvert.DeserializeObject(DisplayConditionPredicateEntity.RightStaticValue, leftSideType));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hope for the best...
|
||||
UpdateRightSide(JsonConvert.DeserializeObject(DisplayConditionPredicateEntity.RightStaticValue));
|
||||
}
|
||||
}
|
||||
catch (JsonReaderException)
|
||||
{
|
||||
// ignored
|
||||
// TODO: Some logging would be nice
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override DisplayConditionPartEntity GetEntity()
|
||||
{
|
||||
return DisplayConditionPredicateEntity;
|
||||
}
|
||||
|
||||
private void ValidateOperator()
|
||||
{
|
||||
if (LeftDataModel == null)
|
||||
if (LeftDataModel == null || Operator == null)
|
||||
return;
|
||||
|
||||
var leftType = LeftDataModel.GetTypeAtPath(LeftPropertyPath);
|
||||
@@ -136,7 +199,6 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
Operator = null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Validates the right side, ensuring it is still compatible with the current left side
|
||||
/// </summary>
|
||||
@@ -217,7 +279,7 @@ namespace Artemis.Core.Models.Profile.Conditions
|
||||
|
||||
private void CreateStaticExpression()
|
||||
{
|
||||
if (LeftDataModel == null)
|
||||
if (LeftDataModel == null || Operator == null)
|
||||
return;
|
||||
|
||||
var leftSideParameter = Expression.Parameter(typeof(DataModel), "leftDataModel");
|
||||
|
||||
Reference in new issue
Block a user