Moved from EF and SQLite to LiteDB

This commit is contained in:
Robert committed 2019-11-20 19:19:13 +01:00
1 parent d4dd371a50
commit 66f7dc94c8
57 files changed
+379 -1279

No files matched your search

+1 -6
View File
@@ -6,12 +6,7 @@
<LangVersion>7</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.4" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
<PackageReference Include="LiteDB" Version="4.1.4" />
</ItemGroup>
</Project>
@@ -1,24 +0,0 @@
using System.ComponentModel.DataAnnotations;
namespace Artemis.Storage.Entities
{
public class DeviceEntity
{
public DeviceEntity()
{
Guid = System.Guid.NewGuid().ToString();
}
[Key]
public string Guid { get; set; }
public int DeviceHashCode { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Rotation { get; set; }
public int ZIndex { get; set; }
public string SurfaceId { get; set; }
public virtual SurfaceEntity Surface { get; set; }
}
}
@@ -1,19 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Artemis.Storage.Entities
{
[Table("Folders")]
public class FolderEntity
{
[Key]
public string Guid { get; set; }
public int Order { get; set; }
public string Name { get; set; }
public virtual ICollection<FolderEntity> Folders { get; set; }
public virtual ICollection<LayerEntity> Layers { get; set; }
}
}
@@ -1,15 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Artemis.Storage.Entities
{
[Table("Keypoints")]
public class KeypointEntity
{
[Key]
public string Guid { get; set; }
public int Time { get; set; }
public string Value { get; set; }
}
}
@@ -1,20 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Artemis.Storage.Entities
{
[Table("Layers")]
public class LayerEntity
{
[Key]
public string Guid { get; set; }
public virtual ICollection<LedEntity> Leds { get; set; }
public virtual ICollection<LayerSettingEntity> Settings { get; set; }
public int Order { get; set; }
public string Name { get; set; }
public string LayerTypeGuid { get; set; }
}
}
@@ -1,18 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Artemis.Storage.Entities
{
[Table("LayerSettings")]
public class LayerSettingEntity
{
[Key]
public string Guid { get; set; }
public string Name { get; set; }
public string Value { get; set; }
public ICollection<KeypointEntity> Keypoints { get; set; }
}
}
-18
View File
@@ -1,18 +0,0 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Artemis.Storage.Entities
{
[Table("Leds")]
public class LedEntity
{
[Key]
public string Guid { get; set; }
public string LedName { get; set; }
public string LimitedToDevice { get; set; }
public string LayerId { get; set; }
public virtual LayerEntity Layer { get; set; }
}
}
@@ -4,9 +4,10 @@ namespace Artemis.Storage.Entities
{
public class PluginSettingEntity
{
public Guid Id { get; set; }
public Guid PluginGuid { get; set; }
public string Name { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}
}
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using LiteDB;
namespace Artemis.Storage.Entities.Profile
{
public class FolderEntity
{
public Guid Id { get; set; }
public Guid ParentId { get; set; }
public int Order { get; set; }
public string Name { get; set; }
public List<ProfileConditionEntity> Conditions { get; set; }
[BsonRef("ProfileEntity")]
public ProfileEntity Profile { get; set; }
public Guid ProfileId { get; set; }
}
}
@@ -0,0 +1,9 @@
using System;
namespace Artemis.Storage.Entities.Profile
{
public class LayerElementEntity
{
public Guid Id { get; set; }
}
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using LiteDB;
namespace Artemis.Storage.Entities.Profile
{
public class LayerEntity
{
public Guid Id { get; set; }
public Guid ParentId { get; set; }
public Guid LayerTypeGuid { get; set; }
public int Order { get; set; }
public string Name { get; set; }
public List<LedEntity> Leds { get; set; }
public List<ProfileConditionEntity> Condition { get; set; }
public List<LayerElementEntity> Elements { get; set; }
[BsonRef("ProfileEntity")]
public ProfileEntity Profile { get; set; }
public Guid ProfileId { get; set; }
}
}
@@ -0,0 +1,12 @@
using System;
namespace Artemis.Storage.Entities.Profile
{
public class LedEntity
{
public Guid Id { get; set; }
public string LedName { get; set; }
public string LimitedToDevice { get; set; }
}
}
@@ -0,0 +1,9 @@
using System;
namespace Artemis.Storage.Entities.Profile
{
public class ProfileConditionEntity
{
public Guid Id { get; set; }
}
}
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Profile
{
public class ProfileEntity
{
public Guid Id { get; set; }
public Guid PluginGuid { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public List<FolderEntity> Folders { get; set; }
public List<LayerEntity> Layers { get; set; }
}
}
@@ -1,19 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Artemis.Storage.Entities
{
public class ProfileEntity
{
[Key]
public string Guid { get; set; }
public Guid PluginGuid { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public int RootFolderId { get; set; }
public virtual FolderEntity RootFolder { get; set; }
}
}
@@ -1,8 +0,0 @@
namespace Artemis.Storage.Entities
{
public class SettingEntity
{
public string Name { get; set; }
public string Value { get; set; }
}
}
@@ -0,0 +1,15 @@
using System;
namespace Artemis.Storage.Entities.Surface
{
public class DeviceEntity
{
public Guid Id { get; set; }
public int DeviceHashCode { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Rotation { get; set; }
public int ZIndex { get; set; }
}
}
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace Artemis.Storage.Entities.Surface
{
public class SurfaceEntity
{
public Guid Id { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public List<DeviceEntity> DeviceEntities { get; set; }
}
}
@@ -1,21 +0,0 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Artemis.Storage.Entities
{
public class SurfaceEntity
{
public SurfaceEntity()
{
Guid = System.Guid.NewGuid().ToString();
}
[Key]
public string Guid { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public virtual ICollection<DeviceEntity> DeviceEntities { get; set; }
}
}
@@ -1,245 +0,0 @@
// <auto-generated />
using System;
using Artemis.Storage;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Artemis.Storage.Migrations
{
[DbContext(typeof(StorageContext))]
[Migration("20191028171528_InitialCreate")]
partial class InitialCreate
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<int>("DeviceHashCode");
b.Property<double>("Rotation");
b.Property<string>("SurfaceId");
b.Property<double>("X");
b.Property<double>("Y");
b.Property<int>("ZIndex");
b.HasKey("Guid");
b.HasIndex("SurfaceId");
b.ToTable("DeviceEntity");
});
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("FolderEntityGuid");
b.Property<string>("Name");
b.Property<int>("Order");
b.HasKey("Guid");
b.HasIndex("FolderEntityGuid");
b.ToTable("Folders");
});
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("LayerSettingEntityGuid");
b.Property<int>("Time");
b.Property<string>("Value");
b.HasKey("Guid");
b.HasIndex("LayerSettingEntityGuid");
b.ToTable("Keypoints");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("FolderEntityGuid");
b.Property<string>("Name");
b.Property<int>("Order");
b.HasKey("Guid");
b.HasIndex("FolderEntityGuid");
b.ToTable("Layers");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("LayerEntityGuid");
b.Property<string>("Name");
b.Property<string>("Value");
b.HasKey("Guid");
b.HasIndex("LayerEntityGuid");
b.ToTable("LayerSettings");
});
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("LayerId");
b.Property<string>("LedName");
b.Property<string>("LimitedToDevice");
b.HasKey("Guid");
b.HasIndex("LayerId");
b.ToTable("Leds");
});
modelBuilder.Entity("Artemis.Storage.Entities.PluginSettingEntity", b =>
{
b.Property<string>("Name");
b.Property<Guid>("PluginGuid");
b.Property<string>("Value");
b.HasKey("Name", "PluginGuid");
b.ToTable("PluginSettings");
});
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("Name");
b.Property<Guid>("PluginGuid");
b.Property<string>("RootFolderGuid");
b.Property<int>("RootFolderId");
b.HasKey("Guid");
b.HasIndex("RootFolderGuid");
b.ToTable("Profiles");
});
modelBuilder.Entity("Artemis.Storage.Entities.SettingEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd();
b.Property<string>("Value");
b.HasKey("Name");
b.ToTable("Settings");
});
modelBuilder.Entity("Artemis.Storage.Entities.SurfaceEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<bool>("IsActive");
b.Property<string>("Name");
b.HasKey("Guid");
b.ToTable("Surfaces");
});
modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.SurfaceEntity", "Surface")
.WithMany("DeviceEntities")
.HasForeignKey("SurfaceId");
});
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.FolderEntity")
.WithMany("Folders")
.HasForeignKey("FolderEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.LayerSettingEntity")
.WithMany("Keypoints")
.HasForeignKey("LayerSettingEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.FolderEntity")
.WithMany("Layers")
.HasForeignKey("FolderEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.LayerEntity")
.WithMany("Settings")
.HasForeignKey("LayerEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer")
.WithMany("Leds")
.HasForeignKey("LayerId");
});
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder")
.WithMany()
.HasForeignKey("RootFolderGuid");
});
#pragma warning restore 612, 618
}
}
}
@@ -1,252 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Artemis.Storage.Migrations
{
public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
"Folders",
table => new
{
Guid = table.Column<string>(),
Order = table.Column<int>(),
Name = table.Column<string>(nullable: true),
FolderEntityGuid = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Folders", x => x.Guid);
table.ForeignKey(
"FK_Folders_Folders_FolderEntityGuid",
x => x.FolderEntityGuid,
"Folders",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
"PluginSettings",
table => new
{
PluginGuid = table.Column<Guid>(),
Name = table.Column<string>(),
Value = table.Column<string>(nullable: true)
},
constraints: table => { table.PrimaryKey("PK_PluginSettings", x => new {x.Name, x.PluginGuid}); });
migrationBuilder.CreateTable(
"Settings",
table => new
{
Name = table.Column<string>(),
Value = table.Column<string>(nullable: true)
},
constraints: table => { table.PrimaryKey("PK_Settings", x => x.Name); });
migrationBuilder.CreateTable(
"Surfaces",
table => new
{
Guid = table.Column<string>(),
Name = table.Column<string>(nullable: true),
IsActive = table.Column<bool>()
},
constraints: table => { table.PrimaryKey("PK_Surfaces", x => x.Guid); });
migrationBuilder.CreateTable(
"Layers",
table => new
{
Guid = table.Column<string>(),
Order = table.Column<int>(),
Name = table.Column<string>(nullable: true),
FolderEntityGuid = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Layers", x => x.Guid);
table.ForeignKey(
"FK_Layers_Folders_FolderEntityGuid",
x => x.FolderEntityGuid,
"Folders",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
"Profiles",
table => new
{
Guid = table.Column<string>(),
PluginGuid = table.Column<Guid>(),
Name = table.Column<string>(nullable: true),
RootFolderId = table.Column<int>(),
RootFolderGuid = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Profiles", x => x.Guid);
table.ForeignKey(
"FK_Profiles_Folders_RootFolderGuid",
x => x.RootFolderGuid,
"Folders",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
"DeviceEntity",
table => new
{
Guid = table.Column<string>(),
DeviceHashCode = table.Column<int>(),
X = table.Column<double>(),
Y = table.Column<double>(),
Rotation = table.Column<double>(),
ZIndex = table.Column<int>(),
SurfaceId = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_DeviceEntity", x => x.Guid);
table.ForeignKey(
"FK_DeviceEntity_Surfaces_SurfaceId",
x => x.SurfaceId,
"Surfaces",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
"LayerSettings",
table => new
{
Guid = table.Column<string>(),
Name = table.Column<string>(nullable: true),
Value = table.Column<string>(nullable: true),
LayerEntityGuid = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_LayerSettings", x => x.Guid);
table.ForeignKey(
"FK_LayerSettings_Layers_LayerEntityGuid",
x => x.LayerEntityGuid,
"Layers",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
"Leds",
table => new
{
Guid = table.Column<string>(),
LedName = table.Column<string>(nullable: true),
LimitedToDevice = table.Column<string>(nullable: true),
LayerId = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Leds", x => x.Guid);
table.ForeignKey(
"FK_Leds_Layers_LayerId",
x => x.LayerId,
"Layers",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
"Keypoints",
table => new
{
Guid = table.Column<string>(),
Time = table.Column<int>(),
Value = table.Column<string>(nullable: true),
LayerSettingEntityGuid = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Keypoints", x => x.Guid);
table.ForeignKey(
"FK_Keypoints_LayerSettings_LayerSettingEntityGuid",
x => x.LayerSettingEntityGuid,
"LayerSettings",
"Guid",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
"IX_DeviceEntity_SurfaceId",
"DeviceEntity",
"SurfaceId");
migrationBuilder.CreateIndex(
"IX_Folders_FolderEntityGuid",
"Folders",
"FolderEntityGuid");
migrationBuilder.CreateIndex(
"IX_Keypoints_LayerSettingEntityGuid",
"Keypoints",
"LayerSettingEntityGuid");
migrationBuilder.CreateIndex(
"IX_Layers_FolderEntityGuid",
"Layers",
"FolderEntityGuid");
migrationBuilder.CreateIndex(
"IX_LayerSettings_LayerEntityGuid",
"LayerSettings",
"LayerEntityGuid");
migrationBuilder.CreateIndex(
"IX_Leds_LayerId",
"Leds",
"LayerId");
migrationBuilder.CreateIndex(
"IX_Profiles_RootFolderGuid",
"Profiles",
"RootFolderGuid");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
"DeviceEntity");
migrationBuilder.DropTable(
"Keypoints");
migrationBuilder.DropTable(
"Leds");
migrationBuilder.DropTable(
"PluginSettings");
migrationBuilder.DropTable(
"Profiles");
migrationBuilder.DropTable(
"Settings");
migrationBuilder.DropTable(
"Surfaces");
migrationBuilder.DropTable(
"LayerSettings");
migrationBuilder.DropTable(
"Layers");
migrationBuilder.DropTable(
"Folders");
}
}
}
@@ -1,242 +0,0 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace Artemis.Storage.Migrations
{
[DbContext(typeof(StorageContext))]
internal class StorageContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.2.4-servicing-10062");
modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<int>("DeviceHashCode");
b.Property<double>("Rotation");
b.Property<string>("SurfaceId");
b.Property<double>("X");
b.Property<double>("Y");
b.Property<int>("ZIndex");
b.HasKey("Guid");
b.HasIndex("SurfaceId");
b.ToTable("DeviceEntity");
});
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("FolderEntityGuid");
b.Property<string>("Name");
b.Property<int>("Order");
b.HasKey("Guid");
b.HasIndex("FolderEntityGuid");
b.ToTable("Folders");
});
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("LayerSettingEntityGuid");
b.Property<int>("Time");
b.Property<string>("Value");
b.HasKey("Guid");
b.HasIndex("LayerSettingEntityGuid");
b.ToTable("Keypoints");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("FolderEntityGuid");
b.Property<string>("Name");
b.Property<int>("Order");
b.HasKey("Guid");
b.HasIndex("FolderEntityGuid");
b.ToTable("Layers");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("LayerEntityGuid");
b.Property<string>("Name");
b.Property<string>("Value");
b.HasKey("Guid");
b.HasIndex("LayerEntityGuid");
b.ToTable("LayerSettings");
});
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("LayerId");
b.Property<string>("LedName");
b.Property<string>("LimitedToDevice");
b.HasKey("Guid");
b.HasIndex("LayerId");
b.ToTable("Leds");
});
modelBuilder.Entity("Artemis.Storage.Entities.PluginSettingEntity", b =>
{
b.Property<string>("Name");
b.Property<Guid>("PluginGuid");
b.Property<string>("Value");
b.HasKey("Name", "PluginGuid");
b.ToTable("PluginSettings");
});
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<string>("Name");
b.Property<Guid>("PluginGuid");
b.Property<string>("RootFolderGuid");
b.Property<int>("RootFolderId");
b.HasKey("Guid");
b.HasIndex("RootFolderGuid");
b.ToTable("Profiles");
});
modelBuilder.Entity("Artemis.Storage.Entities.SettingEntity", b =>
{
b.Property<string>("Name")
.ValueGeneratedOnAdd();
b.Property<string>("Value");
b.HasKey("Name");
b.ToTable("Settings");
});
modelBuilder.Entity("Artemis.Storage.Entities.SurfaceEntity", b =>
{
b.Property<string>("Guid")
.ValueGeneratedOnAdd();
b.Property<bool>("IsActive");
b.Property<string>("Name");
b.HasKey("Guid");
b.ToTable("Surfaces");
});
modelBuilder.Entity("Artemis.Storage.Entities.DeviceEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.SurfaceEntity", "Surface")
.WithMany("DeviceEntities")
.HasForeignKey("SurfaceId");
});
modelBuilder.Entity("Artemis.Storage.Entities.FolderEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.FolderEntity")
.WithMany("Folders")
.HasForeignKey("FolderEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.KeypointEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.LayerSettingEntity")
.WithMany("Keypoints")
.HasForeignKey("LayerSettingEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.FolderEntity")
.WithMany("Layers")
.HasForeignKey("FolderEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.LayerSettingEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.LayerEntity")
.WithMany("Settings")
.HasForeignKey("LayerEntityGuid");
});
modelBuilder.Entity("Artemis.Storage.Entities.LedEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.LayerEntity", "Layer")
.WithMany("Leds")
.HasForeignKey("LayerId");
});
modelBuilder.Entity("Artemis.Storage.Entities.ProfileEntity", b =>
{
b.HasOne("Artemis.Storage.Entities.FolderEntity", "RootFolder")
.WithMany()
.HasForeignKey("RootFolderGuid");
});
#pragma warning restore 612, 618
}
}
}
@@ -9,10 +9,7 @@ namespace Artemis.Storage.Repositories.Interfaces
{
void Add(PluginSettingEntity pluginSettingEntity);
List<PluginSettingEntity> GetByPluginGuid(Guid pluginGuid);
Task<List<PluginSettingEntity>> GetByPluginGuidAsync(Guid pluginGuid);
PluginSettingEntity GetByNameAndPluginGuid(string name, Guid pluginGuid);
Task<PluginSettingEntity> GetByNameAndPluginGuidAsync(string name, Guid pluginGuid);
void Save();
Task SaveAsync();
void Save(PluginSettingEntity pluginSettingEntity);
}
}
@@ -1,17 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Entities.Profile;
namespace Artemis.Storage.Repositories.Interfaces
{
public interface IProfileRepository : IRepository
{
IQueryable<ProfileEntity> GetAll();
Task<IList<ProfileEntity>> GetByPluginGuidAsync(Guid pluginGuid);
Task<ProfileEntity> GetByGuidAsync(string guid);
void Save();
Task SaveAsync();
void Add(ProfileEntity profileEntity);
void Remove(ProfileEntity profileEntity);
List<ProfileEntity> GetAll();
ProfileEntity Get(Guid id);
List<ProfileEntity> GetByPluginGuid(Guid pluginGuid);
void Save(ProfileEntity profileEntity);
}
}
@@ -1,17 +0,0 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
namespace Artemis.Storage.Repositories.Interfaces
{
public interface ISettingRepository : IRepository
{
void Add(SettingEntity settingEntity);
SettingEntity Get(string name);
Task<SettingEntity> GetAsync(string name);
List<SettingEntity> GetAll();
Task<List<SettingEntity>> GetAllAsync();
void Save();
Task SaveAsync();
}
}
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Entities.Surface;
namespace Artemis.Storage.Repositories.Interfaces
{
@@ -8,12 +8,9 @@ namespace Artemis.Storage.Repositories.Interfaces
{
void Add(SurfaceEntity surfaceEntity);
void Remove(SurfaceEntity surfaceEntity);
SurfaceEntity Get(string name);
Task<SurfaceEntity> GetAsync(string name);
SurfaceEntity GetByName(string name);
List<SurfaceEntity> GetAll();
Task<List<SurfaceEntity>> GetAllAsync();
void Save();
Task SaveAsync();
void Save(SurfaceEntity surfaceEntity);
}
}
@@ -1,56 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
using LiteDB;
namespace Artemis.Storage.Repositories
{
public class PluginSettingRepository : IPluginSettingRepository
{
private readonly StorageContext _dbContext;
private readonly LiteRepository _repository;
internal PluginSettingRepository()
internal PluginSettingRepository(LiteRepository repository)
{
_dbContext = new StorageContext();
_dbContext.Database.EnsureCreated();
_repository = repository;
_repository.Database.GetCollection<PluginSettingEntity>().EnsureIndex(s => s.Name);
_repository.Database.GetCollection<PluginSettingEntity>().EnsureIndex(s => s.PluginGuid);
}
public void Add(PluginSettingEntity pluginSettingEntity)
{
_dbContext.PluginSettings.Add(pluginSettingEntity);
_repository.Insert(pluginSettingEntity);
}
public List<PluginSettingEntity> GetByPluginGuid(Guid pluginGuid)
{
return _dbContext.PluginSettings.Where(p => p.PluginGuid == pluginGuid).ToList();
}
public async Task<List<PluginSettingEntity>> GetByPluginGuidAsync(Guid pluginGuid)
{
return await _dbContext.PluginSettings.Where(p => p.PluginGuid == pluginGuid).ToListAsync();
return _repository.Query<PluginSettingEntity>().Where(p => p.PluginGuid == pluginGuid).ToList();
}
public PluginSettingEntity GetByNameAndPluginGuid(string name, Guid pluginGuid)
{
return _dbContext.PluginSettings.FirstOrDefault(p => p.Name == name && p.PluginGuid == pluginGuid);
return _repository.FirstOrDefault<PluginSettingEntity>(p => p.Name == name && p.PluginGuid == pluginGuid);
}
public async Task<PluginSettingEntity> GetByNameAndPluginGuidAsync(string name, Guid pluginGuid)
public void Save(PluginSettingEntity pluginSettingEntity)
{
return await _dbContext.PluginSettings.FirstOrDefaultAsync(p => p.Name == name && p.PluginGuid == pluginGuid);
}
public void Save()
{
_dbContext.SaveChanges();
}
public async Task SaveAsync()
{
await _dbContext.SaveChangesAsync();
_repository.Upsert(pluginSettingEntity);
}
}
}
@@ -1,51 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Entities.Profile;
using Artemis.Storage.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
using LiteDB;
namespace Artemis.Storage.Repositories
{
public class ProfileRepository : IProfileRepository
{
private readonly StorageContext _dbContext;
private readonly LiteRepository _repository;
public ProfileRepository()
internal ProfileRepository(LiteRepository repository)
{
_dbContext = new StorageContext();
_dbContext.Database.EnsureCreated();
_repository = repository;
_repository.Database.GetCollection<ProfileEntity>().EnsureIndex(s => s.Name);
}
public IQueryable<ProfileEntity> GetAll()
public void Add(ProfileEntity profileEntity)
{
return _dbContext.Profiles;
_repository.Insert(profileEntity);
}
public async Task<IList<ProfileEntity>> GetByPluginGuidAsync(Guid pluginGuid)
public void Remove(ProfileEntity profileEntity)
{
return await _dbContext.Profiles.Where(p => p.PluginGuid == pluginGuid).ToListAsync();
_repository.Delete<ProfileEntity>(s => s.Id == profileEntity.Id);
}
public async Task<ProfileEntity> GetActiveProfileByPluginGuidAsync(Guid pluginGuid)
public List<ProfileEntity> GetAll()
{
return await _dbContext.Profiles.FirstOrDefaultAsync(p => p.PluginGuid == pluginGuid && p.IsActive);
return _repository.Query<ProfileEntity>().ToList();
}
public async Task<ProfileEntity> GetByGuidAsync(string guid)
public ProfileEntity Get(Guid id)
{
return await _dbContext.Profiles.FirstOrDefaultAsync(p => p.Guid == guid);
return _repository.FirstOrDefault<ProfileEntity>(p => p.Id == id);
}
public void Save()
public List<ProfileEntity> GetByPluginGuid(Guid pluginGuid)
{
_dbContext.SaveChanges();
return _repository.Query<ProfileEntity>()
.Include(p => p.Folders)
.Include(p => p.Layers)
.Where(s => s.PluginGuid == pluginGuid)
.ToList();
}
public async Task SaveAsync()
public void Save(ProfileEntity profileEntity)
{
await _dbContext.SaveChangesAsync();
_repository.Upsert(profileEntity);
}
}
}
@@ -1,55 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace Artemis.Storage.Repositories
{
public class SettingRepository : ISettingRepository
{
private readonly StorageContext _dbContext;
internal SettingRepository()
{
_dbContext = new StorageContext();
_dbContext.Database.EnsureCreated();
}
public void Add(SettingEntity settingEntity)
{
_dbContext.Settings.Add(settingEntity);
}
public SettingEntity Get(string name)
{
return _dbContext.Settings.FirstOrDefault(p => p.Name == name);
}
public async Task<SettingEntity> GetAsync(string name)
{
return await _dbContext.Settings.FirstOrDefaultAsync(p => p.Name == name);
}
public List<SettingEntity> GetAll()
{
return _dbContext.Settings.ToList();
}
public async Task<List<SettingEntity>> GetAllAsync()
{
return await _dbContext.Settings.ToListAsync();
}
public void Save()
{
_dbContext.SaveChanges();
}
public async Task SaveAsync()
{
await _dbContext.SaveChangesAsync();
}
}
}
@@ -1,60 +1,43 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Artemis.Storage.Entities;
using Artemis.Storage.Entities.Surface;
using Artemis.Storage.Repositories.Interfaces;
using Microsoft.EntityFrameworkCore;
using LiteDB;
namespace Artemis.Storage.Repositories
{
public class SurfaceRepository : ISurfaceRepository
{
private readonly StorageContext _dbContext;
private readonly LiteRepository _repository;
internal SurfaceRepository()
internal SurfaceRepository(LiteRepository repository)
{
_dbContext = new StorageContext();
_dbContext.Database.EnsureCreated();
_repository = repository;
_repository.Database.GetCollection<SurfaceEntity>().EnsureIndex(s => s.Name);
}
public void Add(SurfaceEntity surfaceEntity)
{
_dbContext.Surfaces.Add(surfaceEntity);
_repository.Insert(surfaceEntity);
}
public void Remove(SurfaceEntity surfaceEntity)
{
_dbContext.Surfaces.Remove(surfaceEntity);
_repository.Delete<SurfaceEntity>(s => s.Id == surfaceEntity.Id);
}
public SurfaceEntity Get(string name)
public SurfaceEntity GetByName(string name)
{
return _dbContext.Surfaces.Include(s => s.DeviceEntities).FirstOrDefault(p => p.Name == name);
}
public async Task<SurfaceEntity> GetAsync(string name)
{
return await _dbContext.Surfaces.Include(s => s.DeviceEntities).FirstOrDefaultAsync(p => p.Name == name);
return _repository.FirstOrDefault<SurfaceEntity>(s => s.Name == name);
}
public List<SurfaceEntity> GetAll()
{
return _dbContext.Surfaces.Include(s => s.DeviceEntities).ToList();
return _repository.Query<SurfaceEntity>().Include(s => s.DeviceEntities).ToList();
}
public async Task<List<SurfaceEntity>> GetAllAsync()
public void Save(SurfaceEntity surfaceEntity)
{
return await _dbContext.Surfaces.Include(s => s.DeviceEntities).ToListAsync();
}
public void Save()
{
_dbContext.SaveChanges();
}
public async Task SaveAsync()
{
await _dbContext.SaveChangesAsync();
_repository.Upsert(surfaceEntity);
}
}
}
-37
View File
@@ -1,37 +0,0 @@
using System;
using System.IO;
using Artemis.Storage.Entities;
using Microsoft.EntityFrameworkCore;
using SQLitePCL;
namespace Artemis.Storage
{
public class StorageContext : DbContext
{
public DbSet<ProfileEntity> Profiles { get; set; }
public DbSet<SettingEntity> Settings { get; set; }
public DbSet<SurfaceEntity> Surfaces { get; set; }
public DbSet<PluginSettingEntity> PluginSettings { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// ReSharper disable once RedundantAssignment - Used if not debugging
var dbLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Artemis\\Storage.db");
#if DEBUG
dbLocation = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\Artemis.Storage\Storage.db"));
#endif
optionsBuilder.UseSqlite("Data Source=" + dbLocation);
// Requires Microsoft.Data.Sqlite in the startup project
Batteries.Init();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SettingEntity>().HasKey(s => s.Name);
modelBuilder.Entity<PluginSettingEntity>().HasKey(s => new {s.Name, s.PluginGuid});
base.OnModelCreating(modelBuilder);
}
}
}