public bool ReadFromFile(string[] files, InputTable input, OutputTable output) { if (files.Length != 2) { Console.WriteLine("Argument Error"); return(false); } else { try { using (var reader = new StreamReader(files[0])) { while (!reader.EndOfStream) { string row = reader.ReadLine(); input.Pass_Row(row, row_counter, output); row_counter++; } return(true); } } catch (IOException e) { Console.WriteLine("File Error"); Console.WriteLine(e.Message); return(false); } } }
public void Compute_Cells(InputTable input, CellComputer computer) { while (input.To_Compute.Count != 0) { computer.Cycle_Found = false; computer.Compute_Cell(input.To_Compute[0], input, ref Table); } }
public static void Run(string[] arguments) { Reader reader = new Reader(); InputTable input_table = new InputTable(); OutputTable output_table = new OutputTable(); if (reader.ReadFromFile(arguments, input_table, output_table)) { Compute_Table(input_table, output_table); Writer writer = new Writer(); writer.Write_Output_Table(output_table, arguments[1]); } }
public static void Compute_Table(InputTable input, OutputTable output) { CellComputer computer = new CellComputer(); output.Compute_Cells(input, computer); }
public string Check_And_Compute(string[] formulae, char operand, ref List <string[]> output_table, InputTable input) { if (TryTranslation(formulae[0], out int result_column1, out int result_row1) && TryTranslation(formulae[1], out int result_column2, out int result_row2)) //je validni souradnice { string result1 = ""; string result2 = ""; if (TryIndexOutOfRange(result_column1, result_row1, ref output_table)) //je/neni v tabulce, muzu ukazovat na neco, co jeste neni spocitany { result1 = "0"; } else { if (TypeCell(output_table[result_row1][result_column1]) == "empty") { result1 = "0"; } else if (TypeCell(output_table[result_row1][result_column1]) == "inval") { result1 = "#inval1"; } else if (TypeCell(output_table[result_row1][result_column1]) == "formula") { var cell_in_formula_1 = new Tuple <int, int, string>(result_row1, result_column1, output_table[result_row1][result_column1]); Compute_Cell(cell_in_formula_1, input, ref output_table); result1 = output_table[result_row1][result_column1]; } else //value { result1 = output_table[result_row1][result_column1]; } } if (TryIndexOutOfRange(result_column2, result_row2, ref output_table)) //je/neni v tabulce { result2 = "0"; } else { if (TypeCell(output_table[result_row2][result_column2]) == "empty") { result2 = "0"; } else if (TypeCell(output_table[result_row2][result_column2]) == "inval") { result2 = "#inval2"; } else if (TypeCell(output_table[result_row2][result_column2]) == "formula") { var cell_in_formula_2 = new Tuple <int, int, string>(result_row2, result_column2, output_table[result_row2][result_column2]); Compute_Cell(cell_in_formula_2, input, ref output_table); result2 = output_table[result_row2][result_column2]; } //else value else { result2 = output_table[result_row2][result_column2]; } } if (Cycle_Found) { return("#CYCLE"); } else { return(Compute_Operation(result1, result2, operand)); } }