示例#1
0
        protected static string FormatOperationInfo(PSBaseOperationInfo operationInfo, int indentFactor)
        {
            string formattedString        = string.Empty;
            int    indentFactorForDetails = indentFactor < int.MaxValue ? indentFactor + 1 : indentFactor;

            if (operationInfo != null)
            {
                StringBuilder sb = new StringBuilder();

                var rolloutOperationInfo = operationInfo as PSRolloutOperationInfo;
                if (rolloutOperationInfo != null)
                {
                    sb.AppendFormatWithLeftIndentAndNewLine(indentFactorForDetails, $"Retry Attempt: {rolloutOperationInfo.RetryAttempt}");
                    sb.AppendFormatWithLeftIndentAndNewLine(indentFactorForDetails, $"Skip Succeeded: {rolloutOperationInfo.SkipSucceededOnRetry}");
                }

                var stepOperationInfo = operationInfo as PSStepOperationInfo;
                if (stepOperationInfo != null)
                {
                    sb.AppendFormatWithLeftIndentAndNewLineIfNotNull(indentFactorForDetails, "DeploymentName", stepOperationInfo.DeploymentName);
                    sb.AppendFormatWithLeftIndentAndNewLineIfNotNull(indentFactorForDetails, "CorrelationId", stepOperationInfo.CorrelationId);
                }

                if (operationInfo?.StartTime != null && operationInfo.StartTime.HasValue)
                {
                    sb.AppendFormatWithLeftIndentAndNewLine(indentFactorForDetails, $"Start Time: {operationInfo.StartTime.Value.ToLocalTimeForUserDisplay()}");
                }

                if (operationInfo?.EndTime != null && operationInfo.EndTime.HasValue)
                {
                    sb.AppendFormatWithLeftIndentAndNewLine(indentFactorForDetails, $"End Time: {operationInfo.EndTime.Value.ToLocalTimeForUserDisplay()}");

                    if (operationInfo?.StartTime != null && operationInfo.StartTime.HasValue)
                    {
                        sb.AppendFormatWithLeftIndentAndNewLine(
                            indentFactorForDetails,
                            "Total Duration: {0}",
                            (operationInfo.EndTime.Value - operationInfo.StartTime.Value).ToDisplayFormat());
                    }
                }

                sb.InvariantAppend(RolloutCmdletBase.FormatErrorInfo(operationInfo, indentFactorForDetails));

                formattedString = sb.ToString();
                if (!StringUtilities.IsNullOrWhiteSpace(formattedString))
                {
                    sb.Clear();
                    sb.AppendFormatWithLeftIndentAndNewLine(indentFactor, "Operation Info:");
                    formattedString = string.Concat(sb.ToString(), formattedString);
                }
            }

            return(formattedString);
        }
示例#2
0
        private static string FormatErrorInfo(PSBaseOperationInfo operationInfo, int indentFactor)
        {
            StringBuilder sb = new StringBuilder();

            if (operationInfo != null && operationInfo.Error != null)
            {
                sb.AppendFormatWithLeftIndentAndNewLineIfNotNull(
                    indentFactor,
                    "Error",
                    RolloutCmdletBase.AppendError(operationInfo.Error, indentFactor + 1));
                sb.AppendFormatWithLeftIndentAndNewLineIfNotNull(
                    indentFactor + 1,
                    "Details",
                    operationInfo.Error?.Details?.ToList().Select(e =>
                                                                  RolloutCmdletBase.AppendError(e, indentFactor + 2)).ToCommaDelimitedString());
            }

            return(sb.ToString());
        }