Ejemplo n.º 1
0
        public async Task <bool> Start(PluginCoreContext context)
        {
            foreach (PluginInfo pi in PluginList)
            {
                if (pi.InitFail)
                {
                    continue;
                }
                try
                {
                    var r = await pi.Instance.Start(context);

                    pi.SetStartFail(r.Code != "0");
                    pi.SetMessage(r.Message);
                    //Logger.Debug("plugin {0} start {1} {2}", pi.Name, r.Code, r.Message ?? "");
                    if (r.IsSuccess())
                    {
                        //pi.SetRunning(true);
                    }
                }
                catch (Exception e)
                {
                    //Logger.Error("plugin {0} start error \r\n{1}", pi.Name, e.ToString());
                    pi.SetStartFail(true);
                    pi.SetMessage(e.Message);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> Stop(PluginCoreContext context)
        {
            foreach (PluginInfo pi in PluginList)
            {
                //初始化失败 不调用停止,但如果初始化成功,后面Start失败,依然会调用Stop
                if (pi.InitFail)
                {
                    continue;
                }
                try
                {
                    var r = await pi.Instance.Stop(context);

                    pi.SetMessage(r.Message);
                    //Logger.Debug("plugin {0} stop {1} {2}", pi.Name, r.Code, r.Message ?? "");
                    if (r.IsSuccess())
                    {
                        pi.SetRunning(false);
                    }
                }
                catch (Exception e)
                {
                    //Logger.Error("plugin {0} stop error \r\n{1}", pi.Name, e.ToString());
                    pi.SetMessage(e.Message);
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        // Init
        //configureOptions
        public static PluginCoreBuilder Configure(this IServiceCollection services, Action <PluginCoreOptions> configureOptions)
        {
            var options = new PluginCoreOptions();

            configureOptions(options);

            PluginCoreContext context = new PluginCoreContext();

            context.Services       = services;
            context.PluginBasePath = System.IO.Path.Combine(AppContext.BaseDirectory, options.PluginPath);

            context.Init();
            return(new PluginCoreBuilder(options));
        }
Ejemplo n.º 4
0
        public async Task <bool> Init(PluginCoreContext context)
        {
            foreach (PluginInfo pi in PluginList)
            {
                try
                {
                    var r = await pi.Instance.Init(context);

                    pi.SetInitFail(r.Code != "0");
                }
                catch (Exception e)
                {
                    //Logger.Error("plugin {0} init error \r\n{1}", pi.Name, e.ToString());
                    pi.SetInitFail(true);
                    pi.SetMessage(e.Message);
                }
            }
            return(true);
        }
Ejemplo n.º 5
0
 public virtual Task <PluginResultMessage> Stop(PluginCoreContext context)
 {
     return(Task.FromResult(new PluginResultMessage()));
 }
Ejemplo n.º 6
0
 public virtual Task <PluginResultMessage> Init(PluginCoreContext context)
 {
     this.PluginCoreCtext = context;
     return(Task.FromResult(new PluginResultMessage()));
 }