/// <summary>
        /// Reads a System.Int32 value from the console
        /// </summary>
        /// <param name="inputPrompt">Prompt the user will see before the input</param>
        /// <param name="displayErrorHandler">The Method with which errors will be displayed</param>
        /// <returns>The System.Int32 that was read</returns>
        public static int GetInt(string inputPrompt, DisplayErrorHandler displayErrorHandler)
        {
            //declarations
            int    result = 0;
            string input;
            bool   isInputValid = false;

            //reading input as long as it is invalid
            while (!isInputValid)
            {
                //printing specified prompt and reading the input
                Console.Write(inputPrompt);
                input = Console.ReadLine();

                //validating the input
                if (!StringIsInteger(input))
                {
                    displayErrorHandler("Input was not a number!");
                    isInputValid = false;
                    continue;
                }

                //converting the input
                isInputValid = true;
                result       = int.Parse(input);
            }

            return(result);
        }
        /// <summary>
        /// Reads a System.DateTime object value with a specified format from the console
        /// </summary>
        /// <param name="inputPrompt">Prompt the user will see before the input</param>
        /// <param name="inputFormat">The format in which the DateTime is read (example: [dd.MM.yyyy HH:mm:ss])</param>
        /// <param name="displayErrorHandler">The Method with which errors will be displayed</param>
        /// <returns>The System.DateTime object that was read</returns>
        public static DateTime GetDateTime(string inputPrompt, string inputFormat, DisplayErrorHandler displayErrorHandler)
        {
            //declarations
            DateTime userInputValue   = DateTime.MinValue;
            bool     userInputIsValid = false;

            do
            {
                //displaying the specified Prompt
                Console.Write(inputPrompt);
                try
                {
                    //Reading and converting the input
                    userInputValue   = DateTime.ParseExact(Console.ReadLine(), inputFormat, CultureInfo.InvariantCulture);
                    userInputIsValid = true;
                }
                catch (Exception ex)
                {
                    displayErrorHandler($"Error: {ex.Message}");
                    userInputIsValid = false;
                }
            }while (!userInputIsValid);

            return(userInputValue);
        }
        /// <summary>
        /// Reads a System.String from the console
        /// </summary>
        /// <param name="inputPrompt">Prompt the user will see before the input</param>
        /// <param name="displayErrorHandler">The Method with which errors will be displayed</param>
        /// <returns>The System.String that was read</returns>
        public static string GetString(string inputPrompt, DisplayErrorHandler displayErrorHandler)
        {
            string result = string.Empty;

            //printing prompt and awaiting first input
            Console.Write(inputPrompt);
            result = Console.ReadLine();

            //if the first input was empty and while it is empty, repeating the previous step with error message
            while (string.IsNullOrEmpty(result))
            {
                displayErrorHandler("Input was empty!");
                Console.Write(inputPrompt);
                result = Console.ReadLine();
            }
            return(result);
        }
        /// <summary>
        /// Reads a System.Boolean from the console
        /// </summary>
        /// <param name="inputPrompt">Prompt the user will see before the input</param>
        /// <param name="displayErrorHandler">The Method with which errors will be displayed</param>
        /// <returns>The System.Boolean that was read</returns>
        public static bool GetBool(string inputPrompt, DisplayErrorHandler displayErrorHandler)
        {
            //declarations
            bool   result = false;
            string input;
            bool   isInputValid = false;

            //reading input as long as it is invalid
            while (!isInputValid)
            {
                //printing specified prompt and reading the input
                Console.Write(inputPrompt);
                input = Console.ReadLine();

                //validating the input
                switch (input)
                {
                case "Y":
                case "y":
                    result       = true;
                    isInputValid = true;
                    break;

                case "N":
                case "n":
                    result       = false;
                    isInputValid = true;
                    break;

                default:
                    displayErrorHandler("Invalid Input. Use (Y or y) for yes and (N or n) for no");
                    isInputValid = false;
                    break;
                }
            }

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Responsible for firing off the request to the server and parsing the response.
        /// </summary>
        /// <returns></returns>
        async Task LoadItems()
        {
            // Avoid double loading the data into the view
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                var projectsTask    = _Projects.GetProjects();
                var updatedProjects = new ObservableCollection <ProjectSummary>();
                Projects?.Clear();
                IEnumerable <ProjectSummary> projects = await projectsTask;
                foreach (var project in projects)
                {
                    if (!project.Id.Trim().ToLower().Equals("_root"))
                    {
                        updatedProjects.Add(project);
                    }
                }

                Projects = updatedProjects;
                OnPropertyChanged(nameof(Projects));
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                DisplayErrorHandler?.Invoke(ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
        //Get File,Directory

        /// <summary>
        /// Reads a System.DateTime object value from the console. Input format: [dd.MM.yyyy HH:mm:ss]
        /// </summary>
        /// <param name="inputPrompt">Prompt the user will see before the input</param>
        /// <param name="displayErrorHandler">The Method with which errors will be displayed</param>
        /// <returns>The System.DateTime object that was read</returns>
        public static DateTime GetDateTime(string inputPrompt, DisplayErrorHandler displayErrorHandler)
        {
            return(GetDateTime(inputPrompt, "dd.MM.yyyy HH:mm:ss", displayErrorHandler));
        }