コード例 #1
0
        static void Main(string[] args)
        {
            //user picks persistence form
            long   length       = -1;
            string userResponse = ConsoleView.DisplayChoosePersistence();

            //array for storing repository objects
            SkiRunRepositoryCSV[]    csvArray  = new SkiRunRepositoryCSV[1];
            SkiRunRepositoryXML_DS[] xmlArray  = new SkiRunRepositoryXML_DS[1];
            SkiRunRepositoryJSON[]   jsonArray = new SkiRunRepositoryJSON[1];
            //instantiate the correct classes based on the user's choice
            switch (userResponse)
            {
            case "1":
                DataSettings.dataFilePath = DataSettings.dataFilePathCSV;
                length = new FileInfo(DataSettings.dataFilePath).Length;
                // add test data to the data file but only if there is no data there already
                // and instantiate the right repository
                if (length == 0)
                {
                    InitializeDataFileCSV.AddTestData();
                }

                break;

            case "2":
                DataSettings.dataFilePath = DataSettings.dataFilePathXML;
                length = new FileInfo(DataSettings.dataFilePath).Length;
                // add test data to the data file but only if there is no data there already
                // and instantiate the right repository
                if (length == 0)
                {
                    InitializeDataFileXML_DS.AddTestData();
                }

                break;

            case "3":
                DataSettings.dataFilePath = DataSettings.dataFilePathJSON;
                length = new FileInfo(DataSettings.dataFilePath).Length;
                // add test data to the data file but only if there is no data there already
                // and instantiate the right repository
                if (length == 0)
                {
                    InitializeDataFileJSON.AddTestData();
                }

                break;

            default:
                break;
            }


            Controller controller = new Controller();
        }
コード例 #2
0
        private void ApplicationControl()
        {
            //SkiRunRepositoryCSV skiRunRepository = new SkiRunRepositoryCSV();
            SkiRunRepositoryJSON skiRunRepository = new SkiRunRepositoryJSON();

            //SkiRunRepositorJSON skiRunRepository = new SkiRunRepositorJSON();


            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                int    skiRunID;
                SkiRun skiRun;
                string message;

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRun   = skiRunRepository.GetSkiRunByID(skiRunID);

                        ConsoleView.DisplaySkiRun(skiRun);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:
                        skiRun = ConsoleView.AddSkiRun();
                        skiRunRepository.InsertSkiRun(skiRun);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRun   = skiRunRepository.GetSkiRunByID(skiRunID);

                        skiRun = ConsoleView.UpdateSkiRun(skiRun);

                        skiRunRepository.UpdateSkiRun(skiRun);
                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.DeleteSkiRun(skiRunID);

                        ConsoleView.DisplayReset();
                        message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);
                        ConsoleView.DisplayMessage(message);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:
                        List <SkiRun> matchingSkiRuns = new List <SkiRun>();

                        int minimumVertical;
                        int maximumVertical;
                        ConsoleView.GetVerticalQueryMinMaxValues(out minimumVertical, out maximumVertical);

                        matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical);

                        ConsoleView.DisplayQueryResults(matchingSkiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }