Example #1
0
        /// <summary>
        /// Given the application parameters, creates regular polygon and depending on the option: saves it to default file or displays it on console
        /// /// </summary>
        /// <param name="parameters">Already parsed application parameters</param>
        private static void ProcessInput(AppParameters parameters)
        {
            RegularPolygonFactory factory = new RegularPolygonFactory();

            try
            {
                RegularPolygon polygon =
                    factory.CreateRegularPolygon(parameters.NumberOfVertices, parameters.SideLength, DefaultInitialVertex);
                switch (parameters.Option)
                {
                case AppParameters.ProcessType.DisplayOnConsole:
                    DU.DisplayText(polygon.ToString());
                    DU.DisplayText("Successfully completed operation", DU.InformationType.OnSuccess);
                    break;

                case AppParameters.ProcessType.SaveToFile:
                    SavePolygonToFile(DefaultFilePath, polygon);
                    break;
                }
            }
            catch (RegularPolygonFactoryLogicalException e)
            {
                DU.DisplayText(e.Message, DU.InformationType.OnError);
            }
        }
Example #2
0
 /// <summary>
 /// Saves the polygon to the specified file.
 /// </summary>
 /// <param name="filePath">Filepath</param>
 /// <param name="polygon">Regular polygon to save</param>
 private static void SavePolygonToFile(string filePath, RegularPolygon polygon)
 {
     try
     {
         File.WriteAllText(filePath, polygon.ToString());
         DU.DisplayText($"Successfully completed operation. Regular polygon information saved to: {filePath}", DU.InformationType.OnSuccess);
     }
     catch (Exception e)
     {
         DU.DisplayText(e.Message, DU.InformationType.OnError);
     }
 }
Example #3
0
        private static void Main(string[] args)
        {
            try
            {
                AppParameters parameters = ExtractParametersFromInput(args);
                ProcessInput(parameters);
            }
            catch (InputValidationException e)
            {
                DU.DisplayText(e.Message, DU.InformationType.OnError);
            }

            DU.DisplayText("Press any key to close the program...");
            Console.ReadKey();
        }