Esempio n. 1
0
        public static AutoCall GetDataOptAutoCall(object[] attributes)
        {
            AutoCall autoCall = null;

            foreach (var item in attributes)
            {
                if (null != (item as AutoCall))
                {
                    autoCall = (AutoCall)item;
                    break;
                }
            }
            return(autoCall);
        }
Esempio n. 2
0
        /// <summary>
        /// 当执行接口方法时,根据数据提供者获取sql语句表达式(动态创建sql语句)
        /// </summary>
        /// <param name="dataProvider">sql语句数据提供者</param>
        /// <param name="paraList">接口方法参数集合</param>
        /// <param name="dbParameters">sql语句参数集合</param>
        /// <param name="autoCall">AutoCall对象</param>
        /// <param name="dataOptType">数据操作类型select|insert|update|delete</param>
        /// <param name="sql">返回sql语句提供者动态生成的sql语句</param>
        public void GetSqlByDataProvider(ISqlExpressionProvider dataProvider, PList <Para> paraList, DbList <DbParameter> dbParameters, AutoCall autoCall, DataOptType dataOptType, ref string sql)
        {
            if (null != dataProvider)
            {
                int      ncount = paraList.Count;
                object[] paras  = new object[ncount];
                int      n      = 0;
                foreach (Para p in paraList)
                {
                    paras[n] = p.ParaValue;
                    n++;
                }

                MethodInfo m = typeof(ISqlExpressionProvider).GetMethod("provideSql");

                try
                {
                    object v = m.Invoke(dataProvider, new object[] { dbParameters, dataOptType, paraList, paras });
                    if (null != v)
                    {
                        sql = v.ToString();
                    }
                }
                catch (Exception ex)
                {
                    autoCall.ExecuteExcption(typeof(ISqlExpressionProvider), null, "provideSql", paraList, ex);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 根据名称空间和类名获取sql语句提供者接口实例
        /// </summary>
        /// <param name="dataProviderNamespace">sql语句提供者接口实例所属名称空间</param>
        /// <param name="dataProviderClassName">sql语句提供者接口实例类名称</param>
        /// <param name="autoCall">AutoCall对象</param>
        /// <returns></returns>
        public ISqlExpressionProvider GetDataProvider(string dataProviderNamespace, string dataProviderClassName, AutoCall autoCall)
        {
            Assembly ass           = null;
            string   classPath     = dataProviderNamespace + "." + dataProviderClassName;
            Type     type          = null;
            string   interfaceName = typeof(ISqlExpressionProvider).FullName;

            if (!string.IsNullOrEmpty(_sqlProviderRelativePath) && null != GetDllAbsolutePathByRelativePath)
            {
                string dllFile = GetDllAbsolutePathByRelativePath(_sqlProviderRelativePath);
                if (!File.Exists(dllFile))
                {
                    Exception ex1 = new Exception(string.Format("路径{0}不存在", dllFile));
                    autoCall.ExecuteExcption(typeof(ISqlExpressionProvider), null, null, null, ex1);
                    return(null);
                }
                ass  = Assembly.LoadFrom(dllFile);
                type = ass.GetType(classPath);
                if (null == type.GetInterface(interfaceName))
                {
                    type = null;
                }
            }

            if (null == type && null != AssemblyCollection)
            {
                foreach (Assembly item in AssemblyCollection)
                {
                    type = item.GetType(classPath);
                    if (null != type)
                    {
                        if (null != type.GetInterface(interfaceName))
                        {
                            break;
                        }
                    }
                }
            }

            if (null == type)
            {
                Assembly   curAss = Assembly.GetExecutingAssembly();
                StackTrace trace  = new StackTrace();

                int        n          = 0;
                StackFrame stackFrame = trace.GetFrame(n);
                MethodBase methodBase = null;
                while (null != stackFrame && 10 > n)
                {
                    n++;
                    methodBase = stackFrame.GetMethod();
                    ass        = methodBase.Module.Assembly;
                    type       = ass.GetType(classPath);
                    if (null != type)
                    {
                        if (null != type.GetInterface(interfaceName))
                        {
                            break;
                        }
                    }
                    stackFrame = trace.GetFrame(n);
                }
            }

            if (null == type)
            {
                string    f   = ass.FullName;
                Exception ex2 = new Exception(string.Format("在程序集:{0} 下\r\n类路径 {1} 不存在", f, classPath));
                autoCall.ExecuteExcption(typeof(ISqlExpressionProvider), null, null, null, ex2);
                return(null);
            }

            ISqlExpressionProvider dataProvider = null;

            try
            {
                object obj = Activator.CreateInstance(type);
                if (null == obj.GetType().GetInterface("ISqlExpressionProvider"))
                {
                    throw new Exception(string.Format("类 {0} 未实现接口类 ISqlExpressionProvider", classPath));
                }
                dataProvider = obj as ISqlExpressionProvider;
            }
            catch (Exception ex)
            {
                autoCall.ExecuteExcption(typeof(ISqlExpressionProvider), null, null, null, ex);
            }

            return(dataProvider);
        }
Esempio n. 4
0
 /// <summary>
 /// 每次根据接口创建待装配的实例对象时调用
 /// </summary>
 /// <param name="interfaceType">接口类型</param>
 /// <param name="implement">接口实例对象</param>
 /// <param name="autoCall">AutoCall对象</param>
 /// <param name="tempImplementCount">接口临时实例数量</param>
 public virtual void CreateInstanceByInterface(Type interfaceType, object implement, AutoCall autoCall, int tempImplementCount)
 {
 }