示例#1
0
        public Task ExecuteCommand(CancellationToken token)
        {
            var task = Task.Factory.StartNew(ConsoleActions.WriteConsoleParent)
                       .ContinueWith(x => ConsoleActions.WriteConsoleChild(), TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.ExecuteSynchronously);

            return(task);
        }
        public Task ExecuteCommand(CancellationToken token)
        {
            var task = Task.Run((Action)ConsoleActions.WriteConsoleParent, token)
                       .ContinueWith(x => ConsoleActions.WriteConsoleChild());

            return(task);
        }
        public Task ExecuteCommand(CancellationToken token)
        {
            var task = Task.Run((Action)ConsoleActions.WriteConsoleParent)
                       .ContinueWith(x => ConsoleActions.WriteConsoleChild(), TaskContinuationOptions.NotOnRanToCompletion);

            return(task);
        }
示例#4
0
        static async Task Main(string[] args)
        {
            using var log = new LoggerConfiguration()
                            .WriteTo.File("log.txt")
                            .AddMsSqlServerSink("Server=(localDB)\\MSSQLLocalDB;Initial Catalog=DumpLibrary;Integrated Security=True;")
                            .CreateLogger();

            log.Information($"Application Started {Environment.UserName}");

            try
            {
                var dbCtx         = new SampleDesignTimeDbContextFactory().CreateDbContext(args);
                var dbService     = new DbService(dbCtx);
                var consoleEngine = new ConsoleEngine(log);

                var authors = await dbService.GetAllAuthors();

                consoleEngine.Display(authors);

                ConsoleActions optionCode = ConsoleActions.Exit;
                do
                {
                    optionCode = consoleEngine.ShowMenuAndGetOption();

                    switch (optionCode)
                    {
                    case ConsoleActions.List:
                        var books = await dbService.GetBooksWithAuthors();

                        consoleEngine.DisplayBooks(books);
                        break;

                    case ConsoleActions.Insert:
                        var book = consoleEngine.GetBook();
                        await dbService.Insert(book);

                        break;

                    case ConsoleActions.Update:
                        var bookForUpdate = consoleEngine.GetBookForUpdateTitle();
                        await dbService.UpdateBookTitle(bookForUpdate.Id, bookForUpdate.Title);

                        break;

                    case ConsoleActions.Delete:
                        var deleteBookId = consoleEngine.GetBookForDelete();
                        await dbService.Delete(deleteBookId);

                        break;
                    }
                }while (optionCode != ConsoleActions.Exit);
            }
            catch (Exception ex)
            {
                log.Error(ex, "App error!");
            }

            log.Information("Application Ended");
        }
        public Task ExecuteCommand(CancellationToken token)
        {
            token.Register(ConsoleActions.WriteConsoleChild, false);
            var task = Task.Factory.StartNew(ConsoleActions.WriteConsoleParent)
                       .ContinueWith(x => ConsoleActions.WriteConsoleChild(), token);

            return(task);
        }
        /// <summary>
        ///  initilize objects & start program
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            var validation = new ValidationHelper();
            var apiCalls   = new APICalls("http://api.worldbank.org/v2/country");


            var consoleOutput = new ConsoleActions(validation, apiCalls);

            consoleOutput.RequestISOValue();
        }
示例#7
0
        public static void ReadBinds()
        {
            Actions = new ConsoleActions();

            var path = Path.Combine(FileSystem.GetMyConfigPath(), FILENAME);

            if (!File.Exists(path))
            {
                return;
            }
            customKeyBinds.Clear();
            using (var file = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                BinaryUtils.ReadList(file, customKeyBinds, (x) => KeyBinding.Read(x));
            }
        }
示例#8
0
        public static void Main(string[] args)
        {
            //YatzyGame player = new YatzyGame(new ConsoleActions());
            IConsole  consoleActions = new ConsoleActions();
            IRandom   random         = new Rng();
            YatzyGame player         = new YatzyGame(consoleActions, random);

            List <int> diceList = player.GenerateFiveNumbers();

            PrintList(diceList);

            List <int> indexesNotRolled  = new List <int>();
            List <int> reRolledNumbers   = new List <int>();
            int        totalScore        = 0;
            int        noOfTimesReRolled = 0;

            while (noOfTimesReRolled < 3)
            {
                Console.WriteLine("Would you like to re-roll (Y/N)?");
                string userOption = Console.ReadLine();
                if (userOption == "Y")
                {
                    string[]   userSpecifiedIndexes = player.GetIndexesUserWantsToKeep();
                    List <int> keepIndexes          = player.IndexesToKeepAsInt(userSpecifiedIndexes);
                    diceList = player.KeepIndexesSpecifiedByUser(keepIndexes, diceList);
                    PrintList(diceList);
                    indexesNotRolled = player.DetermineIndexesNotKept(diceList);
                    reRolledNumbers  = player.RollDice(diceList, indexesNotRolled);
                    List <int> afterRerolled = player.AfterReRoll(diceList, reRolledNumbers);
                    PrintList(afterRerolled);
                    noOfTimesReRolled++;
                }
                else if (userOption == "N")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("I think you mistyped, please enter again.");
                }
            }
            totalScore = player.CalculateSum(diceList);
            Console.WriteLine("Your Score: " + totalScore);
        }
        public async Task RunBookLoop()
        {
            ConsoleActions optionCode = ConsoleActions.Exit;

            do
            {
                optionCode = consoleEngine.ShowMenuAndGetOption();

                switch (optionCode)
                {
                case ConsoleActions.List:
                    var books = await bookService.GetBooksWithAuthors();

                    consoleEngine.DisplayBooks(books.ToDTO());
                    break;

                case ConsoleActions.Insert:
                    var book = consoleEngine.GetBook();
                    await bookService.Insert(book.ToModel());

                    break;

                case ConsoleActions.Update:
                    var bookForUpdate = consoleEngine.GetBookForUpdateTitle();
                    await bookService.UpdateBookTitle(bookForUpdate);

                    break;

                case ConsoleActions.Delete:
                    var deleteBookId = consoleEngine.GetBookForDelete();
                    await bookService.Delete(deleteBookId);

                    break;
                }
            }while (optionCode != ConsoleActions.Exit);
        }
示例#10
0
        static void Main(string[] args)
        {
            //TODO
            //Logowanie Lekarza
            ////1. Logowanie
            ////2. Rejestracja
            //Menu:
            ////1. Sprawdz listę pacjentów w bazie
            ////2. Dodaj nowego pacjenta do listy pacjentów
            ////3. Usuń pacjenta
            ////4. Przypisz chorobę do pacjenta
            ////5. Sprawdz wczesniejsze choroby danego pacjenta (PESEL)
            ////6. Wygeneruj receptę (.csv) dla pacjenta (wykorzystując gotowy szablon)
            ////7. Wylogowanie
            //////2a. Id(numer pacjenta), Imie, Nazwisko, PESEL, Numer telefonu, Adres Email
            //////3a. Usuwanie poprzez podanie id lub numeru PESEL
            //////4a. Wybór kategorii: Zakaźna, Nowotwór, Przewlekła, Cywilizacyjna, Psychiczne, Genetyczne itd...
            //////4b. Wybór stopnia zaawansowania choroby (1-5) - różny kolor czcionki przy wypisywaniu w konsoli
            //////4c. Opis objawów
            //////4d. Zalecenia
            //////5a.
            //////6a. Recepta: id lekarza, Zalecenia, Dawkowanie leków

            string path = Directory.GetCurrentDirectory();

            MenuActionService menuActionService = new MenuActionService();
            var loginMenu = menuActionService.GetMenuActionsByMenuName("Login");

            UserService userService = new UserService();
            UserManager userManager = new UserManager(userService);
            User        user        = new User();
            bool        isAnOption  = true;

            do
            {
                Console.WriteLine("Please choose what you want to do: ");
                foreach (var element in loginMenu)
                {
                    Console.WriteLine($"{ element.Id }. {element.Name}");
                }
                do
                {
                    var option = Console.ReadKey();
                    switch (option.KeyChar)
                    {
                    case '1':
                        Console.Clear();
                        Console.WriteLine($"===Log in===");
                        user = userManager.GetLoginData(user);
                        ConsoleActions.ShowWaitingDots();
                        break;

                    case '2':
                        Console.Clear();
                        Console.WriteLine($"===Register===");
                        user = userManager.GetRegisterData(user);
                        Console.WriteLine($"You have successfully registered! Your ID number is: {user.Id}");
                        ConsoleActions.ShowWaitingDots();
                        break;

                    default:
                        ConsoleActions.ClearChosenNumberFromLine();
                        Console.WriteLine($"Operation number {option.KeyChar} does not exist please try again");
                        isAnOption = false;
                        break;
                    }
                }while (!isAnOption);
            }while (!user.IsLoggedIn);

            //User can choose what he want to do

            loginMenu = menuActionService.GetMenuActionsByMenuName("mainMenu");
            IllnessActionService illnessActionService = new IllnessActionService();
            IllnessActionManager illnessActionManager = new IllnessActionManager(illnessActionService);
            PatientService       patientService       = new PatientService();
            PatientManager       patientManager       = new PatientManager(patientService);
            bool quit = true;

            do
            {
                Console.WriteLine("Please choose what you want to do: ");
                foreach (var element in loginMenu)
                {
                    Console.WriteLine($"{ element.Id }. {element.Name}");
                }

                var option = Console.ReadKey();
                switch (option.KeyChar)
                {
                case '1':
                    Console.Clear();
                    List <Patient> patients = new List <Patient>();
                    patients = patientService.GetAll();
                    foreach (var patient in patients)
                    {
                        Console.WriteLine($"{patient.Id} | " +
                                          $"{patient.FirstName} {patient.LastName}  | " +
                                          $"PESEL: {patient.PESEL} | " +
                                          $"Tel: {patient.PhoneNumber} | " +
                                          $"E-mail: {patient.EmailAdress}");
                    }
                    quit = false;
                    break;

                case '2':
                    Console.Clear();
                    patientManager.GetNewPatientData(user);
                    quit = false;
                    break;

                case '3':
                    Console.Clear();
                    Console.WriteLine("Do you want to remove by PESEL number or ID number: \n1. PESEL\n2. ID");
                    option = Console.ReadKey();
                    switch (option.KeyChar)
                    {
                    case '1':
                        string pesel;
                        Console.Write("Please write patient's PESEL number: ");
                        pesel = Console.ReadLine();
                        patientManager.Remove(pesel);
                        break;

                    case '2':
                        int id;
                        Console.Write("Please write patient's ID number: ");
                        Int32.TryParse(Console.ReadLine(), out id);
                        patientManager.Remove(id);
                        break;

                    default:
                        Console.WriteLine($"Operation number { option.KeyChar} does not exist.");
                        break;
                    }
                    quit = false;
                    break;

                case '4':
                    Console.Clear();
                    illnessActionManager.GetPatientAndIllnessData(user, patientService);
                    ConsoleActions.ShowWaitingDots();
                    quit = false;
                    break;

                case '5':
                    Console.Clear();
                    Console.WriteLine("Do you want to search by PESEL number or ID number: \n1. PESEL\n2. ID\n");
                    option = Console.ReadKey();
                    XmlRootAttribute root = new XmlRootAttribute();
                    root             = new XmlRootAttribute();
                    root.ElementName = "Illnesses";
                    root.IsNullable  = true;
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(List <IllnessAction>), root);
                    switch (option.KeyChar)
                    {
                    case '1':
                        ConsoleActions.ClearChosenNumberFromLine();
                        string pesel;
                        Console.Write("Please write patient's PESEL number: ");
                        pesel = Console.ReadLine();
                        var illnesses = illnessActionManager.GetInfoToSerializeCSV(pesel);

                        xmlSerializer.Serialize(new StreamWriter(path + $@"\illnesses_xml\{patientManager.GetByPesel(pesel).PESEL}.xml"), illnesses);
                        break;

                    case '2':
                        ConsoleActions.ClearChosenNumberFromLine();
                        int id;
                        Console.Write("Please write patient's ID number: ");
                        Int32.TryParse(Console.ReadLine(), out id);
                        illnesses = illnessActionManager.GetInfoToSerializeCSV(id);

                        xmlSerializer.Serialize(new StreamWriter(path + $@"\illnesses_xml\{patientManager.GetById(id).PESEL}.xml"), illnesses);
                        break;

                    default:
                        ConsoleActions.ClearChosenNumberFromLine();
                        Console.WriteLine($"Operation number { option.KeyChar} does not exist.");

                        break;
                    }
                    quit = false;
                    break;

                case '6':
                    ConsoleActions.ClearChosenNumberFromLine();
                    Console.Write("Please write PESEL number of patient to read his/her prescription: ");
                    string peselFileName;
                    peselFileName = Console.ReadLine();


                    root             = new XmlRootAttribute();
                    root.ElementName = "Illnesses";
                    root.IsNullable  = true;
                    xmlSerializer    = new XmlSerializer(typeof(List <IllnessAction>), root);
                    string xml = File.ReadAllText(path + $@"\illnesses_xml\{peselFileName}.xml");

                    StringReader stringReader = new StringReader(xml);
                    var          illnessItems = (List <IllnessAction>)xmlSerializer.Deserialize(stringReader);


                    foreach (var item in illnessItems)
                    {
                        Console.Write(item.Id + " | " +
                                      item.NameOfIllness + " | " +
                                      item.IllnessLevel + " | " +
                                      item.DateOfControlVisit + " | " +
                                      item.Category);
                        Console.WriteLine("=============================================");
                    }

                    break;

                case 'q':
                    quit = true;
                    break;

                default:
                    Console.Clear();
                    Console.WriteLine($"Operation number {option.KeyChar} does not exist please try again");
                    quit = false;
                    break;
                }
            }while (!quit);
        }
        public void GetPatientAndIllnessData(User user, PatientService patients)
        {
            string  pesel;
            Patient patient         = new Patient();
            bool    isPatientInList = false;

            while (!isPatientInList)
            {
                Console.Write("Please write patients PESEL number: ");
                pesel = Console.ReadLine();
                foreach (var patientFromList in patients.GetAll())
                {
                    if (patientFromList.PESEL == pesel)
                    {
                        Console.WriteLine("Patient was found in the list!");
                        Console.WriteLine($"{patientFromList.Id} | " +
                                          $"{patientFromList.FirstName} {patientFromList.LastName}  | " +
                                          $"PESEL: {patientFromList.PESEL} | " +
                                          $"Tel: {patientFromList.PhoneNumber} | " +
                                          $"E-mail: {patientFromList.EmailAdress}");
                        patient         = patientFromList;
                        isPatientInList = true;
                    }
                    else
                    {
                        Console.Write($"There's no person with PESEL: {pesel} in the list. \nPlease try again.\n");
                    }
                }
            }
            IllnessAction illnessAction = new IllnessAction();

            Console.Write("Please write number of an illness category: \n1. Infectious \n2. Cancer \n3. Chronic \n4. Civilization \n5. Psychic \n6. Genetic");
            Enum.TryParse(Console.ReadLine(), out illnessAction.Category);
            Console.Write("Please write name of the illness: ");
            illnessAction.NameOfIllness = Console.ReadLine();
            Console.Write("Please write symptoms of the illness: ");
            illnessAction.Symptoms = Console.ReadLine();
            Console.Write("Please write a level of the illness: ");
            illnessAction.IllnessLevel = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Please write prescripted medicines: ");
            bool stop   = false;
            int  number = 1;

            while (!stop)
            {
                Console.Write(number + ". ");
                illnessAction.PrescriptedMedicines.Add(Console.ReadLine());
                bool isAnOption = false;
                while (!isAnOption)
                {
                    Console.WriteLine("Is that's all? \n1. Yes \n2. No");
                    var option = Console.ReadKey();
                    switch (option.KeyChar)
                    {
                    case '1':
                        ConsoleActions.ClearChosenNumberFromLine();
                        stop       = true;
                        isAnOption = true;
                        break;

                    case '2':
                        ConsoleActions.ClearChosenNumberFromLine();
                        isAnOption = true;
                        break;

                    default:
                        ConsoleActions.ClearChosenNumberFromLine();
                        Console.WriteLine($"Theres no option \"{option.KeyChar}\". Please try again.");
                        break;
                    }
                }
                number++;
            }
            illnessAction.DateOfVisit = DateTime.Now;

            Console.Write("In how many days should the control visit be: ");
            int days = Int32.Parse(Console.ReadLine());

            illnessAction.DateOfControlVisit = illnessAction.DateOfVisit.AddDays(days);
            illnessAction = new IllnessAction(user, patient, illnessAction);
            _illnessActionService.Add(illnessAction);
            Console.WriteLine("Illness added successfully!");
        }