Exemplo n.º 1
0
        public void Execute(int timeout, ILog log)
        {
            log.Write("Executing Template Instance '{0}'", this.SavedObjectName);

            string path = FileTools.ResolvePath(this.TemplatePath);

            ZeusTemplate template = new ZeusTemplate(path);

            ZeusInput zin = new ZeusInput();

            zin.AddItems(this.InputItems);

            this.ApplyOverrideData(zin);

            ZeusContext context = new ZeusContext(zin, /*new GuiController(),*/ new Hashtable());

            context.Log = log;

            template.Execute(context, timeout, true);

            foreach (string file in context.Output.SavedFiles)
            {
                if (!SavedFiles.Contains(file))
                {
                    SavedFiles.Add(file);
                }
            }
        }
Exemplo n.º 2
0
        private bool CollectProjectItem(ZeusModule parent, string projectPath, string templatePath)
        {
            bool complete    = false;
            int  moduleIndex = projectPath.LastIndexOf('/');

            if (moduleIndex >= 0)
            {
                string modulePath = projectPath.Substring(0, moduleIndex),
                       objectName = projectPath.Substring(moduleIndex + 1);

                ZeusModule m = FindModule(parent, modulePath);
                if (m != null)
                {
                    ZeusTemplate    template = new ZeusTemplate(templatePath);
                    DefaultSettings settings = DefaultSettings.Instance;

                    SavedTemplateInput savedInput = null;
                    if (m.SavedObjects.Contains(objectName))
                    {
                        savedInput = m.SavedObjects[objectName];
                    }
                    else
                    {
                        savedInput = new SavedTemplateInput();
                        savedInput.SavedObjectName = objectName;
                    }


                    ZeusContext context = new ZeusContext();
                    context.Log = this._log;

                    savedInput.TemplateUniqueID = template.UniqueID;
                    savedInput.TemplatePath     = template.FilePath + template.FileName;

                    settings.PopulateZeusContext(context);
                    if (m != null)
                    {
                        m.PopulateZeusContext(context);
                        m.OverrideSavedData(savedInput.InputItems);
                    }

                    if (template.Collect(context, settings.ScriptTimeout, savedInput.InputItems))
                    {
                        //this._lastRecordedSelectedNode = this.SelectedTemplate;
                    }


                    if (this._argmgr.InternalUseOnly)
                    {
                        this._log.Write("[BEGIN_RECORDING]");

                        this._log.Write(savedInput.XML);

                        this._log.Write("[END_RECORDING]");
                    }
                    complete = true;
                }
            }
            return(complete);
        }
Exemplo n.º 3
0
        static internal bool ExecuteCodeSegment(IZeusCodeSegment segment, IZeusContext context)
        {
            bool returnValue = true;

            if (context == null)
            {
                context = new ZeusContext();
            }
            PopulateContextObjects(context as ZeusContext);

            //Push this template onto the template stack
            if (context is ZeusContext)
            {
                ((ZeusContext)context).TemplateStack.Push(segment.ITemplate);
            }

            if (segment.SegmentType == ZeusConstants.CodeSegmentTypes.GUI_SEGMENT)
            {
                foreach (IZeusContextProcessor processor in ZeusFactory.Preprocessors)
                {
                    processor.Process(context);
                }

                returnValue = ZeusExecutioner.ExecuteGuiCode(segment, context);
            }
            else
            {
                ZeusExecutioner.ExecuteCode(segment, context);
            }

            //Pop the template from the template stack
            if (context is ZeusContext)
            {
                ((ZeusContext)context).TemplateStack.Pop();
            }
            return(returnValue);
        }
        public void ExecuteLoadedInput()
        {
            bool overridden = false;
            
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
            openFileDialog.FilterIndex = 0;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                ZeusSavedInput savedInput = null;
                ZeusTemplate template = null;
                if (ExecuteTemplateOverride != null)
                {
                    try
                    {
                        foreach (string filename in openFileDialog.FileNames)
                        {
                            savedInput = new ZeusSavedInput(filename);
                            if (savedInput.Load())
                            {
                                template = new ZeusTemplate(savedInput.InputData.TemplatePath);

                                overridden = ExecuteTemplateOverride(TemplateOperations.ExecuteLoadedInput, template, savedInput, _guiHandler);
                                if (!overridden) break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        OnErrorsOccurred(ex);
                    }
                }
                

                if (!overridden)
                {
                    try
                    {
                        ZeusSimpleLog log = new ZeusSimpleLog();
                        DefaultSettings settings = DefaultSettings.Instance;

                        Cursor.Current = Cursors.WaitCursor;

                        foreach (string filename in openFileDialog.FileNames)
                        {
                            savedInput = new ZeusSavedInput(filename);
                            if (savedInput.Load())
                            {
                                ZeusContext context = new ZeusContext();
                                context.Input.AddItems(savedInput.InputData.InputItems);
                                context.Log = log;

                                template = new ZeusTemplate(savedInput.InputData.TemplatePath);
                                template.Execute(context, settings.ScriptTimeout, true);

                                foreach (string filePath in context.Output.SavedFiles)
                                {
                                    this.OnGeneratedFileSaved(filePath);
                                }

                                if (log.HasExceptions)
                                {
                                    throw log.Exceptions[0];
                                }
                            }
                        }

                        Cursor.Current = Cursors.Default;
                        MessageBox.Show(this, "Selected files have been executed.");

                    }
                    catch (Exception ex)
                    {
                        OnErrorsOccurred(ex);
                    }

                    Cursor.Current = Cursors.Default;
                }
            }
        }
        public void SaveInput(ZeusTemplate template)
        {
            bool overridden = false;
            if (ExecuteTemplateOverride != null)
            {
                overridden = ExecuteTemplateOverride(TemplateOperations.SaveInput, template, null, _guiHandler);
            }

            if (!overridden)
            {
                try
                {
                    DefaultSettings settings = DefaultSettings.Instance;

                    ZeusSimpleLog log = new ZeusSimpleLog();
                    ZeusContext context = new ZeusContext();
                    context.Log = log;

                    ZeusSavedInput collectedInput = new ZeusSavedInput();
                    collectedInput.InputData.TemplateUniqueID = template.UniqueID;
                    collectedInput.InputData.TemplatePath = template.FilePath + template.FileName;

                    settings.PopulateZeusContext(context);
                    template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);

                    if (log.HasExceptions)
                    {
                        throw log.Exceptions[0];
                    }
                    else
                    {
                        SaveFileDialog saveFileDialog = new SaveFileDialog();
                        saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
                        saveFileDialog.FilterIndex = 0;
                        saveFileDialog.RestoreDirectory = true;
                        if (saveFileDialog.ShowDialog() == DialogResult.OK)
                        {
                            Cursor.Current = Cursors.WaitCursor;

                            collectedInput.FilePath = saveFileDialog.FileName;
                            collectedInput.Save();
                        }
                    }

                    MessageBox.Show(this, "Input collected and saved to file: \r\n" + collectedInput.FilePath);
                }
                catch (Exception ex)
                {
                    OnErrorsOccurred(ex);
                }

                Cursor.Current = Cursors.Default;
            }
        }
        public void ExecuteTemplate(ZeusTemplate template)
        {
            bool overridden = false;
            if (ExecuteTemplateOverride != null)
            {
                overridden = ExecuteTemplateOverride(TemplateOperations.Execute, template, null, _guiHandler);
            }
            
            if (!overridden)
            {
                Cursor.Current = Cursors.WaitCursor;

                DefaultSettings settings = DefaultSettings.Instance;

                IZeusContext context = new ZeusContext();
                IZeusGuiControl guiController = context.Gui;
                IZeusOutput zout = context.Output;

                settings.PopulateZeusContext(context);

                bool exceptionOccurred = false;
                bool result = false;

                try
                {
                    template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.Timeout = settings.ScriptTimeout;
                    template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.SetShowGuiHandler(_guiHandler);
                    result = template.GuiSegment.Execute(context);
                    template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.Cleanup();

                    if (result)
                    {
                        template.BodySegment.ZeusScriptingEngine.ExecutionHelper.Timeout = settings.ScriptTimeout;
                        result = template.BodySegment.Execute(context);

                        foreach (string filePath in context.Output.SavedFiles)
                        {
                            this.OnGeneratedFileSaved(filePath);
                        }

                        template.BodySegment.ZeusScriptingEngine.ExecutionHelper.Cleanup();
                    }
                }
                catch (Exception ex)
                {
                    OnErrorsOccurred(ex);

                    exceptionOccurred = true;
                }

                Cursor.Current = Cursors.Default;

                if (!exceptionOccurred && result)
                {
                    if (settings.EnableClipboard)
                    {
                        try
                        {
                            Clipboard.SetDataObject(zout.text, true);
                        }
                        catch
                        {
                            // HACK: For some reason, Clipboard.SetDataObject throws an error on some systems. I'm cathhing it and doing nothing for now.
                        }
                    }

                    MessageBox.Show("Successfully rendered Template: " + template.Title);
                }
            }
        }
 private void contextItemCacheSettings_Click(object sender, System.EventArgs e)
 {
     SortedProjectTreeNode node = this.treeViewProject.SelectedNode as SortedProjectTreeNode;
     if ((node is ModuleTreeNode) || (node is ProjectTreeNode))
     {
         ZeusModule module = node.Tag as ZeusModule;
         ZeusContext context = new ZeusContext();
         DefaultSettings settings = DefaultSettings.Instance;
         settings.PopulateZeusContext(context);
         module.SavedItems.Add(context.Input);
     }
 }
		public void SaveInput(ZeusTemplate template) 
		{
			try 
			{
                DefaultSettings settings = DefaultSettings.Instance;

				ZeusSimpleLog log = new ZeusSimpleLog();
				ZeusContext context = new ZeusContext();
				context.Log = log;

				ZeusSavedInput collectedInput = new ZeusSavedInput();
				collectedInput.InputData.TemplateUniqueID = template.UniqueID;
				collectedInput.InputData.TemplatePath = template.FilePath + template.FileName;

				settings.PopulateZeusContext(context);
				template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);
					
				if (log.HasExceptions) 
				{
					throw log.Exceptions[0];
				}
				else 
				{
					SaveFileDialog saveFileDialog = new SaveFileDialog();
					saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
					saveFileDialog.FilterIndex = 0;
					saveFileDialog.RestoreDirectory = true;
					if(saveFileDialog.ShowDialog() == DialogResult.OK)
					{
						Cursor.Current = Cursors.WaitCursor;

						collectedInput.FilePath = saveFileDialog.FileName;
						collectedInput.Save();
					}
				}

				MessageBox.Show(this, "Input collected and saved to file: \r\n" + collectedInput.FilePath);
			}
			catch (Exception ex)
			{
                mdi.ErrorsOccurred(ex);
                //ZeusDisplayError formError = new ZeusDisplayError(ex);
				//formError.SetControlsFromException();			
				//formError.ShowDialog(this);
			}

			Cursor.Current = Cursors.Default;
		}
Exemplo n.º 9
0
        private void _Execute()
        {
            this.Cursor = Cursors.WaitCursor;

            Directory.SetCurrentDirectory(Application.StartupPath);

            this.RefreshTemplateFromControl();

            DefaultSettings settings = DefaultSettings.Instance;

            ZeusContext context = new ZeusContext();
            if (context.Log is ZeusSimpleLog)
            {
                ZeusSimpleLog log = context.Log as ZeusSimpleLog;
                log.LogEntryAdded += new EventHandler(Log_EntryAdded);
            }
            IZeusGuiControl guiController = context.Gui;
            IZeusOutput zout = context.Output;

            settings.PopulateZeusContext(context);

            bool exceptionOccurred = false;
            bool result = false;
            Exception tmpEx = null;
            try
            {
                _template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.Timeout = settings.ScriptTimeout;
                _template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.SetShowGuiHandler(new ShowGUIEventHandler(DynamicGUI_Display));
                result = _template.GuiSegment.Execute(context);
                _template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.Cleanup();

                if (result)
                {
                    _template.BodySegment.ZeusScriptingEngine.ExecutionHelper.Timeout = settings.ScriptTimeout;
                    result = _template.BodySegment.Execute(context);
                    _template.BodySegment.ZeusScriptingEngine.ExecutionHelper.Cleanup();
                }
            }
            catch (Exception x)
            {
                HandleExecuteException(x);
                tmpEx = x;
                exceptionOccurred = true;
            }

            if (context.Log is ZeusSimpleLog)
            {
                ZeusSimpleLog simpleLog = context.Log as ZeusSimpleLog;
                if (simpleLog.HasExceptions)
                {
                    foreach (Exception ex in simpleLog.Exceptions)
                    {
                        if (tmpEx != ex)
                        {
                            HandleExecuteException(ex);
                            exceptionOccurred = true;
                        }
                    }
                }
            }

            if (!exceptionOccurred && result)
            {
                zout = context.Output;

                this.scintillaOutput.IsReadOnly = false;

                if (zout.text == string.Empty)
                    this.scintillaOutput.ClearAll();
                else
                    this.scintillaOutput.Text = zout.text;

                this.scintillaOutput.IsReadOnly = true;

                if (this.tabControlTemplate.SelectedTab != this.tabOutput)
                    this.tabControlTemplate.SelectedTab = this.tabOutput;

                this.LogLn("Successfully rendered template: " + this._template.Title);

                if (this.copyOutputToClipboardToolStripMenuItem.Checked)
                {
                    try
                    {
                        Clipboard.SetDataObject(zout.text, true);
                    }
                    catch
                    {
                        // HACK: For some reason, Clipboard.SetDataObject throws an error on some systems. I'm cathing it and doing nothing for now.
                    }
                }
            }

            foreach (string generatedFile in context.Output.SavedFiles)
            {
                this.mdi.SendAlert(this, "FileGenerated", generatedFile);
            }

            this.Cursor = Cursors.Default;
        }
Exemplo n.º 10
0
        protected static void PopulateContextObjects(IZeusContext icontext)
        {
            ZeusContext context = icontext as ZeusContext;

            if (icontext != null)
            {
                ZeusConfig config = ZeusConfig.Current;
                context.SetIntrinsicObjects(ZeusFactory.IntrinsicObjectsArray);

                foreach (ZeusIntrinsicObject obj in config.IntrinsicObjects)
                {
                    Type     intrinsicObjectType = null;
                    Assembly newassembly         = null;
                    object[] objs = null;

                    if (!context.Objects.Contains(obj.VariableName) && !obj.Disabled)
                    {
                        newassembly = obj.Assembly;
                        // First thing, try to create the type without knowing the assembly.

                        /*try
                         * {
                         *  intrinsicObjectType = Type.GetType(obj.ClassPath);
                         * }
                         * catch
                         * {
                         *  intrinsicObjectType = null;
                         * }*/

                        if (intrinsicObjectType == null)
                        {
                            try
                            {
                                if (obj.AssemblyPath != string.Empty)
                                {
                                    string assemblyPath = obj.AssemblyPath;

                                    if (newassembly == null)
                                    {
                                        assemblyPath = FileTools.ResolvePath(assemblyPath, true);
                                        FileInfo finf        = new FileInfo(assemblyPath);
                                        FileInfo callingfinf = new FileInfo(Assembly.GetCallingAssembly().Location);
                                        if (callingfinf.FullName == finf.FullName)
                                        {
                                            newassembly = Assembly.GetCallingAssembly();
                                        }
                                    }

                                    if (newassembly == null)
                                    {
                                        throw new ZeusDynamicException(ZeusDynamicExceptionType.IntrinsicObjectPluginInvalid, "Invalid Assembly: " + assemblyPath);
                                    }
                                    else
                                    {
                                        intrinsicObjectType = newassembly.GetType(obj.ClassPath);
                                    }
                                }
                                else
                                {
                                    intrinsicObjectType = Type.GetType(obj.ClassPath);
                                }
                            }
                            catch (ZeusDynamicException zex)
                            {
                                context.Objects[obj.VariableName] = zex.Message;
                            }
                        }

                        if (intrinsicObjectType != null)
                        {
                            try
                            {
                                if (intrinsicObjectType != null)
                                {
                                    if (newassembly != null)
                                    {
                                        objs = DynamicAssemblyTools.InstantiateClassesByType(newassembly, newassembly.GetType(obj.ClassPath));
                                    }
                                    else
                                    {
                                        objs    = new object[1];
                                        objs[0] = DynamicAssemblyTools.InstantiateClassByType(intrinsicObjectType);
                                    }
                                }
                                else
                                {
                                    throw new ZeusDynamicException(ZeusDynamicExceptionType.IntrinsicObjectPluginInvalid, "Invalid Type: " + obj.ClassPath);
                                }

                                if (objs != null)
                                {
                                    if (objs.Length > 0)
                                    {
                                        context.Objects[obj.VariableName] = objs[0];
                                    }
                                }
                            }
                            catch (ZeusDynamicException zex)
                            {
                                context.Objects[obj.VariableName] = zex.Message;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
		private void _ProcessTemplate() 
		{
			ZeusTemplate template = this._argmgr.Template;
			ZeusSavedInput savedInput = this._argmgr.SavedInput;
			ZeusSavedInput collectedInput = this._argmgr.InputToSave;
			ZeusContext context = new ZeusContext();
			context.Log = _log;
			DefaultSettings settings;
			
			this._log.Write("Executing: " + template.Title);
			try 
			{
				if (savedInput != null) 
				{
					context.Input.AddItems(savedInput.InputData.InputItems);
					template.Execute(context, this._argmgr.Timeout, true);
				}
				else if (collectedInput != null) 
				{
					settings = DefaultSettings.Instance;
					settings.PopulateZeusContext(context);
					template.ExecuteAndCollect(context, this._argmgr.Timeout, collectedInput.InputData.InputItems);
					collectedInput.Save();
				}
				else 
				{
					settings = DefaultSettings.Instance;
					settings.PopulateZeusContext(context);
					template.Execute(context, this._argmgr.Timeout, false);
				}
				
				if (this._argmgr.PathOutput != null) 
				{
					StreamWriter writer = File.CreateText(this._argmgr.PathOutput);
					writer.Write(context.Output.text);
					writer.Flush();
					writer.Close();
				}
				else 
				{
					if (!_argmgr.IsSilent)
						Console.WriteLine(context.Output.text);
				}
			}
			catch (Exception ex)
			{
				this._log.Write(ex);
				this._log.Write("Template execution failed.");
			}

            if (context != null && this._argmgr.InternalUseOnly)
            {
                foreach (string file in context.Output.SavedFiles)
                {
                    this._log.Write("[GENERATED_FILE]" + file);
                }
            }
		}
Exemplo n.º 12
0
        private bool CollectProjectItem(ZeusModule parent, string projectPath, string templatePath)
        {
            bool complete = false;
            int moduleIndex = projectPath.LastIndexOf('/');
            if (moduleIndex >= 0)
            {
                string modulePath = projectPath.Substring(0, moduleIndex),
                    objectName = projectPath.Substring(moduleIndex + 1);

                ZeusModule m = FindModule(parent, modulePath);
                if (m != null)
                {
                    ZeusTemplate template = new ZeusTemplate(templatePath);
                    DefaultSettings settings = DefaultSettings.Instance;

                    SavedTemplateInput savedInput = null;
                    if (m.SavedObjects.Contains(objectName))
                    {
                        savedInput = m.SavedObjects[objectName];
                    }
                    else
                    {
                        savedInput = new SavedTemplateInput();
                        savedInput.SavedObjectName = objectName;
                    }


                    ZeusContext context = new ZeusContext();
                    context.Log = this._log;

                    savedInput.TemplateUniqueID = template.UniqueID;
                    savedInput.TemplatePath = template.FilePath + template.FileName;

                    settings.PopulateZeusContext(context);
                    if (m != null)
                    {
                        m.PopulateZeusContext(context);
                        m.OverrideSavedData(savedInput.InputItems);
                    }

                    if (template.Collect(context, settings.ScriptTimeout, savedInput.InputItems))
                    {
                        //this._lastRecordedSelectedNode = this.SelectedTemplate;
                    }


                    if (this._argmgr.InternalUseOnly)
                    {
                        this._log.Write("[BEGIN_RECORDING]");

                        this._log.Write(savedInput.XML);

                        this._log.Write("[END_RECORDING]");
                    }
                    complete = true;
                }
            }
            return complete;
        }
Exemplo n.º 13
0
        static internal bool ExecuteCodeSegment(IZeusCodeSegment segment, IZeusContext context)
        {
            bool returnValue = true;

            if (context == null) context = new ZeusContext();
            PopulateContextObjects(context as ZeusContext);

            //Push this template onto the template stack
            if (context is ZeusContext)
            {
                ((ZeusContext)context).TemplateStack.Push(segment.ITemplate);
            }

            if (segment.SegmentType == ZeusConstants.CodeSegmentTypes.GUI_SEGMENT)
            {
                foreach (IZeusContextProcessor processor in ZeusFactory.Preprocessors)
                {
                    processor.Process(context);
                }

                returnValue = ZeusExecutioner.ExecuteGuiCode(segment, context);
            }
            else
            {
                ZeusExecutioner.ExecuteCode(segment, context);
            }

            //Pop the template from the template stack
            if (context is ZeusContext)
            {
                ((ZeusContext)context).TemplateStack.Pop();
            }
            return returnValue;
        }
Exemplo n.º 14
0
 public GeneratedTemplate(ZeusContext context)
     : base(context)
 {
 }
Exemplo n.º 15
0
		public void Execute(int timeout, ILog log)
		{
			log.Write("Executing Template Instance '{0}'", this.SavedObjectName);

			string path = FileTools.ResolvePath(this.TemplatePath);
			
			ZeusTemplate template = new ZeusTemplate(path);
			
			ZeusInput zin = new ZeusInput();
			zin.AddItems(this.InputItems);

            this.ApplyOverrideData(zin);

			ZeusContext context = new ZeusContext(zin, /*new GuiController(),*/ new Hashtable());
			context.Log = log;

			template.Execute(context, timeout, true);

            foreach (string file in context.Output.SavedFiles)
            {
                if (!SavedFiles.Contains(file)) SavedFiles.Add(file);
            }
        }
Exemplo n.º 16
0
        private void _SaveTemplateInput()
        {
            try
            {
                Directory.SetCurrentDirectory(Application.StartupPath);
                this.RefreshTemplateFromControl();

                DefaultSettings settings = DefaultSettings.Instance;

                ZeusSimpleLog log = new ZeusSimpleLog();
                log.LogEntryAdded += new EventHandler(Log_EntryAdded);
                ZeusContext context = new ZeusContext();
                context.Log = log;

                ZeusSavedInput collectedInput = new ZeusSavedInput();
                collectedInput.InputData.TemplateUniqueID = _template.UniqueID;
                collectedInput.InputData.TemplatePath = _template.FilePath + _template.FileName;

                settings.PopulateZeusContext(context);

                _template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems);

                if (log.HasExceptions)
                {
                    throw log.Exceptions[0];
                }
                else
                {
                    SaveFileDialog saveFileDialog = new SaveFileDialog();
                    saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
                    saveFileDialog.FilterIndex = 0;
                    saveFileDialog.RestoreDirectory = true;
                    if (saveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        Cursor.Current = Cursors.WaitCursor;

                        collectedInput.FilePath = saveFileDialog.FileName;
                        collectedInput.Save();
                    }
                }

                MessageBox.Show(this, "Input collected and saved to file:" + "\r\n" + collectedInput.FilePath);
            }
            catch (Exception ex)
            {
                HandleExecuteException(ex);
            }

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 17
0
 public GeneratedGui(ZeusContext context)
     : base(context)
 {
 }
Exemplo n.º 18
0
		public void ExecuteTemplate(ZeusTemplate template) 
		{
			Cursor.Current = Cursors.WaitCursor;

            DefaultSettings settings = DefaultSettings.Instance;

			IZeusContext context = new ZeusContext();
			IZeusGuiControl guiController = context.Gui;
			IZeusOutput zout = context.Output;

			settings.PopulateZeusContext(context);

			bool exceptionOccurred = false;
			bool result = false;

			try 
			{	
				template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.Timeout = settings.ScriptTimeout;
				template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.SetShowGuiHandler(new ShowGUIEventHandler(DynamicGUI_Display));
				result = template.GuiSegment.Execute(context); 
				template.GuiSegment.ZeusScriptingEngine.ExecutionHelper.Cleanup();
				
				if (result) 
				{
					template.BodySegment.ZeusScriptingEngine.ExecutionHelper.Timeout = settings.ScriptTimeout;
					result = template.BodySegment.Execute(context);
					template.BodySegment.ZeusScriptingEngine.ExecutionHelper.Cleanup();
				}
			}
			catch (Exception ex)
			{
                mdi.ErrorsOccurred(ex);
				//ZeusDisplayError formError = new ZeusDisplayError(ex);
				//formError.SetControlsFromException();			
				//formError.ShowDialog(this);

				exceptionOccurred = true;
			}

			Cursor.Current = Cursors.Default;

			if (!exceptionOccurred && result)
			{
				if (settings.EnableClipboard) 
				{
					try 
					{
						Clipboard.SetDataObject(zout.text, true);
					}
					catch
					{
						// HACK: For some reason, Clipboard.SetDataObject throws an error on some systems. I'm cathhing it and doing nothing for now.
					}
				}

				MessageBox.Show("Successfully rendered Template: " + template.Title);
			}
		}
Exemplo n.º 19
0
        private void _ProcessTemplate()
        {
            ZeusTemplate   template       = this._argmgr.Template;
            ZeusSavedInput savedInput     = this._argmgr.SavedInput;
            ZeusSavedInput collectedInput = this._argmgr.InputToSave;
            ZeusContext    context        = new ZeusContext();

            context.Log = _log;
            DefaultSettings settings;

            this._log.Write("Executing: " + template.Title);
            try
            {
                if (savedInput != null)
                {
                    context.Input.AddItems(savedInput.InputData.InputItems);
                    template.Execute(context, this._argmgr.Timeout, true);
                }
                else if (collectedInput != null)
                {
                    settings = DefaultSettings.Instance;
                    settings.PopulateZeusContext(context);
                    template.ExecuteAndCollect(context, this._argmgr.Timeout, collectedInput.InputData.InputItems);
                    collectedInput.Save();
                }
                else
                {
                    settings = DefaultSettings.Instance;
                    settings.PopulateZeusContext(context);
                    template.Execute(context, this._argmgr.Timeout, false);
                }

                if (this._argmgr.PathOutput != null)
                {
                    StreamWriter writer = File.CreateText(this._argmgr.PathOutput);
                    writer.Write(context.Output.text);
                    writer.Flush();
                    writer.Close();
                }
                else
                {
                    if (!_argmgr.IsSilent)
                    {
                        Console.WriteLine(context.Output.text);
                    }
                }
            }
            catch (Exception ex)
            {
                this._log.Write(ex);
                this._log.Write("Template execution failed.");
            }

            if (context != null && this._argmgr.InternalUseOnly)
            {
                foreach (string file in context.Output.SavedFiles)
                {
                    this._log.Write("[GENERATED_FILE]" + file);
                }
            }
        }
Exemplo n.º 20
0
		public void ExecuteLoadedInput() 
		{
			try 
			{
                DefaultSettings settings = DefaultSettings.Instance;
				ZeusSimpleLog log = new ZeusSimpleLog();

				OpenFileDialog openFileDialog = new OpenFileDialog();
				openFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp";
				openFileDialog.FilterIndex = 0;
				openFileDialog.RestoreDirectory = true;
				openFileDialog.Multiselect = true;
				if(openFileDialog.ShowDialog() == DialogResult.OK)
				{
					Cursor.Current = Cursors.WaitCursor;

					foreach (string filename in openFileDialog.FileNames) 
					{
						ZeusSavedInput savedInput = new ZeusSavedInput(filename);
						if (savedInput.Load()) 
						{
							ZeusContext context = new ZeusContext();
							context.Input.AddItems(savedInput.InputData.InputItems);
							context.Log = log;

							ZeusTemplate template = new ZeusTemplate(savedInput.InputData.TemplatePath);
							template.Execute(context, settings.ScriptTimeout, true);

							if (log.HasExceptions) 
							{
								throw log.Exceptions[0];
							}
						}
					}

					Cursor.Current = Cursors.Default;
					MessageBox.Show(this, "Selected files have been executed.");
				}
			}
			catch (Exception ex)
			{
                mdi.ErrorsOccurred(ex);
                //ZeusDisplayError formError = new ZeusDisplayError(ex);
				//formError.SetControlsFromException();			
				//formError.ShowDialog(this);
			}

			Cursor.Current = Cursors.Default;
		}
Exemplo n.º 21
0
 public Form1()
 {
     InitializeComponent();
     this.context = new ZeusContext();
 }
Exemplo n.º 22
0
		private void SaveInput() 
		{
			try 
			{
				ZeusTemplate template = new ZeusTemplate(this.SelectedTemplate.Tag.ToString());
                DefaultSettings settings = DefaultSettings.Instance;

				ZeusSimpleLog log = new ZeusSimpleLog();
				ZeusContext context = new ZeusContext();
				context.Log = log;

				SavedObject.TemplateUniqueID = template.UniqueID;
				SavedObject.TemplatePath = template.FilePath + template.FileName;

				settings.PopulateZeusContext(context);
				if (_module != null) 
				{
					_module.PopulateZeusContext(context);
				}

				if (template.Collect(context, settings.ScriptTimeout, SavedObject.InputItems)) 
				{
					this._lastRecordedSelectedNode = this.SelectedTemplate;
				}
					
				if (log.HasExceptions) 
				{
					throw log.Exceptions[0];
				}
			}
			catch (Exception ex)
			{
				ZeusDisplayError formError = new ZeusDisplayError(ex);
				formError.SetControlsFromException();			
				formError.ShowDialog(this);
			}

			Cursor.Current = Cursors.Default;
		}
Exemplo n.º 23
0
		private void SaveInput() 
		{
			try 
			{
                if (_collectInChildProcess)
                {
                    this.buttonCollectInput.Enabled = false;
                    this.Cursor = Cursors.WaitCursor;
                    ZeusProcessManager.RecordProjectItem(this._module.RootProject.FilePath, _module.ProjectPath + "/" + SavedObject.SavedObjectName, this.SelectedTemplate.Tag.ToString(), _executionCallback);
                }
                else
                {
                    //RecordProjectItem
                    ZeusTemplate template = new ZeusTemplate(this.SelectedTemplate.Tag.ToString());
                    DefaultSettings settings = DefaultSettings.Instance;

                    ZeusSimpleLog log = new ZeusSimpleLog();
                    ZeusContext context = new ZeusContext();
                    context.Log = log;

                    SavedObject.TemplateUniqueID = template.UniqueID;
                    SavedObject.TemplatePath = template.FilePath + template.FileName;

                    settings.PopulateZeusContext(context);
                    if (_module != null)
                    {
                        _module.PopulateZeusContext(context);
                        _module.OverrideSavedData(SavedObject.InputItems);
                    }

                    if (template.Collect(context, settings.ScriptTimeout, SavedObject.InputItems))
                    {
                        this._lastRecordedSelectedNode = this.SelectedTemplate;
                    }

                    if (log.HasExceptions)
                    {
                        throw log.Exceptions[0];
                    }
                }
            }
			catch (Exception ex)
			{
                mdi.ErrorsOccurred(ex);
                //ZeusDisplayError formError = new ZeusDisplayError(ex);
				//formError.SetControlsFromException();			
				//formError.ShowDialog(this);
			}

			Cursor.Current = Cursors.Default;
        }