private bool InitializeAutoTyper(string file) { try { _typer_Stopped(null, null); // Dispose old autotyper first if (_typer != null) { _typer.Dispose(); } XDocument doc = XDocument.Load(file); _autoTypedText = new string[FUNCTION_KEYS.Count]; foreach (var eltKey in doc.Root.Elements("Key")) { string key = eltKey.Attribute("value").Value; int numKey = FUNCTION_KEYS.IndexOf(key); if (numKey >= 0 && numKey <= 11) { // Reading CDATA information var cdata = (from n in eltKey.Nodes() where n is XCData select n).FirstOrDefault(); if (cdata != null) { _autoTypedText[numKey] = (cdata as XCData).Value.Replace("\n", "\r\n"); } } } cboKey.SelectedIndex = 0; _typer = new AutoTyper(_autoTypedText); _typer.Started += _typer_Started; _typer.Stopped += _typer_Stopped; _typer.KeyStroke += _typer_KeyStroke; _typer.NbOfLettersTypedChanged += _typer_NbOfLettersTypedChanged; RemoveSelectionColor(); return(true); } catch (Exception ex) { MessageBox.Show($"Error while reading config file '{file}'\r\n{ex.Message}", MSGBOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
private bool InitializeAutoTyper(string file) { try { _typer_Stopped(null, null); // Dispose old autotyper first if (_typer != null) _typer.Dispose(); XDocument doc = XDocument.Load(file); _autoTypedText = new string[FUNCTION_KEYS.Count]; foreach (var eltKey in doc.Root.Elements("Key")) { string key = eltKey.Attribute("value").Value; int numKey = FUNCTION_KEYS.IndexOf(key); if (numKey >= 0 && numKey <= 11) { // Reading CDATA information var cdata = (from n in eltKey.Nodes() where n is XCData select n).FirstOrDefault(); if (cdata != null) _autoTypedText[numKey] = (cdata as XCData).Value.Replace("\n", "\r\n"); } } cboKey.SelectedIndex = 0; _typer = new AutoTyper(_autoTypedText); _typer.Started += _typer_Started; _typer.Stopped += _typer_Stopped; _typer.KeyStroke += _typer_KeyStroke; _typer.NbOfLettersTypedChanged += _typer_NbOfLettersTypedChanged; RemoveSelectionColor(); return true; } catch (Exception ex) { MessageBox.Show($"Error while reading config file '{file}'\r\n{ex.Message}", MSGBOX_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } }