private void buttonRunNHTemplateTest_Click(object sender, RoutedEventArgs args)
        {
            // Setup log4net
            log4net.Config.XmlConfigurator.Configure();

            //hibernatemapping hm = Utility.Open("nhtest.xml");

            var project = new WorkbenchProject();
            project.Load(@"..\..\..\ArchAngel.Templates\NHibernate\Northwind\Northwind.wbproj",
                new NullVerificationIssueSolver(),
                false, @"..\..\..\ArchAngel.Templates\NHibernate\Template\NHibernate.AAT.DLL");
            SharedData.CurrentProject = project;

            MappingSet mappingSet = project.Providers[0].GetAllObjectsOfType(typeof(MappingSet).FullName).OfType<MappingSet>().First();
            var entitySet = mappingSet.EntitySet;

            if (Directory.Exists("Output") == false)
            {
                Directory.CreateDirectory("Output");
            }

            foreach (var entity in entitySet.Entities)
            {
                if (Utility.SkipEntity(entity)) continue;

                try
                {
                    string xml = Utility.CreateMappingXMLFrom(entity, "Test", "Test", true, "", DefaultCascadeTypes.none, true);
                    File.WriteAllText(Path.Combine("Output", entity.Name + ".xml"), xml);
                }
                catch (Exception e)
                {
                    //string msg = string.Format("Exception: {0}\nMessage: {1}\nStack: {2}", e.GetType(), e.Message, e.StackTrace);

                    StringBuilder sb = new StringBuilder();
                    Exception currentEx = e.InnerException;
                    sb.AppendLine(e.ToString());
                    while(currentEx != null)
                    {
                        sb.AppendLine("Inner Exception:");
                        sb.AppendLine(currentEx.ToString());
                        currentEx = currentEx.InnerException;
                    }

                    File.WriteAllText(Path.Combine("Output", entity.Name + ".xml"), sb.ToString());
                }
            }

            Process.Start("Output");

            Application.Current.Shutdown();
        }
        public virtual bool OpenProjectFile(string file)
        {
            log.DebugFormat("Attempting to load project file \"{0}\"", file);
            BusyPopulating = true;
            BeforeOpenProjectFile();
            bool result = false;
            try
            {
                CurrentProject = new WorkbenchProject();
                SharedData.CurrentProject = CurrentProject;
                result = CurrentProject.Load(file, VerificationIssueSolver);

                if (!result)
                {
                    System.Windows.Forms.MessageBox.Show("Load unsuccessful");
                }
                RaiseTemplateLoadedEvent();
                RaiseProjectLoadedEvent();
            }
            catch (OldVersionException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Out-Of-Date Template", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                result = false;
            }
            //catch (Exception e)
            //{
            //    ErrorReportingService.ReportUnhandledException(e);
            //    result = false;
            //}
            finally
            {
                AfterOpenProjectFile(result, CurrentProject.ProjectFile);
            }
            BusyPopulating = false;
            return result;
        }
示例#3
0
		private void TestGenerateProject()
		{
			// Check whether the debug project exists.
			if (Controller.Instance.CheckDebugOptions(true) == false)
				return;

			Cursor = Cursors.WaitCursor;
			try
			{
				using (var worker = new BackgroundWorker())
				{
					worker.DoWork += delegate
					{
						var project = new WorkbenchProject();
						SharedData.CurrentProject = project;

						Utility.DisplayMessagePanel(this, "Generating Files", MessagePanel.ImageType.Hourglass);
						Utility.UpdateMessagePanelStatus(this, "Compiling Project");

						// Compile the template to the new temporary location.
						bool compileResult = FunctionRunner.CreateTemplateFile(false, false);

						if (compileResult == false)
						{
							//ErrorReportingService.ReportError(ErrorLevel.Error, "Could not compile project");
							throw new Exception("Could not compile project");
							//return;
						}

						Utility.UpdateMessagePanelStatus(this, "Loading Project File");

						// Load the project
						bool loadResult = project.Load(Project.Instance.DebugProjectFile, this, false, CompileHelper.CompiledAssemblyFileName);

						if (loadResult == false)
						{
							//ErrorReportingService.ReportError(ErrorLevel.Error, "Could not load project file. Open in ArchAngel Workbench for more information.");
							throw new Exception("Could not load project file. Open in ArchAngel Workbench for more information.");
							//return;
						}

						var helper = new GenerationHelper(new NullTaskProgressHelper<GenerateFilesProgress>(),
										 project.TemplateLoader, project,
										 new FileController());
						Utility.UpdateMessagePanelStatus(this, "Writing Files");
						project.PerformPreAnalysisActions();
						helper.GenerateAllFiles("", project.CombinedOutput.RootFolder, null, null,
							Project.Instance.TestGenerateDirectory);
					};

					worker.RunWorkerCompleted += (sndr, evnt) => Utility.HideMessagePanel(this);

					worker.RunWorkerAsync();
				}
			}
			finally
			{
				Cursor = Cursors.Default;
			}
		}