Example #1
0
        /// <summary>
        /// Creates a copy of the ZeusContext with a new output object;
        /// </summary>
        /// <returns></returns>
        public IZeusContext Copy()
        {
            ZeusTemplateContext context = Activator.CreateInstance(this.GetType()) as ZeusTemplateContext;

            context._input            = this._input;
            context._output           = new ZeusOutput();
            context._objects          = this._objects;
            context._log              = this._log;
            context._gui              = this._gui;
            context._intrinsicObjects = this._intrinsicObjects;
            context._templateStack    = this._templateStack;
            return(context);
        }
		public void ExecuteTemplate(ZeusTemplate template) 
		{
			this.Cursor = Cursors.WaitCursor;

			DefaultSettings settings = new DefaultSettings();
			
			ZeusInput zin = new ZeusInput();
			ZeusOutput zout = new ZeusOutput();
			Hashtable objects = new Hashtable();
			ZeusGuiContext guicontext;
			ZeusTemplateContext bodycontext = null;

			dbRoot myMeta = new dbRoot();

			// Set the global variables for the default template/output paths
			zin["defaultTemplatePath"] = settings.DefaultTemplateDirectory;
			zin["defaultOutputPath"] = settings.DefaultOutputDirectory;

			string driver, connectionString;

			//if there is a connection string set, it in the input section here.
			if (settings.DbDriver != string.Empty) 
			{
				driver = settings.DbDriver;
				connectionString = settings.ConnectionString;

				zin["dbDriver"] = driver;
				zin["dbConnectionString"] = connectionString;
				
				try 
				{
					// Try to connect to the DB with MyMeta (using default connection info)
					myMeta.Connect(settings.DbDriver, settings.ConnectionString);
					
					// Set DB global variables and also input variables

					if (settings.DbTarget != string.Empty)				
						myMeta.DbTarget	= settings.DbTarget;

					if (settings.DbTargetMappingFile != string.Empty)
						myMeta.DbTargetMappingFileName = settings.DbTargetMappingFile;

					if (settings.LanguageMappingFile != string.Empty)
						myMeta.LanguageMappingFileName = settings.LanguageMappingFile;

					if (settings.DbTarget != string.Empty)
						myMeta.DbTarget	= settings.DbTarget;

					if (settings.Language != string.Empty)
						myMeta.Language = settings.Language;

					if (settings.UserMetaDataFileName != string.Empty)
						myMeta.UserMetaDataFileName = settings.UserMetaDataFileName;
				}
				catch 
				{
					// Give them an empty MyMeta
					myMeta = new dbRoot();
				}
			}

			bool exceptionOccurred = false;

			bool result = false;
			try 
			{
				// Add any objects here that need to be embedded in the script.
				objects.Add("MyMeta", myMeta);

				guicontext = new ZeusGuiContext(zin, new GuiController(), objects);

				template.GuiSegment.ZeusScriptingEngine.Executioner.ScriptTimeout = settings.ScriptTimeout;
				template.GuiSegment.ZeusScriptingEngine.Executioner.SetShowGuiHandler(new ShowGUIEventHandler(DynamicGUI_Display));
				result = template.GuiSegment.Execute(guicontext); 

				if (result) 
				{
					bodycontext = new ZeusTemplateContext(guicontext);
					result = template.BodySegment.Execute(bodycontext);
				}
			}
			catch (Exception ex)
			{
				ZeusDisplayError formError = new ZeusDisplayError(ex);
				formError.SetControlsFromException();			
				formError.ShowDialog(this);

				exceptionOccurred = true;
			}

			if (!exceptionOccurred && result)
			{
				MessageBox.Show("Successfully rendered template: " + template.Title);
			}

			this.Cursor = Cursors.Default;
		}