public OnGuildSaved ( int numberOfBytes ) : void | ||
numberOfBytes | int | |
Результат | void |
protected void SaveGuilds(SaveMetrics metrics) { GenericWriter idx; GenericWriter bin; if (UseSequentialWriters) { idx = new BinaryFileWriter(World.GuildIndexPath, false); bin = new BinaryFileWriter(World.GuildDataPath, true); } else { idx = new AsyncWriter(World.GuildIndexPath, false); bin = new AsyncWriter(World.GuildDataPath, true); } idx.Write(BaseGuild.List.Count); foreach (BaseGuild guild in BaseGuild.List.Values) { long start = bin.Position; idx.Write(0); // guilds have no typeid idx.Write(guild.Id); idx.Write(start); guild.Serialize(bin); if (metrics != null) { metrics.OnGuildSaved((int)(bin.Position - start)); } idx.Write((int)(bin.Position - start)); } idx.Close(); bin.Close(); }
private Task SaveGuilds() { //Start the blocking consumer; this runs in background. Task commitTask = StartCommitTask(_guildThreadWriters, _guildData, _guildIndex); IEnumerable <BaseGuild> guilds = BaseGuild.List.Values; //Start the producer. Parallel.ForEach( guilds, () => new QueuedMemoryWriter(), (guild, state, writer) => { long startPosition = writer.Position; guild.Serialize(writer); var size = (int)(writer.Position - startPosition); writer.QueueForIndex(guild, size); if (_metrics != null) { _metrics.OnGuildSaved(size); } return(writer); }, writer => { writer.Flush(); _guildThreadWriters.Add(writer); }); _guildThreadWriters.CompleteAdding(); //We only get here after the Parallel.ForEach completes. Lets our task return(commitTask); }
protected void SaveGuilds(SaveMetrics metrics) { GenericWriter idx; GenericWriter bin; if (UseSequentialWriters) { idx = new BinaryFileWriter( World.GuildIndexPath, false ); bin = new BinaryFileWriter( World.GuildDataPath, true ); } else { idx = new AsyncWriter( World.GuildIndexPath, false ); bin = new AsyncWriter( World.GuildDataPath, true ); } idx.Write( ( int ) BaseGuild.List.Count ); foreach ( BaseGuild guild in BaseGuild.List.Values ) { long start = bin.Position; idx.Write( ( int ) 0 );//guilds have no typeid idx.Write( ( int ) guild.Id ); idx.Write( ( long ) start ); guild.Serialize( bin ); if ( metrics != null ) { metrics.OnGuildSaved( ( int ) ( bin.Position - start ) ); } idx.Write( ( int ) ( bin.Position - start ) ); } idx.Close(); bin.Close(); }