3 using System
.Collections
.Generic
;
6 internal class VxSchemaError
8 // The key of the element that had the error
12 // The SQL error number, or -1 if not applicable.
16 // Default to a level of Error;
17 public VxSchemaError(string newkey
, string newmsg
, int newerrnum
)
22 level
= WvLog
.L
.Error
;
25 public VxSchemaError(string newkey
, string newmsg
, int newerrnum
,
34 public VxSchemaError(VxSchemaError other
)
38 errnum
= other
.errnum
;
42 public VxSchemaError(MessageReader reader
)
44 key
= reader
.ReadString();
45 msg
= reader
.ReadString();
46 errnum
= reader
.ReadInt32();
47 int intlevel
= reader
.ReadInt32();
48 // Note: C# lets you cast an invalid value to an enum without an
49 // exception, we have to check this ourselves. Default to
50 // Critical (i.e. 0) if someone sends us something unexpected.
51 if (Enum
.IsDefined(typeof(WvLog
.L
), intlevel
))
52 level
= (WvLog
.L
)intlevel
;
54 level
= WvLog
.L
.Critical
;
57 public void WriteError(MessageWriter writer
)
62 writer
.Write((int)level
);
65 public override string ToString()
67 return String
.Format("{0} {1}: {2} ({3})", key
, level
, msg
, errnum
);
70 public static string GetDbusSignature()
76 internal class VxSchemaErrors
: Dictionary
<string, List
<VxSchemaError
>>
78 public VxSchemaErrors()
82 public VxSchemaErrors(MessageReader reader
)
84 reader
.ReadArrayFunc(8, (r
) => {
85 VxSchemaError err
= new VxSchemaError(r
);
86 this.Add(err
.key
, err
);
90 public void Add(string key
, VxSchemaError val
)
92 if (!this.ContainsKey(key
))
94 var list
= new List
<VxSchemaError
>();
102 public void Add(VxSchemaErrors other
)
104 foreach (var kvp
in other
)
106 var list
= new List
<VxSchemaError
>();
107 foreach (var elem
in kvp
.Value
)
108 list
.Add(new VxSchemaError(elem
));
109 this.Add(kvp
.Key
, list
);
113 private void _WriteErrors(MessageWriter writer
)
115 foreach (var kvp
in this)
116 foreach (VxSchemaError err
in kvp
.Value
)
119 err
.WriteError(writer
);
123 // Static so we can properly write an empty array for a null object.
124 public static void WriteErrors(MessageWriter writer
, VxSchemaErrors errs
)
126 writer
.WriteDelegatePrependSize(delegate(MessageWriter w
)
129 errs
._WriteErrors(w
);
133 public static string GetDbusSignature()
135 return String
.Format("a({0})", VxSchemaError
.GetDbusSignature());
138 public override string ToString()
140 StringBuilder sb
= new StringBuilder();
141 foreach (var kvp
in this)
142 foreach (var err
in kvp
.Value
)
143 sb
.Append(err
.ToString() + "\n");
144 return sb
.ToString();