private void Space_Click(object sender, EventArgs e) { Morse morse = new Morse(); Message.Text += Morse.MorseCoder(Letter.Text.ToString()); Letter.Text = ""; }
static void Main(string[] args) { bool key3Pressed = false; string key; Morse morse = new Morse(); Console.ForegroundColor = ConsoleColor.White; while (!key3Pressed) { Console.WriteLine("Morse encoder"); Console.WriteLine("1. Text der kodiert werden soll eingaben."); Console.WriteLine("2. Pfad zu einer Datei die kodiert werden soll eingeben."); Console.WriteLine("3. Programm beenden"); Console.Write("Auswahl: "); key = Console.ReadLine(); if (key == "1") { EncodeMessageByUserInput(morse); } if (key == "2") { EncodeMessageByFileInput(morse); } if (key == "3") { key3Pressed = true; } } }
public static string EncodeMessageByFileInput(Morse morse, string pathToFile = null) { string encodedText = null; Console.Write("Pfad zur Datei die kodiert werden soll: "); if (pathToFile == null) { pathToFile = Console.ReadLine(); } try { Console.WriteLine("Kodierter Text: "); using (FileStream fs = File.Open(pathToFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { Console.WriteLine("neue Junk"); encodedText = morse.EncodeMessage(line); Console.WriteLine(encodedText); } Console.WriteLine(); } } catch (IOException) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Die angegebene Datei wurde nicht gefunden"); Console.ForegroundColor = ConsoleColor.White; } return(encodedText); }
public static void DecodeMessage(Morse morse, string path) { string decodedText = null; try { using (FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string line; Console.WriteLine("Dekodierter Text: "); while ((line = sr.ReadLine()) != null) { decodedText = morse.DecodeMessage(line); Console.WriteLine(decodedText); } } } catch (IOException) { Console.WriteLine("Die angegebene Datei wurde nicht gefunden!"); } }
private static void EncodeMessageByUserInput(Morse morse) { Console.Write("Zu kodierender Text: "); string textToEncode = Console.ReadLine(); Console.Write("Kodierter Text: " + morse.EncodeMessage(textToEncode)); Console.WriteLine(); }
static void Main(string[] args) { Morse morse = new Morse(); Console.WriteLine("Pfad zu einer Datei einfügen: "); string path = Console.ReadLine(); DecodeMessage(morse, path); Console.ReadKey(); }
public void But_Space(object sender, EventArgs e) { try { char letter = Morse.MorseCoder(input); Output_Letters.Text += letter; Output_Morse.Text += " "; input = ""; } catch (Exception) { DisplayAlert("Error Occurred", "Oops", "OK"); } }
private void Convert(bool to) { try { textBox.Text = to ? Morse.To(textBox.Text) : Morse.From(textBox.Text); } catch (MorseException ex) { MessageBox.Show("Ongeldige invoer: " + ex.Value, "Fout", MessageBoxButton.OK, MessageBoxImage.Error); textBox.Select(ex.Index, ex.Length); textBox.Focus(); } }
static void Main(string[] args) { string message = "Hello World9"; Console.WriteLine(Morse.Tx(message)); //Console.ReadKey(); //foreach (KeyValuePair<char, string>element in Morse.) //{ // char Key = element.Key; // string code = element.Value; // Console.WriteLine($"Letter/Number: {Key}, code: {code}"); //} Console.WriteLine(Morse.WriteMorsebyDan(message)); Console.ReadKey(); }
private void BtnSpace_Clicked(object sender, EventArgs e) { char morseResult; spaceCount++; if (spaceCount < 2) { morseResult = Morse.MorseCoder(myMorse); myResult += morseResult.ToString(); lblResult.Text = myResult; } else { myMorse = ""; morseResult = Morse.MorseCoder(myMorse); myResult += morseResult.ToString(); lblResult.Text = myResult; spaceCount = 0; } lblInput.Text = ""; myMorse = ""; }