bin/projects/dbatools/dbatools/dbaSystem/DbatoolsExceptionRecord.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
using System;
using System.Collections.Generic; namespace Sqlcollaborative.Dbatools.dbaSystem { /// <summary> /// Carrier class, designed to hold an arbitrary number of exceptions. Used for exporting to XML in nice per-incident packages. /// </summary> [Serializable] public class DbatoolsExceptionRecord { /// <summary> /// Runspace where shit happened. /// </summary> public Guid Runspace; /// <summary> /// When did things go bad? /// </summary> public DateTime Timestamp; /// <summary> /// Name of the function, where fail happened. /// </summary> public string FunctionName; /// <summary> /// The message the poor user was shown. /// </summary> public string Message; /// <summary> /// Displays the name of the exception, the make scanning exceptions easier. /// </summary> public string ExceptionType { get { try { if (Exceptions.Count > 0) { if ((Exceptions[0].GetException().GetType().FullName == "System.Exception") && (Exceptions[0].InnerException != null)) return Exceptions[0].InnerException.GetException().GetType().Name; return Exceptions[0].GetException().GetType().Name; } } catch { } return ""; } set { } } /// <summary> /// The target object of the first exception in the list, if any /// </summary> public object TargetObject { get { if (Exceptions.Count > 0) return Exceptions[0].TargetObject; return null; } set { } } /// <summary> /// List of Exceptions that are part of the incident (usually - but not always - only one). /// </summary> public List<DbatoolsException> Exceptions = new List<DbatoolsException>(); /// <summary> /// Creates an empty container. Ideal for the homeworker who loves doing it all himself. /// </summary> public DbatoolsExceptionRecord() { } /// <summary> /// Creates a container filled with the first exception. /// </summary> /// <param name="Exception"></param> public DbatoolsExceptionRecord(DbatoolsException Exception) { Runspace = Exception.Runspace; Timestamp = Exception.Timestamp; FunctionName = Exception.FunctionName; Message = Exception.Message; } /// <summary> /// Creates a container filled with the meta information but untouched by exceptions /// </summary> /// <param name="Runspace">The runspace where it all happened</param> /// <param name="Timestamp">When did it happen?</param> /// <param name="FunctionName">Where did it happen?</param> /// <param name="Message">What did the witness have to say?</param> public DbatoolsExceptionRecord(Guid Runspace, DateTime Timestamp, string FunctionName, string Message) { this.Runspace = Runspace; this.Timestamp = Timestamp; this.FunctionName = FunctionName; this.Message = Message; } } } |