Exemple #1
0
        static protected bool ExecuteGuiCode(IZeusCodeSegment segment, IZeusContext context)
        {
            IZeusExecutionHelper helper = segment.ZeusScriptingEngine.ExecutionHelper;

            // If the template has an interface block, execute it
            if (!segment.IsEmpty)
            {
                ArrayList reqVars = segment.ITemplate.RequiredInputVariables;

                if (!context.Input.Contains(reqVars))
                {
                    try
                    {
                        helper.EngineExecuteGuiCode(segment, context);

                        if (helper.HasErrors)
                        {
                            IZeusExecutionError[] errors = helper.Errors;
                            helper.ClearErrors();
                            throw new ZeusExecutionException(segment.ITemplate, errors, false);
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new ZeusRuntimeException(segment.ITemplate, ex, false);
                    }
                }

                context.Input.AddItems(context.Gui);
            }

            return(!context.Gui.IsCanceled);
        }
Exemple #2
0
        public bool Collect(ZeusTemplate template, IZeusContext context, int timeout, InputItemCollection collectedinput, ShowGUIEventHandler eventhandler)
        {
            IZeusExecutionHelper execHelper = null;
            bool exceptionOccurred          = false;
            bool result = false;

            try
            {
                //Initialize Context for collection
                collectedinput.CopyTo(context.Gui.Defaults);
                context.Gui.ForceDisplay = true;
                collectedinput.Clear();

                execHelper         = template.GuiSegment.ZeusScriptingEngine.ExecutionHelper;
                execHelper.Timeout = timeout;

                if (eventhandler == null)
                {
                    execHelper.SetShowGuiHandler(new ShowGUIEventHandler(DynamicGUI_Display));
                }
                else
                {
                    execHelper.SetShowGuiHandler(new ShowGUIEventHandler(eventhandler));
                }

                result = template.GuiSegment.Execute(context);
                execHelper.Cleanup();

                if (collectedinput != null)
                {
                    collectedinput.Add(context.Input);
                }
            }
            catch (Exception ex)
            {
                context.Log.Write(ex);
                exceptionOccurred = true;
            }

            if (!exceptionOccurred && result)
            {
                context.Log.Write("Successfully collected input for Template: " + template.Title);
            }
            else
            {
                context.Log.Write("Canceled Template execution: " + template.Title);
            }

            return(result);
        }
Exemple #3
0
        public IZeusContext Execute(ZeusTemplate template, IZeusContext context, int timeout, InputItemCollection collectedinput, ShowGUIEventHandler eventhandler, bool skipGui)
        {
            IZeusExecutionHelper execHelper = null;
            bool exceptionOccurred          = false;
            bool result = false;

            try
            {
                if (skipGui)
                {
                    PopulateContextObjects(context);
                    foreach (IZeusContextProcessor processor in ZeusFactory.Preprocessors)
                    {
                        processor.Process(context);
                    }
                    result = true;
                }
                else
                {
                    execHelper         = template.GuiSegment.ZeusScriptingEngine.ExecutionHelper;
                    execHelper.Timeout = timeout;

                    if (eventhandler == null)
                    {
                        execHelper.SetShowGuiHandler(new ShowGUIEventHandler(DynamicGUI_Display));
                    }
                    else
                    {
                        execHelper.SetShowGuiHandler(new ShowGUIEventHandler(eventhandler));
                    }

                    result = template.GuiSegment.Execute(context);
                    execHelper.Cleanup();

                    if (collectedinput != null)
                    {
                        collectedinput.Add(context.Input);
                    }
                }
                if (result)
                {
                    execHelper         = template.BodySegment.ZeusScriptingEngine.ExecutionHelper;
                    execHelper.Timeout = timeout;
                    result             = template.BodySegment.Execute(context);
                }
            }
            catch (Exception ex)
            {
                context.Log.Write(ex);
                exceptionOccurred = true;
            }

            if (!exceptionOccurred && result)
            {
                context.Log.Write("Successfully rendered Template: " + template.Title);
            }
            else
            {
                context.Log.Write("Canceled Template execution: " + template.Title);
            }

            return(context);
        }
Exemple #4
0
        static protected void ExecuteCode(IZeusExecutionHelper helper, IZeusTemplate template, IZeusContext context, ArrayList templateGroupIds)
        {
            if (!template.BodySegment.IsEmpty)
            {
                try
                {
                    // Execute Template Body
                    helper.EngineExecuteCode(template.BodySegment, context);

                    if (helper.HasErrors)
                    {
                        IZeusExecutionError[] errors = helper.Errors;
                        helper.ClearErrors();
                        throw new ZeusExecutionException(template, errors, true);
                    }
                }
                catch (Exception ex)
                {
                    throw new ZeusRuntimeException(template, ex, true);
                }
            }

            if (template.Type == ZeusConstants.Types.GROUP)
            {
                if (template.IncludedTemplates.Count > 0)
                {
                    // Execute Template Body
                    if (templateGroupIds.Contains(template.UniqueID))
                    {
                        return;
                    }

                    templateGroupIds.Add(template.UniqueID);

                    foreach (ZeusTemplate childTemplate in template.IncludedTemplates)
                    {
                        if (childTemplate.UniqueID != template.UniqueID)
                        {
                            //clear the output buffer before executing the next template!
                            context.Output.clear();

                            //Push the current template onto the Execution stack
                            if (context is ZeusContext)
                            {
                                ((ZeusContext)context).TemplateStack.Push(childTemplate);
                            }

                            try
                            {
                                IZeusScriptingEngine engine = ZeusFactory.GetEngine(childTemplate.BodySegment.Engine);
                                ExecuteCode(engine.ExecutionHelper, childTemplate, context, templateGroupIds);
                            }
                            finally
                            {
                                //Pop the current template off of the Execution stack
                                if (context is ZeusContext)
                                {
                                    ((ZeusContext)context).TemplateStack.Pop();
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        static protected void ExecuteCode(IZeusCodeSegment segment, IZeusContext context)
        {
            IZeusExecutionHelper helper = segment.ZeusScriptingEngine.ExecutionHelper;

            ExecuteCode(helper, segment.ITemplate, context, new ArrayList());
        }
		static protected void ExecuteCode(IZeusExecutionHelper helper, IZeusTemplate template, IZeusContext context, ArrayList templateGroupIds) 
		{
            if (!template.BodySegment.IsEmpty)
            {
                try
                {
                    // Execute Template Body
                    helper.EngineExecuteCode(template.BodySegment, context);

                    if (helper.HasErrors)
                    {
                        IZeusExecutionError[] errors = helper.Errors;
                        helper.ClearErrors();
                        throw new ZeusExecutionException(template, errors, true);
                    }
                }
                catch (Exception ex)
                {
                    throw new ZeusRuntimeException(template, ex, true);
                }
            }
			
			if (template.Type == ZeusConstants.Types.GROUP) 
			{
				if (template.IncludedTemplates.Count > 0) 
				{
					// Execute Template Body
					if (templateGroupIds.Contains(template.UniqueID)) return;

					templateGroupIds.Add(template.UniqueID);

					foreach (ZeusTemplate childTemplate in template.IncludedTemplates)
					{
						if (childTemplate.UniqueID != template.UniqueID) 
						{
							//clear the output buffer before executing the next template!
							context.Output.clear();

							//Push the current template onto the Execution stack
							if (context is ZeusContext)
							{
								((ZeusContext)context).TemplateStack.Push(childTemplate);
							}
							
							try 
							{
								IZeusScriptingEngine engine = ZeusFactory.GetEngine(childTemplate.BodySegment.Engine);
								ExecuteCode(engine.ExecutionHelper, childTemplate, context, templateGroupIds);
							}
							finally 
							{
								//Pop the current template off of the Execution stack
								if (context is ZeusContext)
								{
									((ZeusContext)context).TemplateStack.Pop();
								}
							}
						}
					}
				}
			}
		}