public bool Initialize(ILogger logger, out Exception ex) { bool success = false; ex = null; try { Assembly assembly; Type context; if (!string.IsNullOrEmpty(SchemaAssemblyPath)) { assembly = Assembly.LoadFrom(SchemaAssemblyPath); context = assembly.GetType(SchemaContext); if (context == null) { context = assembly.GetTypes().Where(t => t.AssemblyQualifiedName.Equals(SchemaContext)).FirstOrDefault(); } } else { context = Type.GetType(SchemaContext); } Args.ThrowIf <ArgumentException>(context == null, "The specified SchemaContext ({0}) was not found", SchemaContext); PropertyInfo prop = context.GetProperty("ConnectionName"); Args.ThrowIf <ArgumentException>(prop == null, "{0}.ConnectionName property was not found, make sure you're using the latest Bam.Net.Data.Schema.dll", context.Name); SchemaName = (string)prop.GetValue(null); RegistrarCallerFactory registrarFactory = new RegistrarCallerFactory(); IRegistrarCaller registrarCaller = registrarFactory.CreateRegistrarCaller(RegistrarCaller); Args.ThrowIf <ArgumentException>(registrarCaller == null, "Unable to instanciate IRegistrarCaller of type ({0})", RegistrarCaller); registrarCaller.Register(SchemaName); Exception ensureSchemaException; if (!Db.TryEnsureSchema(SchemaName, out ensureSchemaException)) { string properties = this.PropertiesToString("\r\n\t"); logger.AddEntry("A non fatal error occurred initializing schema ({0}) from ({1}): {2}\r\n{3}", LogEventType.Warning, SchemaName, SchemaContext, ensureSchemaException.Message, properties ); } success = true; } catch (Exception e) { ex = e; success = false; } return(success); }
public IRegistrarCaller CreateRegistrarCaller(string assemblyQualifiedName) { Type returnType = Type.GetType(assemblyQualifiedName); IRegistrarCaller result = null; if (returnType != null) { result = returnType.Construct <IRegistrarCaller>(); } return(result); }
public bool TryCreateRegistrarCaller(string assemblyQualifiedName, out IRegistrarCaller result) { bool success = false; result = null; try { result = CreateRegistrarCaller(assemblyQualifiedName); success = result != null; } catch (Exception ex) { Log.AddEntry("An error occurred trying to create RegistrarCaller: {0}", ex, ex.Message); success = false; } return(success); }