private static PluginPackAttribute GetAttributeByType(Type type) { //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("assembly not contain any plugin package attribute!"); } PluginPackAttribute attr = (PluginPackAttribute)attrs[0]; //attrDicts.Add(key, attr); return(attr); //} // return attrDicts[key]; }
/// <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 = this.GetAttribute(); bool isChanged=false; if(attr.Settings.Contains("enable_base64_image")) { WeblogRPCService.EnableBase64Images=attr.Settings["enable_base64_image"]=="yes"; } else { WeblogRPCService.EnableBase64Images=false; attr.Settings.Set("enable_base64_image","no"); isChanged=true; } if(isChanged) { attr.Settings.Flush(); } return PluginConnectionResult.Success; }
public PluginPackAttribute GetAttribute() { if (this._attr == null) { this._attr = PluginUtil.GetAttribute(this); } return this._attr; }
/// <summary> /// 初始化配置 /// </summary> /// <param name="attr"></param> private static void InitCfg(PluginPackAttribute attr) { // bool isChanged = false; // if (!attr.Settings.Contains("test_conf")) // { // attr.Settings.Add("test_conf", "测试配置", true); // isChanged = true; // } // // if (isChanged) attr.Settings.Flush(); }
/// <summary> /// 获取插件 /// </summary> /// <param name="workerIndent"></param> /// <returns></returns> public static IPlugin GetPlugin(string workerIndent, out PluginPackAttribute attr) { var plugins = BasePluginHost.plugins; foreach (IPlugin p in plugins.Keys) { if (String.Compare(workerIndent, plugins[p].WorkIndent, StringComparison.OrdinalIgnoreCase) == 0) { attr = plugins[p]; return p; } } attr = null; return null; }
/// <summary> /// 获取插件 /// </summary> /// <param name="workerIndent"></param> /// <returns></returns> public static IPlugin GetPlugin(string workerIndent, out PluginPackAttribute attr) { var plugins = BasePluginHost.plugins; foreach (IPlugin p in plugins.Keys) { if (String.Compare(workerIndent, plugins[p].WorkIndent, StringComparison.OrdinalIgnoreCase) == 0) { attr = plugins[p]; return(p); } } attr = null; return(null); }
/// <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); }
public static void Init(IPlugin plugin) { app = plugin; PluginAttr = plugin.GetAttribute(); initCfg(PluginAttr); InitWeixin(PluginAttr.Settings); //提供微信支付信息 var weixinPay_PartnerId = PluginAttr.Settings["WeixinPay_PartnerId"]; var weixinPay_Key = PluginAttr.Settings["WeixinPay_Key"]; var weixinPay_AppId = PluginAttr.Settings["WeixinPay_AppId"]; var weixinPay_AppKey = PluginAttr.Settings["WeixinPay_AppKey"]; var weixinPay_TenpayNotify = PluginAttr.Settings["WeixinPay_TenpayNotify"]; var tenPayV3_MchId = PluginAttr.Settings["TenPayV3_MchId"]; var tenPayV3_Key = PluginAttr.Settings["TenPayV3_Key"]; var tenPayV3_AppId = PluginAttr.Settings["TenPayV3_AppId"]; var tenPayV3_AppSecret = PluginAttr.Settings["TenPayV3_AppSecret"]; var tenPayV3_TenpayNotify = PluginAttr.Settings["TenPayV3_TenpayNotify"]; var weixinPayInfo = new TenPayInfo(weixinPay_PartnerId, weixinPay_Key, weixinPay_AppId, weixinPay_AppKey, weixinPay_TenpayNotify); TenPayInfoCollection.Register(weixinPayInfo); var tenPayV3Info = new TenPayV3Info(tenPayV3_AppId, tenPayV3_AppSecret, tenPayV3_MchId, tenPayV3_Key, tenPayV3_TenpayNotify); TenPayV3InfoCollection.Register(tenPayV3Info); }
public static void Init(IPlugin plugin) { PluginAttr = PluginUtil.GetAttribute(plugin); InitCfg(PluginAttr); }
public PluginPackAttribute GetAttribute() { return this._attr ?? (this._attr = PluginUtil.GetAttribute(this)); }
/// <summary> /// 从程序集中加载插件 /// </summary> /// <param name="assembly"></param> /// <returns></returns> private static bool loadFromAssembly(Assembly assembly) { PluginPackAttribute attribute = null; IPlugin plugin = null; var attbs = assembly.GetCustomAttributes(typeof(PluginPackAttribute), false); if (attbs.Length != 0) { attribute = (PluginPackAttribute)attbs[0]; } else { // foreach (Attribute attr in assembly.GetCustomAttributes(false)) // { // if (attr.ToString().IndexOf("PluginPackAttribute") != -1) // { // attribute = (PluginPackAttribute) attr; // // Log.Println(attribute.Name); // } // else // { // Log.Println(attr.ToString()); // } // } // // Log.Println(assembly.GetName().Name+" not a plugin!"); return(false); } var types = assembly.GetTypes(); foreach (Type type in types) { if (type.IsClass) { foreach (Type t in type.GetInterfaces()) { if (t == typeof(IPlugin)) { plugin = Activator.CreateInstance(type) as IPlugin; if (plugin == null) { continue; } if (attribute != null) { plugins.Add(plugin, attribute); } } } } } if (Log != null) { Log.Println(String.Format("{0}({1}) be found ; version is {2}.", attribute.Name, assembly.GetName().Name, attribute.Version)); } return(true); }
private static void initCfg(PluginPackAttribute attr) { //初始化配置 bool isChanged = false; if (!attr.Settings.Contains("WeixinPay_PartnerId")) { attr.Settings.Add("WeixinPay_PartnerId", ""); isChanged = true; } if (!attr.Settings.Contains("WeixinPay_Key")) { attr.Settings.Add("WeixinPay_Key", ""); isChanged = true; } if (!attr.Settings.Contains("WeixinPay_AppId")) { attr.Settings.Add("WeixinPay_AppId", ""); isChanged = true; } if (!attr.Settings.Contains("WeixinPay_AppKey")) { attr.Settings.Add("WeixinPay_AppKey", ""); isChanged = true; } if (!attr.Settings.Contains("WeixinPay_TenpayNotify")) { attr.Settings.Add("WeixinPay_TenpayNotify", ""); isChanged = true; } if (!attr.Settings.Contains("TenPayV3_MchId")) { attr.Settings.Add("TenPayV3_MchId", ""); isChanged = true; } if (!attr.Settings.Contains("TenPayV3_Key")) { attr.Settings.Add("TenPayV3_Key", ""); isChanged = true; } if (!attr.Settings.Contains("TenPayV3_AppId")) { attr.Settings.Add("TenPayV3_AppId", ""); isChanged = true; } if (!attr.Settings.Contains("TenPayV3_AppSecret")) { attr.Settings.Add("TenPayV3_AppSecret", ""); isChanged = true; } if (!attr.Settings.Contains("TenPayV3_TenpayNotify")) { attr.Settings.Add("TenPayV3_TenpayNotify", ""); isChanged = true; } if (!attr.Settings.Contains("Weixin_AppId")) { attr.Settings.Add("Weixin_AppId", "填写微信AppId"); isChanged = true; } if (!attr.Settings.Contains("Weixin_AppSecret")) { attr.Settings.Add("Weixin_AppSecret", "填写微信AppSecret"); isChanged = true; } if (!attr.Settings.Contains("Weixin_AppEncodeString")) { attr.Settings.Add("Weixin_AppEncodeString", "填写微信App解密字符串"); isChanged = true; } if (!attr.Settings.Contains("Weixin_Token")) { attr.Settings.Add("Weixin_Token", "填写微信token"); isChanged = true; } if (!attr.Settings.Contains("Weixin_ApiDomain")) { attr.Settings.Add("Weixin_ApiDomain", "填写用于对接微信的域名:如http://www.ops.cc/weixin/。"); isChanged = true; } if (!attr.Settings.Contains("Weixin_WelcomeMessage")) { attr.Settings.Add("Weixin_WelcomeMessage", "欢迎来到微信!"); isChanged = true; } if (!attr.Settings.Contains("Weixin_EnterMessage")) { attr.Settings.Add("Weixin_EnterMessage", ""); isChanged = true; } if (!attr.Settings.Contains("Weixin_MenuButtons")) { attr.Settings.Add("Weixin_MenuButtons", "填写微信自定义按钮"); isChanged = true; } if (isChanged) attr.Settings.Flush(); }