Example #1
0
        public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor)
        {
            NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo;
            providerInfo.Clear();
            providerInfo.NhConfigFile = this.NhConfigFile;
            userInteractor.ShowWaitScreen("Loading from your existing NHibernate project");
            // Run this in its own thread
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork
                += (s, args) =>
                {
                try
                {
                    var loader = new ProjectLoader(new FileController(), new IUserInteractorProgressUpdatorAdapter(userInteractor), userInteractor);
                    var result = loader.LoadEntityModelFromCSProj(Filename, this.NhConfigFile);
                    args.Result = new RunResult {
                        MappingSet = result.MappingSet, DatabaseLoader = result.DatabaseLoader, NhConfigFile = result.NhConfigFile, CsProjFile = result.CsProjFile
                    };
                }
                catch (NHibernateLoaderException e)
                {
                    //var sb = new StringBuilder();
                    //sb.Append("The HBM files [").Append(e.Filenames).AppendLine(
                    //    "] could not be loaded due to the following errors:");
                    //e.Errors.ForEach(err => sb.AppendLine(err.Message));
                    //sb.AppendLine("Please send this file to [email protected] so we can make our HBM Loader better.");

                    args.Result = new RunResult {
                        ErrorOccurred = true, Exception = e
                    };
                }
                catch (Exception e)
                {
                    throw new NHibernateLoaderException(e.Message + Environment.NewLine + e.StackTrace, null, null);
                }
                };

            worker.RunWorkerCompleted
                += (s, args) =>
                {
                if (args.Error != null)
                {
                    userInteractor.RemoveWaitScreen();
                    providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                    throw new Exception("An error occurred in RunCustomNewProjectLogic. The inner exception is: " + args.Error.StackTrace, args.Error);
                    //System.Windows.Forms.Clipboard.SetText(args.Error.StackTrace);
                    //userInteractor.ShowError("An Error Occurred", args.Error.Message + Environment.NewLine + Environment.NewLine + "The stacktrace has been copied to the clipboard. Please email to [email protected]");
                    //providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                }
                else
                {
                    var result = (RunResult)args.Result;
                    if (result.ErrorOccurred)
                    {
                        userInteractor.RemoveWaitScreen();
                        providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();

                        string errorMessage = string.Format("Unsupported elements or Schema Validation Errors occurred. Please submit this error.\nFiles: {0}", result.Exception.Filenames);
                        throw new Exception(errorMessage, result.Exception);
                        //var form = new NHibernateHBMLoadErrorView();
                        //form.Title = "Unsupported elements or Schema Validation Errors occurred";
                        //form.NameOfFileWithError = result.Exception.Filename;
                        //form.SetErrors(result.Exception.Errors);

                        //userInteractor.ShowDialog(form);
                    }
                    else
                    {
                        // Set the MappingSet to the result of our work.
                        providerInfo.EntityProviderInfo.MappingSet = result.MappingSet;
                        providerInfo.NhConfigFile = result.NhConfigFile;
                        providerInfo.CsProjFile   = result.CsProjFile;

                        if (!string.IsNullOrEmpty(providerInfo.CsProjFile.GetProjectGuid()))
                        {
                            ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectGuid", providerInfo.CsProjFile.GetProjectGuid());
                        }

                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("CacheProviderClass", providerInfo.NhConfigFile.cache_provider_class);

                        // Then run the validation rules
                        userInteractor.UpdateWaitScreen("Runnng Model Validation");
                        //var rulesEngine = new ValidationRulesEngine(result.MappingSet);
                        //var database = result.DatabaseLoader.LoadDatabase();
                        //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database));
                        providerInfo.EntityProviderInfo.RunValidationRules();                                        //rulesEngine);

                        userInteractor.RemoveWaitScreen();
                    }
                }
                };

            worker.RunWorkerAsync();
        }
        public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor)
        {
            NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo;
            providerInfo.Clear();
            providerInfo.NhConfigFile = this.NhConfigFile;
            userInteractor.ShowWaitScreen("Loading from your existing NHibernate project");
            // Run this in its own thread
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork
                += (s, args) =>
                {
                    try
                    {
                        var loader = new ProjectLoader(new FileController(), new IUserInteractorProgressUpdatorAdapter(userInteractor), userInteractor);
                        var result = loader.LoadEntityModelFromCSProj(Filename, this.NhConfigFile);
                        args.Result = new RunResult { MappingSet = result.MappingSet, DatabaseLoader = result.DatabaseLoader, NhConfigFile = result.NhConfigFile, CsProjFile = result.CsProjFile };
                    }
                    catch (NHibernateLoaderException e)
                    {
                        //var sb = new StringBuilder();
                        //sb.Append("The HBM files [").Append(e.Filenames).AppendLine(
                        //    "] could not be loaded due to the following errors:");
                        //e.Errors.ForEach(err => sb.AppendLine(err.Message));
                        //sb.AppendLine("Please send this file to [email protected] so we can make our HBM Loader better.");

                        args.Result = new RunResult { ErrorOccurred = true, Exception = e };
                    }
                    catch (Exception e)
                    {
                        throw new NHibernateLoaderException(e.Message + Environment.NewLine + e.StackTrace, null, null);
                    }
                };

            worker.RunWorkerCompleted
                += (s, args) =>
                    {
                        if (args.Error != null)
                        {
                            userInteractor.RemoveWaitScreen();
                            providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                            throw new Exception("An error occurred in RunCustomNewProjectLogic. The inner exception is: " + args.Error.StackTrace, args.Error);
                            //System.Windows.Forms.Clipboard.SetText(args.Error.StackTrace);
                            //userInteractor.ShowError("An Error Occurred", args.Error.Message + Environment.NewLine + Environment.NewLine + "The stacktrace has been copied to the clipboard. Please email to [email protected]");
                            //providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();
                        }
                        else
                        {
                            var result = (RunResult)args.Result;
                            if (result.ErrorOccurred)
                            {
                                userInteractor.RemoveWaitScreen();
                                providerInfo.EntityProviderInfo.MappingSet = new MappingSetImpl();

                                string errorMessage = string.Format("Unsupported elements or Schema Validation Errors occurred. Please submit this error.\nFiles: {0}", result.Exception.Filenames);
                                throw new Exception(errorMessage, result.Exception);
                                //var form = new NHibernateHBMLoadErrorView();
                                //form.Title = "Unsupported elements or Schema Validation Errors occurred";
                                //form.NameOfFileWithError = result.Exception.Filename;
                                //form.SetErrors(result.Exception.Errors);

                                //userInteractor.ShowDialog(form);

                            }
                            else
                            {
                                // Set the MappingSet to the result of our work.
                                providerInfo.EntityProviderInfo.MappingSet = result.MappingSet;
                                providerInfo.NhConfigFile = result.NhConfigFile;
                                providerInfo.CsProjFile = result.CsProjFile;

                                if (!string.IsNullOrEmpty(providerInfo.CsProjFile.GetProjectGuid()))
                                    ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectGuid", providerInfo.CsProjFile.GetProjectGuid());

                                ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("CacheProviderClass", providerInfo.NhConfigFile.cache_provider_class);

                                // Then run the validation rules
                                userInteractor.UpdateWaitScreen("Runnng Model Validation");
                                //var rulesEngine = new ValidationRulesEngine(result.MappingSet);
                                //var database = result.DatabaseLoader.LoadDatabase();
                                //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database));
                                providerInfo.EntityProviderInfo.RunValidationRules();//rulesEngine);

                                userInteractor.RemoveWaitScreen();
                            }
                        }
                    };

            worker.RunWorkerAsync();
        }