Пример #1
0
        static void CopyIndex(ArchiveIndexFile indexFile, ArchiveIndexFile oldIndexFile, ArchiveObj serializeObj)
        {
            if (oldIndexFile == null)
            {
                return;
            }

            serializeObj.Foreach((obj) =>
            {
                Profiler.BeginSample("only copy index:" + obj.key);

                ArchiveIndex index = oldIndexFile.GetArchiveIndex(obj.key);
                if (index != null)
                {
                    indexFile.Add(obj.key, index);
                }

                Profiler.EndSample();
            });
        }
Пример #2
0
        void WriteRecord(ArchiveIndexFile indexFile, ArchiveObj serializeObj)
        {
            if (serializeObj.hasNonYird)
            {
                string filePath = GetFilePath(dir, serializeObj.recordName);

                using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter writer = new BinaryWriter(fileStream))
                    {
                        indexFile.header.Write(writer);
                        indexFile.header.BeginWriteCheckSum(writer);

                        serializeObj.Foreach((obj) =>
                        {
                            if (!obj.yird)
                            {
                                Profiler.BeginSample("save:" + obj.key);
                                long beginPos = fileStream.Position;
                                obj.serialize.Serialize(new PeRecordWriter(obj.key, writer));
                                long endPos = fileStream.Position;

                                indexFile.Add(obj.key, new ArchiveIndex(serializeObj.recordName, obj.yird, beginPos, endPos));
                                Profiler.EndSample();
                            }
                        });

                        indexFile.header.EndWriteCheckSum(writer);
                    }
                }
            }

            if (serializeObj.hasYird)
            {
                string yirdDir      = indexFile.GetYirdDir(dir);
                string yirdFilePath = GetFilePath(yirdDir, serializeObj.recordName);

                if (!Directory.Exists(yirdDir))
                {
                    Directory.CreateDirectory(yirdDir);
                }

                using (FileStream yirdFileStream = new FileStream(yirdFilePath, FileMode.Create, FileAccess.Write))
                {
                    using (BinaryWriter yirdWriter = new BinaryWriter(yirdFileStream))
                    {
                        indexFile.header.Write(yirdWriter);
                        indexFile.header.BeginWriteCheckSum(yirdWriter);

                        serializeObj.Foreach((obj) =>
                        {
                            Profiler.BeginSample("save:" + obj.key);

                            if (obj.yird)
                            {
                                long beginPos = yirdFileStream.Position;

                                obj.serialize.Serialize(new PeRecordWriter(obj.key, yirdWriter));

                                long endPos = yirdFileStream.Position;

                                indexFile.Add(obj.key, new ArchiveIndex(serializeObj.recordName, obj.yird, beginPos, endPos));
                            }

                            Profiler.EndSample();
                        });

                        indexFile.header.EndWriteCheckSum(yirdWriter);
                    }
                }
            }
        }