Example #1
0
        /// <summary>
        /// This method serializes a variable list item into a string representation
        /// </summary>
        /// <param name="dataObject"></param>
        /// <param name="padding"></param>
        /// <returns></returns>
        private string MarshalDataObject(dynamic dataObject, int padding)
        {
            // Localize the type of the data
            Type type = (dataObject as object).GetType();
            // Define our line start
            string linePrefix = ("\n" + new string('\t', padding));

            // Check for a nested Runner Message
            if (type.Equals(this.GetType()))
            {
                return(((Message)dataObject)
                       .ToString(padding + 1)
                       .Replace("\n", linePrefix));
            }
            // Check for a system exception
            if (type.Equals(typeof(System.Exception)))
            {
                return(Message.New((System.Exception)dataObject)
                       .ToString(padding + 1)
                       .Replace("\n", linePrefix));
            }
            // Check for a time span
            if (type.Equals(typeof(TimeSpan)))
            {
                return($"{((TimeSpan) dataObject):g}");
            }
            // If we get here, convert it using the core serializer
            return(Core.Convert
                   .ToString(dataObject).Replace("\n", linePrefix));
        }
Example #2
0
 /// <summary>
 /// This method instantiates a new message from a system exception
 /// </summary>
 /// <param name="exception"></param>
 public Message(System.Exception exception)
 {
     // Check for an inner exception and add it to the data objects
     if (exception.InnerException != null)
     {
         WithDataObject($"InnerException[{exception.InnerException.GetType().Name}]",
                        Message.New(exception));
     }
     // Set the source into the data objects
     WithDataObject("Source", exception.Source ?? "Unavailable");
     // Set the target site into the data objects
     WithDataObject("TargetSite", exception.TargetSite?.Name ?? "Unavailable");
     // Split and iterate over the stack trace
     exception.StackTrace?.Split("\n", StringSplitOptions.TrimEntries)
     .ToList().ForEach(s => WithDataObject(s, "stack-trace-list-item"));
     // Reset the exception flag into the instance
     Exception = true;
 }