/// <summary> /// Fires the variable operation event. /// </summary> /// <param name="variable">The variable.</param> /// <param name="eventHandler">The event handler.</param> private void FireVariableLinkOperationEvent(PacketPropertyVariable variable, PacketPropertyVariableLink variableLink, VariableLinkOperationEventHandler eventHandler) { if (null != eventHandler) { eventHandler(variable, variableLink); } }
/// <summary> /// Compares this variable to another one. /// </summary> /// <param name="packetPropertyVariable">The packet property variable.</param> /// <returns><code>true</code> if all fields are equal, <code>false</code> otherwise.</returns> protected bool Equals(PacketPropertyVariable packetPropertyVariable) { if (packetPropertyVariable == null) { return(false); } return(Equals(links, packetPropertyVariable.links) && Equals(name, packetPropertyVariable.name)); }
/// <summary> /// Determines whether variable is linked to packet. /// </summary> /// <param name="variable">The variable.</param> /// <param name="packetType">Type of the packet.</param> /// <returns> /// <c>true</c> if variable is linked to packet; otherwise, <c>false</c>. /// </returns> private bool IsVariableLinkedToPacket(PacketPropertyVariable variable, Type packetType) { bool ret = false; IList <PacketPropertyVariableLink> links = variable.Links; for (int i = links.Count - 1; 0 <= i; --i) { PacketPropertyVariableLink link = links[i]; if (link.PacketClass.type == packetType) { ret = true; } } return(ret); }
/// <summary> /// Gets the variable link to packet. /// </summary> /// <param name="variable">The variable.</param> /// <param name="packetType">Type of the packet.</param> /// <returns>Found variable link, or <code>null</code> otherwise.</returns> private PacketPropertyVariableLink GetVariableLinkToPacket(PacketPropertyVariable variable, Type packetType) { PacketPropertyVariableLink ret = null; // Check every link of a variable IList <PacketPropertyVariableLink> links = variable.Links; for (int i = links.Count - 1; 0 <= i; --i) { PacketPropertyVariableLink link = links[i]; if (link.PacketClass.type.IsAssignableFrom(packetType)) { // Found link - stop the loop ret = link; break; } } return(ret); }
/// <summary> /// Does the variable operation. /// </summary> /// <param name="variableName">Name of the variable.</param> /// <param name="operationHandler">The operation handler.</param> /// <param name="successHandler">The success handler.</param> /// <returns><code>true</code> if variable exists and <paramref name="operationHandler"/> returned <code>true</code>.</returns> private bool DoVariableOperation(string variableName, InternalVariableOperation operationHandler, VariableOperationEventHandler successHandler) { bool ret; try { // Check if variable exists VariableEntry entry; ret = variableEntriesByName.TryGetValue(variableName, out entry); PacketPropertyVariable variable = (ret ? entry.variable : null); if (ret) { // Do operation ret = operationHandler(variable); } if (ret) { // Fire event only on successful modification of list successHandler(variable); } } catch (Exception e) { ret = false; // Format message string message = string.Format("Error in variable operation with params: variableName={0}, operationHandler={1}, successHandler={2}" , variableName ?? "null" , operationHandler ?? (object)"null" , successHandler ?? (object)"null"); Log.Error(message, e); } return(ret); }
/// <summary> /// Adds the variable. /// </summary> /// <param name="variable">The variable.</param> /// <returns><code>true</code> if variable is added successfully, <code>false</code> otherwise.</returns> public bool AddVariable(PacketPropertyVariable variable) { bool ret = false; try { ret = !variableEntriesByName.ContainsKey(variable.Name); if (ret) { // Add variable to collections VariableEntry entry = new VariableEntry(); entry.variable = variable; variableEntriesByName.Add(variable.Name, entry); int oldCount = variableEntriesList.Count; variableEntriesList.Add(entry); // Check for errors ret = (oldCount != variableEntriesList.Count); if (!ret) { string message = "Internal lists are in inconsistent state after adding of variable " + (variable ?? (object)"(null)"); Log.Error(message); throw new Exception(message); } else { // Fire event FireVariableOperationEvent(variable, VariableAdded); } } } catch (Exception e) { ret = false; Log.Error("Error adding a variable: variable=" + (variable ?? (object)"null"), e); } return(ret); }
/// <summary> /// Adds the variable. /// </summary> /// <param name="variable">The variable.</param> /// <returns><code>true</code> if variable is added successfully, <code>false</code> otherwise.</returns> public bool AddVariable(PacketPropertyVariable variable) { bool ret = false; try { ret = !variableEntriesByName.ContainsKey(variable.Name); if (ret) { // Add variable to collections VariableEntry entry = new VariableEntry(); entry.variable = variable; variableEntriesByName.Add(variable.Name, entry); int oldCount = variableEntriesList.Count; variableEntriesList.Add(entry); // Check for errors ret = (oldCount != variableEntriesList.Count); if (!ret) { string message = "Internal lists are in inconsistent state after adding of variable " + (variable ?? (object)"(null)"); Log.Error(message); throw new Exception(message); } else { // Fire event FireVariableOperationEvent(variable, VariableAdded); } } } catch (Exception e) { ret = false; Log.Error("Error adding a variable: variable=" + (variable ?? (object)"null"), e); } return ret; }
/// <summary> /// Handles the Click event of the varAddButton control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> private void varAddButton_Click(object sender, EventArgs e) { try { // Create and select a new var PacketClass pak = (PacketClass) packetClassComboBox.SelectedItem; ClassMemberPath mem = (ClassMemberPath) packetClassPropertyComboBox.SelectedItem; PacketPropertyVariable var = new PacketPropertyVariable(pak, mem, GenerateNewVariableName()); variablesManager.AddVariable(var); } catch (Exception ex) { Log.Error("Error", ex); } }
/// <summary> /// Gets the variable link to packet. /// </summary> /// <param name="variable">The variable.</param> /// <param name="packetType">Type of the packet.</param> /// <returns>Found variable link, or <code>null</code> otherwise.</returns> private PacketPropertyVariableLink GetVariableLinkToPacket(PacketPropertyVariable variable, Type packetType) { PacketPropertyVariableLink ret = null; // Check every link of a variable IList<PacketPropertyVariableLink> links = variable.Links; for (int i = links.Count - 1; 0 <= i; --i) { PacketPropertyVariableLink link = links[i]; if (link.PacketClass.type.IsAssignableFrom(packetType)) { // Found link - stop the loop ret = link; break; } } return ret; }
/// <summary> /// Variableses the manager_ variable link replaced. /// </summary> /// <param name="variable">The variable.</param> /// <param name="link">The link.</param> private void variablesManager_VariableLinkReplaced(PacketPropertyVariable variable, PacketPropertyVariableLink link) { // Update links listbox only if variable is currently selected (and hence links list contains variables links) if (varListBox.SelectedItem == variable) { // Save current selection int selectedIndex = varPacketsLinksListBox.SelectedIndex; // Clear listbox items varPacketsLinksListBox.Items.Clear(); // Add all variable items ListBoxHelpers.AddRange(varPacketsLinksListBox, variable.Links); // Restore selection index varPacketsLinksListBox.SelectedIndex = selectedIndex; } }
/// <summary> /// Removes the variable. /// </summary> /// <param name="variable">The variable.</param> private void variablesManager_VariableRemoved(PacketPropertyVariable variable) { varListBox.Items.Remove(variable); UpdateButtonsEnabledState(); }
/// <summary> /// Modifies the variable. /// </summary> /// <param name="variable">The variable.</param> private void variablesManager_VariableModified(PacketPropertyVariable variable) { // Update modified item int index = varListBox.Items.IndexOf(variable); varListBox.Items[index] = variable; // Update packet filters list ListBoxHelpers.Refresh(filtersListBox); UpdateButtonsEnabledState(); }
// // Synchronize user-visible data with modifications of variables manager // /// <summary> /// Adds the variable. /// </summary> /// <param name="variable">The variable.</param> private void variablesManager_VariableAdded(PacketPropertyVariable variable) { // Add and select new variable varListBox.Items.Add(variable); varListBox.SelectedItem = variable; // Updates UpdateSelectedVariableData(); UpdateButtonsEnabledState(); // Select variable name varNameTextBox.Focus(); varNameTextBox.SelectAll(); }
/// <summary> /// Shows the links of a variable. /// </summary> /// <param name="variable">The variable.</param> private void ShowVariableLinks(PacketPropertyVariable variable) { varPacketsLinksListBox.Items.Clear(); if (null != variable) { ListBoxHelpers.AddRange(varPacketsLinksListBox, variable.Links); } }
/// <summary> /// Determines whether variable is linked to packet. /// </summary> /// <param name="variable">The variable.</param> /// <param name="packetType">Type of the packet.</param> /// <returns> /// <c>true</c> if variable is linked to packet; otherwise, <c>false</c>. /// </returns> private bool IsVariableLinkedToPacket(PacketPropertyVariable variable, Type packetType) { bool ret = false; IList<PacketPropertyVariableLink> links = variable.Links; for (int i = links.Count - 1; 0 <= i; --i) { PacketPropertyVariableLink link = links[i]; if (link.PacketClass.type == packetType) { ret = true; } } return ret; }
/// <summary> /// Variableses the manager_ variable link removed. /// </summary> /// <param name="variable">The variable.</param> /// <param name="link">The link.</param> private void variablesManager_VariableLinkRemoved(PacketPropertyVariable variable, PacketPropertyVariableLink link) { // Update links listbox only if variable is currently selected (and hence links list contains variables links) if (varListBox.SelectedItem == variable) { varPacketsLinksListBox.Items.Remove(link); } }
/// <summary> /// Compares this variable to another one. /// </summary> /// <param name="packetPropertyVariable">The packet property variable.</param> /// <returns><code>true</code> if all fields are equal, <code>false</code> otherwise.</returns> protected bool Equals(PacketPropertyVariable packetPropertyVariable) { if (packetPropertyVariable == null) return false; return Equals(links, packetPropertyVariable.links) && Equals(name, packetPropertyVariable.name); }
/// <summary> /// Fires the variable operation event. /// </summary> /// <param name="variable">The variable.</param> /// <param name="eventHandler">The event handler.</param> private void FireVariableOperationEvent(PacketPropertyVariable variable, VariableOperationEventHandler eventHandler) { if (null != eventHandler) { eventHandler(variable); } }