Beispiel #1
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE ITERATOR PROGRAM -- WHICH IS A BORING PROGRAM TO USE");
            TxtPrinter.PrintInformation("All this program really does is put data onto a stack and then iterate the stack.",
                                        '-', ConsoleColor.Magenta);

            while (true)
            {
                var iterableStack = new IterableStack <string>();

                while (true)
                {
                    var newVal = QuestionAsker.GetValue <string>($"\nEnter a new value to put on the stack.\n");
                    iterableStack.Push(newVal);
                    if (!ContinuationDeterminer.GoAgain("\nDo you want to put another value on the stack?\n"))
                    {
                        break;
                    }
                }

                Console.WriteLine("\nHere are the values that you put on the stack:\n");
                foreach (var item in iterableStack)
                {
                    Console.WriteLine(item);
                }

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE INTERPRETER PROGRAM -- WHICH CAN BE NEAT TO USE");
            TxtPrinter.PrintInformation("This program solves mathematical expressions.", '-', ConsoleColor.Magenta);
            TxtPrinter.PrintInformation("E.g.: Enter '4 + 5 - 2 * (6 + 4)' and you'll receive the answer -11.",
                                        '-', ConsoleColor.DarkYellow);

            while (true)
            {
                Console.Write("Enter a mathematical expression here: ");
                var expression  = Console.ReadLine();
                var interpreter = new MathInterpreter();

                try
                {
                    var answer = interpreter.GetAnswer(expression);
                    Console.Write("\nAnswer: ");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write($"{answer}\n\n");
                    Console.ResetColor();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"\nThere was an error evaluating the expression. " +
                                      $"Error: {ex.Message}\n");
                }

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE DECORATOR PROGRAM -- WHICH IS SORT OF COOL, I GUESS");

            while (true)
            {
Start:
                JObject locationInfo = null;
                try
                {
                    using (var reader = new StreamReader(InfoFile))
                    {
                        var json = reader.ReadToEnd();
                        locationInfo = JObject.Parse(json);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Unable to parse {InfoFile}.");
                    Console.WriteLine($"Exception message: {ex.Message}");
                    Environment.Exit(1);
                }

                var town = GetTown(locationInfo);
                town.PrintInfo();

                foreach (var decorator in Decorators)
                {
                    if (!KeepGoing())
                    {
                        goto Start;
                    }

                    town = Decorate(locationInfo, town, decorator);
                    town.PrintInfo();
                }

                if (KeepGoing())
                {
                    var mind       = GetJToken(locationInfo, "mind");
                    var mindSize   = mind.Value <string>("size");
                    var mindNature = mind.Value <string>("nature");
                    TxtPrinter.PrintInformation($"The {town.Name} universe is in mind, " +
                                                $"which has a size of {mindSize}, and whose nature is {mindNature}. OK?", consoleColor: ConsoleColor.DarkMagenta);
                }

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #4
0
 public void SetAspect()
 {
     TxtPrinter.PrintInformation("Now we'll get information regarding your education.", '-', ConsoleColor.DarkGreen);
     EducationLevel = (EducationLevel)(Asker.GetChoiceFromList("What is the highest level of education you've attained?",
                                                               TypParser.GetEnumValuesList <EducationLevel>()));
     GPA = Asker.GetValue <decimal>($"What was your average GPA in {EducationLevel}?");
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE MEDIATOR PROGRAM -- WHICH IS A MILDLY ENTERTAINING PROGRAM");

            try
            {
                using (var reader = new StreamReader(ArgumentsPath))
                {
                    var json = reader.ReadToEnd();
                    Arguments.AddRange(JsonConvert.DeserializeObject <List <string> >(json));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to retrieve arguments from {ArgumentsPath}.\n " +
                                  $"Using default arguments. Exception message: {ex.Message}\n");
                Arguments.AddRange(DefaultArguments.GetDefaultArguments());
            }

            while (true)
            {
                var debateMediator = new DebateMediator();
                var debators       = GetDebators(debateMediator, "Martha", "Willis", "Redford", "Millie");
                Console.WriteLine("Enter your argument.\n");
                Console.ReadLine();
                Console.WriteLine();
                debateMediator.Mediate();
                Console.WriteLine();

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #6
0
 public void SetAspect()
 {
     TxtPrinter.PrintInformation("Now we'll get information regarding books you've read.", '-', ConsoleColor.DarkGreen);
     NumberOfBooksRead = Asker.GetValue <int>("How many books have you read?");
     FavoriteGenre     = (BookGenre)(Asker.GetChoiceFromList("What is your favorite genre of book?",
                                                             TypParser.GetEnumValuesList <BookGenre>()));
 }
Beispiel #7
0
        static void Main()
        {
            TxtPrinter.PrintInformation("WELCOME TO THE CHARACTER BUILDER PROGRAM -- WHICH IS A PRETTY NEAT PROGRAM!");

            var keepLooping = true;

            while (keepLooping)
            {
                Console.WriteLine("Enter the number of the character that you want to build.\n");

                var(characterBuilders, characterNames) = TypParser.GetInstantiatedTypeDictionaryAndNameList <AbstractCharacterBuilder>();
                TxtParser.PrintStringList(characterNames);

                var choiceString = Console.ReadLine();

                if (!TypParser.TryGetType(choiceString, characterBuilders, out var builder))
                {
                    Console.WriteLine(INVALID_CHOICE_MESSAGE);
                    continue;
                }

                var character = CharacterMaker.GetCharacter(builder);

                DescribeCharacter(character);

                keepLooping = ContinuationDeterminer.GoAgain();
            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE FACADE PROGRAM -- WHICH DOES SOME MILDLY INTERESTING THINGS");

            while (true)
            {
                var       typeObjectChoice = XmlOrJson[Asker.GetChoiceFromList(TypeObjectQuestion, XmlOrJson)];
                XDocument xDocument;
                JObject   jObject;

                switch (typeObjectChoice)
                {
                case "xml":
                    xDocument = XmlJsonUtil.GetXml();

                    TxtPrinter.PrintInformation("Here is the final xml:", '-', ConsoleColor.DarkRed);
                    Console.WriteLine($"\n{xDocument}\n");

                    var convertedToJObject = XmlJsonUtil.ConvertXmlToJson(xDocument);
                    TxtPrinter.PrintInformation("And here is the xml converted to json:", '-', ConsoleColor.DarkRed);
                    Console.WriteLine($"\n{convertedToJObject}\n");

                    break;

                case "json":
                    jObject = XmlJsonUtil.GetJson();

                    TxtPrinter.PrintInformation("Here is the final json:", '-', ConsoleColor.DarkRed);
                    Console.WriteLine($"\n{jObject}\n");

                    var convertedToXDocument = XmlJsonUtil.ConvertJsonToXml(jObject);
                    TxtPrinter.PrintInformation("And here is the json converted to xml:", '-', ConsoleColor.DarkRed);
                    Console.WriteLine($"\n{convertedToXDocument}\n");

                    break;

                default:
                    break;
                }

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE MEMENTO PROGRAM -- WHICH IS RELATIVELY NEAT AND FUN!");

            while (true)
            {
                var mine = new Mine(MineWidth, MineHeight, NumberOfExplositionsAllowed, NumberOfUndosAllowed);
                mine.PrintMineBoard();
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("\nUse the arrow keys to move around the mine. Press space to blast, u to undo, and ESC to quit.");
                Console.ResetColor();
                var cursorReturnPosition = Console.CursorTop;

                Console.CursorVisible = false;
                var key = new ConsoleKey();
                while (key != ConsoleKey.Escape && mine.GetGameState() == GameState.InProgress)
                {
                    key = Console.ReadKey(true).Key;
                    switch (key)
                    {
                    case ConsoleKey.RightArrow:
                        mine.MoveRight();
                        break;

                    case ConsoleKey.LeftArrow:
                        mine.MoveLeft();
                        break;

                    case ConsoleKey.DownArrow:
                        mine.MoveDown();
                        break;

                    case ConsoleKey.UpArrow:
                        mine.MoveUp();
                        break;

                    case ConsoleKey.Spacebar:
                        mine.Explode();
                        break;

                    case ConsoleKey.U:
                        mine.UndoExplode();
                        break;

                    default:
                        break;
                    }
                }

                Console.CursorVisible = true;
                Console.CursorTop     = ++cursorReturnPosition;
                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE ADAPTER PROGRAM -- WHICH IS SORT OF A FUNNY PROGRAM");

            var keepLooping = true;

            while (keepLooping)
            {
                List <InfoGetter> infoGetters;
                try
                {
                    using (var reader = new StreamReader(ConfigurableInformationGettersPath))
                    {
                        var json = reader.ReadToEnd();
                        infoGetters = JsonConvert.DeserializeObject <List <InfoGetter> >(json);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine($"Unable to retrieve questions and answers from '{ConfigurableInformationGettersPath}'.");
                    Console.WriteLine("Using default questions and answers instead.\n");
                    infoGetters = DefaultInfoGetters.GetDefaultInfoGetters();
                }

                var questionsAndAnswers = QuestionAndAnswerGetter.GetQuestionsAndAnswers(infoGetters);

                if (questionsAndAnswers == null)
                {
                    return;
                }

                var choice = GetRenderer();
                if (choice == 0)
                {
                    return;
                }

                switch (choice)
                {
                case Renderer.EvaluationRenderer:
                    var evaluationRenderer = new EvaluationRenderer();
                    var(results, score) = evaluationRenderer.ListTopicsAndScores(questionsAndAnswers);
                    var questionWord = score > 1 ? "questions" : "question";
                    Console.WriteLine(results);
                    Console.WriteLine($"You got a total of {score} {questionWord} correct.\n");
                    break;

                case Renderer.QuestionAndAnswerRenderer:
                    var questionAndAnswerRenderer = new QuestionAndAnswerRenderer();
                    Console.WriteLine(questionAndAnswerRenderer.ListQuestionsAndAnswers(questionsAndAnswers));
                    break;
                }

                keepLooping = ContinuationDeterminer.GoAgain();
            }
        }
Beispiel #11
0
        static void Main()
        {
            var urls        = GetUrls();
            var explorers   = GetExplorers(urls);
            var keepLooping = true;

            TxtPrinter.PrintInformation("WELCOME TO THE PROTOTYPE PROGRAM -- WHICH IS KIND OF A BORING PROGRAM");

            while (keepLooping)
            {
                Console.WriteLine("Enter the number of one of the classic websites below to get information about that site!");

                for (int i = 0; i < urls.Count; i++)
                {
                    Console.WriteLine($"{i + 1}. {urls[i]}");
                }

                Console.WriteLine();

                var choiceString = Console.ReadLine();
                if (!int.TryParse(choiceString, out var choice))
                {
                    Console.WriteLine($"{INVALID_CHOICE_MESSAGE}");
                    continue;
                }

                WebPageExplorer explorer;
                try
                {
                    explorer = explorers[--choice];
                }
                catch
                {
                    Console.WriteLine(INVALID_CHOICE_MESSAGE);
                    continue;
                }

                var(info, error) = explorer.GetInformationAsync().Result;

                if (error != null)
                {
                    Console.WriteLine($"{error.Message}");
                    Console.WriteLine($"{error.Exception.Message}");
                }
                else
                {
                    Console.WriteLine($"The version number of {explorer.CurrentUrl} is {info.Version.ToString()}. Neat!\n");
                }

                keepLooping = ContinuationDeterminer.GoAgain();
            }
        }
Beispiel #12
0
        static void Main()
        {
            const int MAX_ELEMENTS_TO_PRINT = 1000;
            var       keepLooping           = true;
            var       stopWatch             = new Stopwatch();

            TxtPrinter.PrintInformation("WELCOME TO THE SORT PROGRAM -- WHICH IS A PRETTY NEAT PROGRAM!");

            while (keepLooping)
            {
                var array = GetArrayToSort();
                if (array == null || array.Length < 1)
                {
                    continue;
                }

                if (array.Length <= MAX_ELEMENTS_TO_PRINT)
                {
                    Console.WriteLine("\nHERE IS THE UNSORTED ARRAY:*********************************************************\n");
                    PrintArray(array);
                }
                else
                {
                    Console.WriteLine("\n(That array is too large to print to the console, because it would just take too long.)\n");
                }

                var sorter = GetSorter();
                if (sorter == null)
                {
                    continue;
                }

                var elapsedTime = SortArray(array, sorter, stopWatch);

                if (array.Length <= MAX_ELEMENTS_TO_PRINT)
                {
                    Console.WriteLine("\nHERE IS THE SORTED ARRAY:***********************************************************\n");
                    PrintArray(array);
                }
                else
                {
                    Console.WriteLine("\n(Again, the array is too large to print to the console, so I won't print it.)\n");
                }

                PrintResults(elapsedTime);

                keepLooping = ContinuationDeterminer.GoAgain();
                stopWatch.Reset();
                Console.WriteLine();
            }
        }
Beispiel #13
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE COMMAND PROGRAM - WHICH IS MILDLY THOUGHT-PROVOKING");
            List <Item> items;

            try
            {
                using (var reader = new StreamReader(ConfigurableItemsPath))
                {
                    var json = reader.ReadToEnd();
                    items = JsonConvert.DeserializeObject <List <Item> >(json);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to retrieve item from '{ConfigurableItemsPath}'.\n" +
                                  $"Exception message: {ex.Message}\n" +
                                  $"Using default questions and answers instead.\n");

                items = DefaultItems.GetDefaultItems();
            }

            var(commandDict, _) = TypeParser.GetInstantiatedTypeDictionaryAndNameList <ICommand>();
            var commandList = commandDict
                              .OrderBy(c => c.Key)
                              .Select(c => c.Value.Description)
                              .ToList();

            while (true)
            {
                var order = new Order();
                while (true)
                {
                    var commandChoice = Asker.GetChoiceFromList("What do you want to do with your order?", commandList) + 1;

                    order = commandDict[commandChoice].Execute(order, items);

                    if (!ContinuationDeterminer.GoAgain("Do you want to perform another action on your order?"))
                    {
                        break;
                    }
                }

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE COMPOSITE PROGRAM -- WHICH IS A SOMEWHAT INTERESTING PROGRAM");
            TxtPrinter.PrintInformation("This program calculates the share of a decedent's estate per stirpes.", '-', ConsoleColor.Magenta);
            TxtPrinter.PrintInformation("NOTE: If the decedent or any descendant has more than three descendants, the results will " +
                                        "be printed as a series of strings rather than as a graphical tree.", '-', ConsoleColor.DarkYellow);

            while (true)
            {
                var(decedentName, estateValue) = GetDecedentNameAndEstateValue();
                if (decedentName == null || estateValue == 0)
                {
                    Environment.Exit(0);
                }

                var decedent = new Decedent(decedentName, estateValue);
                var tree     = new Tree <string>(decedentName, new string[]
                {
                    string.Format($"Estate value: {estateValue:#,###}", CultureInfo.InvariantCulture)
                });

                tree.PrintTree(tree.GetRoot());
                Console.WriteLine();

                decedent.Descendants = GetDescendants(decedent.Name, tree);
                decedent.DistributeEstate();
                MapDistributionToTree(decedent.Descendants, tree);
                tree.PrintTree(tree.GetRoot());
                Console.WriteLine();

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE STATE PROGRAM -- WHICH PRESENTS A SLIGHT CHALLENGE");

            while (true)
            {
                var mathGame = new MathGame();
                mathGame.PlayGame();

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE INTERPRETER METHOD PROGRAM -- WHICH MAY PROVIDE SOME INTEREST");
            var(departmentDictionary, departmentList) = TypParser.GetInstantiatedTypeDictionaryAndNameList <AbstractHiringProcess>();

            while (true)
            {
                var chosenIndex      = Asker.GetChoiceFromList("For what department do you want to apply for a job?", departmentList);
                var chosenDepartment = departmentDictionary[++chosenIndex];
                chosenDepartment.ExecuteHiringProcess();

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE BRIDGE PROGRAM -- WHICH IS A BORING PROGRAM THAT SORT OF DOES CONVERSIONS");

            var keepLooping = true;

            while (keepLooping)
            {
                var(converters, converterNames) = TypParser.GetTypeDictionaryAndNameList <AbstractConverter>();
                Console.WriteLine("Enter the number of the measurement from which you want to convert.");
                TxtParser.PrintStringList(converterNames);

                var strConverterChoice = TxtParser.GetTextFromConsole();
                if (!TypParser.TryGetType(strConverterChoice, converters, out var converter))
                {
                    Console.WriteLine(INVALID_CHOICE_MESSAGE);
                    continue;
                }

                var(formatters, formatterNames) = TypParser.GetInstantiatedTypeDictionaryAndNameList <IFormatter>();
                Console.WriteLine("Enter the number of the way you want the output formatted.");
                TxtParser.PrintStringList(formatterNames);

                var strFormatterChoice = TxtParser.GetTextFromConsole();
                if (!TypParser.TryGetType(strFormatterChoice, formatters, out var formatter))
                {
                    Console.WriteLine(INVALID_CHOICE_MESSAGE);
                    continue;
                }

                var instantiatedConverter = Activator.CreateInstance(converter, formatter) as AbstractConverter;

                Console.WriteLine("Enter the value that you want converted");

                var strValue = TxtParser.GetTextFromConsole();
                if (!decimal.TryParse(strValue, out var value))
                {
                    Console.WriteLine("That's not a value that can be converted. Let's try this again I guess.");
                    continue;
                }

                instantiatedConverter.Convert(value);

                keepLooping = ContinuationDeterminer.GoAgain();
            }
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE CHAIN OF RESPONSIBILITY PROGRAM -- WHICH IS KIND OF A SILLY PROGRAM");

            while (true)
            {
                List <Question> questions;
                try
                {
                    using (var reader = new StreamReader(ConfigurableQuestionsPath))
                    {
                        var json = reader.ReadToEnd();
                        questions = JsonConvert.DeserializeObject <List <Question> >(json);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Unable to retrieve questions and answers from '{ConfigurableQuestionsPath}'.\n" +
                                      $"Exception message: {ex.Message}\n" +
                                      $"Using default questions and answers instead.\n");

                    questions = DefaultQuestions.GetDefaultQuestions();
                }

                var question = questions[Asker.GetChoiceFromList("Which question do you want to ask the clergy?",
                                                                 questions.Select(q => q.Query).ToList())];

                var priest      = new QuestionHandler(new Clergyman("priest", DegreeOfPhilosophicalDepth.Low));
                var bishop      = new QuestionHandler(new Clergyman("bishop", DegreeOfPhilosophicalDepth.Medium));
                var archibishop = new QuestionHandler(new Clergyman("archbishop", DegreeOfPhilosophicalDepth.High));
                var pope        = new QuestionHandler(new Clergyman("pope", DegreeOfPhilosophicalDepth.Extreme));

                priest.RegisterNext(bishop);
                bishop.RegisterNext(archibishop);
                archibishop.RegisterNext(pope);

                priest.AnswerQuestion(question);

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE FLYWEIGHT PROGRAM -- WHICH SORT OF HAS SOME INTERESTING ASPECTS");

            while (true)
            {
                var characterFactory   = CreateCharacters();
                var stringToManipulate = GetString();

                foreach (var character in stringToManipulate)
                {
                    var qualifiedCharacter = characterFactory.GetCharacter(character);
                    qualifiedCharacter.Render(Console.CursorTop + 1);
                }

                Console.WriteLine("\n\n");

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #20
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE VISITOR PROGRAM -- WHICH MAY OFFER SOME CONSOLATION");

            while (true)
            {
                var personalAspects = TypParser.GetInstantiatedTypeDictionaryAndNameList <IPersonalAspect>()
                                      .Item1.Select(kv => kv.Value).ToList();
                var visitor = new SophisticationLevelVisitor();

                foreach (var aspect in personalAspects)
                {
                    aspect.SetAspect();
                    aspect.Accept(visitor);
                }

                Console.WriteLine($"Your level of sophistication is {visitor.GetSophisticationLevel()}.");

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE PROXY PROGRAM -- WHICH DOES MILDLY INTERESTING THINGS");

            while (true)
            {
                var diskReader = new DiskReaderProxy();

                var drives = diskReader.GetDrives();

                var driveChoice = Asker.GetChoiceFromList("Choose a drive that you want to search: ", drives);

                Console.WriteLine("\nWhat file extension do you want to search for?\n");
                var extension = Console.ReadLine();

                var files = diskReader.GetFiles(drives[driveChoice], extension);

                if (files == null)
                {
                    Console.WriteLine($"There was a problem getting files for extension {extension}.");

                    if (!ContinuationDeterminer.GoAgain())
                    {
                        Environment.Exit(0);
                    }

                    continue;
                }

                if (files.Count == 0)
                {
                    Console.WriteLine($"\nDid not find any files with the extension {extension}.\n");

                    if (!ContinuationDeterminer.GoAgain())
                    {
                        Environment.Exit(0);
                    }

                    continue;
                }

                Console.Write($"\nFound {files.Count} files with the extension ");
                var consoleColor = Console.ForegroundColor;
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine($"{extension}.\n");
                Console.ForegroundColor = consoleColor;
                var printChoice = Asker.GetChoiceFromList("Do you want to see them?", YesOrNo);

                if (YesOrNo[printChoice] == "Yes")
                {
                    foreach (var file in files)
                    {
                        Console.WriteLine(file);
                    }
                }

                Console.WriteLine();

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE OBSERVER PROGRAM -- WHICH IS SOMEWHAT FUNNY");

            var news = new List <News>();

            try
            {
                using (var reader = new StreamReader(NewsItemsPath))
                {
                    var json    = reader.ReadToEnd();
                    var jObject = JObject.Parse(json);
                    foreach (var obj in jObject)
                    {
                        switch (obj.Key)
                        {
                        case "good":
                            news.AddRange(obj.Value.Select(n => n.ToNews(NewsType.Good)));
                            break;

                        case "bad":
                            news.AddRange(obj.Value.Select(n => n.ToNews(NewsType.Bad)));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to load news items from {NewsItemsPath}. Exception: {ex.Message}\n " +
                                  $"Press any key to exit.");
                Console.ReadKey();
                Environment.Exit(1);
            }

            var responses = new List <Response>();

            try
            {
                using (var reader = new StreamReader(ResponsesPath))
                {
                    var json    = reader.ReadToEnd();
                    var jObject = JObject.Parse(json);
                    foreach (var obj in jObject)
                    {
                        switch (obj.Key)
                        {
                        case "good":
                            responses.AddRange(obj.Value.Select(r => r.ToResponse(NewsType.Good)));
                            break;

                        case "bad":
                            responses.AddRange(obj.Value.Select(r => r.ToResponse(NewsType.Bad)));
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to load responses from {ResponsesPath}. Exception: {ex.Message}\n " +
                                  $"Press any key to exit.");
                Console.ReadKey();
                Environment.Exit(1);
            }

            var newsPublisher = new NewsPublisher();

            while (true)
            {
                var choice = Asker.GetChoiceFromList("What do you want to do?", Choices);
                switch (choice)
                {
                case 0:
                    AddSubscriber(newsPublisher, responses);
                    break;

                case 1:
                    RemoveSubscriber();
                    break;

                case 2:
                    PublishNewsItem(news, newsPublisher);
                    break;

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

                default:
                    break;
                }
            }
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            TxtPrinter.PrintInformation("WELCOME TO THE STRATEGY PROGRAM -- WHICH SORT OF MIGHT MAKE YOU THINK");

            var countryTaxSystemMap = new Dictionary <string, List <string> >();

            try
            {
                using (var reader = new StreamReader(MapPath))
                {
                    var json    = reader.ReadToEnd();
                    var jObject = JObject.Parse(json);
                    foreach (var system in jObject)
                    {
                        if (countryTaxSystemMap.ContainsKey(system.Key))
                        {
                            Console.WriteLine($"There is a duplicate tax system entry in {MapPath}. Only the first entry will be used.");
                            continue;
                        }

                        countryTaxSystemMap.Add(system.Key, system.Value.ToObject <List <string> >());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unable to parse the county-tax system map from {MapPath}. Exception: {ex.Message}");
                Console.ReadKey();
                Environment.Exit(1);
            }

            var taxCalculators = new List <ITaxCalculator>();

            try
            {
                var(calulatorDictionary, calculatorNames) = TypParser.GetTypeDictionaryAndNameList <ITaxCalculator>();
                var key = 1;
                foreach (var calculatorName in calculatorNames)
                {
                    if (!countryTaxSystemMap.TryGetValue(calculatorName.ToLower(), out var countries))
                    {
                        Console.WriteLine($"There is no entry for the {calculatorName} tax calculator in the map; therefore, " +
                                          $"this tax calculator will be ignored.");
                        continue;
                    }

                    var calculator = Activator.CreateInstance(calulatorDictionary[key++], countries) as ITaxCalculator;
                    taxCalculators.Add(calculator);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"There was an error trying to create the tax calculators. Exception: {ex.Message}");
                Console.ReadKey();
                Environment.Exit(1);
            }

            var allCountries = taxCalculators
                               .SelectMany(c => c.TaxableCountries)
                               .Distinct()
                               .OrderBy(c => c)
                               .ToList();

            var calculatorContext = new CalculatorContext();

            while (true)
            {
                var currentCountry = allCountries[Asker.GetChoiceFromList("What country do you live in?", allCountries)];
                var taxCalculator  = taxCalculators.FirstOrDefault(c => c.TaxableCountries.Contains(currentCountry));
                calculatorContext.SetCalculator(taxCalculator);
                var tax = calculatorContext.CalculateTax(currentCountry);

                Console.Write("\nYour tax is: ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"{tax.ToString("0.00")}\n");
                Console.ResetColor();

                if (!ContinuationDeterminer.GoAgain())
                {
                    Environment.Exit(0);
                }
            }
        }
 public void SetAspect()
 {
     TxtPrinter.PrintInformation("Now we'll get information regarding your travel experience.", '-', ConsoleColor.DarkGreen);
     NumberOfCountriesVisited = Asker.GetValue <int>("How many countries have you visited?");
     NumberOfMonthsAbroad     = Asker.GetValue <int>("What is the total amount of months you've spent abroad?");
 }