.convert rewritten a bit, isn't saved in the database anymore, but in redis.

This commit is contained in:
Master Kwoth
2017-10-16 12:34:16 +02:00
parent 099ae62c0b
commit f155619793
13 changed files with 1999 additions and 202 deletions

View File

@ -14,7 +14,6 @@ namespace NadekoBot.Core.Services.Database
IReminderRepository Reminders { get; }
ISelfAssignedRolesRepository SelfAssignedRoles { get; }
IBotConfigRepository BotConfig { get; }
IUnitConverterRepository ConverterUnits { get; }
ICustomReactionRepository CustomReactions { get; }
ICurrencyRepository Currency { get; }
ICurrencyTransactionsRepository CurrencyTransactions { get; }

View File

@ -1,47 +0,0 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
namespace NadekoBot.Core.Services.Database.Models
{
public class ConvertUnit : DbEntity
{
public ConvertUnit() { }
[NotMapped]
private string[] _triggersValue;
[NotMapped]
public string[] Triggers
{
get
{
return _triggersValue ?? (_triggersValue = InternalTrigger.Split('|'));
}
set
{
_triggersValue = value;
InternalTrigger = string.Join("|", _triggersValue);
}
}
//protected or private?
/// <summary>
/// DO NOT CALL THIS
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public string InternalTrigger { get; set; }
public string UnitType { get; set; }
public decimal Modifier { get; set; }
public override bool Equals(object obj)
{
var cu = obj as ConvertUnit;
if (cu == null)
return false;
return cu.UnitType == this.UnitType;
}
public override int GetHashCode()
{
return this.UnitType.GetHashCode();
}
}
}

View File

@ -33,7 +33,6 @@ namespace NadekoBot.Core.Services.Database
public DbSet<SelfAssignedRole> SelfAssignableRoles { get; set; }
public DbSet<BotConfig> BotConfig { get; set; }
public DbSet<Currency> Currency { get; set; }
public DbSet<ConvertUnit> ConversionUnits { get; set; }
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
public DbSet<CustomReaction> CustomReactions { get; set; }
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }

View File

@ -1,11 +0,0 @@
using NadekoBot.Core.Services.Database.Models;
using System;
namespace NadekoBot.Core.Services.Database.Repositories
{
public interface IUnitConverterRepository : IRepository<ConvertUnit>
{
void AddOrUpdate(Func<ConvertUnit, bool> check, ConvertUnit toAdd, Func<ConvertUnit, ConvertUnit> toUpdate);
bool Empty();
}
}

View File

@ -1,26 +0,0 @@
using NadekoBot.Core.Services.Database.Models;
using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;
namespace NadekoBot.Core.Services.Database.Repositories.Impl
{
public class UnitConverterRepository : Repository<ConvertUnit>, IUnitConverterRepository
{
public UnitConverterRepository(DbContext context) : base(context)
{
}
public void AddOrUpdate(Func<ConvertUnit, bool> check, ConvertUnit toAdd, Func<ConvertUnit, ConvertUnit> toUpdate)
{
var existing = _set.FirstOrDefault(check);
if (existing != null)
{
existing = toUpdate.Invoke(existing);
}
else _set.Add(toAdd);
}
public bool Empty() => !_set.Any();
}
}

View File

@ -33,9 +33,6 @@ namespace NadekoBot.Core.Services.Database
private ICurrencyTransactionsRepository _currencyTransactions;
public ICurrencyTransactionsRepository CurrencyTransactions => _currencyTransactions ?? (_currencyTransactions = new CurrencyTransactionsRepository(_context));
private IUnitConverterRepository _conUnits;
public IUnitConverterRepository ConverterUnits => _conUnits ?? (_conUnits = new UnitConverterRepository(_context));
private IMusicPlaylistRepository _musicPlaylists;
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));