示例#1
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);
        }
示例#2
0
        private static void testCompressor()
        {
            int[]          size3D          = { 3, 6, 6 }; // (z,y,x)
            IMazeGenerator mazeGenerator3d = new MyMaze3dGenerator();
            Maze3d         maze            = (Maze3d)mazeGenerator3d.generate(size3D);

            maze.print();
            Console.ReadKey();
            byte[] decomp = maze.toByteArray();
            for (int i = 0; i < decomp.Length; i++)
            {
                Console.Write(decomp[i] + " ");
            }
            ICompressor compressor = new MyMaze3DCompressor();

            Console.WriteLine("\ncompression : ");
            byte[] comp = compressor.compress(decomp);
            for (int i = 0; i < comp.Length; i++)
            {
                Console.Write(comp[i] + " ");
            }
            decomp = compressor.decompress(comp);
            Console.WriteLine("\ndecompression : ");
            for (int i = 0; i < decomp.Length; i++)
            {
                Console.Write(decomp[i] + " ");
            }
        }
示例#3
0
 /// <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)
 {
     if (!checkIfNameExist(maze_name))
     {
         ModelChanged("NameIsntExists", maze_name);
     }
     else
     {
         try
         {
             Maze3d maze3d      = (Maze3d)m_DicOfMazes[maze_name];
             byte[] inputSource = maze3d.toByteArray();
             using (MemoryStream input = new MemoryStream(inputSource))
             {
                 using (FileStream outputStream = new FileStream(filePath, FileMode.Create))
                 {
                     byte[] byteArray = new byte[100];
                     int    r         = 0;
                     while ((r = input.Read(byteArray, 0, byteArray.Length)) != 0)
                     {
                         outputStream.Write(byteArray, 0, r);
                         outputStream.Flush();
                         byteArray = new byte[100];
                     }
                 }
             }
             ModelChanged("MazeSaved", maze_name);
         }
         catch (Exception e)
         {
             ModelChanged("ErrorInSaveMaze", maze_name);
         }
     }
 }
示例#4
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);
        }
示例#5
0
        /// <summary>
        /// get the size of the maze
        /// </summary>
        /// <param name="maze_name">name of the maze</param>
        /// <returns>get the size of the maze</returns>
        public int MazeSize(string maze_name)
        {
            int    size_maze;
            Maze   maze   = m_DicOfMazes[maze_name];
            Maze3d maze3d = maze as Maze3d;

            size_maze = maze3d.toByteArray().Length;
            return(size_maze);
        }
示例#6
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));
        }
示例#7
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");
            }
        }
示例#8
0
 /// <summary>
 /// Loads maze from given path and saves it in app memory by given name
 /// </summary>
 /// <param name="path">path</param>
 /// <param name="mazeName">maze name</param>
 public void LoadMaze(string path, string mazeName)
 {
     if (!m_savedMazes.ContainsKey(path))
     {
         ModelChanged("path doesnt exit");
     }
     else //file path exist
     {
         Maze3d savedMaze = m_savedMazes[path];
         byte[] mazeBytes = new byte[savedMaze.toByteArray().Length];
         using (FileStream fileInStream = new FileStream(path, FileMode.Open))
         {
             using (Stream inStream = new MyCompressorStream(fileInStream, ATP2016Library.Compression.CompressionMode.Decompress))
             {
                 inStream.Read(mazeBytes, 0, mazeBytes.Length);
             }
         }
         Maze3d loadedMaze = new Maze3d(mazeBytes);
         AddToGeneratedMazesDictionary(mazeName, loadedMaze);
         ModelChanged("maze " + mazeName + " was loaded successfully");
     }
 }