예제 #1
0
파일: World.cs 프로젝트: uotools/uolite
		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();
		}
예제 #2
0
 public static SaveStrategyTypes GetSaveType(SaveStrategy saveStrategy)
 {
     if (saveStrategy is StandardSaveStrategy)
         return SaveStrategyTypes.StandardSaveStrategy;
     else if (saveStrategy is DualSaveStrategy)
         return SaveStrategyTypes.StandardSaveStrategy;
     else if (saveStrategy is DynamicSaveStrategy)
         return SaveStrategyTypes.DynamicSaveStrategy;
     else if (saveStrategy is ParallelSaveStrategy)
         return SaveStrategyTypes.ParallelSaveStrategy;
     else
         return SaveStrategyTypes.StandardSaveStrategy;
 }
예제 #3
0
 public SaveSettings(bool savesEnabled = true, AccessLevel saveAccessLevel = AccessLevel.Administrator,
     SaveStrategy saveStrategy = SaveStrategy.Acquire(), bool allowBackgroundWrite = false,
     TimeSpan saveDelay = TimeSpan.FromHours(1.0), int noIOHour = -1,
     List<TimeSpan> warningDelays = new List<TimeSpan>() { TimeSpan.FromMinutes(1.0), TimeSpan.FromSeconds(30.0) },
     bool enableEmergencyBackups = true, int emergencyBackupHour = 3,
     CompressionLevel compressionLevel = CompressionLevel.Normal)
 {
     this.m_SavesEnabled = savesEnabled;
     this.m_SaveAccessLevel = saveAccessLevel;
     this.m_SaveStrategy = saveStrategy;
     this.m_AllowBackgroundWrite = allowBackgroundWrite;
     this.m_SaveDelay = saveDelay;
     this.m_WarningDelays = warningDelays;
     this.m_NoIOHour = noIOHour;
     this.m_EnableEmergencyBackups = enableEmergencyBackups;
     this.m_EmergencyBackupHour = emergencyBackupHour;
     this.m_CompressionLevel = compressionLevel;
 }
예제 #4
0
		public SaveSettings(
			SaveStrategy saveStrategy,
			List<TimeSpan> warningDelays,
			TimeSpan saveDelay,
			bool savesEnabled = true,
			AccessLevel saveAccessLevel = AccessLevel.Administrator,
			bool allowBackgroundWrite = false,
			int noIOHour = -1,
			bool enableEmergencyBackups = true,
			int emergencyBackupHour = 3,
			CompressionLevel compressionLevel = CompressionLevel.Normal)
		{
			SavesEnabled = savesEnabled;
			SaveAccessLevel = saveAccessLevel;
			_SaveStrategy = saveStrategy;
			AllowBackgroundWrite = allowBackgroundWrite;
			SaveDelay = saveDelay;
			WarningDelays = warningDelays;
			NoIOHour = noIOHour;
			EnableEmergencyBackups = enableEmergencyBackups;
			EmergencyBackupHour = emergencyBackupHour;
			Compression = compressionLevel;
		}
예제 #5
0
        public static SaveStrategyTypes GetSaveType(this SaveStrategy saveStrategy)
        {
            if (saveStrategy is DualSaveStrategy)
            {
                return(SaveStrategyTypes.StandardSaveStrategy);
            }

            if (saveStrategy is StandardSaveStrategy)
            {
                return(SaveStrategyTypes.StandardSaveStrategy);
            }

            if (saveStrategy is DynamicSaveStrategy)
            {
                return(SaveStrategyTypes.DynamicSaveStrategy);
            }

            if (saveStrategy is ParallelSaveStrategy)
            {
                return(SaveStrategyTypes.ParallelSaveStrategy);
            }

            return(SaveStrategyTypes.StandardSaveStrategy);
        }
예제 #6
0
파일: World.cs 프로젝트: dpisanu/xrunuo
        public static void Save(bool message = true, bool permitBackgroundWrite = false)
        {
            if (Saving)
            {
                return;
            }

            GameServer.Instance.Clients.Each(c => c.Flush());

            WaitForWriteCompletion();             // Blocks Save until current disk flush is done.

            Saving = true;

            m_DiskWriteHandle.Reset();

            if (message)
            {
                Broadcast(0x35, true, "The world is saving, please wait.");
            }

            log.Info("Save started");

            var strategy = SaveStrategy.Acquire();

            log.Info("Using {0} save strategy", strategy.Name.ToLowerInvariant());

            var watch = Stopwatch.StartNew();

            try
            {
                EventSink.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);

            log.Info("Entities saved in {0:F2} seconds.", watch.Elapsed.TotalSeconds);

            try
            {
                EventSink.InvokeWorldSave(new WorldSaveEventArgs(message));
            }
            catch (Exception e)
            {
                throw new Exception("World Save event threw an exception. Save failed!", e);
            }

            if (ManualGC)
            {
                GC.Collect();
            }

            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.OnFinished();

            log.Info("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);
            }
        }
예제 #7
0
파일: World.cs 프로젝트: Pumpk1ns/outlands
        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();
        }
예제 #8
0
        protected override sealed void Deserialize(GenericReader reader)
        {
            int version = reader.ReadInt();

            switch (version)
            {
                case 0:
                    {
                        this.m_SavesEnabled = reader.ReadBool();
                        this.m_SaveAccessLevel = (AccessLevel)reader.ReadByte();
                        this.m_SaveStrategy = Utilities.GetSaveStrategy((SaveStrategyTypes)reader.ReadByte());
                        this.m_AllowBackgroundWrite = reader.ReadBool();
                        this.m_SaveDelay = reader.ReadTimeSpan();

                        this.m_WarningDelays = new List<TimeSpan>();
                        int count = reader.ReadInt();

                        for (int i = 0; i < count; i++)
                        {
                            this.m_WarningDelays.Add(reader.ReadTimeSpan());
                        }

                        this.m_NoIOHour = reader.ReadInt();

                        this.m_EnableEmergencyBackups = reader.ReadBool();
                        this.m_EmergencyBackupHour = reader.ReadInt();
                        this.m_CompressionLevel = (CompressionLevel)reader.ReadByte();
                        break;
                    }
            }
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
		public override void Deserialize(GenericReader reader)
		{
			int version = reader.ReadInt();

			switch (version)
			{
				case 0:
					{
						SavesEnabled = reader.ReadBool();
						SaveAccessLevel = (AccessLevel)reader.ReadByte();
						_SaveStrategy = ((SaveStrategyTypes)reader.ReadByte()).GetSaveStrategy();
						AllowBackgroundWrite = reader.ReadBool();
						SaveDelay = reader.ReadTimeSpan();
						WarningDelays = new List<TimeSpan>();

						int count = reader.ReadInt();

						for (int i = 0; i < count; i++)
						{
							WarningDelays.Add(reader.ReadTimeSpan());
						}

						NoIOHour = reader.ReadInt();

						EnableEmergencyBackups = reader.ReadBool();
						EmergencyBackupHour = reader.ReadInt();
						Compression = (CompressionLevel)reader.ReadByte();
						break;
					}
			}
		}