/// <summary> /// Load a TTY filter file /// </summary> /// <param name="szAbsPath"></param> private void TryLoadTtyFilterFile(string szAbsPath) { try { var xmlDoc = new XmlDocument(); xmlDoc.Load(szAbsPath); if (xmlDoc.DocumentElement == null) { return; } var nodes = xmlDoc.DocumentElement.SelectNodes("TTYFilter"); if ((nodes == null) || (nodes.Count == 0)) { MessageBox.Show( this, SledUtil.TransSub(Localization.SledTTYFilterNoNodesFoundInFile, szAbsPath), Localization.SledTTYFilterFileError, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } foreach (XmlElement elem in nodes) { var filter = new SledTtyFilter( elem.GetAttribute("filter"), ((int.Parse(elem.GetAttribute("result")) == 1) ? SledTtyFilterResult.Show : SledTtyFilterResult.Ignore), Color.FromArgb( int.Parse(elem.GetAttribute("txtColorR")), int.Parse(elem.GetAttribute("txtColorG")), int.Parse(elem.GetAttribute("txtColorB")) ), Color.FromArgb( int.Parse(elem.GetAttribute("bgColorR")), int.Parse(elem.GetAttribute("bgColorG")), int.Parse(elem.GetAttribute("bgColorB")) )); TryAddTtyFilter(filter); } } catch { MessageBox.Show( this, SledUtil.TransSub(Localization.SledTTYFilterErrorLoadingFile, szAbsPath), Localization.SledTTYFilterFileError, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static bool PassesTtyFilter(string message, SledTtyFilter filter) { if (filter.Asterisks.Length <= 0) { // Direct comparison with filter string if (message == filter.Filter) { return(true); } } else { // Filter pattern // If filter string - number of asterisks is greater than the messages length it can't match if ((filter.Filter.Length - filter.Asterisks.Length) > message.Length) { return(false); } var iPos = -1; // Go through checking each part of the filter for (var i = 0; i < filter.FilterList.Count; i++) { iPos = message.IndexOf(filter.FilterList[i], iPos + 1); // Pattern wasn't found if (iPos == -1) { return(false); } // On first iteration check first-asterisk condition if ((i == 0) && !filter.FirstAsterisk && (iPos != 0)) { return(false); } // On last iteration check last-asterisk condition if ((i == (filter.FilterList.Count - 1)) && !filter.LastAsterisk && (iPos != (message.Length - filter.FilterList[filter.FilterList.Count - 1].Length))) { return(false); } } return(true); } return(false); }
/// <summary> /// Try and add a SledTtyFilter to the list /// </summary> /// <param name="filter"></param> private void TryAddTtyFilter(SledTtyFilter filter) { // Search for existing filter with same filter patern var bFound = m_lstTtyFilters.Any( ttyFilter => ttyFilter.Filter == filter.Filter); if (bFound) { return; } // Add to TTY list m_lstTtyFilters.Add(filter); // Add to listbox m_lstBoxFilters.Items.Add(filter); // Select item m_lstBoxFilters.SelectedItem = filter; }
/// <summary> /// Event for clicking the edit button /// </summary> /// <param name="sender">object that fired the event</param> /// <param name="e">event arguments</param> private void BtnEdit_Click(object sender, EventArgs e) { if (m_lstBoxFilters.SelectedItem == null) { return; } var selection = m_lstBoxFilters.SelectedItem as SledTtyFilter; if (selection == null) { return; } using (var form = new SledTtyFilterNameForm()) { form.FilterName = selection.Filter; form.TextColor = selection.TextColor; form.BackgroundColor = selection.BackgroundColor; form.FilterResult = selection.Result; if (form.ShowDialog(this) != DialogResult.OK) { return; } var bCanEdit = true; // Grab name var szFilterName = form.FilterName; // Check if the name was changed (no duplicate names!) if (szFilterName != selection.Filter) { // Name changed, verify its not a duplicate var bFound = m_lstTtyFilters.Any( filter => filter.Filter == szFilterName); if (bFound) { bCanEdit = false; } } if (!bCanEdit) { return; } // Make the edit var editedFilter = new SledTtyFilter( form.FilterName, form.FilterResult, form.TextColor, form.BackgroundColor); // Remove selected item m_lstBoxFilters.Items.Remove(selection); m_lstTtyFilters.Remove(selection); // Add new item m_lstBoxFilters.Items.Add(editedFilter); m_lstTtyFilters.Add(editedFilter); // Select new item m_lstBoxFilters.SelectedItem = editedFilter; } }
/// <summary> /// Event for clicking the edit button /// </summary> /// <param name="sender">object that fired the event</param> /// <param name="e">event arguments</param> private void BtnEdit_Click(object sender, EventArgs e) { if (m_lstBoxFilters.SelectedItem == null) return; var selection = m_lstBoxFilters.SelectedItem as SledTtyFilter; if (selection == null) return; using (var form = new SledTtyFilterNameForm()) { form.FilterName = selection.Filter; form.TextColor = selection.TextColor; form.BackgroundColor = selection.BackgroundColor; form.FilterResult = selection.Result; if (form.ShowDialog(this) != DialogResult.OK) return; var bCanEdit = true; // Grab name var szFilterName = form.FilterName; // Check if the name was changed (no duplicate names!) if (szFilterName != selection.Filter) { // Name changed, verify its not a duplicate var bFound = m_lstTtyFilters.Any( filter => filter.Filter == szFilterName); if (bFound) bCanEdit = false; } if (!bCanEdit) return; // Make the edit var editedFilter = new SledTtyFilter( form.FilterName, form.FilterResult, form.TextColor, form.BackgroundColor); // Remove selected item m_lstBoxFilters.Items.Remove(selection); m_lstTtyFilters.Remove(selection); // Add new item m_lstBoxFilters.Items.Add(editedFilter); m_lstTtyFilters.Add(editedFilter); // Select new item m_lstBoxFilters.SelectedItem = editedFilter; } }
/// <summary> /// Load a TTY filter file /// </summary> /// <param name="szAbsPath"></param> private void TryLoadTtyFilterFile(string szAbsPath) { try { var xmlDoc = new XmlDocument(); xmlDoc.Load(szAbsPath); if (xmlDoc.DocumentElement == null) return; var nodes = xmlDoc.DocumentElement.SelectNodes("TTYFilter"); if ((nodes == null) || (nodes.Count == 0)) { MessageBox.Show( this, SledUtil.TransSub(Localization.SledTTYFilterNoNodesFoundInFile, szAbsPath), Localization.SledTTYFilterFileError, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } foreach (XmlElement elem in nodes) { var filter = new SledTtyFilter( elem.GetAttribute("filter"), ((int.Parse(elem.GetAttribute("result")) == 1) ? SledTtyFilterResult.Show : SledTtyFilterResult.Ignore), Color.FromArgb( int.Parse(elem.GetAttribute("txtColorR")), int.Parse(elem.GetAttribute("txtColorG")), int.Parse(elem.GetAttribute("txtColorB")) ), Color.FromArgb( int.Parse(elem.GetAttribute("bgColorR")), int.Parse(elem.GetAttribute("bgColorG")), int.Parse(elem.GetAttribute("bgColorB")) )); TryAddTtyFilter(filter); } } catch { MessageBox.Show( this, SledUtil.TransSub(Localization.SledTTYFilterErrorLoadingFile, szAbsPath), Localization.SledTTYFilterFileError, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Try and add a SledTtyFilter to the list /// </summary> /// <param name="filter"></param> private void TryAddTtyFilter(SledTtyFilter filter) { // Search for existing filter with same filter patern var bFound = m_lstTtyFilters.Any( ttyFilter => ttyFilter.Filter == filter.Filter); if (bFound) return; // Add to TTY list m_lstTtyFilters.Add(filter); // Add to listbox m_lstBoxFilters.Items.Add(filter); // Select item m_lstBoxFilters.SelectedItem = filter; }
private static bool PassesTtyFilter(string message, SledTtyFilter filter) { if (filter.Asterisks.Length <= 0) { // Direct comparison with filter string if (message == filter.Filter) return true; } else { // Filter pattern // If filter string - number of asterisks is greater than the messages length it can't match if ((filter.Filter.Length - filter.Asterisks.Length) > message.Length) return false; var iPos = -1; // Go through checking each part of the filter for (var i = 0; i < filter.FilterList.Count; i++) { iPos = message.IndexOf(filter.FilterList[i], iPos + 1); // Pattern wasn't found if (iPos == -1) return false; // On first iteration check first-asterisk condition if ((i == 0) && !filter.FirstAsterisk && (iPos != 0)) return false; // On last iteration check last-asterisk condition if ((i == (filter.FilterList.Count - 1)) && !filter.LastAsterisk && (iPos != (message.Length - filter.FilterList[filter.FilterList.Count - 1].Length))) return false; } return true; } return false; }