Ejemplo n.º 1
0
		/// <summary>
		/// 初始化插件
		/// </summary>
		/// <param name="_app"></param>
		/// <returns></returns>
		public PluginConnectionResult Connect(IPluginHost _app)
		{
			IExtendApp app = _app as IExtendApp;
			if (app != null)
			{
				//注册
                app.Register(this,app_OnExtendModuleRequest, app_OnExtendModulePost);
                Cms.Plugins.MapExtendPluginRoute("xmlrpc", app.GetAttribute(this).WorkIndent);
			}
			
			blogService=new WeblogRPCService();
			
			//初始化设置
			attr=PluginUtil.GetAttribute<XmlRpcPluginCore>();
			bool isChanged=false;
			
			if(attr.Settings.Contains("enable_base64_image"))
			{
				WeblogRPCService.EnableBase64Images=attr.Settings["enable_base64_image"]=="yes";
			}
			else
			{
				WeblogRPCService.EnableBase64Images=false;
				attr.Settings.Append("enable_base64_image","no");
				isChanged=true;
			}
			
			if(isChanged)
			{
				attr.Settings.Flush();
			}
			
			return PluginConnectionResult.Success;
		}
Ejemplo n.º 2
0
        private static PluginPackAttribute GetAttributeByType(Type type)
        {
            // if (t.IsSubclassOf(typeof(IPlugin))) { }
            int key = type.Assembly.GetHashCode();

            if (attrDicts == null)
            {
                attrDicts = new Dictionary <int, PluginPackAttribute>();
            }

            if (!attrDicts.Keys.Contains(key))
            {
                object[] attrs = type.Assembly.GetCustomAttributes(typeof(PluginPackAttribute), false);
                if (attrs.Length == 0)
                {
                    throw new Exception();
                }

                PluginPackAttribute attr = (PluginPackAttribute)attrs[0];
                attrDicts.Add(key, attr);
                return(attr);
            }

            return(attrDicts[key]);
        }
Ejemplo n.º 3
0
        static Config()
        {
            PluginAttrs = PluginUtil.GetAttribute<Main>();
            bool isChanged=false;

            //if(!PackAttr.Settings.Contains("notify.workerindent"))
            //{
            //    PackAttr.Settings.Append("notify.workerindent","");
            //    isChanged=true;
            //}

            //if(!PackAttr.Settings.Contains("alipay.account"))
            //{
            //    PackAttr.Settings.Append("alipay.account","");
            //    isChanged=true;
            //}

            //if(!PackAttr.Settings.Contains("alipay.userkey"))
            //{
            //    PackAttr.Settings.Append("alipay.userkey","");
            //    isChanged=true;
            //}

            //if(!PackAttr.Settings.Contains("alipay.secret"))
            //{
            //    PackAttr.Settings.Append("alipay.secret","");
            //    isChanged=true;
            //}

            if (isChanged) PluginAttrs.Settings.Flush();
        }
Ejemplo n.º 4
0
 public PluginPackAttribute GetAttribute()
 {
     if (this._attr == null)
     {
         this._attr = PluginUtil.GetAttribute(this);
     }
     return this._attr;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取插件
        /// </summary>
        /// <param name="workerIndent"></param>
        /// <returns></returns>
        public static IPlugin GetPlugin(string workerIndent, out PluginPackAttribute attr)
        {
            var plugins = PluginAppBase.plugins;

            foreach (IPlugin p in plugins.Keys)
            {
                if (String.Compare(workerIndent, plugins[p].WorkIndent, true) == 0)
                {
                    attr = plugins[p];
                    return(p);
                }
            }

            attr = null;
            return(null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 注册扩展处理程序
        /// </summary>
        /// <param name="extendName">扩展名称,而且也是访问地址的名称。如扩展名称为:ext,那么可使用/ext.sh访问该扩展插件</param>
        /// <param name="getReqHandler">委托PluginHandler<CmsContext,string>的实例</param>
        /// <param name="postReqHandler">委托PluginHandler<CmsContext,string>的实例</param>
        /// <returns></returns>
        public bool Register(IPlugin plugin,
                             PluginHandler <T> reqHandler)
        {
            Type type = plugin.GetType();
            PluginPackAttribute attr = PluginUtil.GetAttribute(plugin);
            string indent            = attr.WorkIndent;

            if (reqHandler == null || reqHandlers.Keys.Contains(indent))
            {
                return(false);
            }

            if (reqHandler != null)
            {
                reqHandlers.Add(indent, reqHandler);
            }

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载单个插件
        /// </summary>
        /// <param name="pluginFile"></param>
        public static bool LoadPlugin(string pluginFile)
        {
            PluginPackAttribute attribute = null;
            IPlugin             obj       = null;

            try
            {
                byte[] bytes = File.ReadAllBytes(pluginFile);
                var    ass   = Assembly.Load(bytes);
                var    attbs = ass.GetCustomAttributes(typeof(PluginPackAttribute), true);

                if (attbs.Length != 0)
                {
                    attribute = (PluginPackAttribute)attbs[0];
                }
                else
                {
                    //StringBuilder sb = new StringBuilder();
                    //foreach (object a in ass.GetCustomAttributes(true))
                    //{
                    //    sb.Append("\r\n")
                    //        .Append(a.GetType() == typeof(PluginPackAttribute));
                    //}
                    throw new NotSupportedException("不可识别的插件!请为程序集标记PluginPack特性!");
                }

                var types = ass.GetTypes();
                foreach (Type type in types)
                {
                    if (type.IsClass)
                    {
                        foreach (Type t in type.GetInterfaces())
                        {
                            if (t == typeof(IPlugin))
                            {
                                obj = Activator.CreateInstance(type) as IPlugin;
                                if (obj == null)
                                {
                                    continue;
                                }

                                if (attribute != null)
                                {
                                    plugins.Add(obj, attribute);
                                }
                            }
                        }
                    }
                }
                if (log != null)
                {
                    log.Append(String.Format("\r\n{0}({1}) found plugin. version:{2}",
                                             attribute.Name,
                                             ass.GetName().Name,
                                             attribute.Version));
                }
            }
            catch (Exception err)
            {
                if (log != null)
                {
                    log.Append(String.Format("\r\nAssembly {0} happend exception:{1}",
                                             pluginFile.Substring(pluginFile.LastIndexOfAny(new char[] { '/', '\\' }) + 1),
                                             err.Message));
                }
                return(false);
            }
            return(true);
        }