public bool Migrate(string path) { Logger.Log($@"Migrating osu! data from ""{Storage.GetFullPath(string.Empty)}"" to ""{path}""..."); IDisposable realmBlocker = null; try { ManualResetEventSlim readyToRun = new ManualResetEventSlim(); Scheduler.Add(() => { realmBlocker = realm.BlockAllOperations(); readyToRun.Set(); }, false); readyToRun.Wait(); bool?cleanupSucceded = (Storage as OsuStorage)?.Migrate(Host.GetStorage(path)); Logger.Log(@"Migration complete!"); return(cleanupSucceded != false); } finally { realmBlocker?.Dispose(); } }
private void load(GameHost host, RealmAccess realm) { SettingsButton blockAction; SettingsButton unblockAction; Children = new Drawable[] { new SettingsButton { Text = DebugSettingsStrings.ClearAllCaches, Action = host.Collect }, new SettingsButton { Text = DebugSettingsStrings.CompactRealm, Action = () => { // Blocking operations implicitly causes a Compact(). using (realm.BlockAllOperations()) { } } }, blockAction = new SettingsButton { Text = "Block realm", }, unblockAction = new SettingsButton { Text = "Unblock realm", }, }; blockAction.Action = () => { try { var token = realm.BlockAllOperations(); blockAction.Enabled.Value = false; // As a safety measure, unblock after 10 seconds. // This is to handle the case where a dev may block, but then something on the update thread // accesses realm and blocks for eternity. Task.Factory.StartNew(() => { Thread.Sleep(10000); unblock(); }); unblockAction.Action = unblock; void unblock() { if (token == null) { return; } token?.Dispose(); token = null; Scheduler.Add(() => { blockAction.Enabled.Value = true; unblockAction.Action = null; }); } } catch (Exception e) { Logger.Error(e, "Blocking realm failed"); } }; }