public override void Uninitialize() { _context = null; _singleFormat = null; _listFormats = null; base.Uninitialize(); }
public override void Initialize(BuildContext context) { base.Initialize(context); if (base.IsInitialized) { _context = context; BuildSettings settings = context.Settings; if (settings == null || settings.Style == null) { this.IsInitialized = false; return; } BuildFormatList listFormats = settings.Formats; if (listFormats == null || listFormats.Count == 0) { this.IsInitialized = false; return; } int itemCount = listFormats.Count; _listFormats = new BuildFormatList(); for (int i = 0; i < itemCount; i++) { BuildFormat format = listFormats[i]; if (format != null && format.Enabled) { _listFormats.Add(format); } } if (_listFormats == null || _listFormats.Count == 0) { this.IsInitialized = false; return; } else if (_listFormats.Count == 1) { _singleFormat = _listFormats[0]; } } }
private bool OpenHelpFile(BuildContext context) { // 1. Start the Microsoft Help Library Agent process... StartHelpAgent(context); // 2. Wait for the help library service to be available... int waitCount = 0; while (!ProcessRunner.IsProcessOpen("HelpLibAgent")) { // We wait for a max of 5 times, should be enough on even slow // systems... if (waitCount >= 5) { break; } waitCount++; Thread.Sleep(100); } BuildLogger logger = context.Logger; if (logger != null) { logger.WriteLine("Opening: " + _helpPath, BuildLoggerLevel.Info); } string helpUrlFormat = "ms-xhelp:///?method=page&id={0}&product={1}&productversion={2}&locale={3}"; string helpUrl = null; // 3. The startup help ID will normally be saved in the context, get it... string helpStartId = context["$HelpTocRoot"]; string tempText = context["$HelpHierarchicalToc"]; // If there is a custom format TOC, we use its root... BuildTocContext tocContext = context.TocContext; BuildFormatList formatList = context.Settings.Formats; FormatMhv mhvFormat = formatList[BuildFormatType.HtmlHelp3] as FormatMhv; string formatTocFile = tocContext.GetValue("$" + mhvFormat.Name); string formatTocRoot = tocContext.GetValue("$" + mhvFormat.Name + "-HelpTocRoot"); if (!(String.IsNullOrEmpty(formatTocFile) && File.Exists(formatTocFile)) && !String.IsNullOrEmpty(formatTocRoot)) { helpStartId = formatTocRoot; } else if (!String.IsNullOrEmpty(tempText) && String.Equals(tempText, Boolean.TrueString, StringComparison.OrdinalIgnoreCase)) { helpStartId = context["$HelpHierarchicalTocRoot"]; } if (String.IsNullOrEmpty(helpStartId)) { helpUrl = String.Format( "ms-xhelp:///?method=page&id=-1&format=html&product={0}&productVersion={1}", _catalogProductId, _catalogVersion); } else { helpUrl = String.Format(helpUrlFormat, helpStartId, _catalogProductId, _catalogVersion, _catalogLocale); } try { // 4. Request the Microsoft Help Library Agent to open the page... Process startHelp = Process.Start(helpUrl); // The return could be null, if no process resource is started // (for example, if an existing process is reused as in browsers). if (startHelp != null) { startHelp.Close(); } return(true); } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } return(false); } }
protected override bool OnExecute(BuildContext context) { string workingDir = this.WorkingDirectory; if (String.IsNullOrEmpty(workingDir)) { throw new BuildException("A working directory is required."); } BuildTocContext tocContext = context.TocContext; string tocFile = tocContext.GetValue("$" + _buildFormat.Name); if (!String.IsNullOrEmpty(tocFile) && File.Exists(tocFile)) { _helpToc = Path.GetFileName(tocFile); } if (String.IsNullOrEmpty(_helpName) || String.IsNullOrEmpty(_helpToc)) { throw new BuildException("The required property values are set."); } _logger = context.Logger; if (_logger != null) { _verbosity = _logger.Verbosity; } bool buildResult = false; _settings = context.Settings; BuildFormatList formats = _settings.Formats; if (formats == null || formats.Count == 0) { return(buildResult); } FormatHxs hxsFormat = formats[BuildFormatType.HtmlHelp2] as FormatHxs; if (hxsFormat == null || hxsFormat.Enabled == false) { return(buildResult); } _buildFormat = hxsFormat; string helpTitleId = _helpTitleId; if (helpTitleId != null) { helpTitleId = helpTitleId.Trim(); } if (String.IsNullOrEmpty(helpTitleId)) { helpTitleId = _helpName; } _helpTitleId = helpTitleId; // We create a common XML Settings for all the writers... _xmlSettings = new XmlWriterSettings(); _xmlSettings.Encoding = Encoding.UTF8; _xmlSettings.Indent = true; _xmlSettings.IndentChars = " "; _xmlSettings.OmitXmlDeclaration = false; _xmlSettings.CloseOutput = true; buildResult = true; try { if (_helpCulture != null) { _langId = _helpCulture.LCID; } // For these properties, we do not mind if set or there is error. string tmpText = _buildFormat["IndexAutoInclude"]; if (String.IsNullOrEmpty(tmpText) == false) { try { _indexAutoInclude = Convert.ToBoolean(tmpText); } catch { } } tmpText = _buildFormat["IndexSort"]; if (String.IsNullOrEmpty(tmpText) == false) { try { _indexSort = Convert.ToBoolean(tmpText); } catch { } } tmpText = _buildFormat["IndexMerge"]; if (String.IsNullOrEmpty(tmpText) == false) { try { _indexMerge = Convert.ToBoolean(tmpText); } catch { } } tmpText = _buildFormat["SampleInfo"]; if (String.IsNullOrEmpty(tmpText) == false) { try { _sampleInfo = Convert.ToBoolean(tmpText); } catch { } } _helpDir = Path.Combine(workingDir, _helpFolder); if (Directory.Exists(_helpDir) == false) { Directory.CreateDirectory(_helpDir); } buildResult = CreateContents(context); if (buildResult == false) { return(buildResult); } buildResult = CreateProject(context); if (buildResult == false) { return(buildResult); } buildResult = CreateToc(context); if (buildResult == false) { return(buildResult); } buildResult = CreateIndex(context); } catch (Exception ex) { if (_logger != null) { _logger.WriteLine(ex, BuildLoggerLevel.Error); } buildResult = false; } return(buildResult); }
public override void Initialize(BuildContext context) { if (this.IsInitialized) { return; } base.Initialize(context); if (!this.IsInitialized) { return; } if (_listGroups == null || _listGroups.Count == 0) { this.IsInitialized = false; return; } BuildSettings settings = this.Settings; _engineSettings = (ReferenceEngineSettings)settings.EngineSettings[ BuildEngineType.Reference]; Debug.Assert(_engineSettings != null, "The settings does not include the reference engine settings."); if (_engineSettings == null) { this.IsInitialized = false; return; } int itemCount = _listGroups.Count; for (int i = 0; i < itemCount; i++) { ReferenceGroup group = _listGroups[i]; BuildGroupContext groupContext = context.GroupContexts[group.Id]; if (groupContext == null) { throw new BuildException( "The group context is not provided, and it is required by the build system."); } string indexText = String.Empty; if (itemCount > 1) { indexText = (i + 1).ToString(); } // Create the build dynamic properties... groupContext.CreateProperties(indexText); group.BeginSources(context); } // Turn the link sources to dynamic groups... this.CreateLinkGroups(context); // Cache the list of applicable formats... _listFormats = new BuildFormatList(); BuildFormatList listFormats = this.Settings.Formats; if (listFormats == null || listFormats.Count == 0) { this.IsInitialized = false; return; } itemCount = listFormats.Count; for (int i = 0; i < itemCount; i++) { BuildFormat format = listFormats[i]; if (format != null && format.Enabled) { _listFormats.Add(format); } } if (_listFormats == null || _listFormats.Count == 0) { this.IsInitialized = false; return; } // Finally, initialize the build groups... itemCount = _listGroups.Count; for (int i = 0; i < itemCount; i++) { ReferenceGroup group = _listGroups[i]; group.Initialize(context); if (!group.IsInitialized) { this.IsInitialized = false; break; } } }
public override void Initialize(BuildContext context) { if (this.IsInitialized) { return; } base.Initialize(context); if (!this.IsInitialized) { return; } if (_listGroups == null || _listGroups.Count == 0) { this.IsInitialized = false; return; } int itemCount = _listGroups.Count; for (int i = 0; i < itemCount; i++) { ConceptualGroup group = _listGroups[i]; BuildGroupContext groupContext = context.GroupContexts[group.Id]; if (groupContext == null) { throw new BuildException( "The group context is not provided, and it is required by the build system."); } string indexText = String.Empty; if (itemCount > 1) { indexText = (i + 1).ToString(); } // Create the build dynamic properties... groupContext.CreateProperties(indexText); group.BeginSources(context); } _listFormats = new BuildFormatList(); BuildFormatList listFormats = this.Settings.Formats; if (listFormats == null || listFormats.Count == 0) { this.IsInitialized = false; return; } itemCount = listFormats.Count; for (int i = 0; i < itemCount; i++) { BuildFormat format = listFormats[i]; if (format != null && format.Enabled) { _listFormats.Add(format); } } if (_listFormats == null || _listFormats.Count == 0) { this.IsInitialized = false; return; } itemCount = _listGroups.Count; for (int i = 0; i < itemCount; i++) { ConceptualGroup group = _listGroups[i]; group.Initialize(context); if (!group.IsInitialized) { this.IsInitialized = false; break; } } }