private void buttonAddController_Click(object sender, EventArgs e) { List <KeyValuePair <string, object> > outputModules = new List <KeyValuePair <string, object> >(); foreach (KeyValuePair <Guid, string> kvp in ApplicationServices.GetAvailableModules <IControllerModuleInstance>()) { outputModules.Add(new KeyValuePair <string, object>(kvp.Value, kvp.Key)); } Common.Controls.ListSelectDialog addForm = new Common.Controls.ListSelectDialog("Add Controller", (outputModules)); if (addForm.ShowDialog() == DialogResult.OK) { IModuleDescriptor moduleDescriptor = ApplicationServices.GetModuleDescriptor((Guid)addForm.SelectedItem); string name = moduleDescriptor.TypeName; ControllerFactory controllerFactory = new ControllerFactory(); OutputController oc = (OutputController)controllerFactory.CreateDevice((Guid)addForm.SelectedItem, name); VixenSystem.OutputControllers.Add(oc); // In the case of a controller that has a form, the form will not be shown // until this event handler completes. To make sure it's in a visible state // before evaluating if it's running or not, we're calling DoEvents. // I hate DoEvents calls, so if you know of a better way... Application.DoEvents(); // select the new controller, and then repopulate the list -- it will make sure the currently // displayed controller is selected. _PopulateFormWithController(oc); _PopulateControllerList(); //We added a controller so set the _changesMade to true _changesMade = true; } }
public bool AddNewControllerOfTypeWithPrompts(Guid controllerTypeId) { IModuleDescriptor moduleDescriptor = ApplicationServices.GetModuleDescriptor(controllerTypeId); if (moduleDescriptor == null) { Logging.Error("couldn't get descriptor for controller of type ID: " + controllerTypeId); return(false); } string defaultName = moduleDescriptor.TypeName; string name; using (TextDialog textDialog = new TextDialog("New Controller Name?", "Controller Name", defaultName, true)) { if (textDialog.ShowDialog() != DialogResult.OK) { return(false); } name = textDialog.Response; if (name.Length <= 0) { name = defaultName; } } int outputCount; using (NumberDialog nd = new NumberDialog("Controller Output Count", "Outputs on this controller?", 0)) { if (nd.ShowDialog() != DialogResult.OK) { return(false); } outputCount = nd.Value; } ControllerFactory controllerFactory = new ControllerFactory(); OutputController oc = (OutputController)controllerFactory.CreateDevice(controllerTypeId, name); oc.OutputCount = outputCount; VixenSystem.OutputControllers.Add(oc); //PopulateControllerTree(oc); AddControllerToTree(oc); OnControllersChanged(); return(true); }
public IOutputDevice ReadObject(XElement element) { try { string name = XmlHelper.GetAttribute(element, ATTR_NAME); if (name == null) { return(null); } Guid?moduleTypeId = XmlHelper.GetGuidAttribute(element, ATTR_HARDWARE_ID); if (moduleTypeId == null) { return(null); } Guid?moduleInstanceId = XmlHelper.GetGuidAttribute(element, ATTR_HARDWARE_INSTANCE_ID); if (moduleInstanceId == null) { return(null); } Guid?deviceId = XmlHelper.GetGuidAttribute(element, ATTR_DEVICE_ID); if (deviceId == null) { return(null); } ControllerFactory controllerFactory = new ControllerFactory(); OutputController controller = (OutputController)controllerFactory.CreateDevice(deviceId.Value, moduleTypeId.Value, moduleInstanceId.Value, name); _ReadOutputs(controller, element); return(controller); } catch (Exception e) { logging.Error(e, "Error loading Controller from XML"); return(null); } }