Exemplo n.º 1
0
        //public void ReadFileFromTape(BackupFile objBackupFile)
        //{
        //    TapeOperator objTapeOperator;
        //    FileStream objFileStream;
        //    byte[] objReadBytes;
        //    Console.WriteLine("ReadFileFromTape Method");
        //    Console.WriteLine("Initializing the tape drive...");
        //    objTapeOperator = new TapeOperator();
        //    objTapeOperator.Load(TapeName);
        //    Console.WriteLine("I'm Setting the tape position...");
        //    objTapeOperator.SetTapePosition(objBackupFile.StartTapeLocation);
        //    Console.WriteLine("Tape Position is " + objTapeOperator.GetTapePosition());
        //    Console.WriteLine("Creating the file on disk...");
        //    objFileStream = new FileStream(objBackupFile.NewFileNameAndPath, FileMode.OpenOrCreate, FileAccess.Write);
        //    if (objBackupFile.isLargeFile)
        //    {
        //        Console.WriteLine("This file will take " + objBackupFile.FileChunkCount + " Passes to read...");
        //        for (int intCounter = 1; intCounter <= objBackupFile.FileChunkCount; intCounter++)
        //        {
        //            if (intCounter < objBackupFile.FileChunkCount)
        //            {
        //                Console.WriteLine("This is pass " + intCounter);
        //                Console.WriteLine("Now I'm Reading file from tape into memory...");
        //                objReadBytes = objTapeOperator.Read(objTapeOperator.GetTapePosition(), BackupFile.MaxMemoryChunk);
        //                //objReadBytes = objTapeOperator.Read(objBackupFile.StartTapeLocation * intCounter, BackUpFile.MaxMemoryChunk);
        //                Console.WriteLine("Now I'm Writing file to disk...");
        //                objFileStream.Write(objReadBytes, 0, objReadBytes.Length);
        //            }
        //            else
        //            {
        //                Console.WriteLine("This is pass " + intCounter);
        //                Console.WriteLine("Now I'm Reading file from tape into memory...");
        //                objReadBytes = objTapeOperator.Read(objTapeOperator.GetTapePosition(), (int)(objBackupFile.Size - BackupFile.MaxMemoryChunk * (intCounter - 1)));
        //                Console.WriteLine("Now I'm Writing file to disk...");
        //                objFileStream.Write(objReadBytes, 0, objReadBytes.Length);
        //            }
        //        }
        //    }
        //    else
        //    {
        //        Console.WriteLine("Now I'm Reading file from tape into memory...");
        //        objReadBytes = objTapeOperator.Read(objBackupFile.StartTapeLocation, objBackupFile.Size);
        //        Console.WriteLine("Now I'm Writing file to disk...");
        //        objFileStream.Write(objReadBytes, 0, objReadBytes.Length);
        //    }
        //    Console.WriteLine("Tape Position is " + objTapeOperator.GetTapePosition());
        //    Console.WriteLine("Now I'm Cleaning up resources...");
        //    objFileStream.Close();
        //    objTapeOperator.Close();
        //    Console.WriteLine("Now I'm Done!");
        //    Console.WriteLine();
        //}
        public void ReadFilesFromTape(BackupFiles objBackupFiles)
        {
            Console.WriteLine("ReadFilesFromTape Method");
            Console.WriteLine("Initializing the tape drive...");
            TapeOperator = new TapeOperator();
            TapeOperator.Load(TapeName);

            foreach (BackupFile objBackupFile in objBackupFiles)
            {
                Console.WriteLine("I'm Setting the tape position...");
                TapeOperator.SetTapePosition(objBackupFile.StartTapeLocation);
                Console.WriteLine("Tape Position is " + TapeOperator.GetTapePosition());

                Console.WriteLine("Creating the file on disk...");
                FileStreamToWrite = new FileStream(objBackupFile.NewFileNameAndPath, FileMode.OpenOrCreate, FileAccess.Write);

                if (objBackupFile.isLargeFile)
                {
                    Console.WriteLine("This file will take " + objBackupFile.FileChunkCount + " Passes to read...");
                    for (int intCounter = 1; intCounter <= objBackupFile.FileChunkCount; intCounter++)
                    {
                        if (intCounter < objBackupFile.FileChunkCount)
                        {
                            ReadBytes = null;//clears the memory...
                            GC.Collect();

                            Console.WriteLine("This is pass " + intCounter);
                            Console.WriteLine("Now I'm Reading file from tape into memory...");
                            ReadBytes = TapeOperator.Read(TapeOperator.GetTapePosition(), BackupFile.MaxMemoryChunk);
                            //objReadBytes = objTapeOperator.Read(objBackupFile.StartTapeLocation * intCounter, BackUpFile.MaxMemoryChunk);

                            Console.WriteLine("Now I'm Writing file to disk...");
                            FileStreamToWrite.Write(ReadBytes, 0, ReadBytes.Length);
                        }
                        else
                        {
                            ReadBytes = null;//clears the memory...
                            GC.Collect();

                            Console.WriteLine("This is pass " + intCounter);
                            Console.WriteLine("Now I'm Reading file from tape into memory...");
                            ReadBytes = TapeOperator.Read(TapeOperator.GetTapePosition(), (int)(objBackupFile.Size - BackupFile.MaxMemoryChunk * (intCounter - 1)));

                            Console.WriteLine("Now I'm Writing file to disk...");
                            FileStreamToWrite.Write(ReadBytes, 0, ReadBytes.Length);
                        }

                    }
                }
                else
                {
                    ReadBytes = null;//clears the memory...
                    GC.Collect();

                    Console.WriteLine("Now I'm Reading file from tape into memory...");
                    ReadBytes = TapeOperator.Read(objBackupFile.StartTapeLocation, objBackupFile.Size);

                    Console.WriteLine("Now I'm Writing file to disk...");
                    FileStreamToWrite.Write(ReadBytes, 0, ReadBytes.Length);
                }
                Console.WriteLine("Tape Position is " + TapeOperator.GetTapePosition());
            }

            Console.WriteLine("Now I'm Cleaning up resources...");
            FileStreamToWrite.Close();
            TapeOperator.Close();

            Console.WriteLine("Now I'm Done!");
            Console.WriteLine();
        }