private void InitializePluginControl(IPluginConfigurationControl configurationControl) { Dictionary <string, string> settings = new Dictionary <string, string>(); using (EnterpriseTestContext context = new EnterpriseTestContext()) { foreach (SystemSetting pluginSetting in context.SystemSettings.Where(n => n.Type.Equals("PluginSetting") && n.SubType.Equals(_metadata.MetadataType))) { settings.Add(pluginSetting.Name, pluginSetting.Value); } } PluginEnvironment environment = new PluginEnvironment ( new SettingsDictionary(settings), GlobalSettings.Items[Setting.Domain], GlobalSettings.Items[Setting.DnsDomain] ); if (string.IsNullOrEmpty(_metadata.Metadata)) { configurationControl.Initialize(environment); } else { PluginConfigurationData configurationData = _metadata.BuildConfigurationData(); configurationControl.Initialize(configurationData, environment); } _editorType = _metadata.MetadataType; _editor = configurationControl; }
/// <summary> /// Initializes this instance with the specified object. /// </summary> /// <param name="entity">The entity.</param> /// <exception cref="ControlTypeMismatchException"> /// Thrown when an object of incorrect type is passed to this instance. /// </exception> public void Initialize(object entity) { _metadata = entity as VirtualResourceMetadata; if (_metadata == null) { throw new ControlTypeMismatchException(entity, typeof(VirtualResourceMetadata)); } name_TextBox.Text = _metadata.Name; // Remove existing plugin from the editor panel foreach (IPluginConfigurationControl control in metadataEditor_Panel.Controls.OfType <IPluginConfigurationControl>()) { control.ConfigurationChanged -= PluginControl_ConfigurationChanged; } metadataEditor_Panel.Controls.Clear(); // Create the edit plugin and add it to the editor panel try { IPluginConfigurationControl pluginControl = CreatePluginControl(); Control control = (Control)pluginControl; control.Dock = DockStyle.Fill; metadataEditor_Panel.Controls.Add(control); } catch (PluginLoadException ex) { MessageBox.Show(ex.Message, "Plugin Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Reset unsaved changes HasUnsavedChanges = false; }
private IPluginConfigurationControl CreatePluginControl() { PluginAssembly assembly = null; try { assembly = PluginFactory.GetPlugin(_metadata.MetadataType); } catch (InvalidOperationException) { // Assembly stays null; error is thrown below } if (assembly?.Implements <IPluginConfigurationControl>() == true) { IPluginConfigurationControl configurationControl = assembly.Create <IPluginConfigurationControl>(); configurationControl.ConfigurationChanged += PluginControl_ConfigurationChanged; InitializePluginControl(configurationControl); return(configurationControl); } else { string errorMessage = Resource.PluginLoadErrorMessage.FormatWith(_metadata.MetadataType); TraceFactory.Logger.Error(errorMessage); throw new PluginLoadException(errorMessage); } }
private void InitializeConfigurationControl() { // Only SystemTrace should be useable during constructor _simulator.SetServiceContext(FrameworkServicesContext.ConfigurationConstructor); _configurationControl = _simulator.CreateConfigurationControl(); // Initialize the rest of the configuration services _simulator.SetServiceContext(FrameworkServicesContext.Configuration); // Call Initialize for the new control if (_configurationControl != null) { _configurationControl.ConfigurationChanged += configurationControl_ConfigurationChanged; _configurationControl.Initialize(_simulator.Environment); } // Add control to the UI SetPanelControl(pluginConfigurationPanel, _configurationControl as Control); SetUnsavedChanges(false); }
private static void UpdateMetadata(VirtualResourceMetadata metadata, IPluginConfigurationControl control) { // Get the XML metadata from the plugin PluginConfigurationData editorData = control.GetConfiguration(); metadata.Metadata = editorData.GetMetadata().ToString(); metadata.MetadataVersion = editorData.MetadataVersion; // Save asset selection data if (editorData.Assets != null) { if (metadata.AssetUsage == null) { metadata.AssetUsage = new VirtualResourceMetadataAssetUsage(); } metadata.AssetUsage.AssetSelectionData = Serializer.Serialize(editorData.Assets).ToString(); } else { metadata.AssetUsage = null; } // Save document selection data if (editorData.Documents != null) { if (metadata.DocumentUsage == null) { metadata.DocumentUsage = new VirtualResourceMetadataDocumentUsage(); } metadata.DocumentUsage.DocumentSelectionData = Serializer.Serialize(editorData.Documents).ToString(); } else { metadata.DocumentUsage = null; } // Save server selection data if (editorData.Servers != null) { if (metadata.ServerUsage == null) { metadata.ServerUsage = new VirtualResourceMetadataServerUsage(); } metadata.ServerUsage.ServerSelectionData = Serializer.Serialize(editorData.Servers).ToString(); } else { metadata.ServerUsage = null; } // Save print queue selection data if (editorData.PrintQueues != null) { if (metadata.PrintQueueUsage == null) { metadata.PrintQueueUsage = new VirtualResourceMetadataPrintQueueUsage(); } metadata.PrintQueueUsage.PrintQueueSelectionData = Serializer.Serialize(editorData.PrintQueues).ToString(); } else { metadata.PrintQueueUsage = null; } }