Пример #1
0
 public virtual void StoreResult <T>(List <T> output)
 {
     using (FileHandler outputFile = new FileHandler(Global.IOMode.Output))
     {
         foreach (object obj in output)
         {
             outputFile.WriteContent(obj);
         }
     }
     CUI.ShowGeneralInformation("\n\nPlease open output.txt to view the result.");
 }
Пример #2
0
 /// <summary>
 /// Check the error type, handles the error if error type is fatal
 /// </summary>
 /// <param name="exception">Exception that needs to be determined for fatality</param>
 /// <returns>true if the exception is fatal, false otherwise</returns>
 public static bool HandleFatalError(this Exception exception)
 {
     if (exception.IsFatal())
     {
         CUI.ShowGeneralInformation("\n\nA fata error occurred. Please find below the error : \n" + exception.ToString() + "\n\nPlease notify Diptarag regarding this error. \n\nSystem will exit now. Press any key to exit.");
         Console.ReadKey();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            int choice;
            Dictionary <Global.Problems, string> problems = new Dictionary <Global.Problems, string>();

            try
            {
                problems = ProblemMetaData.GetProblems();
            }
            catch (DynamicProgrammingException ex)
            {
                CUI.ShowGeneralInformation(ex.Message + "\nPlease revert any changes you have made to the xml file and try again.\n\nSystem will now exit. Press any key to exit...");
                Console.ReadKey();
                System.Environment.Exit(0);
            }

            while (true)
            {
                try
                {
                    switch (CUI.StartScreen())
                    {
                    case "1":
                        while (true)
                        {
                            if (problems.Count >= 0 && int.TryParse(CUI.ShowProblemListings(problems), out choice) && problems.Keys.Any(e => (int)e == choice))
                            {
                                Problem problem = ProblemFactory((Global.Problems)choice);
                                if (problem != null)
                                {
                                    problem.Compute();
                                    //problem.StoreResult();
                                    break;
                                }
                                throw new DynamicProgrammingException("A logical exception occurred.");
                            }
                            CUI.ErrorMessage();
                        }
                        break;

                    case "2": CUI.About();
                        break;

                    case "3": System.Environment.Exit(0);
                        break;

                    default: CUI.ErrorMessage();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (ex.HandleFatalError())
                    {
                        System.Environment.Exit(1);
                    }
                    else
                    {
                        ex.Handle();
                    }
                }
            }
        }