public void ScriptGenerate_Click(object sender, System.EventArgs e) { ZeusParser parser = new ZeusParser(); ZeusOutput zout = null; ZeusTemplate template; try { template = parser.LoadTemplate(this.ScriptStream.BaseStream, this.ScriptFilePath); System.Console.WriteLine(template.ScriptBody); ExecuteZeusTemplate ex = new ExecuteZeusTemplate(); ex.ShowGUI += new ShowGUIEventHandler(DynamicGUI_Display); zout = ex.Execute(template); } catch (Exception x) { ZeusDisplayError formError = new ZeusDisplayError(x); formError.ShowDialog(this); } if (zout != null) { SimpleOutputForm frm = new SimpleOutputForm(); frm.OutText = zout.text; frm.ShowDialog(this); } }
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) { 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); } }
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) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
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) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
private void SaveInput() { try { /*if (_lastRecordedSelectedIndex != this.listBoxTemplates.SelectedIndex) * { * this.SavedObject.InputItems.Clear(); * }*/ ZeusTemplate template = new ZeusTemplate(this.SelectedTemplate.Path); 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)) { _lastRecordedSelectedIndex = this.listBoxTemplates.SelectedIndex; } if (log.HasExceptions) { throw log.Exceptions[0]; } } catch (Exception ex) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
public void DynamicGUI_Display(IZeusGuiControl gui, IZeusFunctionExecutioner executioner) { this.Cursor = Cursors.Default; try { DynamicForm df = new DynamicForm(gui as GuiController, executioner); DialogResult result = df.ShowDialog(this); if (result == DialogResult.Cancel) { gui.IsCanceled = true; } } catch (Exception ex) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
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) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
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) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
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; }
public class ScriptWindow : ScintillaNETForm { public ScriptWindow() {
public void HandleExecuteException(Exception ex) { this.scintillaOutput.IsReadOnly = false; this.scintillaOutput.Text = string.Empty; this.scintillaOutput.IsReadOnly = true; ZeusDisplayError formError = new ZeusDisplayError(ex); formError.ErrorIndexChange += new EventHandler(ZeusDisplayError_ErrorIndexChanged); formError.ShowDialog(this); foreach (string message in formError.LastErrorMessages) { LogLn(message); } }
private void _Initialize(string path, params object[] options) { bool isNew = false; if (path == string.Empty) { isNew = true; } else if (File.Exists(path)) { try { _template = new ZeusTemplate(path); if (_template.SourceType == ZeusConstants.SourceTypes.SOURCE) { this.LogLn("Opened Template: \"" + _template.Title + "\" from \"" + _template.FilePath + _template.FileName + "\"."); } else { throw new Exception("Cannot edit locked templates."); } } catch (Exception x) { this.LogLn("Error loading template with path: " + path); ZeusDisplayError formError = new ZeusDisplayError(x); formError.ShowDialog(this); foreach (string message in formError.LastErrorMessages) { LogLn(message); } // Make sure it's treated as a new template isNew = true; } } if (isNew) { _template = new ZeusTemplate(); _template.Title = "Untitled"; _template.UniqueID = Guid.NewGuid().ToString(); this.panelProperties.Visible = true; if ((options.Length % 2) == 0) { string key, val; for (int i = 0; i < options.Length; i += 2) { key = options[i].ToString(); val = options[i + 1].ToString(); if (key == "ENGINE") { _template.BodySegment.Engine = val; _template.GuiSegment.Engine = val; } else if (key == "LANGUAGE") { _template.BodySegment.Language = val; _template.GuiSegment.Language = val; } } } _template.GuiSegment.CodeUnparsed = _template.GuiSegment.ZeusScriptingEngine.GetNewGuiText(_template.GuiSegment.Language); _template.BodySegment.CodeUnparsed = _template.BodySegment.ZeusScriptingEngine.GetNewTemplateText(_template.BodySegment.Language); } this.RefreshControlFromTemplate(); }
private void RefreshTemplateFromControl() { try { this._template.Title = this.textBoxTitle.Text; this._template.NamespacePathString = this.textBoxGroup.Text; this._template.UniqueID = this.textBoxUniqueID.Text; this._template.Comments = this.textBoxComments.Text; if (comboBoxEngine.SelectedIndex >= 0) { string newEngine = comboBoxEngine.SelectedItem.ToString(); if (newEngine != this._template.BodySegment.Engine) { this._template.BodySegment.Engine = newEngine; } } if (comboBoxLanguage.SelectedIndex >= 0) { this._template.BodySegment.Language = comboBoxLanguage.SelectedItem.ToString(); } if (comboBoxOutputLanguage.SelectedIndex >= 0) { this._template.OutputLanguage = comboBoxOutputLanguage.SelectedItem.ToString(); } this._template.GuiSegment.CodeUnparsed = this.scintillaGUICode.Text; if (this._template.Type == ZeusConstants.Types.GROUP) { this._template.IncludedTemplatePaths.Clear(); foreach (FileListItem item in this.listBoxIncludedTemplateFiles.Items) { this._template.AddIncludedTemplatePath(item.Value); } } this._template.BodySegment.Mode = comboBoxMode.SelectedIndex == 0 ? ZeusConstants.Modes.MARKUP : ZeusConstants.Modes.PURE; this._template.TagStart = this.textBoxStartTag.Text; this._template.TagEnd = this.textBoxEndTag.Text; this._template.BodySegment.CodeUnparsed = this.scintillaTemplateCode.Text; this.scintillaTemplateSource.IsReadOnly = false; this.scintillaTemplateSource.Text = this._template.BodySegment.Code; this.scintillaTemplateSource.IsReadOnly = true; this.scintillaGuiSource.IsReadOnly = false; this.scintillaGuiSource.Text = this._template.GuiSegment.Code; this.scintillaGuiSource.IsReadOnly = true; } catch (Exception x) { ZeusDisplayError formError = new ZeusDisplayError(x); formError.ErrorIndexChange += new EventHandler(ZeusDisplayError_ErrorIndexChanged); formError.ShowDialog(this); foreach (string message in formError.LastErrorMessages) { LogLn(message); } } }
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; }
public void DynamicGUI_Display(IZeusGuiControl gui, IZeusFunctionExecutioner executioner) { this.Cursor = Cursors.Default; try { DynamicForm df = new DynamicForm(gui as GuiController, executioner); DialogResult result = df.ShowDialog(this); if(result == DialogResult.Cancel) { gui.IsCanceled = true; } } catch (Exception ex) { ZeusDisplayError formError = new ZeusDisplayError(ex); formError.SetControlsFromException(); formError.ShowDialog(this); } Cursor.Current = Cursors.Default; }
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; }