mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Moved from EF and SQLite to LiteDB
This commit is contained in:
1 parent
296414001b
commit
2fb2e5444c
57 files changed
+379
-1279
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user