private void docSign_PrintPage(object sender, PrintPageEventArgs e) { try { string dataFolder = _PlantFolder; string templateFile = Path.GetFileName(_TemplatePath); string templateFolder = Path.GetDirectoryName(_TemplatePath); MacroDefinitions macroDefs = new MacroDefinitions(); SingleSign.LoadMacroDefinitions(templateFile, templateFolder, macroDefs); MacroValues macros = new MacroValues(); SingleSign.AddStandardMacroValues(macros); foreach (MacroDefinition macroDef in macroDefs) { macros[macroDef.Name] = macroDef.Value; } XmlDocument dataDoc = SingleSign.CreateEmptySignDataDoc(); dataDoc.LoadXml(txtPlantFileContents.Text); SingleSign.AddDataFileMacros(macros, dataFolder, dataDoc); SingleSign singleSign = new SingleSign(); singleSign.Print(templateFile, templateFolder, macros, dataFolder, e); e.HasMorePages = false; } catch (Exception ex) { SingleSign.ShowException(ex); } }
private void DisplayMacroDef(MacroDefinitions macroDefs, int index, TextBox macroNameControl, TextBox macroValueControl) { macroNameControl.Text = string.Empty; macroValueControl.Text = string.Empty; if (index < macroDefs.Count) { macroNameControl.Text = macroDefs[index].Name; macroValueControl.Text = macroDefs[index].Value; } }
private void LoadMacroDefs() { string templateFolder = Path.GetDirectoryName(_TemplatePath); string templateFile = Path.GetFileName(_TemplatePath); MacroDefinitions macroDefs = new MacroDefinitions(); SingleSign.LoadMacroDefinitions(templateFile, templateFolder, macroDefs); DisplayMacroDef(macroDefs, 0, txtMacro1Name, txtMacro1Value); DisplayMacroDef(macroDefs, 1, txtMacro2Name, txtMacro2Value); DisplayMacroDef(macroDefs, 2, txtMacro3Name, txtMacro3Value); }
public static void LoadMacroDefinitions(string templateFile, string templateFolder, MacroDefinitions macroDefs) { string templatePath = Path.Combine(templateFolder, templateFile); XmlDocument templateDoc = new XmlDocument(); templateDoc.Load(templatePath); foreach (XmlNode templateNode in templateDoc.DocumentElement.ChildNodes) { XmlElement cmdElm = templateNode as XmlElement; if (cmdElm != null) { string cmdName = cmdElm.Name.ToLowerInvariant(); switch (cmdName) { case "macrodef": string macroName; if (!TryGetAttrib(cmdElm, "name", out macroName)) { throw CreateTemplateAttributeException(cmdElm, "name", "Missing [name] attribute"); } string macroValue; if (!TryGetAttrib(cmdElm, "value", out macroValue)) { throw CreateTemplateAttributeException(cmdElm, "value", "Missing [value] attribute"); } macroDefs.Add(new MacroDefinition(macroName, macroValue)); break; case "include": string includePath = cmdElm.InnerText; if (string.IsNullOrEmpty(includePath)) { throw CreateTemplateException(cmdElm, "Missing include file name"); } LoadMacroDefinitions(Path.GetFileName(includePath), templateFolder, macroDefs); break; } } } }
public ProjectInformation(Project project) : base(project) { globals = new Globals(project); macroDefs = new MacroDefinitions(project); }