mirror of
https://github.com/osukey/osukey.git
synced 2025-08-02 06:07:11 +09:00
DatabaseWriteUsage
This commit is contained in:
28
osu.Game/Database/DatabaseWriteUsage.cs
Normal file
28
osu.Game/Database/DatabaseWriteUsage.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
|
||||
namespace osu.Game.Database
|
||||
{
|
||||
public class DatabaseWriteUsage : IDisposable
|
||||
{
|
||||
public readonly OsuDbContext Context;
|
||||
private readonly IDbContextTransaction transaction;
|
||||
private readonly Action<DatabaseWriteUsage> usageCompleted;
|
||||
|
||||
public DatabaseWriteUsage(OsuDbContext context, Action<DatabaseWriteUsage> onCompleted)
|
||||
{
|
||||
Context = context;
|
||||
transaction = Context.BeginTransaction();
|
||||
usageCompleted = onCompleted;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Context.SaveChanges(transaction);
|
||||
usageCompleted?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user