Exemplo n.º 1
0
        static int[][] TryReadMatrixFromFile(ref int size)
        {
            StreamReader streamReader = null;

            int[][] matrix;
            try
            {
                streamReader = File.OpenText(fileName);
                matrix       = MatrixProcessor.ReadMatrixFromFile(out size, streamReader);
                if (matrix.Length == 0)
                {
                    throw new Exception("Input matrix is empty");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Creating a random matrix...");
                matrix = MatrixProcessor.CreateRandomMatrix(out size);
            }
            finally
            {
                if (streamReader != null)
                {
                    streamReader.Close();
                }
            }
            return(matrix);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            int size = 0;

            int[][] matrix = TryReadMatrixFromFile(ref size);

            MatrixProcessor.ConsoleOutputRotatedMatrix(size, matrix);
            Console.WriteLine();
            matrix = MatrixProcessor.RotateMatrix(size, matrix);
            TryWriteMatrixToFile(size, matrix);
            Console.WriteLine("Matrix was written to the file");
        }
Exemplo n.º 3
0
 static void TryWriteMatrixToFile(int size, int[][] matrix)
 {
     try
     {
         using (StreamWriter streamWriter = new StreamWriter(fileName, true))
         {
             MatrixProcessor.FileOutputMatrix(size, matrix, streamWriter);
         }
     }
     catch
     {
         Console.WriteLine("Error occured while writing to file");
     }
 }