protected virtual void Initialize(IPluginServiceProvider serviceProvider) { this.coreForm = serviceProvider.GetService(typeof(Form)) as Form; if (serviceProvider.Contains(typeof(IContainerControl))) { this.mdiUIContainer = serviceProvider.GetService(typeof(IContainerControl)) as Control; } this.currentModulePluginController = serviceProvider.GetService(typeof(IPluginController <>)) as IPluginController <TPluginItem>; this.modulePluginManager = serviceProvider.GetService(typeof(IPluginManager <>)) as IPluginManager <TPluginItem>; this.currentAppModulePluginItem = this.currentModulePluginController.PluginItem; if (this.mdiUIContainer == null) { throw new InfrastructureException("The container which is used to load this UI screen cannot be null. Please specify a container which inherits control. E.g. panel or form."); } if (this.mdiUIContainer != null && !this.mdiUIContainer.Controls.Contains(this)) { this.mdiUIContainer.SuspendLayout(); this.Dock = DockStyle.Fill; this.mdiUIContainer.Controls.Add(this); this.mdiUIContainer.ResumeLayout(); } this.Focus(); this.Hide(); }
public PluginController(TPluginItem pluginItem, IPluginServiceProvider serviceProvider, IPluginManager <TPluginItem> pluginManager) { this.pluginItem = pluginItem; this.serviceProvider = serviceProvider; this.pluginManager = pluginManager; }
public PluginManager(IPluginProvider pluginProvider, IPluginServiceProvider serviceProvider) { this.pluginProvider = pluginProvider; this.serviceProvider = serviceProvider; this.pluginControllers = new PluginControllerCollection <TPluginItem>(); this.serviceProvider.AddService(typeof(IPluginManager <>), this); }
protected override void Initialize(IPluginServiceProvider serviceProvider) { if (serviceProvider.Contains(typeof(Ribbon))) { this.RibbonMenu = serviceProvider.GetService(typeof(Ribbon)) as Ribbon; if (this.RibbonMenu == null) { throw new InfrastructureException("The service provide doesn't contain Ribbon control. Please specify a Ribbon control."); } } base.Initialize(serviceProvider); }
public static TranslationPlugin ThisIsTheFactoryMethod(IPluginServiceProvider services) { var configFromHost = services.GetHostService <IConfiguration>(); var hostService = services.GetSharedHostService(typeof(ICurrentLanguageProvider)); var hostServiceBridge = new CurrentLanguageProviderBridge(hostService); var dictionaryService = services.GetPluginService <IDictionaryService>(); return(new TranslationPlugin( configFromHost, // This service is provided by the Prise.IntegrationTestsHost application and is registered as a Host Type hostServiceBridge, // This service is provided by the Prise.IntegrationTestsHost application and is registered as a Remote Type dictionaryService // This service is provided by the plugin using the PluginBootstrapper )); }
protected virtual object InjectFieldsWithServices(object remoteInstance, IPluginServiceProvider pluginServiceProvider, IEnumerable <PluginService> pluginServices) { foreach (var pluginService in pluginServices) { object serviceInstance = null; switch (pluginService.ProvidedBy) { case ProvidedBy.Host: serviceInstance = pluginServiceProvider.GetHostService(pluginService.ServiceType); break; case ProvidedBy.Plugin: serviceInstance = pluginServiceProvider.GetPluginService(pluginService.ServiceType); break; } try { remoteInstance .GetType() .GetTypeInfo() .DeclaredFields .First(f => f.Name == pluginService.FieldName) .SetValue(remoteInstance, serviceInstance); continue; } catch (ArgumentException) { } if (pluginService.BridgeType == null) { throw new PrisePluginException($"Field {pluginService.FieldName} could not be set, please consider using a PluginBridge."); } var bridgeConstructor = pluginService.BridgeType .GetConstructors(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(c => c.GetParameters().Count() == 1 && c.GetParameters().First().ParameterType == typeof(object)); if (bridgeConstructor == null) { throw new PrisePluginException($"PluginBridge {pluginService.BridgeType.Name} must have a single public constructor with one parameter of type object."); } var bridgeInstance = bridgeConstructor.Invoke(new[] { serviceInstance }); remoteInstance.GetType().GetTypeInfo().DeclaredFields.First(f => f.Name == pluginService.FieldName).SetValue(remoteInstance, bridgeInstance); } return(remoteInstance); }
protected virtual object InjectPluginFieldsWithServices(object remoteInstance, IPluginServiceProvider pluginServiceProvider, IEnumerable <PluginService> pluginServices) { foreach (var pluginService in pluginServices) { var fieldName = pluginService.FieldName; object serviceInstance = null; switch (pluginService.ProvidedBy) { case ProvidedBy.Host: serviceInstance = pluginServiceProvider.GetHostService(pluginService.ServiceType); break; case ProvidedBy.Plugin: serviceInstance = pluginServiceProvider.GetPluginService(pluginService.ServiceType); break; } if (TrySetField(remoteInstance, fieldName, serviceInstance)) { continue; // Field was set successfully, continueing } if (pluginService.ProxyType == null) { throw new PluginActivationException($"Field {pluginService.FieldName} could not be set, please consider using a ReverseProxy."); } var reverseProxyCtor = GetReverseProxyConstructor(pluginService.ProxyType); if (reverseProxyCtor == null) { throw new PluginActivationException($"ReverseProxy {pluginService.ProxyType.Name} must have a single public constructor with one parameter of type object."); } var reverseProxyInstance = AddToDisposables(reverseProxyCtor.Invoke(new[] { serviceInstance })); if (!TrySetField(remoteInstance, fieldName, reverseProxyInstance)) { throw new PluginActivationException($"Field {pluginService.FieldName} on Plugin could not be set."); } } return(remoteInstance); }
public void Run(IPluginServiceProvider serviceProvider) { bool cancelled = false; object actionResult = null; Exception exception = null; try { actionResult = this.RunCore(serviceProvider); } catch (Exception e) { exception = e; } finally { this.OnLoaded(exception, cancelled, actionResult); } }
protected override object RunCore(IPluginServiceProvider serviceProvider) { CostLineType currentCostType = (CostLineType)serviceProvider.GetService(typeof(CostLineType)); CostManagerFactory costManagerFactory = CostManagerFactory.GetInstance(currentCostType); object currentCostManagerObject = EAppRuntime.Instance.CurrentApp.ObjectContainer.Resolve(costManagerFactory.CurrentCostManagerType); ProxyGenerator proxyGenerator = new ProxyGenerator(); var options = new ProxyGenerationOptions(); options.AddMixinInstance(currentCostManagerObject); ICostManager costManager = (ICostManager)proxyGenerator.CreateClassProxy <CostManagerFactory>(options); costManager.AddCostLine(); return(costManager.CurrentDisplayedCostLines); }
protected override object RunCore(IPluginServiceProvider serviceProvider) { CostLineType currentCostType = (CostLineType)serviceProvider.GetService(typeof(CostLineType)); CostManagerFactory costManagerFactory = CostManagerFactory.GetInstance(currentCostType); object currentCostManagerObject = EAppRuntime.Instance.CurrentApp.ObjectContainer.Resolve(costManagerFactory.CurrentCostManagerType); ProxyGenerator proxyGenerator = new ProxyGenerator(); var options = new ProxyGenerationOptions(); options.AddMixinInstance(currentCostManagerObject); ICostManager costManager = (ICostManager)proxyGenerator.CreateClassProxy<CostManagerFactory>(options); costManager.AddCostLine(); return costManager.CurrentDisplayedCostLines; }
/// <summary> /// Creates a sequence of tuples from the given IPluginServiceProvider instance. /// </summary> /// <param name="service"></param> /// <returns></returns> public static IEnumerable <Tuple <Type, object> > AsTuple(this IPluginServiceProvider service) { return(Enumerable.Select(service.PluginService, s => s.AsTuple())); }
public static AuthenticatedDataService Factory(IPluginServiceProvider pluginServiceProvider) { var tokenService = pluginServiceProvider.GetPluginService <ITokenService>(); return(new AuthenticatedDataService(tokenService)); }
protected override object RunCore(IPluginServiceProvider serviceProvider) { return(null); }
protected abstract object RunCore(IPluginServiceProvider serviceProvider);
protected override object RunCore(IPluginServiceProvider serviceProvider) { return null; }
public virtual void Run(IPluginServiceProvider serviceProvider) { return; }
public virtual void Run(IPluginServiceProvider serviceProvider) { this.Initialize(serviceProvider); this.OnViewLoaded(); }