private bool ValidateSandcastle() { if (this.IsDirectSandcastle) { _logger.WriteLine("Sandcastle Version: " + "Using the Sandcastle Assist Version.", BuildLoggerLevel.Info); return(true); } if (String.IsNullOrEmpty(_sandcastleDir) || String.IsNullOrEmpty(_sandcastleToolsDir)) { throw new InvalidOperationException("The validation requires Sandcastle installed paths."); } _logger.WriteLine("Sandcastle Directory: " + _sandcastleDir, BuildLoggerLevel.Info); string sampleTool = Path.Combine(_sandcastleToolsDir, "BuildAssembler.exe"); if (!File.Exists(sampleTool)) { return(false); } FileVersionInfo sandcastleVersionInfo = FileVersionInfo.GetVersionInfo(sampleTool); _logger.WriteLine("Sandcastle Version: " + sandcastleVersionInfo.FileVersion, BuildLoggerLevel.Info); return(true); }
public override void Initialize(BuildContext context) { base.Initialize(context); if (this.IsInitialized) { BuildSettings settings = context.Settings; CultureInfo culture = settings.CultureInfo; BuildLogger logger = context.Logger; string dictionaryDir = Path.Combine( settings.SandAssistDirectory, "Dictionaries"); if (Directory.Exists(dictionaryDir)) { string langName = culture.Name; langName = langName.Replace('-', '_'); string affFile = Path.Combine(dictionaryDir, langName + ".aff"); string dicFile = Path.Combine(dictionaryDir, langName + ".dic"); if (File.Exists(affFile) && File.Exists(dicFile)) { if (logger != null) { logger.WriteLine( "Loading dictionary for: " + culture.EnglishName, BuildLoggerLevel.Info); } _hunspell = new Hunspell(); _hunspell.Load(affFile, dicFile); } else { if (logger != null) { logger.WriteLine( "No dictionary found for: " + culture.EnglishName, BuildLoggerLevel.Warn); } } } } if (_hunspell == null) { this.IsInitialized = false; } }
protected void LogMessage(BuildLoggerLevel level, string message) { if (_logger != null) { _logger.WriteLine(message, level); } }
public override void Uninitialize() { if (_listSteps == null || _listSteps.Count == 0) { base.Uninitialize(); return; } BuildLogger logger = this.Context.Logger; int stepCount = _listSteps.Count; try { for (int i = 0; i < stepCount; i++) { BuildStep buildStep = _listSteps[i]; if (buildStep != null) { buildStep.Uninitialize(); } } } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } } base.Uninitialize(); }
public override void WriteLine(string outputText, BuildLoggerLevel level) { if (_listLoggers == null || this.Enabled == false) { return; } if (level == BuildLoggerLevel.Warn) { _totalWarnings++; } else if (level == BuildLoggerLevel.Error) { _totalErrors++; } int itemCount = _listLoggers.Count; if (String.IsNullOrEmpty(outputText)) { for (int i = 0; i < itemCount; i++) { BuildLogger logger = _listLoggers[i]; logger.WriteLine(); } } else { for (int i = 0; i < itemCount; i++) { BuildLogger logger = _listLoggers[i]; logger.WriteLine(outputText, level); } } }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <param name="logger"></param> private void CopyFiles(DirectoryInfo source, DirectoryInfo target, BuildLogger logger) { FileInfo[] listInfo = source.GetFiles(); int fileCount = (listInfo == null) ? 0 : listInfo.Length; string targetDirName = target.ToString(); string filePath; // Handle the copy of each file into it's new directory. for (int i = 0; i < fileCount; i++) { FileInfo fi = listInfo[i]; FileAttributes fileAttr = fi.Attributes; if (!_includeHidden) { if ((fileAttr & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } } _copiedCount++; filePath = Path.Combine(targetDirName, fi.Name); if (logger != null) { logger.WriteLine(String.Format(@"Copying {0}\{1}", target.FullName, fi.Name), BuildLoggerLevel.Info); } fi.CopyTo(filePath, _isOverwrite); // For most of the build files, we will copy and delete, so we must // remove any readonly flag... if ((fileAttr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { fileAttr -= FileAttributes.ReadOnly; } File.SetAttributes(filePath, fileAttr); // if required to set the security or access control if (_includeSecurity) { File.SetAccessControl(filePath, fi.GetAccessControl()); } } }
public override void WriteLine() { if (_listLoggers == null || this.Enabled == false) { return; } int itemCount = _listLoggers.Count; for (int i = 0; i < itemCount; i++) { BuildLogger logger = _listLoggers[i]; logger.WriteLine(); } }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="target"></param> /// <param name="logger"></param> private void CopyFilesEx(DirectoryInfo source, DirectoryInfo target, BuildLogger logger) { string targetDirName = target.ToString(); string filePath; // Handle the copy of each file into it's new directory. foreach (string file in PathSearch.FindFiles( source, "*.*", SearchOption.TopDirectoryOnly)) { FileAttributes fileAttr = File.GetAttributes(file); if (!_includeHidden) { if ((fileAttr & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } } _copiedCount++; string fileName = Path.GetFileName(file); filePath = Path.Combine(targetDirName, fileName); if (logger != null) { logger.WriteLine(String.Format(@"Copying {0}\{1}", target.FullName, fileName), BuildLoggerLevel.Info); } File.Copy(file, filePath, _isOverwrite); // For most of the build files, we will copy and delete, so we must // remove any readonly flag... if ((fileAttr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { fileAttr -= FileAttributes.ReadOnly; } File.SetAttributes(filePath, fileAttr); // if required to set the security or access control if (_includeSecurity) { File.SetAccessControl(filePath, File.GetAccessControl(file)); } } }
/// <summary> /// Prepares or initializes this group visitor for processing of its /// operations. /// </summary> /// <param name="context"> /// An instance of the <see cref="BuildContext"/> specifying the /// build context for this visitor. /// </param> /// <remarks> /// This will not be initialized, if already in the initialized state. /// </remarks> /// <exception cref="ArgumentNullException"> /// If the <paramref name="context"/> is <see langword="null"/>. /// </exception> /// <seealso cref="BuildGroupVisitor.Uninitialize()"/> /// <seealso cref="BuildGroupVisitor.IsInitialized"/> public virtual void Initialize(BuildContext context) { BuildExceptions.NotNull(context, "context"); if (_isInitialized) { BuildLogger logger = context.Logger; if (logger != null) { logger.WriteLine("This visitor is already initialized.", BuildLoggerLevel.Warn); } return; } _context = context; _isInitialized = true; }
public override void Initialize(BuildContext context) { base.Initialize(context); if (!this.IsInitialized) { return; } if (_listSteps == null || _listSteps.Count == 0) { this.IsInitialized = false; return; } BuildLogger logger = context.Logger; int stepCount = _listSteps.Count; for (int i = 0; i < stepCount; i++) { BuildStep buildStep = _listSteps[i]; if (buildStep != null) { buildStep.Initialize(context); if (!buildStep.IsInitialized) { logger.WriteLine( "An error occurred when initializing the multi-step = " + i.ToString(), BuildLoggerLevel.Error); this.IsInitialized = false; break; } } } }
protected override bool OnExecute(BuildContext context) { BuildLogger logger = context.Logger; bool buildResult = true; if (_listSteps == null || _listSteps.Count == 0) { if (logger != null) { logger.WriteLine("This multi-step contains no build step.", BuildLoggerLevel.Warn); } return(buildResult); } int stepCount = _listSteps.Count; try { for (int i = 0; i < stepCount; i++) { BuildStep buildStep = _listSteps[i]; if (buildStep == null || buildStep.Enabled == false) { continue; } bool executeIt = context.StepStarts(buildStep); if (executeIt == false) { continue; } if (_listMessages != null && _listMessages.Count == stepCount) { if (logger != null) { logger.WriteLine(_listMessages[i], BuildLoggerLevel.Info); } } if (!buildStep.Execute()) { //if (logger != null) //{ // logger.WriteLine( // "An error occurred in the multi-step = " + i.ToString(), // BuildLoggerLevel.Error); //} context.StepError(buildStep); if (!buildStep.ContinueOnError) { buildResult = false; break; } } context.StepEnds(buildStep); if (i != (stepCount - 1) && logger != null) { logger.WriteLine(); } } } catch (Exception ex) { if (logger != null) { logger.WriteLine(ex, BuildLoggerLevel.Error); } buildResult = false; } return(buildResult); }
/// <summary> /// /// </summary> /// <param name="settings"></param> /// <param name="logger"></param> /// <seealso cref="BuildContext.IsInitialized"/> /// <seealso cref="BuildContext.Uninitialize()"/> public virtual void Initialize(BuildSettings settings, BuildLogger logger) { if (_isInitialized) { return; } _processedTopics = 0; BuildExceptions.NotNull(logger, "logger"); BuildExceptions.NotNull(settings, "settings"); Debug.Assert(_listGroups != null && _listGroups.Count != 0); Debug.Assert(_groupContexts != null && _groupContexts.Count != 0); _logger = logger; _settings = settings; _isBuildSuccess = false; _sandcastleDir = String.Empty; _sandcastleToolsDir = String.Empty; // Get the Sandcastle installed directory and tools path information.... string sandPath = _settings.SandcastleDirectory; if (!String.IsNullOrEmpty(sandPath)) { sandPath = Environment.ExpandEnvironmentVariables(sandPath); if (!Directory.Exists(sandPath)) { sandPath = Environment.ExpandEnvironmentVariables("%DXROOT%"); } } else { sandPath = Environment.ExpandEnvironmentVariables("%DXROOT%"); } if (!Directory.Exists(sandPath)) { _logger.WriteLine( "The sandcastle installed directory could not be found.", BuildLoggerLevel.Error); return; } else { _sandcastleDir = sandPath; _sandcastleToolsDir = Path.Combine(sandPath, "ProductionTools"); if (!Directory.Exists(_sandcastleToolsDir)) { _sandcastleDir = String.Empty; _sandcastleToolsDir = String.Empty; _logger.WriteLine( "The sandcastle installed directory found, but ProductionTools sub-directory is not found.", BuildLoggerLevel.Error); return; } _isInitialized = this.ValidateSandcastle(); } _tocContext.Initialize(this); if (_groupContexts != null && _groupContexts.Count != 0) { for (int i = 0; i < _groupContexts.Count; i++) { _groupContexts[i].Initialize(this); } } _isInitialized = true; }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <returns></returns> protected virtual bool OnDefaultExecute(BuildContext context) { bool mainResult = false; BuildLogger logger = context.Logger; try { this.OnStartTiming(); if (logger != null) { if (!String.IsNullOrEmpty(_title)) { logger.WriteLine(_title, BuildLoggerLevel.Started); } if (!String.IsNullOrEmpty(_message)) { logger.WriteLine(_message, BuildLoggerLevel.Info); } } mainResult = this.OnExecute(_context); this.OnStopTiming(); if (mainResult) { if (logger != null && _logTimeSpan) { string timeInfo = String.Empty; if (this.IsMultiSteps) { logger.WriteLine(); timeInfo = String.Format("All tasks successfully completed in: {0}", this.TimeElapsed.ToString()); } else { timeInfo = String.Format("Successfully completed in: {0}", this.TimeElapsed.ToString()); } logger.WriteLine(timeInfo, BuildLoggerLevel.Info); } } else { if (!this.IsMultiSteps) { if (logger != null) { logger.WriteLine(this.GetType().Name + ": An error occurred in this build step.", BuildLoggerLevel.Error); } } } } finally { if (logger != null && !String.IsNullOrEmpty(_title)) { logger.WriteLine(_title, BuildLoggerLevel.Ended); } } return(mainResult); }