Example #1
0
        public static void StoryTwo()
        {
            SentenceConfiguration config = new SentenceConfiguration();

            Console.WriteLine("Write your sentence please:");
            var sentence = Console.ReadLine();

            config.Sentence = sentence;
            config.Word     = new List <string>();

            var word = string.Empty;

            do
            {
                Console.WriteLine("Select the words you don't want to(Write EXIT to finish):");
                word = Console.ReadLine();

                if (!config.Word.Contains(word))
                {
                    config.Word.Add(word);
                }
                else
                {
                    Console.WriteLine("This word is already on the list.");
                }
            } while (!word.ToUpper().Equals("EXIT"));


            var createdJson = JSONHelper.CreateJson(config) != null;

            if (createdJson)
            {
                Console.WriteLine("The Configuration was created with success.");
                Console.WriteLine("Sentence:");
                Console.WriteLine(config.Sentence);

                Console.WriteLine("Words:");

                foreach (var item in config.Word)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("Press ANY key to exit.");
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Something is wrong with your configuration file.");
                Console.WriteLine("Press ANY key to exit.");
                Console.ReadKey();
            }
        }
Example #2
0
        public static SentenceConfiguration CreateJson(SentenceConfiguration _data)
        {
            string json = JsonConvert.SerializeObject(_data);

            try
            {
                //write string to file
                System.IO.File.WriteAllText(
                    @"D:\NB21467\Desktop\Euromoney.RecruitmentTest-master\ContentConsole\Content\Data.json", json);
            }
            catch (Exception ex)
            {
                return(null);
            }
            return(_data);
        }
Example #3
0
        public static SentenceConfiguration ReadJson()
        {
            SentenceConfiguration config = new SentenceConfiguration();

            try
            {
                StreamReader file =
                    File.OpenText(
                        @"D:\NB21467\Desktop\Euromoney.RecruitmentTest-master\ContentConsole\Content\Data.json");


                JsonSerializer serializer = new JsonSerializer();
                config = (SentenceConfiguration)serializer.Deserialize(file, typeof(SentenceConfiguration));
            }
            catch (Exception ex)
            {
                return(null);
            }


            return(config);
        }