/// <summary> /// Constructor /// </summary> /// <param name="assembler">A reference to the build assembler.</param> /// <param name="configuration">The configuration information</param> /// <exception cref="ConfigurationErrorsException">This is thrown if /// an error is detected in the configuration.</exception> public PostTransformComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator nav; string attr; Assembly asm = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); base.WriteMessage(MessageLevel.Info, String.Format( CultureInfo.InvariantCulture, "\r\n [{0}, version {1}]\r\n Post-Transform Component. " + "{2}\r\n http://www.codeplex.com/SHFB", fvi.ProductName, fvi.ProductVersion, fvi.LegalCopyright)); // The <colorizer> element is required and defines the colorizer // file locations. nav = configuration.SelectSingleNode("colorizer"); if (nav == null) { throw new ConfigurationErrorsException("You must specify " + "a <colorizer> element to define the code colorizer " + "files."); } // All of the attributes are required stylesheet = nav.GetAttribute("stylesheet", String.Empty); scriptFile = nav.GetAttribute("scriptFile", String.Empty); copyImage = nav.GetAttribute("copyImage", String.Empty); if (String.IsNullOrEmpty(stylesheet)) { throw new ConfigurationErrorsException("You must specify a " + "'stylesheet' attribute on the <colorizer> element"); } if (String.IsNullOrEmpty(scriptFile)) { throw new ConfigurationErrorsException("You must specify a " + "'scriptFile' attribute on the <colorizer> element"); } if (String.IsNullOrEmpty(copyImage)) { throw new ConfigurationErrorsException("You must specify a " + "'copyImage' attribute on the <colorizer> element"); } // This specifies the output and the XPath expression used // to get the filename. If the base class found them, we will. nav = configuration.SelectSingleNode("outputPath"); if (nav != null) { outputPath = nav.GetAttribute("value", String.Empty); } if (String.IsNullOrEmpty(outputPath)) { throw new ConfigurationErrorsException("You must specify a " + "'value' attribute on the <outputPath> element"); } // All present. Make sure they exist. stylesheet = Path.GetFullPath(stylesheet); scriptFile = Path.GetFullPath(scriptFile); copyImage = Path.GetFullPath(copyImage); if (!outputPath.EndsWith(@"\")) { outputPath += @"\"; } if (!File.Exists(stylesheet)) { throw new ConfigurationErrorsException("Could not find " + "stylesheet file: " + stylesheet); } if (!File.Exists(stylesheet)) { throw new ConfigurationErrorsException("Could not find " + "script file: " + scriptFile); } if (!File.Exists(copyImage)) { throw new ConfigurationErrorsException("Could not find " + "image file: " + copyImage); } if (!Directory.Exists(outputPath)) { throw new ConfigurationErrorsException("The output path '" + outputPath + "' must exist"); } // The logo element is optional. The file must exist if // specified. nav = configuration.SelectSingleNode("logoFile"); if (nav != null) { logoFilename = nav.GetAttribute("filename", String.Empty); if (!String.IsNullOrEmpty(logoFilename)) { if (!File.Exists(logoFilename)) { throw new ConfigurationErrorsException("The logo " + "file '" + logoFilename + "' must exist"); } logoAltText = nav.GetAttribute("altText", String.Empty); attr = nav.GetAttribute("height", String.Empty); if (!String.IsNullOrEmpty(attr)) { if (!Int32.TryParse(attr, out logoHeight)) { throw new ConfigurationErrorsException("The logo " + "height must be an integer value"); } } attr = nav.GetAttribute("width", String.Empty); if (!String.IsNullOrEmpty(attr)) { if (!Int32.TryParse(attr, out logoWidth)) { throw new ConfigurationErrorsException("The logo " + "width must be an integer value"); } } // Ignore them if negative if (logoHeight < 0) { logoHeight = 0; } if (logoWidth < 0) { logoWidth = 0; } // Placement and alignment are optional attr = nav.GetAttribute("placement", String.Empty); if (!String.IsNullOrEmpty(attr)) { placement = (LogoPlacement)Enum.Parse( typeof(LogoPlacement), attr, true); } else { placement = LogoPlacement.Left; } attr = nav.GetAttribute("alignment", String.Empty); if (!String.IsNullOrEmpty(attr)) { alignment = attr; } else { alignment = "left"; } } } }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="assembler">A reference to the build assembler.</param> /// <param name="configuration">The configuration information</param> /// <exception cref="ConfigurationErrorsException">This is thrown if /// an error is detected in the configuration.</exception> public PostTransformComponent(BuildAssembler assembler, XPathNavigator configuration) : base(assembler, configuration) { XPathNavigator nav; string attr; int pos; Assembly asm = Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location); base.WriteMessage(MessageLevel.Info, String.Format(CultureInfo.InvariantCulture, "\r\n [{0}, version {1}]\r\n Post-Transform Component. " + "{2}\r\n http://SHFB.CodePlex.com", fvi.ProductName, fvi.ProductVersion, fvi.LegalCopyright)); outputPaths = new List<string>(); // The <colorizer> element is required and defines the colorizer // file locations. nav = configuration.SelectSingleNode("colorizer"); if(nav == null) throw new ConfigurationErrorsException("You must specify " + "a <colorizer> element to define the code colorizer " + "files."); // All of the attributes are required stylesheet = nav.GetAttribute("stylesheet", String.Empty); scriptFile = nav.GetAttribute("scriptFile", String.Empty); copyImage = nav.GetAttribute("copyImage", String.Empty); if(String.IsNullOrEmpty(stylesheet)) throw new ConfigurationErrorsException("You must specify a " + "'stylesheet' attribute on the <colorizer> element"); if(String.IsNullOrEmpty(scriptFile)) throw new ConfigurationErrorsException("You must specify a " + "'scriptFile' attribute on the <colorizer> element"); if(String.IsNullOrEmpty(copyImage)) throw new ConfigurationErrorsException("You must specify a " + "'copyImage' attribute on the <colorizer> element"); // This element is obsolete, if found, tell the user to edit and save the configuration nav = configuration.SelectSingleNode("outputPath"); if(nav != null) throw new ConfigurationErrorsException("The PostTransformComponent configuration contains an " + "obsolete <outputPath> element. Please edit the configuration to update it with the new " + "<outputPaths> element."); // Get the output paths foreach(XPathNavigator path in configuration.Select("outputPaths/path")) { attr = path.GetAttribute("value", String.Empty); if(attr[attr.Length - 1] != '\\') attr += @"\"; if(!Directory.Exists(attr)) throw new ConfigurationErrorsException("The output path '" + attr + "' must exist"); outputPaths.Add(attr); } if(outputPaths.Count == 0) throw new ConfigurationErrorsException("You must specify at least one <path> element in the " + "<outputPaths> element"); // All present. Make sure they exist. stylesheet = Path.GetFullPath(stylesheet); scriptFile = Path.GetFullPath(scriptFile); copyImage = Path.GetFullPath(copyImage); // The highlight image will have the same name but with an "_h" // suffix. If it doesn't exist, the copy image will be used. pos = copyImage.LastIndexOf('.'); if(pos == -1) copyImage_h = copyImage + "_h"; else copyImage_h = copyImage.Substring(0, pos) + "_h" + copyImage.Substring(pos); if(!File.Exists(stylesheet)) throw new ConfigurationErrorsException("Could not find stylesheet file: " + stylesheet); if(!File.Exists(stylesheet)) throw new ConfigurationErrorsException("Could not find script file: " + scriptFile); if(!File.Exists(copyImage)) throw new ConfigurationErrorsException("Could not find image file: " + copyImage); // The logo element is optional. The file must exist if specified. nav = configuration.SelectSingleNode("logoFile"); if(nav != null) { logoFilename = nav.GetAttribute("filename", String.Empty); if(!String.IsNullOrEmpty(logoFilename)) { if(!File.Exists(logoFilename)) throw new ConfigurationErrorsException("The logo file '" + logoFilename + "' must exist"); logoAltText = nav.GetAttribute("altText", String.Empty); attr = nav.GetAttribute("height", String.Empty); if(!String.IsNullOrEmpty(attr)) if(!Int32.TryParse(attr, out logoHeight)) throw new ConfigurationErrorsException("The logo height must be an integer value"); attr = nav.GetAttribute("width", String.Empty); if(!String.IsNullOrEmpty(attr)) if(!Int32.TryParse(attr, out logoWidth)) throw new ConfigurationErrorsException("The logo width must be an integer value"); // Ignore them if negative if(logoHeight < 0) logoHeight = 0; if(logoWidth < 0) logoWidth = 0; // Placement and alignment are optional attr = nav.GetAttribute("placement", String.Empty); if(!String.IsNullOrEmpty(attr)) placement = (LogoPlacement)Enum.Parse(typeof(LogoPlacement), attr, true); else placement = LogoPlacement.Left; attr = nav.GetAttribute("alignment", String.Empty); if(!String.IsNullOrEmpty(attr)) alignment = attr; else alignment = "left"; } } }