Пример #1
0
        public void SerializeNow()
        {
            // for init
            root_item          = new CatalogItem();
            catalog_table      = new CatalogTable();
            folderStack        = new Stack <CatalogItem>();
            stateRecord        = new StateRecord();
            disk               = new Disk();
            root_item.fileName = "root";
            File root_file = new File(root_item);

            root_file.Path = "root";
            catalog_table.map(root_item, root_file);
            current_item = root_item;

            FileStream      fileStream = new FileStream(System.IO.Path.Combine(dir, "catalogTree.dat"), FileMode.Create);
            BinaryFormatter b          = new BinaryFormatter();

            b.Serialize(fileStream, root_item);
            fileStream.Close();

            FileStream fileStream2 = new FileStream(System.IO.Path.Combine(dir, "catalogTable.dat"), FileMode.Create);

            b.Serialize(fileStream2, catalog_table);
            fileStream2.Close();

            FileStream fileStream3 = new FileStream(System.IO.Path.Combine(dir, "disk.dat"), FileMode.Create);

            b.Serialize(fileStream3, disk);
            fileStream3.Close();

            stateRecord.fileCount = CatalogItem.fileCount;
            FileStream fileStream4 = new FileStream(System.IO.Path.Combine(dir, "stateRecord.dat"), FileMode.Create);

            b.Serialize(fileStream4, stateRecord);
            fileStream4.Close();
        }
Пример #2
0
        public void DeSerializeNow()
        {
            FileStream      fileStream = new FileStream(System.IO.Path.Combine(dir, "catalogTree.dat"), FileMode.Open, FileAccess.Read, FileShare.Read);
            BinaryFormatter b          = new BinaryFormatter();

            root_item = b.Deserialize(fileStream) as CatalogItem;
            fileStream.Close();

            FileStream fileStream2 = new FileStream(System.IO.Path.Combine(dir, "catalogTable.dat"), FileMode.Open, FileAccess.Read, FileShare.Read);

            catalog_table = b.Deserialize(fileStream2) as CatalogTable;
            fileStream2.Close();

            FileStream fileStream3 = new FileStream(System.IO.Path.Combine(dir, "disk.dat"), FileMode.Open, FileAccess.Read, FileShare.Read);

            disk = b.Deserialize(fileStream3) as Disk;
            fileStream3.Close();

            FileStream fileStream4 = new FileStream(System.IO.Path.Combine(dir, "stateRecord.dat"), FileMode.Open, FileAccess.Read, FileShare.Read);

            stateRecord = b.Deserialize(fileStream4) as StateRecord;
            fileStream3.Close();
            CatalogItem.fileCount = stateRecord.fileCount;
        }