| 1 |
/* |
| 2 |
* Created by SharpDevelop. |
| 3 |
* User: lextm |
| 4 |
* Date: 2008/5/17 |
| 5 |
* Time: 16:33 |
| 6 |
* |
| 7 |
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
| 8 |
*/ |
| 9 |
|
| 10 |
using System; |
| 11 |
using System.Globalization; |
| 12 |
#if (!SILVERLIGHT) |
| 13 |
using System.Runtime.Serialization; |
| 14 |
using System.Security.Permissions; |
| 15 |
#endif |
| 16 |
|
| 17 |
namespace Lextm.SharpSnmpLib.Mib |
| 18 |
{ |
| 19 |
/// <summary> |
| 20 |
/// Description of MibException. |
| 21 |
/// </summary> |
| 22 |
[Serializable] |
| 23 |
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Mib")] |
| 24 |
public sealed class MibException : Exception |
| 25 |
{ |
| 26 |
/// <summary> |
| 27 |
/// Symbol. |
| 28 |
/// </summary> |
| 29 |
public Symbol Symbol { get; private set; } |
| 30 |
|
| 31 |
/// <summary> |
| 32 |
/// Creates a <see cref="MibException"/>. |
| 33 |
/// </summary> |
| 34 |
public MibException() |
| 35 |
{ |
| 36 |
} |
| 37 |
|
| 38 |
/// <summary> |
| 39 |
/// Creates a <see cref="SnmpException"/> instance with a specific <see cref="string"/>. |
| 40 |
/// </summary> |
| 41 |
/// <param name="message">Message</param> |
| 42 |
public MibException(string message) : base(message) |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
/// <summary> |
| 47 |
/// Creates a <see cref="MibException"/> instance with a specific <see cref="string"/> and an <see cref="Exception"/>. |
| 48 |
/// </summary> |
| 49 |
/// <param name="message">Message</param> |
| 50 |
/// <param name="inner">Inner exception</param> |
| 51 |
public MibException(string message, Exception inner) |
| 52 |
: base(message, inner) |
| 53 |
{ |
| 54 |
} |
| 55 |
#if (!SILVERLIGHT) |
| 56 |
/// <summary> |
| 57 |
/// Creates a <see cref="MibException"/> instance. |
| 58 |
/// </summary> |
| 59 |
/// <param name="info">Info</param> |
| 60 |
/// <param name="context">Context</param> |
| 61 |
private MibException(SerializationInfo info, StreamingContext context) : base(info, context) |
| 62 |
{ |
| 63 |
if (info == null) |
| 64 |
{ |
| 65 |
throw new ArgumentNullException("info"); |
| 66 |
} |
| 67 |
|
| 68 |
Symbol = (Symbol)info.GetValue("Symbol", typeof(Symbol)); |
| 69 |
} |
| 70 |
|
| 71 |
/// <summary> |
| 72 |
/// Gets object data. |
| 73 |
/// </summary> |
| 74 |
/// <param name="info">Info</param> |
| 75 |
/// <param name="context">Context</param> |
| 76 |
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] |
| 77 |
public override void GetObjectData(SerializationInfo info, StreamingContext context) |
| 78 |
{ |
| 79 |
base.GetObjectData(info, context); |
| 80 |
info.AddValue("Symbol", Symbol); |
| 81 |
} |
| 82 |
#endif |
| 83 |
|
| 84 |
/// <summary> |
| 85 |
/// Creates a <see cref="MibException"/> with a specific <see cref="Symbol"/>. |
| 86 |
/// </summary> |
| 87 |
/// <param name="message">Message</param> |
| 88 |
/// <param name="symbol">Symbol</param> |
| 89 |
/// <returns></returns> |
| 90 |
public static MibException Create(string message, Symbol symbol) |
| 91 |
{ |
| 92 |
if (symbol == null) |
| 93 |
{ |
| 94 |
throw new ArgumentNullException("symbol"); |
| 95 |
} |
| 96 |
|
| 97 |
if (String.IsNullOrEmpty(message)) |
| 98 |
{ |
| 99 |
message = "Unknown MIB Exception"; |
| 100 |
} |
| 101 |
|
| 102 |
message = String.Format( |
| 103 |
"{0} (file: \"{1}\"; row: {2}; column: {3})", |
| 104 |
message, |
| 105 |
symbol.File, |
| 106 |
symbol.Row + 1, |
| 107 |
symbol.Column + 1); |
| 108 |
|
| 109 |
MibException ex = new MibException(message) { Symbol = symbol }; |
| 110 |
return ex; |
| 111 |
} |
| 112 |
} |
| 113 |
} |