/// <summary> /// Checks a level for the action. /// </summary> /// <param name="context">The context.</param> /// <param name="levelToCheck">The level to check.</param> /// <param name="actionName">Name of the action.</param> /// <param name="clearProperty">The clear property.</param> /// <returns> /// <c>true</c> if the level was matched; <c>false</c> otherwise. /// </returns> private static bool CheckLevelForAction(ActionRequestContext context, ActionHandlerTargets levelToCheck, string actionName, Action clearProperty) { context.Level = levelToCheck; var reportLevel = Manager.Current.ReportLevels.FirstOrDefault(level => level.Target == levelToCheck) ?? new ReportLevel(); if (actionName == null) { RetrieveDefaultAction(context, reportLevel); return(true); } var action = reportLevel .Reports .FirstOrDefault( rep => string.Equals(rep.ActionName, actionName, StringComparison.InvariantCultureIgnoreCase)); if (action != null) { context.Report = actionName; clearProperty(); return(true); } return(false); }
/// <summary> /// Retrieves the default action for a level. /// </summary> /// <param name="context">The context.</param> /// <param name="level">The level.</param> private static void RetrieveDefaultAction(ActionRequestContext context, ReportLevel level) { var defaultAction = level.Reports.FirstOrDefault(rep => rep.IsDefault); if (defaultAction != null) { Logger.Debug("Action is default " + level.Target + " level report"); context.Report = defaultAction.ActionName; } else { Logger.Warn("Unable to find default action for " + level.Target + " level!"); context.Report = "!!unknownAction!!"; } }
/// <summary> /// Generates the context for an action. /// </summary> /// <param name="server">The server.</param> /// <param name="project">The project.</param> /// <param name="build">The build.</param> /// <param name="report">The report.</param> /// <returns>The <see cref="ActionRequestContext"/> for the action.</returns> public ActionRequestContext GenerateContext(string server, string project, string build, string report) { Logger.Debug("Generating request context"); // Set the properties to what is received first var context = new ActionRequestContext { Server = string.IsNullOrWhiteSpace(server) ? null : server, Project = string.IsNullOrWhiteSpace(project) ? null : project, Build = string.IsNullOrWhiteSpace(build) ? null : build, Report = string.IsNullOrWhiteSpace(report) ? null : report }; // If everything is set, we are golden - just return the instance if ((context.Server != null) && (context.Project != null) && (context.Build != null) && (context.Report != null)) { Logger.Debug("Action is a build level report"); context.Level = ActionHandlerTargets.Build; return(context); } // If nothing is set, find the default root-level action and return that if (!CheckLevelForAction(context, ActionHandlerTargets.Root, context.Server, () => context.Server = null)) { if (!CheckLevelForAction(context, ActionHandlerTargets.Server, context.Project, () => context.Project = null)) { if (!CheckLevelForAction(context, ActionHandlerTargets.Project, context.Build, () => context.Build = null)) { CheckLevelForAction(context, ActionHandlerTargets.Build, null, () => { }); } } } return(context); }
/// <summary> /// Checks a level for the action. /// </summary> /// <param name="context">The context.</param> /// <param name="levelToCheck">The level to check.</param> /// <param name="actionName">Name of the action.</param> /// <param name="clearProperty">The clear property.</param> /// <returns> /// <c>true</c> if the level was matched; <c>false</c> otherwise. /// </returns> private static bool CheckLevelForAction(ActionRequestContext context, ActionHandlerTargets levelToCheck, string actionName, Action clearProperty) { context.Level = levelToCheck; var reportLevel = Manager.Current.ReportLevels.FirstOrDefault(level => level.Target == levelToCheck) ?? new ReportLevel(); if (actionName == null) { RetrieveDefaultAction(context, reportLevel); return true; } var action = reportLevel .Reports .FirstOrDefault( rep => string.Equals(rep.ActionName, actionName, StringComparison.InvariantCultureIgnoreCase)); if (action != null) { context.Report = actionName; clearProperty(); return true; } return false; }
/// <summary> /// Generates the context for an action. /// </summary> /// <param name="server">The server.</param> /// <param name="project">The project.</param> /// <param name="build">The build.</param> /// <param name="report">The report.</param> /// <returns>The <see cref="ActionRequestContext"/> for the action.</returns> public ActionRequestContext GenerateContext(string server, string project, string build, string report) { Logger.Debug("Generating request context"); // Set the properties to what is received first var context = new ActionRequestContext { Server = string.IsNullOrWhiteSpace(server) ? null : server, Project = string.IsNullOrWhiteSpace(project) ? null : project, Build = string.IsNullOrWhiteSpace(build) ? null : build, Report = string.IsNullOrWhiteSpace(report) ? null : report }; // If everything is set, we are golden - just return the instance if ((context.Server != null) && (context.Project != null) && (context.Build != null) && (context.Report != null)) { Logger.Debug("Action is a build level report"); context.Level = ActionHandlerTargets.Build; return context; } // If nothing is set, find the default root-level action and return that if (!CheckLevelForAction(context, ActionHandlerTargets.Root, context.Server, () => context.Server = null)) { if (!CheckLevelForAction(context, ActionHandlerTargets.Server, context.Project, () => context.Project = null)) { if (!CheckLevelForAction(context, ActionHandlerTargets.Project, context.Build, () => context.Build = null)) { CheckLevelForAction(context, ActionHandlerTargets.Build, null, () => { }); } } } return context; }
/// <summary> /// Generates the result from this handler. /// </summary> /// <param name="context">The context.</param> /// <returns>The result.</returns> public abstract ActionResult Generate(ActionRequestContext context);