Пример #1
0
        /// <summary>
        /// Converts the results of this instance into a single
        /// string using the supplied delimeter.
        /// </summary>
        /// <param name="itemFormat">The format for each execution step.
        /// Use '{Message}' in the format string to locate the message.
        /// Use '{StepType}' in the format string to locate the step type name.
        /// Do not include any other format specifications
        /// (IE. '{1}', '{2}', etc...)</param>
        /// <param name="delimeter">A string to place between each item.</param>
        /// <returns>A string containing all execution steps
        /// in this instance.</returns>
        /// <example>
        /// An example of a call to a business component from a web page that
        /// contains a Label control called 'messageLabel'.
        /// <code>
        /// ExecutionResults result = SomeClass.SomeMethod(arg1);
        ///	messageLabel.Text = result.ToString(
        ///		"{StepType}: {Message}", "&lt;BR&gt;");
        /// </code>
        /// <code>
        /// ExecutionResults result = new ExecutionResults();
        /// SomeClass.SomeMethod(arg1, result);
        ///	messageLabel.Text = result.ToString(
        ///		"{StepType}: {Message}", "&lt;BR&gt;");
        /// </code>
        /// </example>
        public string ToString(string itemFormat, string delimeter)
        {
            if (itemFormat == null)
            {
                itemFormat = "{StepType} : {Message}";
            }
            if (delimeter == null)
            {
                delimeter = string.Empty;
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this.messages_.Count; i++)
            {
                ExecutionStep item         = this.messages_[i];
                string        stepTypeName = Enum.GetName(typeof(ExecutionStepType), item.StepType);
                sb.Append(itemFormat
                          .Replace("{StepType}", stepTypeName)
                          .Replace("{Message}", item.Message));
                if (delimeter.Length > 0)
                {
                    sb.Append(delimeter);
                }
            }
            if (delimeter.Length > 0 && sb.Length > delimeter.Length)
            {                   //remove last delimeter
                sb.Remove(sb.Length - delimeter.Length, delimeter.Length);
            }
            return(sb.ToString());
        }
Пример #2
0
        /// <summary>
        /// Combines the results of another ExecutionResults into this instance.
        /// </summary>
        /// <param name="results">The results to be combined.</param>
        public void Combine(ExecutionResults results)
        {
            if (results == null)
            {
                throw new ArgumentNullException("results");
            }
            if (results == this)
            {
                return;
            }

            for (int i = 0; i < results.messages_.Count; i++)
            {
                ExecutionStep step = results.messages_[i];
                this.messages_.Add(step);
                if (step.StepType == ExecutionStepType.Error)
                {
                    this.success_ = false;
                }
            }
        }