コード例 #1
0
        private void SaveSingleContainer(
            ArchiveConcurrentSerializer headerSerializer,
            byte[][] containerData,
            int id)
        {
            object            childContainer    = this._childContainers[id];
            ArchiveSerializer archiveSerializer = new ArchiveSerializer();
            SaveEntryFolder   rootFolder1       = SaveEntryFolder.CreateRootFolder();
            SaveEntryFolder   rootFolder2       = SaveEntryFolder.CreateRootFolder();
            ContainerType     containerType;

            childContainer.GetType().IsContainer(out containerType);
            ContainerSaveData containerSaveData = new ContainerSaveData((ISaveContext)this, id, childContainer, containerType);

            containerSaveData.CollectChildren();
            containerSaveData.CollectStructs();
            containerSaveData.CollectMembers();
            containerSaveData.CollectStrings();
            containerSaveData.SaveHeaderTo(rootFolder2, (IArchiveContext)headerSerializer);
            containerSaveData.SaveTo(rootFolder1, (IArchiveContext)archiveSerializer);
            headerSerializer.SerializeFolderConcurrent(rootFolder2);
            archiveSerializer.SerializeFolder(rootFolder1);
            byte[] binaryData = archiveSerializer.FinalizeAndGetBinaryData();
            containerData[id] = binaryData;
        }
コード例 #2
0
 public bool Save(object target, MetaData metaData)
 {
     Debug.Print("SaveContext::Save");
     try
     {
         this.RootObject = target;
         using (new PerformanceTestBlock("SaveContext::Save"))
         {
             BinaryWriterFactory.Initialize();
             this.CollectObjects();
             ArchiveConcurrentSerializer headerSerializer = new ArchiveConcurrentSerializer();
             byte[][] objectData = new byte[this._childObjects.Count][];
             using (new PerformanceTestBlock("SaveContext::Saving Objects"))
                 TWParallel.For(0, this._childObjects.Count, (Action <int>)(i => this.SaveSingleObject(headerSerializer, objectData, i)));
             byte[][] containerData = new byte[this._childContainers.Count][];
             using (new PerformanceTestBlock("SaveContext::Saving Containers"))
                 TWParallel.For(0, this._childContainers.Count, (Action <int>)(i => this.SaveSingleContainer(headerSerializer, containerData, i)));
             using (new PerformanceTestBlock("SaveContext::SaveObjects config"))
             {
                 SaveEntryFolder rootFolder   = SaveEntryFolder.CreateRootFolder();
                 BinaryWriter    binaryWriter = BinaryWriterFactory.GetBinaryWriter();
                 binaryWriter.WriteInt(this._idsOfChildObjects.Count);
                 binaryWriter.WriteInt(this._strings.Count);
                 binaryWriter.WriteInt(this._idsOfChildContainers.Count);
                 rootFolder.CreateEntry(new EntryId(-1, SaveEntryExtension.Config)).FillFrom(binaryWriter);
                 headerSerializer.SerializeFolderConcurrent(rootFolder);
                 BinaryWriterFactory.ReleaseBinaryWriter(binaryWriter);
             }
             ArchiveSerializer archiveSerializer = new ArchiveSerializer();
             using (new PerformanceTestBlock("SaveContext::SaveObjects strings"))
             {
                 SaveEntryFolder rootFolder = SaveEntryFolder.CreateRootFolder();
                 SaveEntryFolder folder     = archiveSerializer.CreateFolder(rootFolder, new FolderId(-1, SaveFolderExtension.Strings), this._strings.Count);
                 for (int index = 0; index < this._strings.Count; ++index)
                 {
                     string str = this._strings[index];
                     SaveContext.SaveStringTo(folder, index, str);
                 }
                 archiveSerializer.SerializeFolder(rootFolder);
             }
             byte[] header  = (byte[])null;
             byte[] strings = (byte[])null;
             using (new PerformanceTestBlock("SaveContext::FinalizeAndGetBinaryHeaderDataConcurrent"))
                 header = headerSerializer.FinalizeAndGetBinaryDataConcurrent();
             using (new PerformanceTestBlock("SaveContext::FinalizeAndGetBinaryStringDataConcurrent"))
                 strings = archiveSerializer.FinalizeAndGetBinaryData();
             this.SaveData = new GameData(header, strings, objectData, containerData);
             BinaryWriterFactory.Release();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #3
0
        private void SaveSingleObject(
            ArchiveConcurrentSerializer headerSerializer,
            byte[][] objectData,
            int id)
        {
            object            childObject       = this._childObjects[id];
            ArchiveSerializer archiveSerializer = new ArchiveSerializer();
            SaveEntryFolder   rootFolder1       = SaveEntryFolder.CreateRootFolder();
            SaveEntryFolder   rootFolder2       = SaveEntryFolder.CreateRootFolder();
            ObjectSaveData    objectSaveData    = new ObjectSaveData((ISaveContext)this, id, childObject, true);

            objectSaveData.CollectStructs();
            objectSaveData.CollectMembers();
            objectSaveData.CollectStrings();
            objectSaveData.SaveHeaderTo(rootFolder2, (IArchiveContext)headerSerializer);
            objectSaveData.SaveTo(rootFolder1, (IArchiveContext)archiveSerializer);
            headerSerializer.SerializeFolderConcurrent(rootFolder2);
            archiveSerializer.SerializeFolder(rootFolder1);
            byte[] binaryData = archiveSerializer.FinalizeAndGetBinaryData();
            objectData[id] = binaryData;
        }