public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor) { //if (theProviderInfo is ArchAngel.Providers.EntityModel.ProviderInfo) //{ // ArchAngel.Providers.EntityModel.ProviderInfo providerInfo = (ArchAngel.Providers.EntityModel.ProviderInfo)theProviderInfo; // providerInfo.Clear(); // return; //} try { log.Debug("Loading project..."); userInteractor.UpdateWaitScreen("Loading project..."); NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo; providerInfo.Clear(); log.Debug("Loading database..."); Database database = DatabaseLoader.LoadDatabase(DatabaseLoader.DatabaseObjectsToFetch, null); DatabaseProcessor dbProcessor = new DatabaseProcessor(); dbProcessor.LogErrors = true; log.Debug("Creating relationships..."); dbProcessor.CreateRelationships(database); if (dbProcessor.Errors.Count > 0) { log.Debug("Database errors exist..." + dbProcessor.Errors.Count.ToString()); UI.FormErrors form = new UI.FormErrors("<b><font color='Red'>Note:</font></b> Database problems exist. Please <b>fix</b> these problems (or <b>omit the tables</b> in question) before trying again.", dbProcessor.Errors); form.ShowDialog(); return; } log.Debug("Creating 1 to 1 mappings..."); var mappingSet = new MappingProcessor(new OneToOneEntityProcessor()) .CreateOneToOneMapping(database, this.TablePrefixes, this.ColumnPrefixes, this.TableSuffixes, this.ColumnSuffixes); foreach (var entity in mappingSet.EntitySet.Entities) { ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.ExistingPropertyNames = new List <string>(); foreach (Property prop in entity.Properties) { IColumn mappedCol = prop.MappedColumn(); ArchAngel.Interfaces.Scripting.NHibernate.Model.IColumn scriptCol = new Interfaces.Scripting.NHibernate.Model.IColumn() { IsNullable = mappedCol.IsNullable, //IsText = Length = mappedCol.Size, Name = mappedCol.Name, ScriptObject = mappedCol, Type = mappedCol.OriginalDataType }; prop.Name = ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.GetPropertyName(scriptCol); } } providerInfo.EntityProviderInfo.MappingSet = mappingSet; ///////////////////////////////// providerInfo.EntityProviderInfo.Engine.AddModule(new NHibernateProjectLoaderModule(database)); // Then run the validation rules log.Debug("Validating model..."); userInteractor.UpdateWaitScreen("Validating model..."); //var rulesEngine = new ValidationRulesEngine(mappingSet); //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database)); log.Debug("Running validation rules..."); providerInfo.EntityProviderInfo.RunValidationRules(); //rulesEngine); } //catch (Exception ex) //{ // MessageBox. //} finally { log.Debug("Removing wait screen..."); userInteractor.RemoveWaitScreen(); } }
public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor) { //if (theProviderInfo is ArchAngel.Providers.EntityModel.ProviderInfo) //{ // ArchAngel.Providers.EntityModel.ProviderInfo providerInfo = (ArchAngel.Providers.EntityModel.ProviderInfo)theProviderInfo; // providerInfo.Clear(); // return; //} try { log.Debug("Loading project..."); userInteractor.UpdateWaitScreen("Loading project..."); NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo; providerInfo.Clear(); log.Debug("Loading database..."); Database database = DatabaseLoader.LoadDatabase(DatabaseLoader.DatabaseObjectsToFetch, null); DatabaseProcessor dbProcessor = new DatabaseProcessor(); dbProcessor.LogErrors = true; log.Debug("Creating relationships..."); dbProcessor.CreateRelationships(database); if (dbProcessor.Errors.Count > 0) { log.Debug("Database errors exist..." + dbProcessor.Errors.Count.ToString()); UI.FormErrors form = new UI.FormErrors("<b><font color='Red'>Note:</font></b> Database problems exist. Please <b>fix</b> these problems (or <b>omit the tables</b> in question) before trying again.", dbProcessor.Errors); form.ShowDialog(); return; } log.Debug("Creating 1 to 1 mappings..."); var mappingSet = new MappingProcessor(new OneToOneEntityProcessor()) .CreateOneToOneMapping(database, this.TablePrefixes, this.ColumnPrefixes, this.TableSuffixes, this.ColumnSuffixes); foreach (var entity in mappingSet.EntitySet.Entities) { ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.ExistingPropertyNames = new List<string>(); foreach (Property prop in entity.Properties) { IColumn mappedCol = prop.MappedColumn(); ArchAngel.Interfaces.Scripting.NHibernate.Model.IColumn scriptCol = new Interfaces.Scripting.NHibernate.Model.IColumn() { IsNullable = mappedCol.IsNullable, //IsText = Length = mappedCol.Size, Name = mappedCol.Name, ScriptObject = mappedCol, Type = mappedCol.OriginalDataType }; prop.Name = ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.GetPropertyName(scriptCol); } } providerInfo.EntityProviderInfo.MappingSet = mappingSet; ///////////////////////////////// providerInfo.EntityProviderInfo.Engine.AddModule(new NHibernateProjectLoaderModule(database)); // Then run the validation rules log.Debug("Validating model..."); userInteractor.UpdateWaitScreen("Validating model..."); //var rulesEngine = new ValidationRulesEngine(mappingSet); //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database)); log.Debug("Running validation rules..."); providerInfo.EntityProviderInfo.RunValidationRules();//rulesEngine); } //catch (Exception ex) //{ // MessageBox. //} finally { log.Debug("Removing wait screen..."); userInteractor.RemoveWaitScreen(); } }