コード例 #1
0
        private static void testCompression()
        {
            MyMaze3dGenerator smg = new MyMaze3dGenerator();
            Maze maze             = smg.generate(9, 6, 5);

            byte[] byets = ((Maze3d)maze).toByteArray();
            using (FileStream fileOutStream = new FileStream("1.maze", FileMode.Create))
            {
                using (MyCompressorStream outStream = new MyCompressorStream(fileOutStream, MyCompressorStream.Compress))
                {
                    outStream.Write(byets, 0, byets.Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream("1.maze", FileMode.Open))
            {
                using (MyCompressorStream inStream = new MyCompressorStream(fileInStream, MyCompressorStream.Decompress))
                {
                    mazeBytes = new byte[byets.Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine(loadedMaze.equals(maze));

            Console.WriteLine("*******************************");
            Console.WriteLine("Press any key to continue");
            Console.WriteLine();
            Console.ReadKey();
        }
コード例 #2
0
        /// <summary>
        /// Save Maze - Creates a compression of the maze and
        /// saves the file on the disk with a given file path
        /// </summary>
        /// <param name="mazeName">Maze name</param>
        /// <param name="path">File Name</param>
        /// <returns>True if successful saving the maze</returns>
        public bool saveMaze(string mazeName, string filePath)
        {
            //MessageBox.Show("save: " + mazeName);
            WinMaze winMaze     = m_currentWinMaze;
            Maze3d  currentMaze = winMaze.getMaze();

            add3dMaze(mazeName, currentMaze);
            if (isSolutionExists)
            {
                m_solutionsDictionary[mazeName] = mCurrentSolution;
            }

            if (currentMaze == null)
            {
                return(false);
            }
            using (FileStream fileOutStream = new FileStream(filePath, FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(currentMaze.toByteArray(), 0, currentMaze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            return(true);
        }
コード例 #3
0
        private static void TestMyCompressorStream()
        {
            IMazeGenerator mg   = new MyMaze3dGenerator();
            Maze           maze = mg.generate(10, 14, 5);

            Console.WriteLine("Test - My Stream Compressor");
            string filePath = @"compressedFile.txt";

            using (FileStream fileOutStream = new FileStream(filePath, FileMode.Create))
            {
                using (MyCompressorStream c = new MyCompressorStream(fileOutStream, 1))
                {
                    byte[] byteArray = ((Maze3d)maze).toByteArray();
                    int    length    = byteArray.Length;
                    Console.WriteLine();
                    for (int i = 0; i < byteArray.Length; i++)
                    {
                        Console.Write(byteArray[i]);
                    }
                    Console.WriteLine();

                    Console.WriteLine();
                    c.Write(byteArray, 0, length);
                }
            }
            Console.WriteLine();
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream(filePath, FileMode.Open))
            {
                using (MyCompressorStream inStream = new MyCompressorStream(fileInStream, 2))
                {
                    mazeBytes = new byte[(((Maze3d)maze).toByteArray()).Length];
                    int length = mazeBytes.Length;
                    inStream.Read(mazeBytes, 0, length);
                    Console.WriteLine();
                    Console.WriteLine("*** Data Bytes after reading from the file ***");
                    for (int i = 0; i < mazeBytes.Length; i++)
                    {
                        Console.Write(mazeBytes[i]);
                    }
                    Console.WriteLine();
                }
            }
            Console.WriteLine();
            Console.WriteLine("*******Before writing to the file*******");
            maze.print();
            Console.WriteLine("*******After reading from the file*******");
            Maze3d mazeAfterReading = new Maze3d(mazeBytes);

            mazeAfterReading.print();
        }
コード例 #4
0
ファイル: MyModel.cs プロジェクト: danafeld/Maze_MVC
        /// <summary>
        /// save the maze to disk
        /// </summary>
        /// <param name="maze_name">name of the file</param>
        /// <param name="filePath">path of the file</param>
        public void SaveMazeToDisk(string maze_name, string filePath)
        {
            byte[] mazeToByte;
            string fullPath = filePath + maze_name;

            using (Stream stream = new FileStream(fullPath, FileMode.Create))
            {
                using (Stream file_s = new MyCompressorStream(stream, 1))
                {
                    MyCompressorStream file_Str = file_s as MyCompressorStream;
                    mazeToByte = ((Maze3d)(m_DicOfMazes[maze_name])).toByteArray();
                    file_Str.Write(mazeToByte, 0, mazeToByte.Length);
                    file_Str.Flush();
                }
            }
        }
コード例 #5
0
ファイル: MyModel.cs プロジェクト: AdarOv/Maze
        /// <summary>
        /// Compress the maze 'mazeName' and save it into a file with a given path
        /// </summary>
        /// <param name="mazeName">the name of the maze to save</param>
        /// <param name="path">file path</param>
        /// <returns>true - for success, false for failure</returns>
        public bool saveMaze(string mazeName, string path)
        {
            Maze3d maze = retrieveMaze(mazeName);

            if (null == maze)
            {
                return(false);
            }
            using (FileStream fileOutStream = new FileStream(path, FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            return(true);
        }
コード例 #6
0
ファイル: MyModel.cs プロジェクト: adi-ronen/ATP-Project
 public void SaveToDisk(string mazeName, string path)
 {
     if (IsMazeExists(mazeName))
     {
         using (Stream compressed = new FileStream(@path, FileMode.Create))
         {
             using (Stream mycompressor = new MyCompressorStream(compressed, MyCompressorStream.Compress))
             {
                 byte[] mazebytes = m_mazes[mazeName].toByteArray();
                 mycompressor.Write(mazebytes, 0, mazebytes.Length);
             }
         }
     }
     else
     {
         throw new Exception("maze name " + mazeName + " doesn't exist!");
     }
 }
コード例 #7
0
 private static void CompressFile(string originalFilePath, string compressedFilePath)
 {
     //Compress bart.txt => bart_compressed.txt
     using (FileStream originalFileStream = new FileStream(originalFilePath, FileMode.Open))
     {
         using (FileStream compressedFileStream = new FileStream(compressedFilePath, FileMode.Create))
         {
             using (MyCompressorStream myCompressorStream = new MyCompressorStream(compressedFileStream))
             {
                 //Read original bart
                 byte[] buffer = new byte[50];
                 int    r      = 0;
                 while ((r = originalFileStream.Read(buffer, 0, buffer.Length)) != 0)
                 {
                     myCompressorStream.Write(buffer, 0, r);
                 }
             }
         }
     }
 }
コード例 #8
0
        private static void testMyCompressorStream()
        {
            Console.WriteLine("*******  testMyCompressorStream  *******\n");
            int[]          size3D          = { 3, 6, 7 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size3D);

            // save the maze to a file – compressed
            using (FileStream fileOutStream = new FileStream(@"D:\1.maze.txt", FileMode.Create))
            {
                using (Stream outStream = new MyCompressorStream(fileOutStream))
                {
                    outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                    outStream.Flush();
                }
            }
            byte[] mazeBytes;
            using (FileStream fileInStream = new FileStream(@"D:\1.maze.txt", FileMode.Open))
            {
                using (Stream inStream = new MyCompressorStream(fileInStream))
                {
                    mazeBytes = new byte[maze.toByteArray().Length];
                    inStream.Read(mazeBytes, 0, mazeBytes.Length);
                }
            }
            Maze3d loadedMaze = new Maze3d(mazeBytes);

            Console.WriteLine("The original maze : ");
            maze.print();
            maze.getStartPosition().print();
            maze.getGoalPosition().print();

            Console.WriteLine("The decompress maze : ");
            loadedMaze.print();
            loadedMaze.getStartPosition().print();
            loadedMaze.getGoalPosition().print();
            Console.WriteLine(loadedMaze.Equals(maze));
        }
コード例 #9
0
        /// <summary>
        /// Saves maze by name to a spesific path
        /// </summary>
        /// <param name="mazeName">maze name</param>
        /// <param name="path">path</param>
        public void SaveMaze(string mazeName, string path)
        {
            if (m_generatedMazes.ContainsKey(mazeName))
            {
                Maze3d maze = m_generatedMazes[mazeName];
                AddToSavedMazes(path, maze);//add the maze to the saved mazes Dictionary

                using (FileStream fileOutStream = new FileStream(path, FileMode.Create))
                {
                    using (Stream outStream = new MyCompressorStream(fileOutStream, ATP2016Library.Compression.CompressionMode.Compress))
                    {
                        outStream.Write(maze.toByteArray(), 0, maze.toByteArray().Length);
                        outStream.Flush();
                    }
                }

                ModelChanged("maze " + mazeName + " was saved in " + path);
            }
            else
            {
                ModelChanged("maze doesnt exist");
            }
        }