/// <summary> /// Overloaded constructor that accepts a reference to a collection of dashboad items. Presumably, this is the collection used by the Dashboard Panel. /// </summary> /// <param name="dashboardItems">Collection of dashboard items to edit.</param> public DashboardPanelProperties(DashboardPanel parent) { int counter = 0; _parent = parent; InitializeComponent(); // Populate our list of choices foreach (Type nextHandlerType in ELM327Connection.LoadedHandlerTypes) { HandlerWrapper wrapper = new HandlerWrapper(nextHandlerType); if (wrapper.HandlerCategory == HandlerCategory.REAL_TIME_STATUS) { _panelPropertyOptions.Add(new PanelPropertyOption(wrapper, _panelPropertyOptions.Count)); } } // Move items to their positions and mark the selected ones foreach (String nextHandlerName in ((String)Properties.ApplicationSettings.Default[Variables.SETTINGS_DASHBOARD_HANDLERS]).Split(Variables.SETTINGS_SEPARATOR)) { String actualHandlerName = String.Copy(nextHandlerName); bool isShown = false; if (actualHandlerName.Length > 0) { if (actualHandlerName[0] == '+') { isShown = true; actualHandlerName = actualHandlerName.Substring(1); } for(int i = 0; i < _panelPropertyOptions.Count; i++) { PanelPropertyOption nextOption = _panelPropertyOptions[i]; if (nextOption.HandlerWrapper.HandlerType.Name.Equals(actualHandlerName)) { _panelPropertyOptions[i].IsChecked = isShown; _panelPropertyOptions[i].Position = counter; _panelPropertyOptions.Move(i, counter++); break; } } } } // Set the columns _columns = _parent.Columns; OnPropertyChanged("PanelPropertyOptions"); OnPropertyChanged("Columns"); }
/// <summary> /// Adds a handler to the list of available handlers. This is a necessary step before accepting and/or fulfilling any /// requests/responses that are processed by this handler. /// </summary> /// <param name="handlerType">The Type metaclass for the Handler to be added.</param> /// <returns>True if the Handler is successfully added; otherwise, false.</returns> public bool AddHandler(Type handlerType) { HandlerWrapper newHandlerWrapper = null; // Ensure the type provided is actually an IHandler type if (typeof(IHandler).IsAssignableFrom(handlerType)) { // Create a new HandlerWrapper of the provided type try { newHandlerWrapper = new HandlerWrapper(handlerType); } catch (Exception e) { log.Error("An exception occurred while attempting to create a HandlerWrapper object from Type [" + handlerType.AssemblyQualifiedName + "].", e); return false; } // Ensure the Handler does not already exist in the handler dictionary and add it if(_loadedHandlers.ContainsKey(handlerType.Name) || !(_loadedHandlers.TryAdd(handlerType.Name, newHandlerWrapper))) { log.Error("An attempt was made to add a preexisting Handler to the Dictionary of loaded handlers."); return false; } // If we made it here, we were successful return true; } else { // Log a failed attempt log.Error("An attempt was made to add an object as a Handler that did not implement the IHandler interface."); } return false; }
public PanelPropertyOption(HandlerWrapper wrapper, int position) { _handlerWrapper = wrapper; _isChecked = false; _position = position; }