Exemplo n.º 1
0
        private object LoadPluginOnUiThread(PluginStartupInfo startupInfo)
        {
            _log.Debug("Creating plugin on UI thread");

            var assembly  = startupInfo.AssemblyName;
            var mainClass = startupInfo.MainClass;

            try
            {
                var obj = PluginCreator.CreatePlugin(startupInfo.AssemblyName, startupInfo.MainClass, _host);
                _log.Debug("Created local plugin class instance");

                var localPlugin = obj as IPlugin;

                if (localPlugin == null)
                {
                    var message = string.Format("Object of type {0} cannot be loaded as plugin " +
                                                "because it does not implement IPlugin interface", mainClass);

                    throw new InvalidOperationException(message);
                }

                var remotePlugin = new RemotePlugin(localPlugin);
                _log.Debug("Created plugin control");
                return(remotePlugin);
            }
            catch (Exception ex)
            {
                var message = String.Format("Error loading type '{0}' from assembly '{1}'. {2}",
                                            mainClass, assembly, ex.Message);

                return(new ApplicationException(message, ex));
            }
        }
Exemplo n.º 2
0
        private void Initialize()
        {
            _childContainer.RegisterType <IWpfHost, PluginViewOfHost>(new ContainerControlledLifetimeManager());
            _childContainer.RegisterType <PluginProcessProxy>(new ContainerControlledLifetimeManager());

            _startupInfp = new PluginStartupInfo
            {
                FullAssemblyPath = CatalogEntry.AssemblyPath,
                AssemblyName     = Path.GetFileNameWithoutExtension(CatalogEntry.AssemblyPath),
                Bits             = CatalogEntry.Bits,
                MainClass        = CatalogEntry.MainClass,
                Name             = CatalogEntry.Name,
                Parameters       = CatalogEntry.Parameters
            };

            _childContainer.RegisterInstance(_startupInfp);
        }
Exemplo n.º 3
0
        public IRemotePlugin LoadPlugin(IWpfHost host, PluginStartupInfo startupInfo)
        {
            _host = host;

            _log.Info(String.Format("LoadPlugin('{0}','{1}')", startupInfo.AssemblyName, startupInfo.MainClass));

            new ProcessMonitor(Dispose).Start(_host.HostProcessId);

            Func <PluginStartupInfo, object> createOnUiThread = LoadPluginOnUiThread;
            var result = _dispatcher.Invoke(createOnUiThread, startupInfo);

            _log.Debug("Returning plugin object to host");

            if (result is Exception)
            {
                _log.Error("Error loading plugin", (Exception)result);
                throw new TargetInvocationException((Exception)result);
            }
            return((IRemotePlugin)result);
        }
Exemplo n.º 4
0
 public PluginProcessProxy(PluginStartupInfo startupInfo, IWpfHost host, ErrorHandlingService errorHandlingService)
 {
     _startupInfo          = startupInfo;
     _host                 = host;
     _errorHandlingService = errorHandlingService;
 }