public void Write(string filepath, ZeusTemplate template) { FileStream fs = File.Create(filepath); ZeusWriter writer = new ZeusWriter(); this.Write(fs, template); fs.Close(); }
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); }
public string Write(ZeusTemplate template) { StringWriter writer = new StringWriter(); BuildTemplateText(writer, template); return(writer.ToString()); }
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); } } }
private bool ExecuteTemplateOverride(TemplateOperations operation, ZeusTemplate template, ZeusSavedInput input, ShowGUIEventHandler guiEventHandler) { switch (operation) { case TemplateOperations.Execute: this._mdi.PerformMdiFuntion(this, "ExecutionQueueStart"); ZeusProcessManager.ExecuteTemplate(template.FullFileName, _executionCallback); break; case TemplateOperations.ExecuteLoadedInput: this._mdi.PerformMdiFuntion(this, "ExecutionQueueStart"); ZeusProcessManager.ExecuteSavedInput(input.FilePath, _executionCallback); break; case TemplateOperations.SaveInput: SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp"; saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { this._mdi.PerformMdiFuntion(this, "ExecutionQueueStart"); ZeusProcessManager.RecordTemplateInput(template.FullFileName, saveFileDialog.FileName, _executionCallback); } break; } return true; }
public ZeusTemplate LoadTemplate(string filePath) { ZeusTemplate template = new ZeusTemplate(); LoadIntoTemplate(filePath, template); return template; }
public ZeusTemplate LoadIntoTemplate(Stream stream, string filepath, ZeusTemplate template) { StreamReader reader = new StreamReader(stream, true); LoadIntoTemplate(reader, filepath, template); reader.Close(); return template; }
public ZeusTemplate LoadIntoTemplate(Stream stream, string filepath, ZeusTemplate template) { StreamReader reader = new StreamReader(stream, true); LoadIntoTemplate(reader, filepath, template); reader.Close(); return(template); }
public ZeusTemplate LoadTemplate(string filePath) { ZeusTemplate template = new ZeusTemplate(); LoadIntoTemplate(filePath, template); return(template); }
public IZeusTemplate LoadTemplateFromFile(string path) { ZeusTemplate template = new ZeusTemplate(path); ZeusTemplateParser templateParser = new ZeusTemplateParser(); templateParser.LoadIntoTemplate(path, template); return(template); }
public void Write(string filepath, ZeusTemplate template) { FileStream fs = File.Create(filepath); ZeusWriter writer = new ZeusWriter(); this.Write(fs, template); fs.Close(); }
protected void BuildTemplateText(TextWriter writer, ZeusTemplate template) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.TYPE + " " + template.Type); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.UNIQUEID + " " + template.UniqueID); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.TITLE + " " + template.Title); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.NAMESPACE + " " + template.NamespacePathString); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.SOURCE_TYPE + " " + template.SourceType); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.OUTPUT_LANGUAGE + " " + template.OutputLanguage); string inputvars = template.RequiredInputVariablesString; if (inputvars != string.Empty) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.INPUT_VARS + " " + inputvars); } if (template.HasCommentBlock) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.COMMENTS_BEGIN); writer.WriteLine(template.Comments); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.COMMENTS_END); } writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_ENGINE + " " + template.GuiSegment.Engine); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_LANGUAGE + " " + template.GuiSegment.Language); if (!template.GuiSegment.IsEmpty) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_BEGIN); writer.WriteLine(template.GuiSegment.CodeUnparsed); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_END); } writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_MODE + " " + template.BodySegment.Mode); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_ENGINE + " " + template.BodySegment.Engine); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_LANGUAGE + " " + template.BodySegment.Language); if (template.BodySegment.Mode == ZeusConstants.Modes.MARKUP) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_TAG_START + " " + template.TagStart); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_TAG_END + " " + template.TagEnd); } if (!template.BodySegment.IsEmpty) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_BEGIN); writer.WriteLine(template.BodySegment.CodeUnparsed); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_END); } if (template.Type == ZeusConstants.Types.GROUP) { foreach (string path in template.IncludedTemplatePaths) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.INCLUDE_TEMPLATE + " " + path); } } writer.Flush(); }
protected void BuildTemplateText(TextWriter writer, ZeusTemplate template) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.TYPE + " " + template.Type); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.UNIQUEID + " " + template.UniqueID); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.TITLE + " " + template.Title); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.NAMESPACE + " " + template.NamespacePathString); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.SOURCE_TYPE + " " + template.SourceType); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.OUTPUT_LANGUAGE + " " + template.OutputLanguage); string inputvars = template.RequiredInputVariablesString; if (inputvars != string.Empty) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.INPUT_VARS + " " + inputvars); } if (template.HasCommentBlock) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.COMMENTS_BEGIN); writer.WriteLine(template.Comments); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.COMMENTS_END); } writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_ENGINE + " " + template.GuiSegment.Engine); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_LANGUAGE + " " + template.GuiSegment.Language); if (!template.GuiSegment.IsEmpty) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_BEGIN); writer.WriteLine(template.GuiSegment.CodeUnparsed); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.GUI_END); } writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_MODE + " " + template.BodySegment.Mode); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_ENGINE + " " + template.BodySegment.Engine); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_LANGUAGE + " " + template.BodySegment.Language); if (template.BodySegment.Mode == ZeusConstants.Modes.MARKUP) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_TAG_START + " " + template.TagStart); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_TAG_END + " " + template.TagEnd); } if (!template.BodySegment.IsEmpty) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_BEGIN); writer.WriteLine(template.BodySegment.CodeUnparsed); writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.BODY_END); } if (template.Type == ZeusConstants.Types.GROUP) { foreach (string path in template.IncludedTemplatePaths) { writer.WriteLine(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.INCLUDE_TEMPLATE + " " + path); } } writer.Flush(); }
public void TestMethod1() { // // TODO: Add test logic here // //Assert.AreEqual(1, 3); string dir = TestContext.TestDir; string directory = @"E:\source code\codegenerate\mygeneration\MyGeneration.Test\Test.zeus"; ZeusTemplate _template = new ZeusTemplate(directory); string sourceCode = _template.BodySegment.Code; }
public IZeusSavedInput ExecuteTemplateAndCollectInput(IZeusContext context, string templatePath) { var template = new ZeusTemplate(templatePath); var collectedInput = new ZeusSavedInput(); DefaultSettings.Instance.PopulateZeusContext(context); template.ExecuteAndCollect(context, DefaultSettings.Instance.ScriptTimeout, collectedInput.InputData.InputItems); collectedInput.Save(); return(collectedInput); }
public IZeusSavedInput ExecuteTemplateAndCollectInput(IZeusContext context, string templatePath) { ZeusTemplate template = new ZeusTemplate(templatePath); ZeusSavedInput collectedInput = new ZeusSavedInput(); DefaultSettings settings = DefaultSettings.Instance; settings.PopulateZeusContext(context); template.ExecuteAndCollect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems); collectedInput.Save(); return collectedInput; }
public IZeusSavedInput CollectTemplateInput(IZeusContext context, string templatePath) { ZeusTemplate template = new ZeusTemplate(templatePath); ZeusSavedInput collectedInput = new ZeusSavedInput(); DefaultSettings settings = DefaultSettings.Instance; settings.PopulateZeusContext(context); template.Collect(context, settings.ScriptTimeout, collectedInput.InputData.InputItems); collectedInput.Save(); return(collectedInput); }
public void Execute(string path, bool copyContext) { ZeusTemplate template = new ZeusTemplate(FileTools.MakeAbsolute(path, this.ExecutingTemplate.FilePath)); if (copyContext) { template.Execute(this.Copy(), 0, true); } else { template.Execute(this, 0, true); } }
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); }
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; }
protected void AssignGroup(ZeusTemplate template, string key, StringBuilder builder) { switch (key) { case ZeusConstants.Directives.BODY_END: template.BodySegment.CodeUnparsed = builder.ToString().TrimEnd(); break; case ZeusConstants.Directives.GUI_END: template.GuiSegment.CodeUnparsed = builder.ToString().TrimEnd(); break; case ZeusConstants.Directives.COMMENTS_END: template.Comments = builder.ToString().TrimEnd(); break; } }
public void LoadIntoTemplate(string filePath, ZeusTemplate template) { try { StreamReader reader = new StreamReader(filePath, true); LoadIntoTemplate(reader, filePath, template); reader.Close(); } catch (ZeusParseException parseEx) { if (parseEx.ParseError == ZeusParseError.OutdatedTemplateStructure) { LegacyTemplateParser parser = new LegacyTemplateParser(); parser.LoadIntoTemplate(filePath, template); } else { throw parseEx; } } }
public void LoadIntoTemplate(string filePath, ZeusTemplate template) { try { StreamReader reader = new StreamReader(filePath, true); LoadIntoTemplate(reader, filePath, template); reader.Close(); } catch (ZeusParseException parseEx) { if (parseEx.ParseError == ZeusParseError.OutdatedTemplateStructure) { LegacyTemplateParser parser = new LegacyTemplateParser(); parser.LoadIntoTemplate(filePath, template); } else { throw parseEx; } } }
public void ExecuteTemplate(IZeusContext context, string templatePath, string inputFilePath) { var template = new ZeusTemplate(templatePath); ZeusSavedInput savedInput = null; if (!string.IsNullOrEmpty(inputFilePath)) { savedInput = new ZeusSavedInput(inputFilePath); } context.Log.Write("Executing: " + template.Title); if (savedInput != null) { context.Input.AddItems(savedInput.InputData.InputItems); template.Execute(context, DefaultSettings.Instance.ScriptTimeout, true); } else { DefaultSettings.Instance.PopulateZeusContext(context); template.Execute(context, DefaultSettings.Instance.ScriptTimeout, false); } }
public void ExecuteTemplate(IZeusContext context, string templatePath, string inputFilePath) { ZeusTemplate template = new ZeusTemplate(templatePath); ZeusSavedInput savedInput = null; DefaultSettings settings = DefaultSettings.Instance; if (!string.IsNullOrEmpty(inputFilePath)) { savedInput = new ZeusSavedInput(inputFilePath); } context.Log.Write("Executing: " + template.Title); if (savedInput != null) { context.Input.AddItems(savedInput.InputData.InputItems); template.Execute(context, settings.ScriptTimeout, true); } else { settings.PopulateZeusContext(context); template.Execute(context, settings.ScriptTimeout, false); } }
private bool templateBrowserControl1_ExecuteOverride(TemplateOperations operation, ZeusTemplate template, ZeusSavedInput input, ShowGUIEventHandler guiEventHandler) { switch (operation) { case TemplateOperations.Execute: ZeusProcessManager.ExecuteTemplate(template.FullFileName, processCallback); break; case TemplateOperations.ExecuteLoadedInput: ZeusProcessManager.ExecuteSavedInput(input.FilePath, processCallback); break; case TemplateOperations.SaveInput: SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Zues Input Files (*.zinp)|*.zinp"; saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ZeusProcessManager.RecordTemplateInput(template.FullFileName, saveFileDialog.FileName, processCallback); } break; } return true; }
public IZeusContext ExecuteAndCollect(ZeusTemplate template, IZeusContext context, int timeout, InputItemCollection inputitems) { return(this.Execute(template, context, timeout, inputitems, null, false)); }
internal ZeusCodeSegment(ZeusTemplate template, string segmentType) { this._template = template; this._segmentType = segmentType; }
public bool Collect(ZeusTemplate template, IZeusContext context, int timeout, InputItemCollection inputitems) { return(this.Collect(template, context, timeout, inputitems, null)); }
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); } }
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; }
/// <summary> /// Depricated! Use: Execute(string path, bool copyContext) /// </summary> /// <param name="path"></param> public void ExecuteTemplate(string path) { ZeusTemplate template = new ZeusTemplate(FileTools.MakeAbsolute(path, this.ExecutingTemplate.FilePath)); template.Execute(this, 0, true); }
public void Execute() { if (this.treeViewTemplates.SelectedNode is TemplateTreeNode) { ZeusTemplate template = new ZeusTemplate(this.treeViewTemplates.SelectedNode.Tag.ToString()); ExecuteTemplate(template); } }
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 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; } } }
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); } } }
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); } } }
protected void Write(Stream stream, ZeusTemplate template) { StreamWriter writer = new StreamWriter(stream, Encoding.UTF8); BuildTemplateText(writer, template); }
public string Write(ZeusTemplate template) { StringWriter writer = new StringWriter(); BuildTemplateText(writer, template); return writer.ToString(); }
protected void Write(Stream stream, ZeusTemplate template) { StreamWriter writer = new StreamWriter(stream, Encoding.UTF8); BuildTemplateText(writer, template); }
public IZeusContext Execute(ZeusTemplate template, IZeusContext context, int timeout, bool skipGui) { return(this.Execute(template, context, timeout, null, null, skipGui)); }
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); }
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.LogException(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(); }
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); } }
protected void AssignProperty(ZeusTemplate template, string key, string val) { template.AddDirective(key, val); switch (key) { case ZeusConstants.Directives.TYPE: template.Type = val; break; case ZeusConstants.Directives.SOURCE_TYPE: template.SourceType = val; break; case ZeusConstants.Directives.BODY_ENGINE: template.BodySegment.Engine = val; break; case ZeusConstants.Directives.BODY_LANGUAGE: template.BodySegment.Language = val; break; case ZeusConstants.Directives.BODY_MODE: template.BodySegment.Mode = val; break; case ZeusConstants.Directives.GUI_ENGINE: template.GuiSegment.Engine = val; break; case ZeusConstants.Directives.GUI_LANGUAGE: template.GuiSegment.Language = val; break; case ZeusConstants.Directives.OUTPUT_LANGUAGE: template.OutputLanguage = val; break; case ZeusConstants.Directives.UNIQUEID: template.UniqueID = val; break; case ZeusConstants.Directives.TITLE: template.Title = val; break; case ZeusConstants.Directives.NAMESPACE: template.NamespacePathString = val; break; case ZeusConstants.Directives.BODY_TAG_START: template.TagStart = val; break; case ZeusConstants.Directives.BODY_TAG_END: template.TagEnd = val; break; case ZeusConstants.Directives.INCLUDE_TEMPLATE: template.AddIncludedTemplatePath(val); break; } }
public void LoadIntoTemplate(StreamReader reader, string filepath, ZeusTemplate template) { char[] whitespace = new char[4] {'\n', '\r', '\t', ' '}; string key, val, line; int tagLength = ZeusConstants.START_DIRECTIVE.Length; int x, y; bool inGroupMode = false; string startGroupTag = string.Empty; StringBuilder builder = null; if (filepath != null) { int lastIndex = filepath.LastIndexOf('\\'); template.FileName = filepath.Substring(lastIndex + 1); template.FilePath = filepath.Substring(0, lastIndex + 1); } line = reader.ReadLine(); if (!line.StartsWith(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.TYPE)) { throw new ZeusParseException(template, ZeusParseError.OutdatedTemplateStructure, "OutdatedTemplateStructure"); } while (line != null) { if (line.StartsWith(ZeusConstants.START_DIRECTIVE)) { x = line.IndexOfAny(whitespace); if (x < 0) x = line.Length; y = x - tagLength; key = line.Substring(tagLength, y); if (!inGroupMode) { if (IsGroupStartTag(key)) { inGroupMode = true; startGroupTag = key; builder = new StringBuilder(); } else { val = line.Substring(x).Trim(); AssignProperty(template, key, val); } } else { if (IsGroupEndTag(key)) { AssignGroup(template, key, builder); inGroupMode = false; startGroupTag = string.Empty; } else { //TODO: *** Could put a warning here. Possibly have a warnings collection. Maybe a CompileInfo class? builder.Append(line + "\r\n"); } } } else if (inGroupMode) { builder.Append(line + "\r\n"); } line = reader.ReadLine(); } }
public void SaveInput() { if (this.treeViewTemplates.SelectedNode is TemplateTreeNode) { ZeusTemplate template = new ZeusTemplate(this.treeViewTemplates.SelectedNode.Tag.ToString()); SaveInput(template); } }
protected void AssignGroup(ZeusTemplate template, string key, StringBuilder builder) { switch (key) { case ZeusConstants.Directives.BODY_END: template.BodySegment.CodeUnparsed = builder.ToString().TrimEnd(); break; case ZeusConstants.Directives.GUI_END: template.GuiSegment.CodeUnparsed = builder.ToString().TrimEnd(); break; case ZeusConstants.Directives.COMMENTS_END: template.Comments = builder.ToString().TrimEnd(); break; } }
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; }
protected void AssignProperty(ZeusTemplate template, string key, string val) { template.AddDirective(key, val); switch (key) { case ZeusConstants.Directives.TYPE: template.Type = val; break; case ZeusConstants.Directives.SOURCE_TYPE: template.SourceType = val; break; case ZeusConstants.Directives.BODY_ENGINE: template.BodySegment.Engine = val; break; case ZeusConstants.Directives.BODY_LANGUAGE: template.BodySegment.Language = val; break; case ZeusConstants.Directives.BODY_MODE: template.BodySegment.Mode = val; break; case ZeusConstants.Directives.GUI_ENGINE: template.GuiSegment.Engine = val; break; case ZeusConstants.Directives.GUI_LANGUAGE: template.GuiSegment.Language = val; break; case ZeusConstants.Directives.OUTPUT_LANGUAGE: template.OutputLanguage = val; break; case ZeusConstants.Directives.UNIQUEID: template.UniqueID = val; break; case ZeusConstants.Directives.TITLE: template.Title = val; break; case ZeusConstants.Directives.NAMESPACE: template.NamespacePathString = val; break; case ZeusConstants.Directives.BODY_TAG_START: template.TagStart = val; break; case ZeusConstants.Directives.BODY_TAG_END: template.TagEnd = val; break; case ZeusConstants.Directives.INCLUDE_TEMPLATE: template.AddIncludedTemplatePath(val); break; } }
private void Parse(string[] args) { int numargs = args.Length; string arg; if (numargs == 0) { this._showHelp = true; return; } for (int i = 0; i < numargs; i++) { arg = args[i]; switch (arg) { case "-internaluse": this._internalUse = true; break; case "-installvs2005": this._installVS2005 = true; break; case "-tc": case "-testconnection": this._mode = ProcessMode.MyMeta; if (numargs > (i + 2)) { this._connType = args[++i]; this._connString = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-aio": case "-addintrinsicobject": if (numargs > (i + 3)) { string assembly = args[++i]; string classpath = args[++i]; string varname = args[++i]; ZeusIntrinsicObject iobj = new ZeusIntrinsicObject(assembly, classpath, varname); this._intrinsicObjects.Add(iobj); } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-rio": case "-removeintrinsicobject": if (numargs > (i + 1)) { string varname = args[++i]; foreach (ZeusIntrinsicObject zio in ZeusConfig.Current.IntrinsicObjects) { if (zio.VariableName == varname && !_intrinsicObjectsToRemove.Contains(zio)) { this._intrinsicObjectsToRemove.Add(zio); break; } } } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-r": case "-relative": this._makeRelative = true; break; case "-s": case "-silent": this._silent = true; break; case "-?": case "-h": case "-help": this._showHelp = true; break; case "-l": case "-logfile": this._enableLog = true; if (numargs > (i + 1)) { this._pathLog = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-o": case "-outfile": if (numargs > (i + 1)) { this._pathOutput = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-p": case "-project": this._mode = ProcessMode.Project; if (numargs > (i + 1)) { this._pathProject = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-mumd": case "-mergeusermetadata": this._mode = ProcessMode.MyMeta; this._metaDataMerge = true; if (numargs > (i + 5)) { this._metaDataFile1 = args[++i]; this._metaDatabase1 = args[++i]; this._metaDataFile2 = args[++i]; this._metaDatabase2 = args[++i]; this._metaDataFileMerged = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-m": case "-pf": case "-module": case "-projectfolder": if (numargs > (i + 1)) { string data = args[++i]; if (!_moduleNames.Contains(data)) { this._moduleNames.Add(data); } } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-rti": case "-recordtemplateinstance": if (numargs > (i + 1)) { this._projectItemToRecord = args[++i]; this._mode = ProcessMode.Project; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-ti": case "-templateinstance": if (numargs > (i + 1)) { string data = args[++i]; if (!_projectItems.Contains(data)) { this._projectItems.Add(data); } } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-i": case "-inputfile": this._mode = ProcessMode.Template; if (numargs > (i + 1)) { this._pathXmlData = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-t": case "-template": this._mode = ProcessMode.Template; if (numargs > (i + 1)) { this._pathTemplate = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-c": case "-collect": this._mode = ProcessMode.Template; if (numargs > (i + 1)) { this._pathCollectXmlData = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-e": case "-timeout": if (numargs > (i + 1)) { try { this._timeout = Int32.Parse(args[++i]); } catch { this._timeout = -1; } } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; default: _valid = false; this._errorMessage = "Invalid argument: " + arg; break; } } if (this._makeRelative) { if (this._pathCollectXmlData != null) { this._pathCollectXmlData = Zeus.FileTools.MakeAbsolute(this._pathCollectXmlData, FileTools.ApplicationPath); } if (this._pathLog != null) { this._pathLog = Zeus.FileTools.MakeAbsolute(this._pathLog, FileTools.ApplicationPath); } if (this._pathOutput != null) { this._pathOutput = Zeus.FileTools.MakeAbsolute(this._pathOutput, FileTools.ApplicationPath); } if (this._pathProject != null) { this._pathProject = Zeus.FileTools.MakeAbsolute(this._pathProject, FileTools.ApplicationPath); } if (this._pathTemplate != null) { this._pathTemplate = Zeus.FileTools.MakeAbsolute(this._pathTemplate, FileTools.ApplicationPath); } if (this._pathXmlData != null) { this._pathXmlData = Zeus.FileTools.MakeAbsolute(this._pathXmlData, FileTools.ApplicationPath); } if (this._metaDataFile1 != null) { this._metaDataFile1 = Zeus.FileTools.MakeAbsolute(this._metaDataFile1, FileTools.ApplicationPath); } if (this._metaDataFile2 != null) { this._metaDataFile2 = Zeus.FileTools.MakeAbsolute(this._metaDataFile2, FileTools.ApplicationPath); } if (this._metaDataFileMerged != null) { this._metaDataFileMerged = Zeus.FileTools.MakeAbsolute(this._metaDataFileMerged, FileTools.ApplicationPath); } } // Validate required fields are filled out for the selected mode. if (_valid) { if (this.Mode == ProcessMode.MyMeta) { if (this._metaDataMerge) { if (!System.IO.File.Exists(_metaDataFile1) || !System.IO.File.Exists(_metaDataFile2)) { _valid = false; this._errorMessage = "The two source files must exist for the merge to work!"; } } } else if (this._mode == ProcessMode.Project) { if (this._pathProject == null) { _valid = false; this._errorMessage = "Project Path Required"; } else { try { this._project = new ZeusProject(this._pathProject); this._project.Load(); } catch (Exception ex) { this._project = null; this._valid = false; this._errorMessage = ex.Message; } } if (this._pathTemplate != null) { try { this._template = new ZeusTemplate(this._pathTemplate); } catch (Exception ex) { this._template = null; this._valid = false; this._errorMessage = ex.Message; } } } else if (this._mode == ProcessMode.Template) { if ((this._pathTemplate == null) && (this._pathXmlData == null)) { _valid = false; this._errorMessage = "Template path or XML input path required."; } else { if (this._pathTemplate != null) { try { this._template = new ZeusTemplate(this._pathTemplate); } catch (Exception ex) { this._template = null; this._valid = false; this._errorMessage = ex.Message; } } if ((this._valid) && (this._pathXmlData != null)) { try { this._savedInput = new ZeusSavedInput(this._pathXmlData); this._savedInput.Load(); if (this._template == null) { this._template = new ZeusTemplate(this._savedInput.InputData.TemplatePath); } } catch (Exception ex) { this._savedInput = null; this._template = null; this._valid = false; this._errorMessage = ex.Message; } } if ((this._valid) && (this._pathCollectXmlData != null)) { try { this._inputToSave = new ZeusSavedInput(this._pathCollectXmlData); this._inputToSave.InputData.TemplatePath = this._template.FilePath + this._template.FileName; this._inputToSave.InputData.TemplateUniqueID = this._template.UniqueID; } catch (Exception ex) { this._inputToSave = null; this._valid = false; this._errorMessage = ex.Message; } } } } } }
internal ZeusCodeSegment(ZeusTemplate template, string segmentType) { this._template = template; this._segmentType = segmentType; }
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 LoadTemplates(string selectedid) { DefaultSettings settings = DefaultSettings.Instance; ArrayList filenames = new ArrayList(); filenames.Add(settings.DefaultTemplateDirectory); ArrayList templatePaths = FileTools.GetFilenamesRecursive(filenames, this._extensions); ZeusTemplate template; TemplateListItem item; this.listBoxTemplates.Items.Clear(); foreach (string path in templatePaths) { try { template = new ZeusTemplate(FileTools.ResolvePath(path)); string ns = template.NamespacePathString.Trim(); string title = template.Title.Trim(); title = (title.Length > 0) ? title : "<unnamed>"; if (ns.Length > 0) { ns = template.NamespacePathString + "." + title; } else { ns = title; } item = new TemplateListItem(template.UniqueID, path, ns); this.listBoxTemplates.Items.Add(item); if (item.ID == selectedid) { this.listBoxTemplates.SelectedItem = item; } } catch { continue; } } if ((this.listBoxTemplates.SelectedItem == null) && (this.listBoxTemplates.Items.Count > 0)) { this.listBoxTemplates.SelectedIndex = 0; } }
private void Parse(string[] args) { int numargs = args.Length; string arg; if (numargs == 0) { this._showHelp = true; return; } for (int i = 0; i < numargs; i++) { arg = args[i]; switch (arg) { case "-internaluse": this._internalUse = true; break; case "-installvs2005": this._installVS2005 = true; break; case "-tc": case "-testconnection": this._mode = ProcessMode.MyMeta; if (numargs > (i + 2)) { this._connType = args[++i]; this._connString = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-aio": case "-addintrinsicobject": if (numargs > (i+3)) { string assembly = args[++i]; string classpath = args[++i]; string varname = args[++i]; ZeusIntrinsicObject iobj = new ZeusIntrinsicObject(assembly, classpath, varname); this._intrinsicObjects.Add(iobj); } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-rio": case "-removeintrinsicobject": if (numargs > (i + 1)) { string varname = args[++i]; foreach (ZeusIntrinsicObject zio in ZeusConfig.Current.IntrinsicObjects) { if (zio.VariableName == varname && !_intrinsicObjectsToRemove.Contains(zio)) { this._intrinsicObjectsToRemove.Add(zio); break; } } } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-r": case "-relative": this._makeRelative = true; break; case "-s": case "-silent": this._silent = true; break; case "-?": case "-h": case "-help": this._showHelp = true; break; case "-l": case "-logfile": this._enableLog = true; if (numargs > (i+1)) this._pathLog = args[++i]; else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-o": case "-outfile": if (numargs > (i+1)) this._pathOutput = args[++i]; else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-p": case "-project": this._mode = ProcessMode.Project; if (numargs > (i+1)) this._pathProject = args[++i]; else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-mumd": case "-mergeusermetadata": this._mode = ProcessMode.MyMeta; this._metaDataMerge = true; if (numargs > (i + 5)) { this._metaDataFile1 = args[++i]; this._metaDatabase1 = args[++i]; this._metaDataFile2 = args[++i]; this._metaDatabase2 = args[++i]; this._metaDataFileMerged = args[++i]; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-m": case "-pf": case "-module": case "-projectfolder": if (numargs > (i+1)) { string data = args[++i]; if (!_moduleNames.Contains(data)) this._moduleNames.Add(data); } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-rti": case "-recordtemplateinstance": if (numargs > (i + 1)) { this._projectItemToRecord = args[++i]; this._mode = ProcessMode.Project; } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-ti": case "-templateinstance": if (numargs > (i + 1)) { string data = args[++i]; if (!_projectItems.Contains(data)) this._projectItems.Add(data); } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-i": case "-inputfile": this._mode = ProcessMode.Template; if (numargs > (i+1)) this._pathXmlData = args[++i]; else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-t": case "-template": this._mode = ProcessMode.Template; if (numargs > (i+1)) this._pathTemplate = args[++i]; else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-c": case "-collect": this._mode = ProcessMode.Template; if (numargs > (i+1)) this._pathCollectXmlData = args[++i]; else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; case "-e": case "-timeout": if (numargs > (i+1)) { try { this._timeout = Int32.Parse(args[++i]); } catch { this._timeout = -1; } } else { this._valid = false; this._errorMessage = "Invalid switch usage: " + arg; } break; default: _valid = false; this._errorMessage = "Invalid argument: " + arg; break; } } if (this._makeRelative) { if (this._pathCollectXmlData != null) this._pathCollectXmlData = Zeus.FileTools.MakeAbsolute(this._pathCollectXmlData, FileTools.ApplicationPath); if (this._pathLog != null) this._pathLog = Zeus.FileTools.MakeAbsolute(this._pathLog, FileTools.ApplicationPath); if (this._pathOutput != null) this._pathOutput = Zeus.FileTools.MakeAbsolute(this._pathOutput, FileTools.ApplicationPath); if (this._pathProject != null) this._pathProject = Zeus.FileTools.MakeAbsolute(this._pathProject, FileTools.ApplicationPath); if (this._pathTemplate != null) this._pathTemplate = Zeus.FileTools.MakeAbsolute(this._pathTemplate, FileTools.ApplicationPath); if (this._pathXmlData != null) this._pathXmlData = Zeus.FileTools.MakeAbsolute(this._pathXmlData, FileTools.ApplicationPath); if (this._metaDataFile1 != null) this._metaDataFile1 = Zeus.FileTools.MakeAbsolute(this._metaDataFile1, FileTools.ApplicationPath); if (this._metaDataFile2 != null) this._metaDataFile2 = Zeus.FileTools.MakeAbsolute(this._metaDataFile2, FileTools.ApplicationPath); if (this._metaDataFileMerged != null) this._metaDataFileMerged = Zeus.FileTools.MakeAbsolute(this._metaDataFileMerged, FileTools.ApplicationPath); } // Validate required fields are filled out for the selected mode. if (_valid) { if (this.Mode == ProcessMode.MyMeta) { if (this._metaDataMerge) { if (!System.IO.File.Exists(_metaDataFile1) || !System.IO.File.Exists(_metaDataFile2)) { _valid = false; this._errorMessage = "The two source files must exist for the merge to work!"; } } } else if (this._mode == ProcessMode.Project) { if (this._pathProject == null) { _valid = false; this._errorMessage = "Project Path Required"; } else { try { this._project = new ZeusProject(this._pathProject); this._project.Load(); } catch (Exception ex) { this._project = null; this._valid = false; this._errorMessage = ex.Message; } } if (this._pathTemplate != null) { try { this._template = new ZeusTemplate(this._pathTemplate); } catch (Exception ex) { this._template = null; this._valid = false; this._errorMessage = ex.Message; } } } else if (this._mode == ProcessMode.Template) { if ( (this._pathTemplate == null) && (this._pathXmlData == null) ) { _valid = false; this._errorMessage = "Template path or XML input path required."; } else { if (this._pathTemplate != null) { try { this._template = new ZeusTemplate(this._pathTemplate); } catch (Exception ex) { this._template = null; this._valid = false; this._errorMessage = ex.Message; } } if ( (this._valid) && (this._pathXmlData != null) ) { try { this._savedInput = new ZeusSavedInput(this._pathXmlData); this._savedInput.Load(); if (this._template == null) { this._template = new ZeusTemplate(this._savedInput.InputData.TemplatePath); } } catch (Exception ex) { this._savedInput = null; this._template = null; this._valid = false; this._errorMessage = ex.Message; } } if ( (this._valid) && (this._pathCollectXmlData != null) ) { try { this._inputToSave = new ZeusSavedInput(this._pathCollectXmlData); this._inputToSave.InputData.TemplatePath = this._template.FilePath + this._template.FileName; this._inputToSave.InputData.TemplateUniqueID = this._template.UniqueID; } catch (Exception ex) { this._inputToSave = null; this._valid = false; this._errorMessage = ex.Message; } } } } } }
public void LoadIntoTemplate(StreamReader reader, string filepath, ZeusTemplate template) { char[] whitespace = new char[4] { '\n', '\r', '\t', ' ' }; string key, val, line; int tagLength = ZeusConstants.START_DIRECTIVE.Length; int x, y; bool inGroupMode = false; string startGroupTag = string.Empty; StringBuilder builder = null; if (filepath != null) { int lastIndex = filepath.LastIndexOf('\\'); template.FileName = filepath.Substring(lastIndex + 1); template.FilePath = filepath.Substring(0, lastIndex + 1); } line = reader.ReadLine(); if (!line.StartsWith(ZeusConstants.START_DIRECTIVE + ZeusConstants.Directives.TYPE)) { throw new ZeusParseException(template, ZeusParseError.OutdatedTemplateStructure, "OutdatedTemplateStructure"); } while (line != null) { if (line.StartsWith(ZeusConstants.START_DIRECTIVE)) { x = line.IndexOfAny(whitespace); if (x < 0) { x = line.Length; } y = x - tagLength; key = line.Substring(tagLength, y); if (!inGroupMode) { if (IsGroupStartTag(key)) { inGroupMode = true; startGroupTag = key; builder = new StringBuilder(); } else { val = line.Substring(x).Trim(); AssignProperty(template, key, val); } } else { if (IsGroupEndTag(key)) { AssignGroup(template, key, builder); inGroupMode = false; startGroupTag = string.Empty; } else { //TODO: *** Could put a warning here. Possibly have a warnings collection. Maybe a CompileInfo class? builder.Append(line + "\r\n"); } } } else if (inGroupMode) { builder.Append(line + "\r\n"); } line = reader.ReadLine(); } }