public static string GetStepNameById(ActivityElement activityElementToProcess, string activityElementId) { var output = string.Empty; var parentActivityElement = activityElementToProcess; var childCheck = activityElementToProcess.Children.Where(c => c.Id.Equals(activityElementId)).FirstOrDefault(); if (childCheck == null) { foreach (var activityElement in activityElementToProcess.Children) { if (string.IsNullOrWhiteSpace(output)) { return(output); } else { output = GetStepNameById(activityElement, activityElementId); } } } else { output = parentActivityElement.Name; } return(output); }
void RenderToTeamCity(ActivityElement element, ILog log) { if (!IsPrintable(element)) { return; } var blockName = element.Status + ": " + element.Name; log.ServiceMessage("blockOpened", new { name = blockName }); foreach (var logEntry in element.LogElements) { var lines = logEntry.MessageText.Split('\n').Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(); foreach (var line in lines) { log.ServiceMessage("message", new { text = line, status = ConvertToTeamCityMessageStatus(logEntry.Category) }); } } foreach (var child in element.Children) { RenderToTeamCity(child, log); } log.ServiceMessage("blockClosed", new { name = blockName }); }
public void ToActivity() { var element = new ActivityElement { Name = "Resource.Action", AllowUnauthenticated = true, Default = true, Allow = new PermissionElement { Roles = "A", Users = "Alice" }, Deny = new PermissionElement { Roles = "B", Users = "Bob" } }; var expected = new Activity { Resource = "Resource", Action = "Action", AllowUnauthenticated = true, Default = true, Allow = new Permission { Roles = new List <string> { "A" }, Users = new List <string> { "Alice" } }, Deny = new Permission { Roles = new List <string> { "B" }, Users = new List <string> { "Bob" } }, }; var candidate = element.ToActivity(); Check(expected, candidate); }
bool IsPrintable(ActivityElement element) { if (element.Status == ActivityStatus.Pending || element.Status == ActivityStatus.Running) { return(false); } if (printed.Contains(element.Id)) { return(false); } printed.Add(element.Id); return(true); }
/// </summary> /// <param name="activityElementToProcess">The ActivityElement to gather info from.</param> /// <param name="tabIndex">Tab Index for spacing sub ActivityElements</param> /// <param name="statusesToCheck">Allotment to check for only specific Statuses</param> /// <returns>Formatted Message text from activity elements. </returns> public static string GetLogInfo(ActivityElement activityElementToProcess, int tabIndex) { var output = string.Empty; var tabCount = new string(' ', tabIndex * 5); output += activityElementToProcess.Name + ResourceStrings.Return; foreach (var activityLogElement in activityElementToProcess.LogElements) { output += (string.Format(ResourceStrings.LogPrinting, tabCount, activityLogElement.MessageText.Replace(ResourceStrings.Return, string.Format(ResourceStrings.LogPrinting, ResourceStrings.Return, tabCount)))) + ResourceStrings.Return; } foreach (var activityElement in activityElementToProcess.Children) { output += GetLogInfo(activityElement, tabIndex + 1); } return(output.TrimEnd()); }
/// <summary> /// Convert an <see cref="ActivityElement"/> into an <see cref="Activity"/>. /// </summary> /// <param name="element"></param> /// <returns></returns> public static Activity ToActivity(this ActivityElement element) { var parts = element.Name.Split('.'); var resource = string.IsNullOrEmpty(element.Resource) ? parts[0] : element.Resource; var action = string.IsNullOrEmpty(element.Action) ? (parts.Length > 1 ? parts[1] : string.Empty) : element.Action; var activity = new Activity { Resource = resource, Action = action, Default = element.Default, AllowUnauthenticated = element.AllowUnauthenticated, Allow = element.Allow.ToPermission(), Deny = element.Deny.ToPermission() }; return(activity); }
void RenderToVSTS(ActivityElement element, ICommandOutputProvider commandOutputProvider, string indent) { if (!IsPrintable(element)) { return; } commandOutputProvider.Information("{Indent:l} {Status:l}: {Name:l}", indent, element.Status, element.Name); foreach (var logEntry in element.LogElements) { commandOutputProvider.Information("{Category,-8:l}{Indent:l} {Message:l}", logEntry.Category, logEntry.MessageText); } foreach (var child in element.Children) { RenderToVSTS(child, commandOutputProvider, indent + " "); } }
/// <summary> /// Gathers log info based on the list of the Statuses To Check /// </summary> /// <param name="activityElementToProcess">The ActivityElement to gather info from.</param> /// <param name="tabIndex">Tab Index for spacing sub ActivityElements</param> /// <param name="statusesToCheck">Allotment to check for only specific Statuses</param> /// <returns>Formatted Message text from activity elements. </returns> public static string GetLogInfo(ActivityElement activityElementToProcess, int tabIndex, List <ActivityStatus> statusesToCheck = null) { var output = string.Empty; var tabCount = new string(' ', tabIndex * 5); if (statusesToCheck.Contains(activityElementToProcess.Status)) { output += activityElementToProcess.Name + ResourceStrings.Return; foreach (var activityLogElement in activityElementToProcess.LogElements) { output += (string.Format(ResourceStrings.LogPrinting, tabCount, activityLogElement.MessageText.Replace(ResourceStrings.Return, string.Format(ResourceStrings.LogPrinting, ResourceStrings.Return, tabCount)))) + ResourceStrings.Return; } foreach (var activityElement in activityElementToProcess.Children) { output += GetLogInfo(activityElement, tabIndex + 1, statusesToCheck); } } return(output.TrimEnd()); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); sectionActive = new Section(); activeElem = new ActivityElement() { Animating = true }; activeElem.Caption = "Loading..."; activeElem.Animating = true; sectionActive.Add(activeElem); this.Root.Clear(); this.Root.Add(sectionActive); this.RefreshSource(); }
void RenderToVSTS(ActivityElement element, ILogger log, string indent) { if (!IsPrintable(element)) { return; } log.Information($"{indent} {element.Status}: {element.Name}"); foreach (var logEntry in element.LogElements) { log.Information($"{logEntry.Category,-8}{indent} {logEntry.MessageText}"); } foreach (var child in element.Children) { RenderToVSTS(child, log, indent + " "); } }
/// <summary> /// Gathers all failures/error messages. /// </summary> /// <param name="activityElementToProcess">The activity element to check for failures for.</param> /// <param name="tabIndex">Tab index used for indenting for levels of failure.</param> /// <returns>Returns the combine string of failures.</returns> private string GetFailures(ActivityElement activityElementToProcess, int tabIndex) { var output = string.Empty; var tabCount = new string(' ', tabIndex * 5); if (activityElementToProcess.Status == ActivityStatus.Failed || activityElementToProcess.Status == ActivityStatus.SuccessWithWarning || activityElementToProcess.Status == ActivityStatus.Running) { output += activityElementToProcess.Name + ResourceStrings.Return; foreach (var activityLogElement in activityElementToProcess.LogElements) { output += (string.Format(ResourceStrings.LogPrinting, tabCount, activityLogElement.MessageText.Replace(ResourceStrings.Return, string.Format(ResourceStrings.LogPrinting, ResourceStrings.Return, tabCount)))) + ResourceStrings.Return; } foreach (var activityElement in activityElementToProcess.Children) { output += GetFailures(activityElement, tabIndex + 1); } } return(output.TrimEnd()); }
void RenderToConsole(ActivityElement element, ICommandOutputProvider commandOutputProvider, string indent) { if (!IsPrintable(element)) { return; } if (element.Status == ActivityStatus.Success) { Console.ForegroundColor = ConsoleColor.Green; } else if (element.Status == ActivityStatus.SuccessWithWarning) { Console.ForegroundColor = ConsoleColor.Yellow; } else if (element.Status == ActivityStatus.Failed) { Console.ForegroundColor = ConsoleColor.Red; } Console.WriteLine("{0} {1}: {2}", indent, element.Status, element.Name); Console.ResetColor(); foreach (var logEntry in element.LogElements) { if (logEntry.Category == "Error" || logEntry.Category == "Fatal") { Console.ForegroundColor = ConsoleColor.Red; } else if (logEntry.Category == "Warning") { Console.ForegroundColor = ConsoleColor.Yellow; } Console.WriteLine("{0}{1,-8} {2}", indent, logEntry.Category, LineSplitter.Split(indent + new string(' ', 11), logEntry.MessageText)); Console.ResetColor(); } foreach (var child in element.Children) { RenderToConsole(child, commandOutputProvider, indent + " "); } }
void RenderToTeamCity(ActivityElement element, ICommandOutputProvider commandOutputProvider) { if (!IsPrintable(element)) { return; } var blockName = element.Status + ": " + element.Name; commandOutputProvider.ServiceMessage("blockOpened", new { name = blockName }); foreach (var logEntry in element.LogElements) { var lines = logEntry.MessageText.Split('\n').Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(); foreach (var line in lines) { // If a customer writes custom TeamCity service messages in their scripts we should output it as-is, // otherwise they won't be treated as a service message in TeamCity. // https://github.com/OctopusDeploy/OctopusCLI/issues/7 var isAlreadyTeamCityServiceMessage = line.StartsWith("##teamcity", StringComparison.OrdinalIgnoreCase); if (isAlreadyTeamCityServiceMessage) { commandOutputProvider.Information(line); } else { commandOutputProvider.ServiceMessage("message", new { text = line, status = ConvertToTeamCityMessageStatus(logEntry.Category) }); } } } foreach (var child in element.Children) { RenderToTeamCity(child, commandOutputProvider); } commandOutputProvider.ServiceMessage("blockClosed", new { name = blockName }); }
private IResult executeActivity(ActivityElement activityNode) { String currentId = activityNode.getAttribute(AttributeConstants.ID).getValue().ToString(); IActivity toExecute = this._stateProvider.getActivities()[currentId]; log.DebugFormat("executing activity [{0}]", toExecute.getId()); IResult currentResult = toExecute.run(); if (currentResult.getStatus().Equals(ResultStatus.SUCCESS)) { Int32 resultCount = 0; if (currentResult.getData() != null) { resultCount = currentResult.getData().Count; } log.DebugFormat("Execute Activity success >> {0}, Result Data count: {1}", currentId, resultCount); } else { log.DebugFormat("Execute Activity[{0}] error >> {1}", currentId, currentResult.getException().Message); } return(currentResult); }