mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Storage - Added migration to clear the DB
Profile - Don't store empty visual scripts Profile tree - Improved drag & drop
This commit is contained in:
1 parent
73a80ef476
commit
e9566ca689
22 files changed
+73
-515
No files matched your search
@@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.11"/>
|
||||
<PackageReference Include="Serilog" Version="2.10.0"/>
|
||||
<PackageReference Include="LiteDB" Version="5.0.11" />
|
||||
<PackageReference Include="Serilog" Version="2.10.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,18 +0,0 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0001AttributeBasedPropertiesMigration : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 1;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
// DropCollection will open a transaction so commit the current one
|
||||
repository.Database.Commit();
|
||||
if (repository.Database.CollectionExists("ProfileEntity"))
|
||||
repository.Database.DropCollection("ProfileEntity");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0002ProfileEntitiesEnabledMigration : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 2;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
List<ProfileEntity> profiles = repository.Query<ProfileEntity>().ToList();
|
||||
foreach (ProfileEntity profileEntity in profiles)
|
||||
{
|
||||
foreach (FolderEntity profileEntityFolder in profileEntity.Folders)
|
||||
{
|
||||
profileEntityFolder.Suspended = false;
|
||||
// Commented out during Avalonia port when Suspended was moved into the LayerEffect's LayerProperties
|
||||
// foreach (LayerEffectEntity layerEffectEntity in profileEntityFolder.LayerEffects)
|
||||
// layerEffectEntity.Suspended = false;
|
||||
}
|
||||
|
||||
foreach (LayerEntity profileEntityLayer in profileEntity.Layers)
|
||||
{
|
||||
profileEntityLayer.Suspended = false;
|
||||
// Commented out during Avalonia port when Suspended was moved into the LayerEffect's LayerProperties
|
||||
// foreach (LayerEffectEntity layerEffectEntity in profileEntityLayer.LayerEffects)
|
||||
// layerEffectEntity.Suspended = false;
|
||||
}
|
||||
|
||||
repository.Upsert(profileEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0003PluginEntitiesIndexChangesMigration : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 3;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
// DropCollection will open a transaction so commit the current one
|
||||
repository.Database.Commit();
|
||||
if (repository.Database.CollectionExists("PluginEntity"))
|
||||
repository.Database.DropCollection("PluginEntity");
|
||||
if (repository.Database.CollectionExists("PluginSettingEntity"))
|
||||
repository.Database.DropCollection("PluginSettingEntity");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0004ProfileSegmentsMigration : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 4;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
// Lesson for next time: Use BsonDocuments in migrations
|
||||
// List<ProfileEntity> profiles = repository.Query<ProfileEntity>().ToList();
|
||||
// foreach (ProfileEntity profileEntity in profiles)
|
||||
// {
|
||||
// foreach (FolderEntity folder in profileEntity.Folders.Where(f => f.MainSegmentLength == TimeSpan.Zero))
|
||||
// {
|
||||
// if (folder.PropertyEntities.Any(p => p.KeyframeEntities.Any()))
|
||||
// folder.MainSegmentLength = folder.PropertyEntities.Where(p => p.KeyframeEntities.Any()).Max(p => p.KeyframeEntities.Max(k => k.Position));
|
||||
// if (folder.MainSegmentLength == TimeSpan.Zero)
|
||||
// folder.MainSegmentLength = TimeSpan.FromSeconds(5);
|
||||
//
|
||||
// folder.PlayMode = 0;
|
||||
// }
|
||||
//
|
||||
// foreach (LayerEntity layer in profileEntity.Layers.Where(l => l.MainSegmentLength == TimeSpan.Zero))
|
||||
// {
|
||||
// if (layer.PropertyEntities.Any(p => p.KeyframeEntities.Any()))
|
||||
// layer.MainSegmentLength = layer.PropertyEntities.Where(p => p.KeyframeEntities.Any()).Max(p => p.KeyframeEntities.Max(k => k.Position));
|
||||
// if (layer.MainSegmentLength == TimeSpan.Zero)
|
||||
// layer.MainSegmentLength = TimeSpan.FromSeconds(5);
|
||||
//
|
||||
// layer.PlayMode = 0;
|
||||
// }
|
||||
//
|
||||
// repository.Update(profileEntity);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0005DataBindingTypes : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 5;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
{
|
||||
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
|
||||
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
|
||||
}
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
{
|
||||
foreach (BsonValue bsonPropertyEntity in bsonLayer["PropertyEntities"].AsArray)
|
||||
bsonPropertyEntity["DataBindingEntities"].AsArray.Clear();
|
||||
}
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using System;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0006PredicateAbstraction : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 6;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0008PluginFeatures : IStorageMigration
|
||||
{
|
||||
private void Migrate(BsonValue bsonValue, Dictionary<string, string> pluginMap)
|
||||
{
|
||||
if (bsonValue.IsArray)
|
||||
{
|
||||
foreach (BsonValue child in bsonValue.AsArray)
|
||||
Migrate(child, pluginMap);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bsonValue.IsDocument)
|
||||
{
|
||||
// Data model paths
|
||||
ReplaceIfFound(bsonValue, "DataModelGuid", "DataModelId", pluginMap);
|
||||
// Layer effects
|
||||
if (bsonValue.AsDocument.ContainsKey("EffectType"))
|
||||
ReplaceIfFound(bsonValue, "PluginGuid", "ProviderId", pluginMap);
|
||||
// Properties
|
||||
if (bsonValue.AsDocument.ContainsKey("KeyframesEnabled"))
|
||||
ReplaceIfFound(bsonValue, "PluginGuid", "FeatureId", pluginMap);
|
||||
|
||||
foreach (BsonValue documentValue in bsonValue.AsDocument.Values)
|
||||
Migrate(documentValue, pluginMap);
|
||||
}
|
||||
}
|
||||
|
||||
private bool ReplaceIfFound(BsonValue bsonValue, string oldKey, string newKey, Dictionary<string, string> pluginMap)
|
||||
{
|
||||
if (bsonValue.AsDocument.TryGetValue(oldKey, out BsonValue dataModelValue))
|
||||
if (pluginMap.TryGetValue(dataModelValue.AsGuid.ToString(), out string featureId))
|
||||
{
|
||||
bsonValue.AsDocument[newKey] = featureId;
|
||||
bsonValue.AsDocument.Remove(oldKey);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int UserVersion => 8;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
Dictionary<string, string> pluginMap = new()
|
||||
{
|
||||
{"ffffffff-ffff-ffff-ffff-ffffffffffff", "Artemis.Core.CorePluginFeature-ffffffff"},
|
||||
{"ab41d601-35e0-4a73-bf0b-94509b006ab0", "Artemis.Plugins.DataModelExpansions.TestData.PluginDataModelExpansion-ab41d601"},
|
||||
{"c20e876f-7cb0-4fa1-b0cc-ae1afb5865d1", "Artemis.Plugins.Devices.Asus.AsusDeviceProvider-c20e876f"},
|
||||
{"b78f644b-827f-4bb4-bf03-2adaa365b58b", "Artemis.Plugins.Devices.CoolerMaster.CoolerMasterDeviceProvider-b78f644b"},
|
||||
{"926629ab-8170-42f3-be18-22c694aa91cd", "Artemis.Plugins.Devices.Corsair.CorsairDeviceProvider-926629ab"},
|
||||
{"cad475d3-c621-4ec7-bbfc-784e3b4723ce", "Artemis.Plugins.Devices.Debug.DebugDeviceProvider-cad475d3"},
|
||||
{"6f073d4d-d97d-4040-9750-841fdbe06915", "Artemis.Plugins.Devices.DMX.DMXDeviceProvider-6f073d4d"},
|
||||
{"62a45c0c-884c-4868-9fd7-3c5987fe07ca", "Artemis.Plugins.Devices.Logitech.LogitechDeviceProvider-62a45c0c"},
|
||||
{"9177c320-1206-48a3-af52-b1749c758786", "Artemis.Plugins.Devices.Msi.MsiDeviceProvider-9177c320"},
|
||||
{"a487332f-c4b3-43e7-b80f-f33adc6fff87", "Artemis.Plugins.Devices.Novation.NovationDeviceProvider-a487332f"},
|
||||
{"58a3d80e-d5cb-4a40-9465-c0a5d54825d6", "Artemis.Plugins.Devices.Razer.RazerDeviceProvider-58a3d80e"},
|
||||
{"10049953-94c1-4102-988b-9e4f0b64c232", "Artemis.Plugins.Devices.Roccat.RoccatDeviceProvider-10049953"},
|
||||
{"27945704-6edd-48b4-bc0e-319cce9693fc", "Artemis.Plugins.Devices.SteelSeries.SteelSeriesDeviceProvider-27945704"},
|
||||
{"e70fd5ba-9881-480a-8ff6-078ed5f747fa", "Artemis.Plugins.Devices.Wooting.WootingDeviceProvider-e70fd5ba"},
|
||||
{"ec86de32-1010-4bf7-97d7-1dcc46659ab6", "Artemis.Plugins.Devices.WS281X.WS281XDeviceProvider-ec86de32"},
|
||||
{"92a9d6ba-6f7a-4937-94d5-c1d715b4141a", "Artemis.Plugins.LayerBrushes.Color.ColorBrushProvider-92a9d6ba"},
|
||||
{"0bbf931b-87ad-4809-9cd9-bda33f4d4695", "Artemis.Plugins.LayerBrushes.ColorRgbNet.RgbNetColorBrushProvider-0bbf931b"},
|
||||
{"61cbbf01-8d69-4ede-a972-f3f269da66d9", "Artemis.Plugins.LayerBrushes.Noise.NoiseBrushProvider-61cbbf01"},
|
||||
{"0cb99d89-915b-407e-82ac-8316d0559c4e", "Artemis.Plugins.LayerBrushes.Chroma.ChromaLayerBrushProvider-0cb99d89"},
|
||||
{"bf9cf3ac-9f97-4328-b32f-aa39df1698ff", "Artemis.Plugins.LayerBrushes.Gif.GifLayerBrushProvider-bf9cf3ac"},
|
||||
{"4570510a-7c8b-4324-b915-cea738a65ac2", "Artemis.Plugins.LayerBrushes.Particle.ParticleLayerBrushProvider-4570510a"},
|
||||
{"245aa860-4224-4d1c-ab81-2d6b5593a9fa", "Artemis.Plugins.LayerBrushes.Spectrum.PluginLayerBrushProvider-245aa860"},
|
||||
{"fca5b5d6-3f86-4ea7-a271-06ec3fc219e2", "Artemis.Plugins.LayerEffects.Filter.FilterEffectProvider-fca5b5d6"},
|
||||
{"0de2991a-d7b8-4f61-ae4e-6623849215b5", "Artemis.Plugins.Modules.General.GeneralModule-0de2991a"},
|
||||
{"29e3ff97-83a5-44fc-a2dc-04f446b54146", "Artemis.Plugins.Modules.Overlay.OverlayModule-29e3ff97"},
|
||||
{"ea2064cc-63ad-4a22-93e3-bfc71beb6c4b", "Artemis.Plugins.Modules.Fallout4.Fallout4Module-ea2064cc"},
|
||||
{"a34dd13c-2d66-47a3-91fc-265749144d01", "Artemis.Plugins.Modules.LeagueOfLegends.LeagueOfLegendsModule-a34dd13c"},
|
||||
{"49dff3a6-3d2a-444a-8346-582b2d61b776", "Module.EliteDangerous.EliteDangerousModule-49dff3a6"},
|
||||
{"8f493ff1-0590-4c70-8a1d-e599e5580d21", "Artemis.Plugins.Modules.TruckSimulator.TruckSimulatorModule-8f493ff1"},
|
||||
{"184ce933-b8ff-465f-b3d2-a23a17b35f65", "Artemis.Plugins.PhilipsHue.HueDataModelExpansion-184ce933"}
|
||||
};
|
||||
|
||||
// Remove the default brush the user selected, this will make the UI pick a new one
|
||||
repository.Database.Execute("DELETE PluginSettingEntity WHERE $.Name = \"ProfileEditor.DefaultLayerBrushDescriptor\"");
|
||||
|
||||
// Profiles
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
ReplaceIfFound(bsonDocument, "PluginGuid", "ModuleId", pluginMap);
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
{
|
||||
Migrate(bsonLayer, pluginMap);
|
||||
MigrateProperties(bsonLayer, pluginMap);
|
||||
}
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
{
|
||||
Migrate(bsonLayer, pluginMap);
|
||||
MigrateProperties(bsonLayer, pluginMap);
|
||||
}
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateProperties(BsonValue profileElementBson, Dictionary<string, string> pluginMap)
|
||||
{
|
||||
foreach (BsonValue bsonValue in profileElementBson["PropertyEntities"].AsArray)
|
||||
{
|
||||
if (bsonValue["Path"].AsString == "General.BrushReference")
|
||||
{
|
||||
bsonValue["Value"] = bsonValue["Value"].AsString.Replace("BrushPluginGuid", "LayerBrushProviderId");
|
||||
foreach ((string key, string value) in pluginMap)
|
||||
bsonValue["Value"] = bsonValue["Value"].AsString.Replace(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0009DeviceCalibration : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 9;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("SurfaceEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
foreach (BsonValue bsonDevice in bsonDocument["DeviceEntities"].AsArray)
|
||||
{
|
||||
bsonDevice["RedScale"] = 1d;
|
||||
bsonDevice["GreenScale"] = 1d;
|
||||
bsonDevice["BlueScale"] = 1d;
|
||||
}
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0010BetterDataBindings : IStorageMigration
|
||||
{
|
||||
private void Migrate(BsonValue bsonValue)
|
||||
{
|
||||
if (!bsonValue.IsDocument || !bsonValue.AsDocument.TryGetValue("PropertyEntities", out BsonValue propertyEntities))
|
||||
return;
|
||||
|
||||
foreach (BsonValue propertyEntity in propertyEntities.AsArray)
|
||||
{
|
||||
if (!propertyEntity.AsDocument.TryGetValue("DataBindingEntities", out BsonValue dataBindingEntities))
|
||||
continue;
|
||||
foreach (BsonValue dataBindingEntity in dataBindingEntities.AsArray)
|
||||
{
|
||||
if (!dataBindingEntity.AsDocument.TryGetValue("TargetExpression", out BsonValue targetExpression))
|
||||
continue;
|
||||
string value = targetExpression.AsString;
|
||||
if (value == "value => value" || value == "b => b")
|
||||
{
|
||||
dataBindingEntity.AsDocument["Identifier"] = "Value";
|
||||
}
|
||||
else
|
||||
{
|
||||
string selector = value.Split("=>")[1];
|
||||
string property = selector.Split(".")[1];
|
||||
dataBindingEntity.AsDocument["Identifier"] = property;
|
||||
}
|
||||
|
||||
dataBindingEntity.AsDocument.Remove("TargetExpression");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int UserVersion => 10;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0011ColorGradients : IStorageMigration
|
||||
{
|
||||
private void Migrate(BsonValue bsonValue)
|
||||
{
|
||||
if (!bsonValue.IsDocument || !bsonValue.AsDocument.TryGetValue("PropertyEntities", out BsonValue propertyEntities))
|
||||
return;
|
||||
|
||||
foreach (BsonValue propertyEntity in propertyEntities.AsArray)
|
||||
{
|
||||
if (propertyEntity["Value"] == null)
|
||||
continue;
|
||||
string valueString = propertyEntity["Value"].AsString;
|
||||
if (valueString == null)
|
||||
continue;
|
||||
if (!valueString.StartsWith("{\"Stops\":[{") || !valueString.EndsWith("}]}"))
|
||||
continue;
|
||||
|
||||
valueString = valueString.Replace("{\"Stops\":[{", "[{");
|
||||
valueString = valueString.Replace("}]}", "}]");
|
||||
propertyEntity["Value"] = valueString;
|
||||
}
|
||||
}
|
||||
|
||||
public int UserVersion => 11;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Layers"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
foreach (BsonValue bsonLayer in bsonDocument["Folders"].AsArray)
|
||||
Migrate(bsonLayer);
|
||||
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0012ProfileCategories : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 12;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
ILiteCollection<ProfileCategoryEntity> profileCategories = repository.Database.GetCollection<ProfileCategoryEntity>();
|
||||
profileCategories.EnsureIndex(s => s.Name, true);
|
||||
ProfileCategoryEntity profileCategoryEntity = profileCategories.Find(c => c.Name == "Converted").FirstOrDefault();
|
||||
if (profileCategoryEntity == null)
|
||||
{
|
||||
profileCategoryEntity = new ProfileCategoryEntity {Name = "Imported"};
|
||||
profileCategories.Insert(profileCategoryEntity);
|
||||
}
|
||||
|
||||
ILiteCollection<BsonDocument> collection = repository.Database.GetCollection("ProfileEntity");
|
||||
foreach (BsonDocument bsonDocument in collection.FindAll())
|
||||
{
|
||||
// Profiles with a ModuleId have not been converted
|
||||
if (bsonDocument.ContainsKey("ModuleId"))
|
||||
{
|
||||
string moduleId = bsonDocument["ModuleId"].AsString;
|
||||
bsonDocument.Remove("ModuleId");
|
||||
|
||||
ProfileConfigurationEntity profileConfiguration = new()
|
||||
{
|
||||
Name = bsonDocument["Name"].AsString,
|
||||
MaterialIcon = "ApplicationImport",
|
||||
ModuleId = moduleId,
|
||||
ProfileId = bsonDocument["_id"].AsGuid
|
||||
};
|
||||
|
||||
profileCategoryEntity.ProfileConfigurations.Add(profileConfiguration);
|
||||
collection.Update(bsonDocument);
|
||||
}
|
||||
}
|
||||
|
||||
profileCategories.Update(profileCategoryEntity);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Artemis.Storage.Entities.Profile;
|
||||
using Artemis.Storage.Migrations.Interfaces;
|
||||
using LiteDB;
|
||||
|
||||
namespace Artemis.Storage.Migrations
|
||||
{
|
||||
public class M0020AvaloniaReset : IStorageMigration
|
||||
{
|
||||
public int UserVersion => 20;
|
||||
|
||||
public void Apply(LiteRepository repository)
|
||||
{
|
||||
repository.Database.Commit();
|
||||
|
||||
List<string> collectionNames = repository.Database.GetCollectionNames().ToList();
|
||||
foreach (string collectionName in collectionNames)
|
||||
repository.Database.DropCollection(collectionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user