/// <summary>Initializes the PluginDockManagerViewModel.</summary> /// <returns>The view model for the PluginDockManager.</returns> public PluginDockManagerViewModel InitializePluginDockManagerViewModel() { PluginDockManagerViewModel viewModel = new PluginDockManagerViewModel(PluginLoader.PluginReader.PluginDirectory); PluginModelCollection plugins = PluginLoader.LoadPlugins(); PluginViewModelCollection pluginViewModels = new PluginViewModelCollection(); pluginViewModels.AddMany(plugins.Select(p => new PluginViewModel(p, PluginLoader, viewModel))); viewModel.Plugins.AddMany(pluginViewModels); return(viewModel); }
/// <summary>Loads the plug-ins.</summary> /// <returns>A collection of the PluginModel's describing each plug-in.</returns> /// <exception cref="PluginException">An error occurred attempting to retrieve the plug-in assembly names.</exception> /// <exception cref="PluginException">An error occurred attempting to load the plug-in assembly types.</exception> /// <exception cref="PluginException">An error occurred attempting to build a plug-in model for type [type].</exception> public PluginModelCollection LoadPlugins() { IReadOnlyList <PluginLocation> plugins = PluginReader.ReadPluginDirectory(); PluginTypeCollection pluginTypeCollection = PluginReader.LoadPluginAssemblyTypes(plugins); PluginModelCollection pluginModelCollection = new PluginModelCollection(); if (pluginTypeCollection == null || pluginTypeCollection.Count == 0) { return(pluginModelCollection); } foreach (Type type in pluginTypeCollection) { try { PluginInstanceAllowanceAttribute pluginInstanceAllowanceAttribute = type.GetCustomAttribute <PluginInstanceAllowanceAttribute>(); PluginNameAttribute pluginNameAttribute = type.GetCustomAttribute <PluginNameAttribute>(); ControlWrapperAttribute pluginControlWrapperAttribute = type.GetCustomAttribute <ControlWrapperAttribute>(); ControlWrapper pluginControlWrapper = pluginControlWrapperAttribute?.ControlWrapper ?? ControlWrapper.LayoutAnchorable; InstanceAllowance pluginInstanceAllowance = pluginInstanceAllowanceAttribute?.InstanceAllowance ?? InstanceAllowance.Single; string pluginName = pluginNameAttribute?.PluginName ?? type.Name; // double check to make sure the PluginName wasn't set to "" or string.Empty if (string.IsNullOrWhiteSpace(pluginName)) { pluginName = type.Name; } pluginModelCollection.Add(new PluginModel(type, pluginInstanceAllowance, pluginName, pluginControlWrapper)); } catch (Exception ex) { throw new PluginException(FormattableString.Invariant($"An error occurred attempting to build a plug-in model for type {type}."), ex); } } return(pluginModelCollection); }