예제 #1
0
        /*
         * ---------------------------------------------------------------
         *                  METHOD FOR USER LOGIN
         * ---------------------------------------------------------------
         */

        public static bool UserLogin()
        {
            //Method that prints out the logo, checks the input password and log in the user if correct.

            bool   loggedIn      = default(bool);
            string error         = default(string);
            int    loginCount    = default(int);
            int    maxLoginTries = 3;

            do
            {
                Console.Clear();
                FileHandling.LogoPrint("start");

                //If wrong password, errormessage is printed in red as long as logincount is less than maxLoginTries.
                if (!string.IsNullOrEmpty(error) && loginCount < maxLoginTries)
                {
                    Console.SetCursorPosition(15, 10);
                    Print.Red(error);
                    error = default(string);
                }
                Console.SetCursorPosition(15, 7);
                var        pass = default(string);
                ConsoleKey key;
                Print.Yellow("Ange lösenordet (eller \"a\" för att avsluta)");
                Console.SetCursorPosition(15, 8);
                Print.Blue(@"Lösenord \> ");
                Console.SetCursorPosition(26, 8);


                /*
                 * If logincount is 3 or more, print out that the program will stop, and then exit the program after 3 seconds.
                 */
                if (loginCount >= 3)
                {
                    Console.SetCursorPosition(15, 10);
                    Print.Red("Du har skrivit fel lösenord för många gånger. Programmet avslutas");
                    Thread.Sleep(3000);
                    Environment.Exit(0);
                }


                /*Do while that checks the keys that the user presses and overrides that key
                 * and prints an * insted. Real password gets saved into pass variable and then checked in a switch case.
                 */

                do
                {
                    //Overrids ReadKey so the typed Char is not displayed. This will be replaced further down.
                    var keyInfo = Console.ReadKey(intercept: true);
                    key = keyInfo.Key;
                    //Check if backspace is pressed and string is longer than 1 char.
                    if (key == ConsoleKey.Backspace && pass.Length > 0)
                    {
                        //Does 2 backspace and replaces the earlier saved password with everything in password until second last index
                        Console.Write("\b \b");
                        pass = pass[0..^ 1];
                    }
예제 #2
0
        /// <summary>
        /// Method for searching for a parent to add, or choose to add a new parent
        /// </summary>
        /// <param name="whatToAskFor">Should be either mamma or pappa</param>
        /// <returns>Returns the id as a string of last added person in the database.</returns>
        private string AskUserForParentInput(string whatToAskFor)
        {
            /*******************************************************************
            *              ASKUSERFORPARENTINPUT() - PRIVATE
            *******************************************************************/
            string input;
            bool   continueLoop = true;

            do
            {
                Console.Write($"\t\tAnge {whatToAskFor}> ");
                input = Console.ReadLine();

                switch (input)
                {
                case "":
                    continueLoop = false;
                    break;

                case "0":
                    continueLoop = false;
                    break;

                default:
                    Crud crud   = new Crud(standardDatabaseName);
                    var  result = crud.GetAllPersons(input);
                    if (result.Rows.Count == 0)
                    {
                        Print.Red($"\t\tIngen {whatToAskFor} med de sökkriterierna hittades.");
                        Console.Write($"\t\tVill du lägga till en ny {whatToAskFor}? y/n> ");
                        if (CreateMotherOrFather(whatToAskFor))
                        {
                            input = crud.GetLastAddedDatabasePost();
                            Print.Green($"\t\tNy koppling till {whatToAskFor} skapades");
                            Thread.Sleep(1500);
                        }
                        else
                        {
                            Print.Red($"\t\tIngen {whatToAskFor} skapades");
                            input = "";
                            Thread.Sleep(1500);
                        }
                    }
                    else
                    {
                        Print.Blue("\t\tSökresultat");
                        input = ListPerson(result, crud, false, true).ToString();
                    }

                    continueLoop = false;
                    break;
                }
            } while (continueLoop);

            return(input);
        }
예제 #3
0
        public async Task RunAsync()
        {
            Console.Clear();
            Print.White("Please enter server IP:", true);
            Print.Cyan("", true);
            var address = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(address))
            {
                address = NetworkUtils.GetLocalIPAddress();
            }

            var connection = new HubConnection($"http://{address}:{Program.PORT}/");
            var myHub      = connection.CreateHubProxy("ChatHub");

            await connection.Start().ContinueWith(task =>
            {
                if (task.IsFaulted)
                {
                    Print.Red($"There was an error opening the connection:{task.Exception.GetBaseException()}");
                }
                else
                {
                    Print.Green("Server connection established...");
                }
            });

            myHub.On <string, string>("addMessage", (who, message) =>
            {
                Print.Blue($"{who} :: {message}");
            });

            var count    = 100;
            var runAgain = false;

            do
            {
                Print.White("How many iterations you want to perform?", true); Print.Cyan("");
                if (!Int32.TryParse(Console.ReadLine(), out count))
                {
                    count = 10;
                }
                NetworkThroughputBenchmark.Perform(new Action(() =>
                {
                    myHub.Invoke <string>("Send", address, DateTime.Now.Ticks).Wait();
                }), count);

                Print.White("Press [A] to run again...");
                runAgain = (Console.ReadKey(intercept: true).Key == ConsoleKey.A);
            } while (runAgain);

            connection.Stop();
        }
예제 #4
0
        /// <summary>
        /// List all the availible information about the chosen person
        /// </summary>
        /// <param name="userChoice">The ID of the person that you want to see more info about</param>
        /// <param name="persons">List of persons</param>
        private void ListPersonDetails(int userChoice, List <Relative> persons)
        {
            /*******************************************************************
            *                   LISTPERSONDETAILS() - PRIVATE
            *******************************************************************/
            Crud crud = new Crud(standardDatabaseName);

            foreach (var person in persons.Where(x => x.Id == userChoice))
            {
                Console.WriteLine();
                Console.WriteLine("\t\t" + new string('═', 45));
                Print.Blue($"\t\t{person.FirstName} {person.LastName}\t\t");
                Console.WriteLine("\t\t" + new string('═', 45));

                if (person.DeathDate == null)
                {
                    Console.Write("\t\tStatus: ");
                    Print.Green("Lever");
                }
                else
                {
                    Console.Write("\t\tStatus: ");
                    Print.RedW("Avliden ");
                    Console.WriteLine($"i {person.DeathPlace}");
                }

                if (person.BirthDate != null)
                {
                    Console.Write($"\t\tFödelseinformation: {String.Format("{0:yyyy/MM/dd}", person.BirthDate)}");
                    if (person.BirthPlace != null)
                    {
                        Console.Write(" född i ");
                        Console.WriteLine($"{person.BirthPlace}");
                    }
                    else
                    {
                        Console.WriteLine("\t\tFödelseplats ej specificerad");
                    }
                }
                else
                {
                    if (person.BirthPlace != null)
                    {
                        Console.Write(" född i ");
                        Print.Green($"{person.BirthPlace}");
                    }
                    else
                    {
                        Console.WriteLine("\t\tFödelsedatum ej specificerat");
                    }
                }

                Console.WriteLine();
                Print.DarkGrey("\t\tBarn");
                Console.WriteLine("\t\t" + new string('═', 10));

                var childrenList = crud.GetSiblings(new List <int> {
                    person.Id
                });
                if (childrenList == null)
                {
                    Console.WriteLine($"\t\tPersonen har inga barn.");
                }
                else
                {
                    foreach (var child in childrenList)
                    {
                        Console.WriteLine($"\t\t{child.FirstName} {child.LastName}");
                    }
                }

                if (person.MotherId != 0 || person.FatherId != 0)
                {
                    Console.WriteLine();
                    Print.DarkGrey("\t\tFöräldrar");
                    Console.WriteLine("\t\t" + new string('═', 10));

                    var parentList = crud.GetParents(new List <int> {
                        person.MotherId, person.FatherId
                    });
                    foreach (var parent in parentList)
                    {
                        Console.WriteLine($"\t\t{parent.FirstName} {parent.LastName}");
                    }
                }
                else
                {
                    Console.WriteLine();
                    Print.DarkGrey("\t\tFöräldrar");
                    Console.WriteLine("\t\t" + new string('═', 10));
                    Console.WriteLine("\t\tInga föräldrar hittades.");
                }

                Console.WriteLine();
                Print.DarkGrey("\t\tSyskon");
                Console.WriteLine("\t\t" + new string('═', 10));
                var siblingList = crud.GetSiblings(new List <int> {
                    person.MotherId, person.FatherId
                }, person.Id);
                if (siblingList != null)
                {
                    foreach (var parent in siblingList.Where(x => x != null))
                    {
                        Console.WriteLine($"\t\t{parent.FirstName} {parent.LastName}");
                    }
                }
                else
                {
                    Console.WriteLine("\t\tInga syskon hittades.");
                }
            }
        }