当前位置: 首页>>代码示例>>C#>>正文


C# BinaryFileWriter.Close方法代码示例

本文整理汇总了C#中Server.BinaryFileWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryFileWriter.Close方法的具体用法?C# BinaryFileWriter.Close怎么用?C# BinaryFileWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Server.BinaryFileWriter的用法示例。


在下文中一共展示了BinaryFileWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

		public static void Serialize(FileInfo file, Action<GenericWriter> serializer)
		{
			file.Refresh();

			if (file.Directory != null && !file.Directory.Exists)
			{
				file.Directory.Create();
			}

			if (!file.Exists)
			{
				file.Create().Close();
			}
				
			file.Refresh();

			using (var fs = file.OpenWrite())
			{
				var writer = new BinaryFileWriter(fs, true);

				try
				{
					serializer(writer);
				}
				finally
				{
					writer.Flush();
					writer.Close();
				}
			}
		}
开发者ID:Crome696,项目名称:ServUO,代码行数:31,代码来源:Persistence.cs

示例2: CustomSeperateSave

        public static void CustomSeperateSave(SeperateSaveData data)
        {
            GenericWriter writer = new BinaryFileWriter(Path.Combine(data.SaveLocation, data.SaveName + ".bin"), true);
            DirectoryCheck(data.SaveLocation);

            data.SaveMethod(writer);
            writer.Write(writer.Position);
            writer.Close();
        }
开发者ID:kamronbatman,项目名称:Defiance-AOS-Pre-2012,代码行数:9,代码来源:CustomSaving.cs

示例3: OnSave

		private static void OnSave( WorldSaveEventArgs e )
		{try{

			if ( !Directory.Exists( "Saves/Gumps/" ) )
				Directory.CreateDirectory( "Saves/Gumps/" );

			GenericWriter writer = new BinaryFileWriter( Path.Combine( "Saves/Gumps/", "Gumps.bin" ), true );

			writer.Write( 0 ); // version

			ArrayList list = new ArrayList();

			GumpInfo gumpi;
			foreach( object obj in new ArrayList( s_Infos.Values ) )
			{
				if ( !(obj is Hashtable) )
					continue;

				foreach( object obje in new ArrayList( ((Hashtable)obj).Values ) )
				{
					if ( !(obje is GumpInfo ) )
						continue;

					gumpi = (GumpInfo)obje;

					if ( gumpi.Mobile != null
					&& gumpi.Mobile.Player
					&& !gumpi.Mobile.Deleted
					&& gumpi.Mobile.Account != null
					&& ((Account)gumpi.Mobile.Account).LastLogin > DateTime.Now - TimeSpan.FromDays( 30 ) )
						list.Add( obje );
				}
			}

			writer.Write( list.Count );

			foreach( GumpInfo info in list )
				info.Save( writer );

			writer.Close();

		}catch{ Errors.Report( "GumpInfo-> OnSave" ); } }
开发者ID:greeduomacro,项目名称:uodarktimes-1,代码行数:42,代码来源:GumpInfo.cs

示例4: Save

		public static void Save()
		{
            try
            {
                if (!Directory.Exists(General.SavePath))
                    Directory.CreateDirectory(General.SavePath);

                GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "Gumps.bin"), true);

                writer.Write(0); // version

                writer.Write(s_ForceMenu);
                writer.Write(s_ForceInfos.Count);
                foreach (GumpInfo ginfo in s_ForceInfos.Values)
                    ginfo.Save(writer);

                ArrayList list = new ArrayList();
                GumpInfo info;

                foreach (object o in new ArrayList(s_Infos.Values))
                {
                    if (!(o is Hashtable))
                        continue;

                    foreach (object ob in new ArrayList(((Hashtable)o).Values))
                    {
                        if (!(ob is GumpInfo))
                            continue;

                        info = (GumpInfo)ob;

                        if (info.Mobile != null
                        && info.Mobile.Player
                        && !info.Mobile.Deleted
                        && info.Mobile.Account != null
                        && ((Account)info.Mobile.Account).LastLogin > DateTime.Now - TimeSpan.FromDays(30))
                            list.Add(ob);
                    }
                }

                writer.Write(list.Count);

                foreach (GumpInfo ginfo in list)
                    ginfo.Save(writer);

                writer.Close();
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(199));
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
		}
开发者ID:Jascen,项目名称:UOSmart,代码行数:55,代码来源:GumpInfo.cs

示例5: HandleError

        private static void HandleError(Exception error, string name, object[] loadinfo)
        {
            bool sep = loadinfo == null;
            bool nerr = error == null;
            string type = sep ? "seperate savefile" : "save module";
            string placename = sep ? "the file can be found at" : "this module was indexed under the name";

            Console.WriteLine();
            if (nerr)
            {
                Console.WriteLine("The loading and saving methods of a {0} are inconsistent, {1} \"{2}\".", type, placename, name);
                if (!sep && (bool)loadinfo[3])
                    Console.WriteLine("More data was read than written.");
                else
                    Console.WriteLine("More data was written than read.");
            }
            else
            {
                Console.WriteLine("During the loading of a {0} an exception was caught, {1} \"{2}\".", type, placename, name);
                Console.WriteLine("The following error was caught:");
                Console.WriteLine(error.ToString());
            }

            Console.WriteLine("Please Review your Save/Load methods for this {0}", sep ? "file" : "module");

            if (!m_IgnoreErrors)
            {
                string str = sep ? "Do you wish to continue loading with faulty data(Y), or stop the program(N)?" : "Do you wish to remove this module and restart(Y), or continue loading with faulty data(N)?";
                Console.WriteLine(str);

                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                {
                    if (!sep)
                    {
                        int oldcount = (int)loadinfo[0];
                        int location = (int)loadinfo[1];
                        BinaryFileReader idxreader = (BinaryFileReader)loadinfo[2];

                        int newcount = oldcount - 1;
                        string[] indexarray = new string[newcount];
                        long[] binposarray = new long[newcount];
                        long[] finposarray = new long[newcount];

                        idxreader.Seek(0, SeekOrigin.Begin);
                        idxreader.ReadInt();
                        int loc = 0;
                        for (int j = 0; j < oldcount; j++)
                        {
                            if (j != location)
                            {
                                indexarray[loc] = idxreader.ReadString();
                                binposarray[loc] = idxreader.ReadLong();
                                finposarray[loc] = idxreader.ReadLong();
                                loc++;
                            }
                            else
                            {
                                idxreader.ReadString();
                                idxreader.ReadLong();
                                idxreader.ReadLong();
                            }
                        }
                        idxreader.Close();
                        GenericWriter idxwriter = new BinaryFileWriter(m_FullPath + ".idx", true);

                        idxwriter.Write(newcount);
                        for (int j = 0; j < newcount; j++)
                        {
                            idxwriter.Write(indexarray[j]);
                            idxwriter.Write(binposarray[j]);
                            idxwriter.Write(finposarray[j]);
                        }
                        idxwriter.Close();

                        Process.Start(Core.ExePath, Core.Arguments);
                        Core.Process.Kill();
                    }
                }

                else if (sep)
                    Core.Process.Kill();
            }
        }
开发者ID:kamronbatman,项目名称:Defiance-AOS-Pre-2012,代码行数:83,代码来源:CustomSaving.cs

示例6: Save

		// Saves blue mage information to it's own file at Saves/BlueMagic/.
		public static void Save( WorldSaveEventArgs e )
		{
			if ( !Directory.Exists( "Saves/BlueMagic/" ) )
				Directory.CreateDirectory( "Saves/BlueMagic/" );

			if ( BlueMageSpells.Keys.Count > 0 )
			{
				BinaryFileWriter writer = new BinaryFileWriter( "Saves/BlueMagic/MobileAndSpellList.bin", false );

				writer.Write( (int)BlueMageSpells.Keys.Count );
				writer.Write( (int)SPELLCOUNT );

				foreach( KeyValuePair<Serial, bool[]> kvp in BlueMageSpells )
				{
					writer.Write( (Serial)kvp.Key );

					for( int j = 0; j < kvp.Value.Length; j++ )
					{
						writer.Write( (bool)kvp.Value[j] );
					}
				}

				writer.Close();
				PrintBlueMageLog();
			}
		}
开发者ID:greeduomacro,项目名称:cov-shard-svn-1,代码行数:27,代码来源:BlueMageControl.cs

示例7: SaveGlobalOptions

        public static void SaveGlobalOptions()
        {
            CleanUpData();

            if (!Directory.Exists(General.SavePath))
                Directory.CreateDirectory(General.SavePath);

            GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "GlobalOptions.bin"), true);

            writer.Write(2); // version

            writer.Write(s_MultiPort);
            writer.Write(s_MultiServer);

            writer.Write(s_Notifications.Count);
            foreach (Notification not in s_Notifications)
                not.Save(writer);

            writer.Write(s_Filters.Count);
            foreach (string str in s_Filters)
                writer.Write(str);

            writer.Write((int)s_FilterPenalty);
            writer.Write((int)s_MacroPenalty);
            writer.Write(s_MaxMsgs);
            writer.Write(s_ChatSpam);
            writer.Write(s_MsgSpam);
            writer.Write(s_RequestSpam);
            writer.Write(s_FilterBanLength);
            writer.Write(s_FilterWarnings);
            writer.Write(s_AntiMacroDelay);
            writer.Write(s_IrcPort);
            writer.Write(s_IrcMaxAttempts);
            writer.Write(s_IrcEnabled);
            writer.Write(s_IrcAutoConnect);
            writer.Write(s_IrcAutoReconnect);
            writer.Write(s_FilterSpeech);
            writer.Write(s_FilterMsg);
            writer.Write(s_Debug);
            writer.Write(s_LogChat);
            writer.Write(s_LogPms);
            writer.Write((int)s_IrcStaffColor);
            writer.Write(s_IrcServer);
            writer.Write(s_IrcRoom);
            writer.Write(s_IrcNick);
            writer.Write(s_TotalChats+1);

            writer.Close();
        }
开发者ID:guy489,项目名称:runuot2a,代码行数:49,代码来源:Data.cs

示例8: SaveBackup

        public static void SaveBackup( Mobile mobile, ArrayList ArgsList )
        {
            MC.SetProcess( Process.SaveBackup );

            if ( !Directory.Exists( MC.BackupDirectory ) )
                Directory.CreateDirectory( MC.BackupDirectory );

            string path = Path.Combine( MC.BackupDirectory, "Backup.mbk" );

            mobile.SendMessage( "Creating backup file..." );

            MC.CheckSpawners();

            ArrayList SpawnerList = CompileSpawnerList();

            GenericWriter writer;

            try
            {
                writer = new BinaryFileWriter( path, true );
            }
            catch(Exception ex)
            {
                MC.SetProcess( Process.None );

                ArgsList[2] = "Create Backup File";
                ArgsList[4] = String.Format( "Exception caught:\n{0}", ex );

                mobile.SendGump( new FileMenuGump( mobile, ArgsList ) );

                return;
            }

            writer.Write( SpawnerList.Count );

            try
            {
                foreach ( MegaSpawner megaSpawner in SpawnerList )
                    Serialize( megaSpawner, writer );
            }
            catch{}

            writer.Close();

            MC.SetProcess( Process.None );

            ArgsList[2] = "Create Backup File";
            ArgsList[4] = "All Mega Spawners have now been backed up to the backup file.";

            mobile.SendGump( new FileMenuGump( mobile, ArgsList ) );
        }
开发者ID:cynricthehun,项目名称:UOLegends,代码行数:51,代码来源:BackupSystem.cs

示例9: Save

		public static void Save( WorldSaveEventArgs args )
		{
			if( !Directory.Exists( "Saves/ACC" ) )
				Directory.CreateDirectory( "Saves/ACC" );

			string filename = "acc.sav";
			string path [email protected]"Saves/ACC/";
			string pathNfile = path+filename;
			DateTime start = DateTime.Now;

			Console.WriteLine();
			Console.WriteLine();
			Console.WriteLine( "----------" );
			Console.WriteLine( "Saving ACC..." );

			try
			{
				using( FileStream m_FileStream = new FileStream( pathNfile, FileMode.OpenOrCreate, FileAccess.Write ) )
				{
					BinaryFileWriter writer = new BinaryFileWriter( m_FileStream, true );

					writer.Write( (int) m_RegSystems.Count );
					foreach( DictionaryEntry de in m_RegSystems )
					{
						Type t = ScriptCompiler.FindTypeByFullName( (string)de.Key );
						if( t != null )
						{
							writer.Write( (string)de.Key );
							writer.Write( (bool)de.Value );

							if( (bool)m_RegSystems[(string)de.Key] )
							{
								ACCSystem system = (ACCSystem)Activator.CreateInstance( t );
								if( system != null )
									system.StartSave( path );
							}
						}

					}

					writer.Close();
					m_FileStream.Close();
				}

				Console.WriteLine( "Done in {0:F1} seconds.", (DateTime.Now-start).TotalSeconds );
				Console.WriteLine( "----------" );
				Console.WriteLine();
			}
			catch( Exception err )
			{
				Console.WriteLine( "Failed. Exception: "+err );
			}
		}
开发者ID:greeduomacro,项目名称:cov-shard-svn-1,代码行数:53,代码来源:ACC.cs

示例10: Save

        public static void Save()
        {
            log.Info("Saving...");
            log.Info(String.Format("idxPath: '{0}'", idxPath));
            log.Info(String.Format("binPath: '{0}'", binPath));

            if (!Directory.Exists(Path.Combine("Saves", "Donation")))
                Directory.CreateDirectory(Path.Combine("Saves", "Donation"));

            GenericWriter idx = new BinaryFileWriter(idxPath, false);
            GenericWriter bin = new BinaryFileWriter(binPath, true);

            log.Info(String.Format("m_ClaimedOrders.Count: '{0}'", m_ClaimedOrders.Count));
            idx.Write((int)m_ClaimedOrders.Count);
            foreach (ClaimedOrder claimed in m_ClaimedOrders)
            {
                long startPos = bin.Position;
                claimed.Serialize(bin);
                idx.Write((long)startPos);
                idx.Write((int)(bin.Position - startPos));
            }
            idx.Close();
            bin.Close();
            log.Info("Saving done.");
        }
开发者ID:kamronbatman,项目名称:Defiance-AOS-Pre-2012,代码行数:25,代码来源:Donation.cs

示例11: Serialize

        public static void Serialize(BinaryFileWriter writer)
        {
            writer.Write((int)0); //Version

            writer.Write((int)AllianceLimit);
            writer.Write((bool)useXML);
            writer.Write((int)Alliances.Count);

            foreach (BaseAlliance a in Alliances)
            {
                a.Serialize(writer);
            }

            writer.Close();
        }
开发者ID:greeduomacro,项目名称:hubroot,代码行数:15,代码来源:Alliances.cs

示例12: Save

        public static void Save(WorldSaveEventArgs e)
        {
            if (XmlAttach.MobileAttachments == null && XmlAttach.ItemAttachments == null) return;

            CleanUp();

            if (!Directory.Exists("Saves/Attachments"))
                Directory.CreateDirectory("Saves/Attachments");

            string filePath = Path.Combine("Saves/Attachments", "Attachments.bin");        // the attachment serializations
            string imaPath = Path.Combine("Saves/Attachments", "Attachments.ima");         // the item/mob attachment tables
            string fpiPath = Path.Combine("Saves/Attachments", "Attachments.fpi");        // the file position indices

            BinaryFileWriter writer = null;
            BinaryFileWriter imawriter = null;
            BinaryFileWriter fpiwriter = null;

            try
            {
                writer = new BinaryFileWriter(filePath, true);
                imawriter = new BinaryFileWriter(imaPath, true);
                fpiwriter = new BinaryFileWriter(fpiPath, true);

            }
            catch (Exception err)
            {
                ErrorReporter.GenerateErrorReport(err.ToString());
                return;
            }

            if (writer != null && imawriter != null && fpiwriter != null)
            {
                // save the current global attachment serial state
                ASerial.GlobalSerialize(writer);

                // remove all deleted attachments
                XmlAttach.FullDefrag();

                // save the attachments themselves
                if (XmlAttach.AllAttachments != null)
                {
                    writer.Write(XmlAttach.AllAttachments.Count);

                    object[] valuearray = new object[XmlAttach.AllAttachments.Count];
                    XmlAttach.AllAttachments.Values.CopyTo(valuearray, 0);

                    object[] keyarray = new object[XmlAttach.AllAttachments.Count];
                    XmlAttach.AllAttachments.Keys.CopyTo(keyarray, 0);

                    for (int i = 0; i < keyarray.Length; i++)
                    {
                        // write the key
                        writer.Write((int)keyarray[i]);

                        XmlAttachment a = valuearray[i] as XmlAttachment;

                        // write the value type
                        writer.Write((string)a.GetType().ToString());

                        // serialize the attachment itself
                        a.Serialize(writer);

                        // save the fileposition index
                        fpiwriter.Write((long)writer.Position);
                    }
                }
                else
                {
                    writer.Write((int)0);
                }

                writer.Close();

                // save the hash table info for items and mobiles
                // mobile attachments
                if (XmlAttach.MobileAttachments != null)
                {
                    imawriter.Write(XmlAttach.MobileAttachments.Count);

                    object[] valuearray = new object[XmlAttach.MobileAttachments.Count];
                    XmlAttach.MobileAttachments.Values.CopyTo(valuearray, 0);

                    object[] keyarray = new object[XmlAttach.MobileAttachments.Count];
                    XmlAttach.MobileAttachments.Keys.CopyTo(keyarray, 0);

                    for (int i = 0; i < keyarray.Length; i++)
                    {
                        // write the key
                        imawriter.Write((Mobile)keyarray[i]);

                        // write out the attachments
                        ArrayList alist = (ArrayList)valuearray[i];

                        imawriter.Write((int)alist.Count);
                        foreach (XmlAttachment a in alist)
                        {
                            // write the attachment serial
                            imawriter.Write((int)a.Serial.Value);

                            // write the value type
//.........这里部分代码省略.........
开发者ID:greeduomacro,项目名称:vivre-uo,代码行数:101,代码来源:XmlAttach.cs

示例13: OnSave

		public static void OnSave(WorldSaveEventArgs e)
		{
			try
			{
				Console.WriteLine("KinCityManager Saving...");
				if (!Directory.Exists("Saves/AngelIsland"))
					Directory.CreateDirectory("Saves/AngelIsland");

				string filePath = Path.Combine("Saves/AngelIsland", "KinCityManager.bin");

				GenericWriter writer;
				writer = new BinaryFileWriter(filePath, true);

				writer.Write(1); //version

				//v1 below
				//write out the city data class'
				writer.Write(_cityData.Count);
				foreach (KeyValuePair<KinFactionCities, KinCityData> pair in _cityData)
					pair.Value.Save(writer);

				writer.Close();
			}
			catch (Exception ex)
			{
				System.Console.WriteLine("Error saving KinCityManager!");
				Scripts.Commands.LogHelper.LogException(ex);
			}
		}
开发者ID:zerodowned,项目名称:angelisland,代码行数:29,代码来源:KinCityManager.cs

示例14: Save

        public static void Save()
        {
            try
            {
                if (!Directory.Exists(General.SavePath))
                    Directory.CreateDirectory(General.SavePath);

                GenericWriter writer = new BinaryFileWriter(Path.Combine(General.SavePath, "Channels.bin"), true);

                writer.Write(0); // version

                writer.Write(s_Channels.Count);
                foreach (Channel c in s_Channels)
                {
                    writer.Write(c.GetType().ToString());
                    c.Save(writer);
                }

                writer.Close();
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(187));
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
        }
开发者ID:FreeReign,项目名称:imaginenation,代码行数:28,代码来源:Channel.cs

示例15: SerializeMessages

		public static void SerializeMessages()
		{
			if( !Directory.Exists( SavePath ) )
				Directory.CreateDirectory( SavePath );

			BinaryFileWriter writer = new BinaryFileWriter( SaveFile, true );

			writer.Write( (int)_messageTable.Count );

			if( _messageTable.Count > 0 )
			{
				foreach( KeyValuePair<Mobile, List<ChatMessage>> kvp in _messageTable )
				{
					if( kvp.Key == null || kvp.Key.Deleted || kvp.Value == null )
					{
						writer.Write( (int)-1 );
					}
					else
					{
						writer.Write( (int)kvp.Key.Serial );

						writer.Write( (int)kvp.Value.Count );
						kvp.Value.ForEach(
							delegate( ChatMessage message )
							{
								message.Serialize( writer );
							} );
					}
				}
			}

			writer.Close();
		}
开发者ID:greeduomacro,项目名称:hubroot,代码行数:33,代码来源:ChatMessageManager.cs


注:本文中的Server.BinaryFileWriter.Close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。