internal static Type GetCustomTypeByClass(string className)
        {
            var key         = "Assembly_" + CustomDllName + assembly.GetHashCode();
            var newAssembly = new ReflectionInoCacheService().GetOrCreate <Assembly>(key, () => {
                try
                {
                    var path = Assembly.GetExecutingAssembly().Location;
                    if (path.HasValue())
                    {
                        path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), CustomDllName + ".dll");
                    }
                    if (path.HasValue() && FileHelper.IsExistFile(path))
                    {
                        return(Assembly.LoadFrom(path));
                    }
                    else
                    {
                        return(Assembly.LoadFrom(CustomDllName + ".dll"));
                    }
                }
                catch
                {
                    var message = "Not Found " + CustomDllName + ".dll";
                    Check.Exception(true, message);
                    return(null);
                }
            });
            Type type = newAssembly.GetType(className);

            return(type);
        }
Beispiel #2
0
 public virtual void ExecuteBefore(string sql, SugarParameter[] parameters)
 {
     if (this.Context.IsAsyncMethod == false && this.Context.CurrentConnectionConfig.Debugger != null && this.Context.CurrentConnectionConfig.Debugger.EnableThreadSecurityValidation == true)
     {
         var contextId = this.Context.ContextID.ToString();
         var processId = Thread.CurrentThread.ManagedThreadId.ToString();
         var cache     = new ReflectionInoCacheService();
         if (!cache.ContainsKey <string>(contextId))
         {
             cache.Add(contextId, processId);
         }
         else
         {
             var cacheValue = cache.Get <string>(contextId);
             if (processId != cacheValue)
             {
                 throw new SqlSugarException(this.Context, ErrorMessage.GetThrowMessage("Detection of SqlSugarClient cross-threading usage,a thread needs a new one", "检测到声名的SqlSugarClient跨线程使用,请检查是否静态、是否单例、或者IOC配置错误引起的,保证一个线程new出一个对象 ,具本Sql:") + sql, parameters);
             }
         }
     }
     this.BeforeTime = DateTime.Now;
     if (this.IsEnableLogEvent)
     {
         Action <string, SugarParameter[]> action = LogEventStarting;
         if (action != null)
         {
             if (parameters == null || parameters.Length == 0)
             {
                 action(sql, new SugarParameter[] { });
             }
             else
             {
                 action(sql, parameters);
             }
         }
     }
 }