public abstract Save ( |
||
metrics | ||
permitBackgroundWrite | bool | |
return | void |
public static void Save( bool message ) { if ( m_Saving || AsyncWriter.ThreadCount > 0 ) return; NetState.FlushAll(); NetState.Pause(); m_Saving = true; if ( message ) Broadcast( 0x35, true, "The world is saving, please wait." ); SaveStrategy strategy = SaveStrategy.Acquire(); Console.WriteLine( "Core: Using {0} save strategy", strategy.Name.ToLowerInvariant() ); Console.Write( "World: Saving..." ); Stopwatch watch = Stopwatch.StartNew(); if ( !Directory.Exists( "Saves/Mobiles/" ) ) Directory.CreateDirectory( "Saves/Mobiles/" ); if ( !Directory.Exists( "Saves/Items/" ) ) Directory.CreateDirectory( "Saves/Items/" ); if ( !Directory.Exists( "Saves/Guilds/" ) ) Directory.CreateDirectory( "Saves/Guilds/" ); /*using ( SaveMetrics metrics = new SaveMetrics() ) {*/ strategy.Save( null ); /*}*/ try { EventSink.InvokeWorldSave( new WorldSaveEventArgs( message ) ); } catch ( Exception e ) { throw new Exception( "World Save event threw an exception. Save failed!", e ); } watch.Stop(); m_Saving = false; ProcessSafetyQueues(); strategy.ProcessDecay(); Console.WriteLine( "done in {0:F2} seconds.", watch.Elapsed.TotalSeconds ); if ( message ) Broadcast( 0x35, true, "World save complete. The entire process took {0:F1} seconds.", watch.Elapsed.TotalSeconds ); NetState.Resume(); }
public static void Save(bool message, bool permitBackgroundWrite) { if (m_Saving) { return; } ++m_Saves; NetState.FlushAll(); NetState.Pause(); World.WaitForWriteCompletion();//Blocks Save until current disk flush is done. m_Saving = true; m_DiskWriteHandle.Reset(); if (message) { Broadcast(0x35, true, "The world is saving, please wait."); } SaveStrategy strategy = SaveStrategy.Acquire(); Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLowerInvariant()); Console.Write("World: Saving..."); Stopwatch watch = Stopwatch.StartNew(); if (!Directory.Exists("Saves/Mobiles/")) { Directory.CreateDirectory("Saves/Mobiles/"); } if (!Directory.Exists("Saves/Items/")) { Directory.CreateDirectory("Saves/Items/"); } /*using ( SaveMetrics metrics = new SaveMetrics() ) {*/ strategy.Save(null, permitBackgroundWrite); /*}*/ try { EventSink.InvokeWorldSave(new WorldSaveEventArgs(message)); } catch (Exception e) { throw new Exception("World Save event threw an exception. Save failed!", e); } watch.Stop(); m_Saving = false; if (!permitBackgroundWrite) { World.NotifyDiskWriteComplete(); //Sets the DiskWriteHandle. If we allow background writes, we leave this upto the individual save strategies. } ProcessSafetyQueues(); strategy.ProcessDecay(); Console.WriteLine("Save done in {0:F2} seconds.", watch.Elapsed.TotalSeconds); if (message) { Broadcast(0x35, true, "World save complete. The entire process took {0:F1} seconds.", watch.Elapsed.TotalSeconds); } NetState.Resume(); }
public void Save(bool message = true, bool permitBackgroundWrite = false) { if (m_Saving) { return; } GameServer.Instance.Clients.Each(c => c.Flush()); WaitForWriteCompletion(); // Blocks Save until current disk flush is done. m_Saving = true; m_DiskWriteHandle.Reset(); if (message) { Broadcast(0x35, true, "The world is saving, please wait."); } Console.WriteLine("World: Save started"); SaveStrategy strategy = SaveStrategy.Acquire(); Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLowerInvariant()); Stopwatch watch = Stopwatch.StartNew(); try { EventSink.Instance.InvokeWorldBeforeSave(); } catch (Exception e) { throw new Exception("World Before Save event threw an exception. Save failed!", e); } if (!Directory.Exists(MobileBasePath)) { Directory.CreateDirectory(MobileBasePath); } if (!Directory.Exists(ItemBasePath)) { Directory.CreateDirectory(ItemBasePath); } if (!Directory.Exists(GuildBasePath)) { Directory.CreateDirectory(GuildBasePath); } strategy.Save(permitBackgroundWrite); Console.WriteLine("World: Entities saved in {0:F2} seconds.", watch.Elapsed.TotalSeconds); try { EventSink.Instance.InvokeWorldSave(new WorldSaveEventArgs(message)); } catch (Exception e) { throw new Exception("World Save event threw an exception. Save failed!", e); } if (ManualGC) { System.GC.Collect(); } watch.Stop(); m_Saving = false; if (!permitBackgroundWrite) { NotifyDiskWriteComplete(); // Sets the DiskWriteHandle. If we allow background writes, we leave this upto the individual save strategies. } ProcessSafetyQueues(); strategy.OnFinished(); Console.WriteLine("World: Save done in {0:F2} seconds.", watch.Elapsed.TotalSeconds); if (message) { Broadcast(0x35, true, "World save complete. The entire process took {0:F2} seconds.", watch.Elapsed.TotalSeconds); } }
public static void Save(bool message, bool permitBackgroundWrite) { if (Saving) { return; } ++m_Saves; NetState.FlushAll(); NetState.Pause(); WaitForWriteCompletion(); //Blocks Save until current disk flush is done. Saving = true; m_DiskWriteHandle.Reset(); if (message) { Broadcast(0x35, false, AccessLevel.Player, "The world is saving, please wait."); } SaveStrategy strategy = SaveStrategy.Acquire(); Console.WriteLine("Core: Using {0} save strategy", strategy.Name.ToLowerInvariant()); Console.WriteLine("World: Saving..."); Stopwatch watch = Stopwatch.StartNew(); if (!Directory.Exists("Saves/Mobiles/")) { Directory.CreateDirectory("Saves/Mobiles/"); } if (!Directory.Exists("Saves/Items/")) { Directory.CreateDirectory("Saves/Items/"); } if (!Directory.Exists("Saves/Guilds/")) { Directory.CreateDirectory("Saves/Guilds/"); } try { EventSink.InvokeBeforeWorldSave(new BeforeWorldSaveEventArgs()); } catch (Exception e) { throw new Exception("FATAL: Exception in EventSink.BeforeWorldSave", e); } if (m_Metrics) { using (SaveMetrics metrics = new SaveMetrics()) strategy.Save(metrics, permitBackgroundWrite); } else { strategy.Save(null, permitBackgroundWrite); } try { EventSink.InvokeWorldSave(new WorldSaveEventArgs(message)); } catch (Exception e) { throw new Exception("FATAL: Exception in EventSink.WorldSave", e); } watch.Stop(); Saving = false; if (!permitBackgroundWrite) { NotifyDiskWriteComplete(); //Sets the DiskWriteHandle. If we allow background writes, we leave this upto the individual save strategies. } ProcessSafetyQueues(); strategy.ProcessDecay(); Console.WriteLine("Save finished in {0:F2} seconds.", watch.Elapsed.TotalSeconds); if (message) { Broadcast(0x35, false, AccessLevel.Player, "World save done in {0:F1} seconds.", watch.Elapsed.TotalSeconds); } NetState.Resume(); try { EventSink.InvokeAfterWorldSave(new AfterWorldSaveEventArgs()); } catch (Exception e) { throw new Exception("FATAL: Exception in EventSink.AfterWorldSave", e); } }