mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-02 10:43:31 +00:00
Storage - Added migration for DB v5 to v6
Conditions - Fixed a conversion issue in operators
This commit is contained in:
parent
26daa8e1dd
commit
bdcca6b4be
@ -7,6 +7,12 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ConditionOperator<TLeftSide, TRightSide> : BaseConditionOperator
|
public abstract class ConditionOperator<TLeftSide, TRightSide> : BaseConditionOperator
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Type LeftSideType => typeof(TLeftSide);
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Type RightSideType => typeof(TRightSide);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Evaluates the operator on a and b
|
/// Evaluates the operator on a and b
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,33 +27,31 @@ namespace Artemis.Core
|
|||||||
TLeftSide leftSide;
|
TLeftSide leftSide;
|
||||||
if (leftSideValue != null)
|
if (leftSideValue != null)
|
||||||
{
|
{
|
||||||
if (leftSideValue.GetType() != typeof(TLeftSide))
|
if (leftSideValue.GetType() != typeof(TLeftSide) && leftSideValue is IConvertible)
|
||||||
leftSide = (TLeftSide) Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
leftSide = (TLeftSide) Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
||||||
else
|
else
|
||||||
leftSide = (TLeftSide) leftSideValue;
|
leftSide = (TLeftSide) leftSideValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
leftSide = default;
|
leftSide = default;
|
||||||
|
}
|
||||||
|
|
||||||
TRightSide rightSide;
|
TRightSide rightSide;
|
||||||
if (rightSideValue != null)
|
if (rightSideValue != null)
|
||||||
{
|
{
|
||||||
if (rightSideValue.GetType() != typeof(TRightSide))
|
if (rightSideValue.GetType() != typeof(TRightSide) && leftSideValue is IConvertible)
|
||||||
rightSide = (TRightSide) Convert.ChangeType(rightSideValue, typeof(TRightSide));
|
rightSide = (TRightSide) Convert.ChangeType(rightSideValue, typeof(TRightSide));
|
||||||
else
|
else
|
||||||
rightSide = (TRightSide) rightSideValue;
|
rightSide = (TRightSide) rightSideValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
rightSide = default;
|
rightSide = default;
|
||||||
|
}
|
||||||
|
|
||||||
return Evaluate(leftSide!, rightSide!);
|
return Evaluate(leftSide!, rightSide!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Type LeftSideType => typeof(TLeftSide);
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Type RightSideType => typeof(TRightSide);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -55,6 +59,14 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class ConditionOperator<TLeftSide> : BaseConditionOperator
|
public abstract class ConditionOperator<TLeftSide> : BaseConditionOperator
|
||||||
{
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Type LeftSideType => typeof(TLeftSide);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Always <c>null</c>, not applicable to this type of condition operator
|
||||||
|
/// </summary>
|
||||||
|
public override Type? RightSideType => null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Evaluates the operator on a and b
|
/// Evaluates the operator on a and b
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -68,23 +80,17 @@ namespace Artemis.Core
|
|||||||
TLeftSide leftSide;
|
TLeftSide leftSide;
|
||||||
if (leftSideValue != null)
|
if (leftSideValue != null)
|
||||||
{
|
{
|
||||||
if (leftSideValue.GetType() != typeof(TLeftSide))
|
if (leftSideValue.GetType() != typeof(TLeftSide) && leftSideValue is IConvertible)
|
||||||
leftSide = (TLeftSide) Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
leftSide = (TLeftSide) Convert.ChangeType(leftSideValue, typeof(TLeftSide));
|
||||||
else
|
else
|
||||||
leftSide = (TLeftSide) leftSideValue;
|
leftSide = (TLeftSide) leftSideValue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
leftSide = default;
|
leftSide = default;
|
||||||
|
}
|
||||||
|
|
||||||
return Evaluate(leftSide!);
|
return Evaluate(leftSide!);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override Type LeftSideType => typeof(TLeftSide);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Always <c>null</c>, not applicable to this type of condition operator
|
|
||||||
/// </summary>
|
|
||||||
public override Type? RightSideType => null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,34 +1,49 @@
|
|||||||
using Artemis.Storage.Migrations.Interfaces;
|
using System;
|
||||||
|
using Artemis.Storage.Migrations.Interfaces;
|
||||||
using LiteDB;
|
using LiteDB;
|
||||||
|
|
||||||
namespace Artemis.Storage.Migrations
|
namespace Artemis.Storage.Migrations
|
||||||
{
|
{
|
||||||
public class M6PredicateAbstraction : IStorageMigration
|
public class M6PredicateAbstraction : IStorageMigration
|
||||||
{
|
{
|
||||||
public int UserVersion => 7;
|
public int UserVersion => 6;
|
||||||
|
|
||||||
public void Apply(LiteRepository repository)
|
public void Apply(LiteRepository repository)
|
||||||
{
|
{
|
||||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||||
{
|
Migrate(bsonLayer);
|
||||||
bsonLayer["DisplayCondition"] = null;
|
|
||||||
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
|
|
||||||
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||||
{
|
Migrate(bsonLayer);
|
||||||
bsonLayer["DisplayCondition"] = null;
|
|
||||||
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
|
|
||||||
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
collection.Update(bsonDocument);
|
collection.Update(bsonDocument);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Migrate(BsonValue bsonValue)
|
||||||
|
{
|
||||||
|
if (bsonValue.IsArray)
|
||||||
|
{
|
||||||
|
foreach (BsonValue child in bsonValue.AsArray)
|
||||||
|
Migrate(child);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bsonValue.IsDocument)
|
||||||
|
{
|
||||||
|
// See if the document has a type
|
||||||
|
if (bsonValue.AsDocument.TryGetValue("_type", out BsonValue typeValue))
|
||||||
|
{
|
||||||
|
if (typeValue.AsString == "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionPredicateEntity, Artemis.Storage")
|
||||||
|
bsonValue.AsDocument["_type"] = "Artemis.Storage.Entities.Profile.Conditions.DataModelConditionGeneralPredicateEntity, Artemis.Storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (BsonValue documentValue in bsonValue.AsDocument.Values)
|
||||||
|
Migrate(documentValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user