/// <summary> /// Gets commands from the discovered command bundles. /// </summary> /// <param name="et"></param> /// <returns></returns> public static CommandCollection GetCommandsFromCommandBundles(EntityType et) { if (et == null) { throw new ArgumentNullException("et"); } // finder... TypeFinder finder = new TypeFinder(typeof(CommandBundle)); finder.AddAttributeSpecification(typeof(CommandBundleAttribute), false, "Type", et.Type); // create... CommandBundle[] bundles = (CommandBundle[])finder.CreateInstances(); if (bundles == null) { throw new InvalidOperationException("bundles is null."); } // walk... CommandCollection all = new CommandCollection(); foreach (CommandBundle bundle in bundles) { all.AddRange(bundle.GetAllCommands()); } // return... return(all); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); // set... // TODO: use typefinder... // this.listConnectionTypes.Items.Add(new ConnectionType(typeof(SqlServerConnection), "SQL Server")); // this.listConnectionTypes.Items.Add(new ConnectionType(typeof(OracleConnection), "Oracle")); // this.listConnectionTypes.Items.Add(new ConnectionType(typeof(MySqlConnection), "MySQL")); // mbr - 2008-08-31 - added typefinder for the others... TypeFinder finder = new TypeFinder(typeof(Connection)); finder.AddAttributeSpecification(typeof(ConnectionAttribute), false); foreach (Type type in finder.GetTypes()) { this.listConnectionTypes.Items.Add(new ConnectionType(type, Runtime.Current.GetDescription(type))); } // set... for (int index = 0; index < this.listConnectionTypes.Items.Count; index++) { if (((ConnectionType)this.listConnectionTypes.Items[index]).Type == typeof(SqlServerConnection)) { this.listConnectionTypes.SelectedIndex = index; break; } } }
/// <summary> /// Gets the control types for the given entity type. /// </summary> /// <param name="entityType"></param> /// <returns></returns> private static Type[] GetControlTypesForEntityType(Type entityType) { if (entityType == null) { throw new ArgumentNullException("entityType"); } // get them... TypeFinder finder = new TypeFinder(typeof(Control)); finder.AddAttributeSpecification(typeof(PropertyPageAttribute), false, "EntityType", entityType); // return... return(finder.GetTypes()); }
/// <summary> /// Creates ot updates the database. /// </summary> /// <param name="create"></param> /// <param name="checkOnly"></param> // mbr - 28-09-2007 - case 814 - added args. private DatabaseUpdateCheckResults CreateUpdateDatabase(IOperationItem operation, bool create, bool checkOnly, DatabaseUpdateArgs args) { if (args == null) { throw new ArgumentNullException("args"); } // operation... if (operation == null) { operation = new OperationItem(); } // set... operation.Status = "Loading existing schema..."; // database... SqlSchema databaseSchema = null; if (create) { databaseSchema = new SqlSchema(); } else { if (args.Trace) { this.LogInfo(() => "Loading schema..."); } // mbr - 28-09-2007 - case 814 - defer to a method that can limit the types... // databaseSchema = Database.GetSchema();fic databaseSchema = this.GetSchema(args); if (databaseSchema == null) { throw new InvalidOperationException("databaseSchema is null."); } } // Create an entity schema SqlSchema entitySchema = new SqlSchema(); // Load all the entity types from the path ArrayList entityTypes = new ArrayList(); // mbr - 02-10-2007 - for c7 - changed so that we can limit the entity types... if (args.LimitEntityTypes.Count == 0) { // mbr - 04-10-2007 - case 851 - do not do this behaviour (oddly both of these statements are // actually identical), // entityTypes.AddRange(EntityType.GetAllEntityTypes()); // this.MergeEntityTypes(entityTypes, EntityType.LoadFromAttributes(AssemblyPath)); // foreach(Assembly asm in this.Assemblies) // this.MergeEntityTypes(entityTypes, EntityType.LoadFromAttributes(asm)); // load... this.MergeEntityTypes(entityTypes, EntityType.GetEntityTypes()); } else { this.MergeEntityTypes(entityTypes, args.LimitEntityTypes); } // log... if (args.Trace) { this.LogInfo(() => string.Format("Found '{0}' entity types.", entityTypes.Count)); } // steps... DatabaseUpdateStepCollection steps = new DatabaseUpdateStepCollection(); if (args.AddArrayParameterUdts) { steps.Add(new AddArrayParameterUdtsUpdateStep()); } SyncSchemaDatabaseUpdateStep syncStep = new SyncSchemaDatabaseUpdateStep(); steps.Add(syncStep); // mbr - 02-03-2006 - we can have update steps that don't have an entity type... TypeFinder finder = new TypeFinder(typeof(DatabaseUpdateStep)); finder.AddAttributeSpecification(typeof(DatabaseUpdateStepAttribute), false); Type[] stepTypes = finder.GetTypes(); if (stepTypes == null) { throw new InvalidOperationException("stepTypes is null."); } // mbr - 02-10-2007 - for c7... if (Database.ExtensibilityProvider == null) { throw new InvalidOperationException("Database.ExtensibilityProvider is null."); } // Walk each entity type and add to entitySchema foreach (EntityType entityType in entityTypes) { // mbr - 14-12-2005 - should we do it? bool skip = entityType.Type.IsDefined(typeof(SkipDatabaseUpdateAttribute), false); // mbr - 2010-01-29 - changed the log here to allow db update to do named databases... // if(!(skip) && entityType.UsesDefaultDatabase) bool ok = false; if (!(skip)) { // no named database, and entity has no named database... if (!(args.HasDatabaseName) && entityType.UsesDefaultDatabase) { ok = true; } else if (args.HasDatabaseName && string.Compare(entityType.DatabaseName, args.DatabaseName, true, Cultures.System) == 0) { ok = true; } } else { ok = false; } // do we do it? if (ok) { if (args.Trace) { this.LogInfo(() => string.Format("Touching '{0}' ({1})...", entityType.Name, entityType.Type.Assembly.GetName().Name)); } // add the base table... SqlTable coreTable = SqlTable.GetTable(entitySchema, entityType); if (coreTable == null) { throw new InvalidOperationException("coreTable is null."); } entitySchema.Tables.Add(coreTable); // type... Type type = entityType.Type; if (type == null) { throw new InvalidOperationException("type is null."); } // reload it - something weird happens with these and they can't be used with the metadata so reload it so that we're // certain we have the right ones... type = Type.GetType(type.AssemblyQualifiedName, true, true); if (type == null) { throw new InvalidOperationException("type is null."); } // mbr - 02-10-2007 - for c7 - add other tables that we need... Database.ExtensibilityProvider.AddSchemaTables(entityType, type, coreTable, entitySchema); // add the custom units... foreach (Type stepType in stepTypes) { // get the attribute... DatabaseUpdateStepAttribute[] attrs = (DatabaseUpdateStepAttribute[])stepType.GetCustomAttributes(typeof(DatabaseUpdateStepAttribute), true); if (attrs == null) { throw new InvalidOperationException("attrs is null."); } // walk... foreach (DatabaseUpdateStepAttribute attr in attrs) { if (attr.EntityType != null && attr.EntityType.IsAssignableFrom(type)) { // create... DatabaseUpdateStep step = (DatabaseUpdateStep)Activator.CreateInstance(stepType, new object[] { type }); if (step == null) { throw new InvalidOperationException("step is null."); } // add.. steps.Add(step); } } } } else { if (args.Trace) { this.LogInfo(() => string.Format("Skipping '{0}'.", entityType.Name)); } } } // mbr - 02-10-2007 - for c7 - don't do custom steps if we're limiting entity types... if (args.LimitEntityTypes.Count == 0) { // do the ones that don't have entity types... foreach (Type stepType in stepTypes) { // get the attribute... DatabaseUpdateStepAttribute[] attrs = (DatabaseUpdateStepAttribute[])stepType.GetCustomAttributes(typeof(DatabaseUpdateStepAttribute), true); if (attrs == null) { throw new InvalidOperationException("attrs is null."); } // walk... foreach (DatabaseUpdateStepAttribute attr in attrs) { if (attr.EntityType == null) { // create... DatabaseUpdateStep step = (DatabaseUpdateStep)Activator.CreateInstance(stepType); if (step == null) { throw new InvalidOperationException("step is null."); } // add.. steps.Add(step); } } } } // get the work units... operation.Status = "Creating schema delta..."; // mbr - 02-10-2007 - for c7 - changed to deferral. // syncStep.WorkUnits.AddRange(entitySchema.GetSchemaWorkUnits(databaseSchema, operation)); syncStep.Initialize(entitySchema, databaseSchema); // run... if (!(checkOnly)) { if (args.Trace) { this.LogInfo(() => string.Format("Applying '{0}' steps...", steps.Count)); } // context... DatabaseUpdateContext context = new DatabaseUpdateContext(operation, args.Trace); // mbr - 21-12-2005 - run the steps... foreach (DatabaseUpdateStep step in steps) { try { if (args.Trace) { this.LogInfo(() => string.Format("Applying step: {0}", step)); } // set... operation.Status = string.Format("Running step '{0}'...", step); step.Execute(context); } catch (Exception ex) { // log... string message = string.Format("Failed database update when running step '{0}'.", step); if (this.Log.IsErrorEnabled) { this.Log.Error(message, ex); } // throw... throw new InvalidOperationException(message, ex); } } } else { if (args.Trace) { this.LogInfo(() => "Checking only -- not doing work."); } } if (args.Trace) { this.LogInfo(() => "Database update finished."); } this.OnUpdated(); // return... return(new DatabaseUpdateCheckResults(steps)); }