/// <summary> /// Execute all plug-ins that need to execute in the given build step that have the given execution /// behavior. /// </summary> /// <param name="behavior">The execution behavior</param> /// <returns>True if at least one plug-in was executed or false if no plug-ins were executed.</returns> /// <remarks>Plug-ins will execute based on their execution priority. Those with a higher priority value /// will execute before those with a lower value. Plug-ins with identical priority values may execute /// in any order within their group.</remarks> private bool ExecutePlugIns(ExecutionBehaviors behavior) { List <IPlugIn> executeList; ExecutionContext context; BuildStep step; int numberExecuted = 0; if (loadedPlugIns == null) { return(false); } step = progressArgs.BuildStep; // Find plug-ins that need to be executed executeList = loadedPlugIns.Values.Where(p => p.ExecutionPoints.RunsAt(step, behavior)).ToList(); if (executeList.Count == 0) { return(false); } // Sort by execution priority in descending order executeList.Sort((x, y) => y.ExecutionPoints.PriorityFor(step, behavior) - x.ExecutionPoints.PriorityFor(step, behavior)); context = new ExecutionContext(step, behavior); foreach (IPlugIn plugIn in executeList) { var metadata = (HelpFileBuilderPlugInExportAttribute)plugIn.GetType().GetCustomAttributes( typeof(HelpFileBuilderPlugInExportAttribute), false).First(); try { // Wrap plug-in output in an element so that it can be formatted differently swLog.WriteLine("<plugIn name=\"{0}\" behavior=\"{1}\" priority=\"{2}\">", metadata.Id, behavior, plugIn.ExecutionPoints.PriorityFor(step, behavior)); context.Executed = true; plugIn.Execute(context); swLog.Write("</plugIn>"); } catch (Exception ex) { swLog.WriteLine("</plugIn>"); throw new BuilderException("BE0029", "Unexpected error while executing plug-in '" + metadata.Id + "': " + ex.ToString(), ex); } if (context.Executed) { numberExecuted++; } } return(numberExecuted != 0); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="buildStep">The step in which the plug-in should run.</param> /// <param name="behavior">The behavior of the plug-in when it is ran.</param> /// <exception cref="ArgumentException">This is thrown if an attempt is made to set the Before or After /// behavior with the InsteadOf behavior. It is also thrown for invalid combinations of build step and /// behavior, i.e. Initializing with Before or InsteadOf. See the help file for a full list.</exception> /// <overloads>There are two overloads for the constructor.</overloads> public ExecutionPoint(BuildStep buildStep, ExecutionBehaviors behavior) { bool isValid = true; this.BuildStep = buildStep; this.Behavior = behavior; this.Priority = DefaultPriority; // Don't allow Before or After if InsteadOf is specified if((behavior & ExecutionBehaviors.InsteadOf) != 0 && (behavior & ExecutionBehaviors.BeforeAndAfter) != 0) throw new ArgumentException("Before and/or After cannot be specified with InsteadOf", "behavior"); if(buildStep == BuildStep.None) throw new ArgumentException("None is not a valid build step for a plug-in", "buildStep"); // This was getting messy so it's broken up to be more readable // Before and InsteadOf can't be used with Initializing, Canceled, or Failed. if((behavior & (ExecutionBehaviors.Before | ExecutionBehaviors.InsteadOf)) != 0 && (buildStep == BuildStep.Initializing || buildStep > BuildStep.Completed)) isValid = false; // InsteadOf cannot be used with or Completed, Canceled, or Failed. if(behavior == ExecutionBehaviors.InsteadOf && buildStep >= BuildStep.Completed) isValid = false; if(!isValid) throw new ArgumentException("The specified combination of build step and execution behavior " + "is not valid. See the help file for details.", "behavior"); }
/// <summary> /// This is used to obtain the execution priority for a plug-in in the given build step and behavior /// </summary> /// <param name="executionPoints">An enumerable list of execution points to search</param> /// <param name="step">The build step</param> /// <param name="behavior">The behavior</param> /// <returns>The execution priority is used to determine the order in which the plug-ins will be /// executed. Those with a higher priority value will be executed before those with a lower value. /// Those with an identical priority may be executed in any order within their group.</returns> public static int PriorityFor(this IEnumerable <ExecutionPoint> executionPoints, BuildStep step, ExecutionBehaviors behavior) { var point = executionPoints.FirstOrDefault(p => p.BuildStep == step && (p.Behavior & behavior) != 0); if (point != null) { return(point.Priority); } return(ExecutionPoint.DefaultPriority); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="buildStep">The current build step.</param> /// <param name="behavior">The behavior of the plug-in for the current context.</param> /// <exception cref="ArgumentException">This is thrown if an attempt is made to specify more than one /// behavior type.</exception> internal ExecutionContext(BuildStep buildStep, ExecutionBehaviors behavior) { this.BuildStep = buildStep; this.Behavior = behavior; this.Executed = true; // Don't allow more than one behavior type if(behavior != ExecutionBehaviors.Before && behavior != ExecutionBehaviors.After && behavior != ExecutionBehaviors.InsteadOf) throw new ArgumentException("Combinations of behavior are not allowed for the execution " + "context", "behavior"); }
/// <summary> /// This is used to obtain the execution priority for a plug-in /// in the given build step and behavior. /// </summary> /// <param name="step">The build step</param> /// <param name="behavior">The behavior</param> /// <returns>The execution priority is used to determine the order in /// which the plug-ins will be executed. Those with a higher priority /// value will be executed before those with a lower value. Those with /// an identical priority may be executed in any order within their /// group.</returns> public int PriorityFor(BuildStep step, ExecutionBehaviors behavior) { foreach (ExecutionPoint p in this) { if (p.BuildStep == step && (p.Behavior & behavior) != 0) { return(p.Priority); } } return(ExecutionPoint.DefaultPriority); }
/// <summary> /// This is used to determine if the collection contains an entry for /// the specified build step and behavior. /// </summary> /// <param name="step">The build step</param> /// <param name="behavior">The behavior</param> /// <returns>True if the collection contains an entry for the specified /// build step and behavior or false if it does not.</returns> public bool RunsAt(BuildStep step, ExecutionBehaviors behavior) { foreach (ExecutionPoint p in this) { if (p.BuildStep == step && (p.Behavior & behavior) != 0) { return(true); } } return(false); }
/// <summary> /// Constructor /// </summary> /// <param name="plugInBuildStep">The current build step.</param> /// <param name="plugInBehavior">The behavior of the plug-in for the /// current context.</param> /// <exception cref="ArgumentException">This is thrown if an attempt /// is made to specify more than one behavior type.</exception> internal ExecutionContext(BuildStep plugInBuildStep, ExecutionBehaviors plugInBehavior) { buildStep = plugInBuildStep; behavior = plugInBehavior; executed = true; // Don't allow more than one behavior type if(behavior != ExecutionBehaviors.Before && behavior != ExecutionBehaviors.After && behavior != ExecutionBehaviors.InsteadOf) throw new ArgumentException("Combinations of behavior are " + "not allowed for the execution context", "plugInBehavior"); }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="buildStep">The current build step.</param> /// <param name="behavior">The behavior of the plug-in for the current context.</param> /// <exception cref="ArgumentException">This is thrown if an attempt is made to specify more than one /// behavior type.</exception> internal ExecutionContext(BuildStep buildStep, ExecutionBehaviors behavior) { this.BuildStep = buildStep; this.Behavior = behavior; this.Executed = true; // Don't allow more than one behavior type if (behavior != ExecutionBehaviors.Before && behavior != ExecutionBehaviors.After && behavior != ExecutionBehaviors.InsteadOf) { throw new ArgumentException("Combinations of behavior are not allowed for the execution " + "context", "behavior"); } }
//===================================================================== /// <summary> /// Constructor /// </summary> /// <param name="plugInBuildStep">The step in which the plug-in /// should run.</param> /// <param name="plugInBehavior">The behavior of the plug-in when it /// is ran.</param> /// <exception cref="ArgumentException">This is thrown if an attempt /// is made to set the Before or After behavior with the InsteadOf /// behavior. It is also thrown for invalid combinations of build /// step and behavior, i.e. Initializing with Before or InsteadOf. /// See the help file for a full list.</exception> /// <overloads>There are two overloads for the constructor.</overloads> public ExecutionPoint(BuildStep plugInBuildStep, ExecutionBehaviors plugInBehavior) { bool isValid = true; buildStep = plugInBuildStep; behavior = plugInBehavior; priority = DefaultPriority; // Don't allow Before or After if InsteadOf is specified if ((behavior & ExecutionBehaviors.InsteadOf) != 0 && (behavior & ExecutionBehaviors.BeforeAndAfter) != 0) { throw new ArgumentException("Before and/or After cannot be " + "specified with InsteadOf", "plugInBehavior"); } if (buildStep == BuildStep.None) { throw new ArgumentException("None is not a valid build " + "step for a plug-in", "plugInBuildStep"); } // This was getting messy so it's broken up to be more readable // Before and InsteadOf can't be used with Initializing, // Canceled, or Failed. if ((behavior & (ExecutionBehaviors.Before | ExecutionBehaviors.InsteadOf)) != 0 && (buildStep == BuildStep.Initializing || buildStep > BuildStep.Completed)) { isValid = false; } // InsteadOf cannot be used with FindingTools // or Completed. if (behavior == ExecutionBehaviors.InsteadOf && ( buildStep == BuildStep.FindingTools || buildStep == BuildStep.Completed)) { isValid = false; } if (!isValid) { throw new ArgumentException("The specified combination of " + "build step and execution behavior is not valid. See " + "the help file for details.", "plugInBehavior"); } }
/// <summary> /// Constructor /// </summary> /// <param name="plugInBuildStep">The current build step.</param> /// <param name="plugInBehavior">The behavior of the plug-in for the /// current context.</param> /// <exception cref="ArgumentException">This is thrown if an attempt /// is made to specify more than one behavior type.</exception> internal ExecutionContext(BuildStep plugInBuildStep, ExecutionBehaviors plugInBehavior) { buildStep = plugInBuildStep; behavior = plugInBehavior; executed = true; // Don't allow more than one behavior type if (behavior != ExecutionBehaviors.Before && behavior != ExecutionBehaviors.After && behavior != ExecutionBehaviors.InsteadOf) { throw new ArgumentException("Combinations of behavior are " + "not allowed for the execution context", "plugInBehavior"); } }
/// <summary> /// Execute all plug-ins that need to execute in the given build step /// that have the given execution behavior. /// </summary> /// <param name="behavior">The execution behavior</param> /// <returns>True if at least one plug-in was executed or false if /// no plug-ins were executed.</returns> /// <remarks>Plug-ins will execute based on their execution priority. /// Those with a higher priority value will execute before those with /// a lower value. Plug-ins with identical priority values may execute /// in any order within their group.</remarks> private bool ExecutePlugIns(ExecutionBehaviors behavior) { List <IPlugIn> executeList; ExecutionContext context; BuildStep step; int numberExecuted = 0; if (loadedPlugIns == null) { return(false); } executeList = new List <IPlugIn>(); step = progressArgs.BuildStep; // Find plug-ins that need to be executed foreach (IPlugIn plugIn in loadedPlugIns.Values) { if (plugIn.ExecutionPoints.RunsAt(step, behavior)) { executeList.Add(plugIn); } } if (executeList.Count == 0) { return(false); } // Sort by execution priority in descending order executeList.Sort( delegate(IPlugIn x, IPlugIn y) { return(y.ExecutionPoints.PriorityFor(step, behavior) - x.ExecutionPoints.PriorityFor(step, behavior)); }); context = new ExecutionContext(step, behavior); foreach (IPlugIn plugIn in executeList) { try { // Wrap plug-in output in an element so that it // can be formatted differently. swLog.WriteLine("<plugIn name=\"{0}\" " + "behavior=\"{1}\" priority=\"{2}\">", plugIn.Name, behavior, plugIn.ExecutionPoints.PriorityFor(step, behavior)); context.Executed = true; plugIn.Execute(context); swLog.Write("</plugIn>"); } catch (Exception ex) { swLog.WriteLine("</plugIn>"); throw new BuilderException("BE0029", "Unexpected " + "error while executing plug-in '" + plugIn.Name + "': " + ex.ToString(), ex); } if (context.Executed) { numberExecuted++; } } return(numberExecuted != 0); }
/// <summary> /// This is used to obtain the execution priority for a plug-in in the given build step and behavior /// </summary> /// <param name="executionPoints">An enumerable list of execution points to search</param> /// <param name="step">The build step</param> /// <param name="behavior">The behavior</param> /// <returns>The execution priority is used to determine the order in which the plug-ins will be /// executed. Those with a higher priority value will be executed before those with a lower value. /// Those with an identical priority may be executed in any order within their group.</returns> public static int PriorityFor(this IEnumerable<ExecutionPoint> executionPoints, BuildStep step, ExecutionBehaviors behavior) { var point = executionPoints.FirstOrDefault(p => p.BuildStep == step && (p.Behavior & behavior) != 0); if(point != null) return point.Priority; return ExecutionPoint.DefaultPriority; }
//===================================================================== /// <summary> /// This is used to determine if the enumerable list of execution points contains an entry for the /// specified build step and behavior. /// </summary> /// <param name="executionPoints">An enumerable list of execution points to check</param> /// <param name="step">The build step</param> /// <param name="behavior">The behavior</param> /// <returns>True if the enumerable list of execution points contains an entry for the specified build /// step and behavior or false if it does not.</returns> public static bool RunsAt(this IEnumerable<ExecutionPoint> executionPoints, BuildStep step, ExecutionBehaviors behavior) { return executionPoints.Any(p => p.BuildStep == step && (p.Behavior & behavior) != 0); }
/// <summary> /// This constructor is used to set a specific execution priority. /// </summary> /// <param name="buildStep">The step in which the plug-in should run.</param> /// <param name="behavior">The behavior of the plug-in when it is ran.</param> /// <param name="priority">The execution priority for the plug-in.</param> public ExecutionPoint(BuildStep buildStep, ExecutionBehaviors behavior, int priority) : this(buildStep, behavior) { this.Priority = priority; }
/// <summary> /// This constructor is used to set a specific execution priority. /// </summary> /// <param name="plugInBuildStep">The step in which the plug-in /// should run.</param> /// <param name="plugInBehavior">The behavior of the plug-in when it /// is ran.</param> /// <param name="plugInPriority">The execution priority for the /// plug-in.</param> public ExecutionPoint(BuildStep plugInBuildStep, ExecutionBehaviors plugInBehavior, int plugInPriority) : this(plugInBuildStep, plugInBehavior) { priority = plugInPriority; }
/// <summary> /// Execute all plug-ins that need to execute in the given build step /// that have the given execution behavior. /// </summary> /// <param name="behavior">The execution behavior</param> /// <returns>True if at least one plug-in was executed or false if /// no plug-ins were executed.</returns> /// <remarks>Plug-ins will execute based on their execution priority. /// Those with a higher priority value will execute before those with /// a lower value. Plug-ins with identical priority values may execute /// in any order within their group.</remarks> private bool ExecutePlugIns(ExecutionBehaviors behavior) { List<IPlugIn> executeList; ExecutionContext context; BuildStep step; int numberExecuted = 0; if(loadedPlugIns == null) return false; executeList = new List<IPlugIn>(); step = progressArgs.BuildStep; // Find plug-ins that need to be executed foreach(IPlugIn plugIn in loadedPlugIns.Values) if(plugIn.ExecutionPoints.RunsAt(step, behavior)) executeList.Add(plugIn); if(executeList.Count == 0) return false; // Sort by execution priority in descending order executeList.Sort( delegate(IPlugIn x, IPlugIn y) { return y.ExecutionPoints.PriorityFor(step, behavior) - x.ExecutionPoints.PriorityFor(step, behavior); }); context = new ExecutionContext(step, behavior); foreach(IPlugIn plugIn in executeList) { try { // Wrap plug-in output in an element so that it // can be formatted differently. swLog.WriteLine("<plugIn name=\"{0}\" " + "behavior=\"{1}\" priority=\"{2}\">", plugIn.Name, behavior, plugIn.ExecutionPoints.PriorityFor(step, behavior)); context.Executed = true; plugIn.Execute(context); swLog.Write("</plugIn>"); } catch(Exception ex) { swLog.WriteLine("</plugIn>"); throw new BuilderException("BE0029", "Unexpected " + "error while executing plug-in '" + plugIn.Name + "': " + ex.ToString(), ex); } if(context.Executed) numberExecuted++; } return (numberExecuted != 0); }
/// <summary> /// Execute all plug-ins that need to execute in the given build step that have the given execution /// behavior. /// </summary> /// <param name="behavior">The execution behavior</param> /// <returns>True if at least one plug-in was executed or false if no plug-ins were executed.</returns> /// <remarks>Plug-ins will execute based on their execution priority. Those with a higher priority value /// will execute before those with a lower value. Plug-ins with identical priority values may execute /// in any order within their group.</remarks> private bool ExecutePlugIns(ExecutionBehaviors behavior) { List<IPlugIn> executeList; ExecutionContext context; BuildStep step; int numberExecuted = 0; if(loadedPlugIns == null) return false; step = progressArgs.BuildStep; // Find plug-ins that need to be executed executeList = loadedPlugIns.Values.Where(p => p.ExecutionPoints.RunsAt(step, behavior)).ToList(); if(executeList.Count == 0) return false; // Sort by execution priority in descending order executeList.Sort((x, y) => y.ExecutionPoints.PriorityFor(step, behavior) - x.ExecutionPoints.PriorityFor(step, behavior)); context = new ExecutionContext(step, behavior); foreach(IPlugIn plugIn in executeList) { var metadata = (HelpFileBuilderPlugInExportAttribute)plugIn.GetType().GetCustomAttributes( typeof(HelpFileBuilderPlugInExportAttribute), false).First(); try { // Wrap plug-in output in an element so that it can be formatted differently swLog.WriteLine("<plugIn name=\"{0}\" behavior=\"{1}\" priority=\"{2}\">", metadata.Id, behavior, plugIn.ExecutionPoints.PriorityFor(step, behavior)); context.Executed = true; plugIn.Execute(context); swLog.Write("</plugIn>"); } catch(Exception ex) { swLog.WriteLine("</plugIn>"); throw new BuilderException("BE0029", "Unexpected error while executing plug-in '" + metadata.Id + "': " + ex.ToString(), ex); } if(context.Executed) numberExecuted++; } return (numberExecuted != 0); }
//===================================================================== /// <summary> /// This is used to determine if the enumerable list of execution points contains an entry for the /// specified build step and behavior. /// </summary> /// <param name="executionPoints">An enumerable list of execution points to check</param> /// <param name="step">The build step</param> /// <param name="behavior">The behavior</param> /// <returns>True if the enumerable list of execution points contains an entry for the specified build /// step and behavior or false if it does not.</returns> public static bool RunsAt(this IEnumerable <ExecutionPoint> executionPoints, BuildStep step, ExecutionBehaviors behavior) { return(executionPoints.Any(p => p.BuildStep == step && (p.Behavior & behavior) != 0)); }