Ejemplo n.º 1
0
        //Get Alphabet
        public ActionResult ViewAlphabet()
        {
            //Get Configuration
            var alphabet = new MorseCodeModel().MorseCodeAlphabet;

            return(View(alphabet));
        }
Ejemplo n.º 2
0
        private string ConvertToMorseCode(string plainText)
        {
            StringBuilder resultBuilder = new StringBuilder();
            var           alphabet      = new MorseCodeModel().MorseCodeAlphabet;

            //Morse code file is limit to lower case alphas
            foreach (Char v in plainText.ToLower().ToCharArray())
            {
                try
                {
                    MorseCodeLetter pair = (from c in alphabet
                                            where c.Letter == v.ToString()
                                            select c).First();

                    if (v.ToString() == "\r")
                    {
                        resultBuilder.Append(Environment.NewLine);
                    }
                    else
                    {
                        if (pair != null)
                        {
                            resultBuilder.Append(pair.Code);
                            resultBuilder.Append(@"||");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.InnerException);
                }
            }

            return(resultBuilder.ToString());
        }
        public ActionResult MorseCodeInput(MorseCodeModel request)
        {
            if (ModelState.IsValid)
            {
                var morseConverter = new MorseCodeConverter();
                var morseData      = new MorseCodeRequest();
                morseData.UserInput = request.UserInput;

                var result = morseConverter.ConvertToMorse(morseData);
                return(View("MorseCodeOutput", result));
            }
            else
            {
                return(View(request));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Index(IFormFile file)
        {
            MorseCodeModel model = new MorseCodeModel();
            List <string>  text  = new List <string>();


            if (file.Length > 0 && file != null)
            {
                text = model.ReadFileAndSave(file);
                model.ConvertedText = text;
            }



            // tempdata -- redirect back to index


            return(RedirectToAction("Translation", model));
        }
Ejemplo n.º 5
0
        public string ConvertToPlainText(StreamReader reader)
        {
            //Append each ling for return
            StringBuilder resultBuilder = new StringBuilder();
            var           alphabet      = new MorseCodeModel().MorseCodeAlphabet;

            string[] currentString = reader.ReadLine().Split(new string[] { "||" }, StringSplitOptions.None);

            while (currentString != null)
            {
                foreach (string code in currentString)
                {
                    try
                    {
                        MorseCodeLetter pair = (from c in alphabet
                                                where c.Code == code
                                                select c).First();

                        resultBuilder.Append(pair.Letter);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.InnerException);
                    }
                }

                resultBuilder.Append(Environment.NewLine);


                if (!reader.EndOfStream)
                {//read the next line
                    currentString = reader.ReadLine().Split(new string[] { "||" }, StringSplitOptions.None);
                }
                else
                {
                    currentString = null;
                }
            }


            return(resultBuilder.ToString());
        }
        public ActionResult MorseCodeInput()
        {
            var model = new MorseCodeModel();

            return(View(model));
        }
Ejemplo n.º 7
0
 public IActionResult Translation(MorseCodeModel model)
 {
     return(View(model));
 }
Ejemplo n.º 8
0
        public IActionResult Index()
        {
            MorseCodeModel model = new MorseCodeModel();

            return(View(model));
        }