mirror of
https://github.com/ppy/osu
synced 2024-12-28 09:52:56 +00:00
Connection -> context
This commit is contained in:
parent
c92e0e2dc1
commit
66894d11ea
@ -80,9 +80,9 @@ namespace osu.Game.Beatmaps
|
||||
/// </summary>
|
||||
public Func<Storage> GetStableStorage { private get; set; }
|
||||
|
||||
public BeatmapManager(Storage storage, FileStore files, OsuDbContext connection, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
|
||||
public BeatmapManager(Storage storage, FileStore files, OsuDbContext context, RulesetStore rulesets, APIAccess api, IIpcHost importHost = null)
|
||||
{
|
||||
beatmaps = new BeatmapStore(connection);
|
||||
beatmaps = new BeatmapStore(context);
|
||||
beatmaps.BeatmapSetAdded += s => BeatmapSetAdded?.Invoke(s);
|
||||
beatmaps.BeatmapSetRemoved += s => BeatmapSetRemoved?.Invoke(s);
|
||||
beatmaps.BeatmapHidden += b => BeatmapHidden?.Invoke(b);
|
||||
|
@ -20,8 +20,8 @@ namespace osu.Game.Beatmaps
|
||||
public event Action<BeatmapInfo> BeatmapHidden;
|
||||
public event Action<BeatmapInfo> BeatmapRestored;
|
||||
|
||||
public BeatmapStore(OsuDbContext connection)
|
||||
: base(connection)
|
||||
public BeatmapStore(OsuDbContext context)
|
||||
: base(context)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,11 +30,11 @@ namespace osu.Game.Beatmaps
|
||||
if (reset)
|
||||
{
|
||||
// https://stackoverflow.com/a/10450893
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM BeatmapMetadata");
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM BeatmapDifficulty");
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetInfo");
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetFileInfo");
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM BeatmapInfo");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM BeatmapMetadata");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM BeatmapDifficulty");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetInfo");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM BeatmapSetFileInfo");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM BeatmapInfo");
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,8 +50,8 @@ namespace osu.Game.Beatmaps
|
||||
/// <param name="beatmapSet">The beatmap to add.</param>
|
||||
public void Add(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
Connection.BeatmapSetInfo.Attach(beatmapSet);
|
||||
Connection.SaveChanges();
|
||||
Context.BeatmapSetInfo.Attach(beatmapSet);
|
||||
Context.SaveChanges();
|
||||
|
||||
BeatmapSetAdded?.Invoke(beatmapSet);
|
||||
}
|
||||
@ -66,8 +66,8 @@ namespace osu.Game.Beatmaps
|
||||
if (beatmapSet.DeletePending) return false;
|
||||
|
||||
beatmapSet.DeletePending = true;
|
||||
Connection.BeatmapSetInfo.Update(beatmapSet);
|
||||
Connection.SaveChanges();
|
||||
Context.BeatmapSetInfo.Update(beatmapSet);
|
||||
Context.SaveChanges();
|
||||
|
||||
BeatmapSetRemoved?.Invoke(beatmapSet);
|
||||
return true;
|
||||
@ -83,8 +83,8 @@ namespace osu.Game.Beatmaps
|
||||
if (!beatmapSet.DeletePending) return false;
|
||||
|
||||
beatmapSet.DeletePending = false;
|
||||
Connection.BeatmapSetInfo.Update(beatmapSet);
|
||||
Connection.SaveChanges();
|
||||
Context.BeatmapSetInfo.Update(beatmapSet);
|
||||
Context.SaveChanges();
|
||||
|
||||
BeatmapSetAdded?.Invoke(beatmapSet);
|
||||
return true;
|
||||
@ -100,8 +100,8 @@ namespace osu.Game.Beatmaps
|
||||
if (beatmap.Hidden) return false;
|
||||
|
||||
beatmap.Hidden = true;
|
||||
Connection.BeatmapInfo.Update(beatmap);
|
||||
Connection.SaveChanges();
|
||||
Context.BeatmapInfo.Update(beatmap);
|
||||
Context.SaveChanges();
|
||||
|
||||
BeatmapHidden?.Invoke(beatmap);
|
||||
return true;
|
||||
@ -117,8 +117,8 @@ namespace osu.Game.Beatmaps
|
||||
if (!beatmap.Hidden) return false;
|
||||
|
||||
beatmap.Hidden = false;
|
||||
Connection.BeatmapInfo.Update(beatmap);
|
||||
Connection.SaveChanges();
|
||||
Context.BeatmapInfo.Update(beatmap);
|
||||
Context.SaveChanges();
|
||||
|
||||
BeatmapRestored?.Invoke(beatmap);
|
||||
return true;
|
||||
@ -126,18 +126,18 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
private void cleanupPendingDeletions()
|
||||
{
|
||||
Connection.BeatmapSetInfo.RemoveRange(Connection.BeatmapSetInfo.Where(b => b.DeletePending && !b.Protected));
|
||||
Connection.SaveChanges();
|
||||
Context.BeatmapSetInfo.RemoveRange(Context.BeatmapSetInfo.Where(b => b.DeletePending && !b.Protected));
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
public IEnumerable<BeatmapSetInfo> BeatmapSets => Connection.BeatmapSetInfo
|
||||
public IEnumerable<BeatmapSetInfo> BeatmapSets => Context.BeatmapSetInfo
|
||||
.Include(s => s.Metadata)
|
||||
.Include(s => s.Beatmaps).ThenInclude(s => s.Ruleset)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Difficulty)
|
||||
.Include(s => s.Beatmaps).ThenInclude(b => b.Metadata)
|
||||
.Include(s => s.Files).ThenInclude(f => f.FileInfo);
|
||||
|
||||
public IEnumerable<BeatmapInfo> Beatmaps => Connection.BeatmapInfo
|
||||
public IEnumerable<BeatmapInfo> Beatmaps => Context.BeatmapInfo
|
||||
.Include(b => b.BeatmapSet).ThenInclude(s => s.Metadata)
|
||||
.Include(b => b.Metadata)
|
||||
.Include(b => b.Ruleset)
|
||||
|
@ -10,12 +10,12 @@ namespace osu.Game.Database
|
||||
public abstract class DatabaseBackedStore
|
||||
{
|
||||
protected readonly Storage Storage;
|
||||
protected readonly OsuDbContext Connection;
|
||||
protected readonly OsuDbContext Context;
|
||||
|
||||
protected DatabaseBackedStore(OsuDbContext connection, Storage storage = null)
|
||||
protected DatabaseBackedStore(OsuDbContext context, Storage storage = null)
|
||||
{
|
||||
Storage = storage;
|
||||
Connection = connection;
|
||||
Context = context;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.IO
|
||||
|
||||
public readonly ResourceStore<byte[]> Store;
|
||||
|
||||
public FileStore(OsuDbContext connection, Storage storage) : base(connection, storage)
|
||||
public FileStore(OsuDbContext context, Storage storage) : base(context, storage)
|
||||
{
|
||||
Store = new NamespacedResourceStore<byte[]>(new StorageBackedResourceStore(storage), prefix);
|
||||
}
|
||||
@ -34,7 +34,7 @@ namespace osu.Game.IO
|
||||
if (Storage.ExistsDirectory(prefix))
|
||||
Storage.DeleteDirectory(prefix);
|
||||
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM FileInfo");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM FileInfo");
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ namespace osu.Game.IO
|
||||
{
|
||||
string hash = data.ComputeSHA2Hash();
|
||||
|
||||
var existing = Connection.FileInfo.FirstOrDefault(f => f.Hash == hash);
|
||||
var existing = Context.FileInfo.FirstOrDefault(f => f.Hash == hash);
|
||||
|
||||
var info = existing ?? new FileInfo { Hash = hash };
|
||||
|
||||
@ -75,34 +75,34 @@ namespace osu.Game.IO
|
||||
{
|
||||
foreach (var f in files.GroupBy(f => f.ID))
|
||||
{
|
||||
var refetch = Connection.Find<FileInfo>(f.First().ID) ?? f.First();
|
||||
var refetch = Context.Find<FileInfo>(f.First().ID) ?? f.First();
|
||||
refetch.ReferenceCount += f.Count();
|
||||
Connection.FileInfo.Update(refetch);
|
||||
Context.FileInfo.Update(refetch);
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
public void Dereference(params FileInfo[] files)
|
||||
{
|
||||
foreach (var f in files.GroupBy(f => f.ID))
|
||||
{
|
||||
var refetch = Connection.Find<FileInfo>(f.First().ID);
|
||||
var refetch = Context.Find<FileInfo>(f.First().ID);
|
||||
refetch.ReferenceCount -= f.Count();
|
||||
Connection.Update(refetch);
|
||||
Context.Update(refetch);
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
private void deletePending()
|
||||
{
|
||||
foreach (var f in Connection.FileInfo.Where(f => f.ReferenceCount < 1))
|
||||
foreach (var f in Context.FileInfo.Where(f => f.ReferenceCount < 1))
|
||||
{
|
||||
try
|
||||
{
|
||||
Storage.Delete(Path.Combine(prefix, f.StoragePath));
|
||||
Connection.FileInfo.Remove(f);
|
||||
Context.FileInfo.Remove(f);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -110,7 +110,7 @@ namespace osu.Game.IO
|
||||
}
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ namespace osu.Game.Input
|
||||
{
|
||||
public class KeyBindingStore : DatabaseBackedStore
|
||||
{
|
||||
public KeyBindingStore(OsuDbContext connection, RulesetStore rulesets, Storage storage = null)
|
||||
: base(connection, storage)
|
||||
public KeyBindingStore(OsuDbContext context, RulesetStore rulesets, Storage storage = null)
|
||||
: base(context, storage)
|
||||
{
|
||||
foreach (var info in rulesets.AvailableRulesets)
|
||||
{
|
||||
@ -30,7 +30,7 @@ namespace osu.Game.Input
|
||||
protected override void Prepare(bool reset = false)
|
||||
{
|
||||
if (reset)
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM KeyBinding");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM KeyBinding");
|
||||
}
|
||||
|
||||
private void insertDefaults(IEnumerable<KeyBinding> defaults, int? rulesetId = null, int? variant = null)
|
||||
@ -46,7 +46,7 @@ namespace osu.Game.Input
|
||||
|
||||
foreach (var insertable in group.Skip(count).Take(aimCount - count))
|
||||
// insert any defaults which are missing.
|
||||
Connection.DatabasedKeyBinding.Add(new DatabasedKeyBinding
|
||||
Context.DatabasedKeyBinding.Add(new DatabasedKeyBinding
|
||||
{
|
||||
KeyCombination = insertable.KeyCombination,
|
||||
Action = insertable.Action,
|
||||
@ -55,7 +55,7 @@ namespace osu.Game.Input
|
||||
});
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -64,12 +64,12 @@ namespace osu.Game.Input
|
||||
/// <param name="rulesetId">The ruleset's internal ID.</param>
|
||||
/// <param name="variant">An optional variant.</param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<KeyBinding> Query(int? rulesetId = null, int? variant = null) => Connection.DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant);
|
||||
public IEnumerable<KeyBinding> Query(int? rulesetId = null, int? variant = null) => Context.DatabasedKeyBinding.Where(b => b.RulesetID == rulesetId && b.Variant == variant);
|
||||
|
||||
public void Update(KeyBinding keyBinding)
|
||||
{
|
||||
Connection.Update(keyBinding);
|
||||
Connection.SaveChanges();
|
||||
Context.Update(keyBinding);
|
||||
Context.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,8 @@ namespace osu.Game.Rulesets
|
||||
loadRulesetFromFile(file);
|
||||
}
|
||||
|
||||
public RulesetStore(OsuDbContext connection)
|
||||
: base(connection)
|
||||
public RulesetStore(OsuDbContext context)
|
||||
: base(context)
|
||||
{
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ namespace osu.Game.Rulesets
|
||||
/// <summary>
|
||||
/// All available rulesets.
|
||||
/// </summary>
|
||||
public IEnumerable<RulesetInfo> AvailableRulesets => Connection.RulesetInfo.Where(r => r.Available);
|
||||
public IEnumerable<RulesetInfo> AvailableRulesets => Context.RulesetInfo.Where(r => r.Available);
|
||||
|
||||
private static Assembly currentDomain_AssemblyResolve(object sender, ResolveEventArgs args) => loaded_assemblies.Keys.FirstOrDefault(a => a.FullName == args.Name);
|
||||
|
||||
@ -51,7 +51,7 @@ namespace osu.Game.Rulesets
|
||||
{
|
||||
if (reset)
|
||||
{
|
||||
Connection.Database.ExecuteSqlCommand("DELETE FROM RulesetInfo");
|
||||
Context.Database.ExecuteSqlCommand("DELETE FROM RulesetInfo");
|
||||
}
|
||||
|
||||
var instances = loaded_assemblies.Values.Select(r => (Ruleset)Activator.CreateInstance(r, new RulesetInfo())).ToList();
|
||||
@ -60,29 +60,29 @@ namespace osu.Game.Rulesets
|
||||
foreach (var r in instances.Where(r => r.LegacyID >= 0).OrderBy(r => r.LegacyID))
|
||||
{
|
||||
var rulesetInfo = createRulesetInfo(r);
|
||||
if (Connection.RulesetInfo.SingleOrDefault(rsi => rsi.ID == rulesetInfo.ID) == null)
|
||||
if (Context.RulesetInfo.SingleOrDefault(rsi => rsi.ID == rulesetInfo.ID) == null)
|
||||
{
|
||||
Connection.RulesetInfo.Add(rulesetInfo);
|
||||
Context.RulesetInfo.Add(rulesetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
|
||||
//add any other modes
|
||||
foreach (var r in instances.Where(r => r.LegacyID < 0))
|
||||
{
|
||||
var us = createRulesetInfo(r);
|
||||
|
||||
var existing = Connection.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo);
|
||||
var existing = Context.RulesetInfo.FirstOrDefault(ri => ri.InstantiationInfo == us.InstantiationInfo);
|
||||
|
||||
if (existing == null)
|
||||
Connection.RulesetInfo.Add(us);
|
||||
Context.RulesetInfo.Add(us);
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
|
||||
//perform a consistency check
|
||||
foreach (var r in Connection.RulesetInfo)
|
||||
foreach (var r in Context.RulesetInfo)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -95,7 +95,7 @@ namespace osu.Game.Rulesets
|
||||
}
|
||||
}
|
||||
|
||||
Connection.SaveChanges();
|
||||
Context.SaveChanges();
|
||||
}
|
||||
|
||||
private static void loadRulesetFromFile(string file)
|
||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.Scoring
|
||||
// ReSharper disable once NotAccessedField.Local (we should keep a reference to this so it is not finalised)
|
||||
private ScoreIPCChannel ipc;
|
||||
|
||||
public ScoreStore(Storage storage, OsuDbContext connection, IIpcHost importHost = null, BeatmapManager beatmaps = null, RulesetStore rulesets = null) : base(connection)
|
||||
public ScoreStore(Storage storage, OsuDbContext context, IIpcHost importHost = null, BeatmapManager beatmaps = null, RulesetStore rulesets = null) : base(context)
|
||||
{
|
||||
this.storage = storage;
|
||||
this.beatmaps = beatmaps;
|
||||
|
Loading…
Reference in New Issue
Block a user