//Get Alphabet public ActionResult ViewAlphabet() { //Get Configuration var alphabet = new MorseCodeModel().MorseCodeAlphabet; return(View(alphabet)); }
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)); } }
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)); }
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)); }
public IActionResult Translation(MorseCodeModel model) { return(View(model)); }
public IActionResult Index() { MorseCodeModel model = new MorseCodeModel(); return(View(model)); }