/// <summary> /// 注册类型。 /// </summary> /// <param name="type"></param> /// <returns></returns> public DatabaseSchemaHandler RegisterType(System.Type type) { if (type == null || !type.IsClass || type.IsAbstract || !TypeExtensions.IsInheritFrom(type, typeof(DatabaseSchemaHandler))) { return(null); } DatabaseSchemaHandler handler = null; string key = type.FullName; if (_caches.TryGetValue(key, out handler)) { return(handler); } string fullName = TypeExtensions.FullName2(type); try { _log.Info("创建实例:{0}", fullName); handler = (DatabaseSchemaHandler)FastWrapper.CreateInstance(type); _caches.Add(key, handler); _list.Add(handler); ClassOrder(handler.Attribute.TableName, handler.Attribute.Order); CacheRef(type.Assembly, handler); return(handler); } catch (System.Exception error) { _log.Warning("创建实例失败:{0}\r\n{1}", fullName, LogBase.ExceptionToString(error)); return(null); } }
/// <summary> /// 注册程序集。 /// </summary> /// <param name="assembly"></param> /// <returns></returns> public System.Collections.Generic.List <DatabaseSchemaHandler> RegisterAssembly(System.Reflection.Assembly assembly) { System.Collections.Generic.List <DatabaseSchemaHandler> list = new System.Collections.Generic.List <DatabaseSchemaHandler>(); if (assembly == null || assembly.FullName.StartsWith("System") || assembly.FullName.StartsWith("mscorlib") //|| assembly.IsDynamic ) { return(list); } _log.Info("反射程序集:{0}", assembly.FullName); System.Type[] types; try { types = assembly.GetExportedTypes(); } catch (System.Exception error) { _log.Warning("反射程序集失败:{0}\r\n{1}", assembly.FullName, LogBase.ExceptionToString(error)); return(list); } foreach (System.Type type in types) { DatabaseSchemaHandler item = RegisterType(type); if (item == null) { continue; } list.Add(item); } return(list); }
/// <summary> /// 数据库架构处理。 /// </summary> /// <param name="context">上下文对象。</param> public DatabaseSchemaProcessResults Process(DatabaseSchemaContext context) { string fullName = TypeExtensions.FullName2(this.GetType()); if (!_attribute.IsValid) { context.Log.Warning("{0}.Attribute.IsValid=false,[{1}]{2},{3}", fullName, _attribute.Order, _attribute.TableName, _attribute.Description); return(DatabaseSchemaProcessResults.Ignore); } context.DataContext.ChangeDatabase(); context.Log.Info("执行 [{0} {1}] {2} {3} {4}", EnumExtensions.ToName(_attribute.Type).PadRight(6, ' '), _attribute.Order.ToString().PadRight(8, ' '), _attribute.TableName.PadRight(32, ' '), _attribute.Description.PadRight(32, ' '), fullName); DatabaseSchemaProcessResults result; try { result = OnProcess(context); context.Log.Info(" [{0}] {1}", EnumExtensions.ToName(result), fullName); } catch (System.Exception error) { result = DatabaseSchemaProcessResults.Error; context.Log.Info(" [{0}] {1}", EnumExtensions.ToName(result), fullName); context.Log.Error(LogBase.ExceptionToString(error)); } return(result); }
public static void ExceptionToString(Exception error, System.Text.StringBuilder builder, int layer) { LogBase.ExceptionToString(error, builder, layer); }
public static string ExceptionToString(Exception error) { return(LogBase.ExceptionToString(error)); }