public static IExtendAction GetExtendAction(ISession session, string name) { ExtendFuncBizModel entity = ExtendConfigure.GetConfigureEntity(name); //找不到对应的配置则返回空 if (entity == null) { return(null); } EnumAddinType type = entity.MstModel.FuncType; IExtendAction executor = null; if (type == EnumAddinType.Url) { executor = new ExtendUrlAction(); } else if (type == EnumAddinType.Sql) { executor = new ExtendSqlAction(); } else if (type == EnumAddinType.Assembly) { executor = new ExtendAssemblyAction(); } //注入参数 if (executor != null) { executor.Session = session; executor.ConfigureEntity = entity; } return(executor); }
public string Executor(string extendName) { LogHelper <ExtendExecutor> .Info("当前扩展程序的方法名是:" + extendName); ISession session = null; string rtn = string.Empty; try { session = hibernateTemplate.SessionFactory.OpenSession(); if (session == null) { throw new AddinException("NHibernate无法获取Session"); } //初始化配置 ExtendConfigure.InitConfigure(session); //打出环境参数 LogHelper <ExtendExecutor> .PrintEvn(); IExtendAction action = ExtendActionFactory.GetExtendAction(session, extendName); if (action != null) { rtn = action.Execute(); } session.Close(); LogHelper <ExtendExecutor> .Info("当前扩展程序的执行结果集是:" + (rtn == null?"null":rtn)); return(rtn); } catch (Exception e) { LogHelper <ExtendExecutor> .Error("执行扩展方法出错:" + e.Message); throw; } finally { try { if (session.IsOpen) { session.Close(); } } catch (Exception) { throw; } } }