Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlugInData"/> class.
        /// </summary>
        /// <param name="plugIn">A <see cref="IPlugIn"/>-reference to the PlugIn for which to keep the information.</param>
        public PlugInData(IPlugIn plugIn)
        {
            if (plugIn == null)
            {
                throw new ArgumentNullException("plugIn");
            }

            this.plugIn = plugIn;

            Type type = plugIn.GetType();

            if (type == null)
            {
                throw new InvalidOperationException("Unable to retrieve type of 'plugIn'-instance");
            }

            Assembly asm = type.Assembly;

            if (asm == null)
            {
                throw new InvalidOperationException("Unable to retrieve assembly-information for plugIn-Type");
            }

            this.assemblyFullName = asm.FullName;
        }
        /// <summary>
        ///     Loads the <paramref name = "plugIn" /> (calling its <see cref = "IPlugIn.LoadPlugIn" /> method) and
        ///     adds it to the <see cref = "Plugins" /> dictionary for access by other services.
        /// </summary>
        /// <param name = "plugIn">The plugin to load.</param>
        /// <exception cref = "ArgumentNullException">If <paramref name = "plugIn" /> is null.</exception>
        public void LoadPlugIn(IPlugIn plugIn)
        {
            if (plugIn == null)
            {
                throw new ArgumentNullException("plugIn");
            }

            //Services核心服务会从这里传入插件!!查看类PluginLoaderBase的实现
            plugIn.LoadPlugIn(this);
            _plugins.Add(plugIn.GetType(), plugIn);
            //_container.AddComponent(plugIn.GetType().FullName, typeof(IPlugIn), plugIn.GetType());

            //插件加载后,立刻加入容器
            var _builder = new ContainerBuilder();

            //_builder.Register();
            _builder.RegisterType(plugIn.GetType()).As <IPlugIn>();
            _builder.Update(_container);
            //  _builder.Update(_container);
        }
Esempio n. 3
0
		/// <summary>
		/// 	Loads the <paramref name = "plugIn" /> (calling its <see cref = "IPlugIn.LoadPlugIn" /> method) and
		/// 	adds it to the <see cref = "Plugins" /> dictionary for access by other services.
		/// </summary>
		/// <param name = "plugIn">The plugin to load.</param>
		/// <exception cref = "ArgumentNullException">If <paramref name = "plugIn" /> is null.</exception>
		public void LoadPlugIn(IPlugIn plugIn)
		{
			if (plugIn == null)
			{
				throw new ArgumentNullException("plugIn");
			}

			plugIn.LoadPlugIn(this);
		    var type = plugIn.GetType();
		    _plugins.Add(type, plugIn);
            _container.Bind<IPlugIn>().To(type).InSingletonScope().Named(type.FullName);
        }
        public FrameworkElement GetElement(IPlugIn plugInManager)
        {
            var fullType = plugInManager.GetType();

            var method = fullType.GetMethod("GetElement");

            var element = method.Invoke(
                plugInManager,
                new object[]
            {
            });

            return(element as FrameworkElement);
        }
        public void PlacePlugIn(IPlugIn plugIn, object dataContext)
        {
            var bootstrapper = ServiceLocator.Current.GetInstance <Bootstrapper>();

            FrameworkElement element = null;

            try
            {
                element = bootstrapper.GetElement(plugIn);
            }
            catch
            {
                MessageBox.Show(
                    "Error when creating element for plugin " + plugIn.GetType());
            }

            if (element == null)
            {
                return;
            }

            element.DataContext = dataContext;

            if (PlugInHost1.Child == null)
            {
                PlugInHost1.Child = element;
                return;
            }

            if (PlugInHost2.Child == null)
            {
                PlugInHost2.Child = element;
                return;
            }

            MessageBox.Show("No more room");
        }
Esempio n. 6
0
        public void ExecuteRequest(string jobId, string pluginName, Version plugInVersion, PerformContext context)
        {
            // create a logger
            var logger = context.CreateLoggerForPerformContext <HangfireManager>();

            // This is a 1st pass at preventing duplicate recurring job when the previous execution is still running
            var job = JobStorage.Current.GetConnection().GetRecurringJobs().Where(j => j.Id == jobId).FirstOrDefault();

            if (job != null)
            {
                if (job.LastJobState == "Enqueued" || job.LastJobState == "Processing")
                {
                    logger.Information("This goes to the job console automatically");

                    logger.Warning("Skipping execution of JobId: {jobId}, it is still running from a previous execution.", jobId);
                    return;
                }
            }

            // dynamically select the correct plug-in assy to use to process the event
            IPlugIn jobPlugIn = _plugInsManager.GetJobPlugIn(pluginName, plugInVersion).PlugInImpl;;

            var plugInLoadContextName = AssemblyLoadContext.GetLoadContext(jobPlugIn.GetType().Assembly).Name;

            logger.Information("Running plugin {pluginInfo} in ALC: {plugInLoadContextName}.", jobPlugIn.GetPlugInInfo(), plugInLoadContextName);

            try
            {
                // call the method on the dynamically selected assy passing in an anonymous action delagate for the logging method
                var result = jobPlugIn.Execute(context.BackgroundJob.Id, (LOG_LEVEL logLevel, string logMessage) =>
                {
                    switch (logLevel)
                    {
                    case LOG_LEVEL.INFO:
                        logger.Information(logMessage);
                        break;

                    case LOG_LEVEL.WARNING:
                        logger.Warning(logMessage);
                        break;

                    case LOG_LEVEL.ERROR:
                        logger.Error(logMessage);
                        break;
                    }
                });

                // write post execution log message
                switch (result.StepStatus)
                {
                case STD_STEP_STATUS.SUCCESS:
                    logger.Information(result.ReturnMessage);
                    break;

                case STD_STEP_STATUS.FAILURE:
                    logger.Error(result.ReturnMessage);
                    break;
                }
            }
            catch (Exception ex)
            {
                logger.Error($"Unhandled exception occured in plugin: [{ex.ToString()}]");
            }
            finally
            {
                if (jobPlugIn != null)
                {
                    jobPlugIn = null;
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Loads the PlugIns.
        /// </summary>
        /// <param name="alreadyLoadedPlugIns"> List of Plugins </param>
        public void LoadPlugIns(PlugInDataList alreadyLoadedPlugIns)
        {
            this.plugIns.Clear();
            var textReader = new XmlTextReader(this.FileName);

            while (textReader.Read())
            {
                if (textReader.Name == "add")
                {
                    string  type   = textReader.GetAttribute("type");
                    IPlugIn plugIn = null;

                    if (type != null)
                    {
                        Type plugInType = Type.GetType(type);
                        if (plugInType != null)
                        {
                            object plugInInstance = Activator.CreateInstance(plugInType);

                            plugIn = plugInInstance as IPlugIn;
                        }
                    }

                    if (plugIn != null)
                    {
                        PlugInData plugInData    = new PlugInData(plugIn);
                        bool       alreadyLoaded = false;

                        foreach (PlugInData loadedPlugInData in this.LoadedPlugIns)
                        {
                            if (loadedPlugInData.AssemblyFullName == plugInData.AssemblyFullName)
                            {
                                alreadyLoaded = true;
                                break;
                            }
                        }

                        if (!alreadyLoaded)
                        {
                            this.LoadedPlugIns.Add(plugInData);
                        }
                    }
                }
            }

            // create a plugIn list to collect invalid PlugIns
            var invalidPlugIns = new PlugInDataList();

            // try and get the baseobjects published by the PlugIn
            foreach (PlugInData plugInData in this.plugIns)
            {
                IPlugIn plugIn     = plugInData.PlugIn;
                Type    plugInType = plugIn.GetType();

                // JP 22/12/2011 - This does not do anything
                System.Reflection.Assembly plugInAssembly = plugInType.Assembly;
            }

            // Remove all invalid PlugIns from the PlugIns list
            foreach (PlugInData plugInData in invalidPlugIns)
            {
                this.plugIns.Remove(plugInData);
            }
        }