/SharpSnmpLib/Messaging/TimeoutException.cs

# · C# · 122 lines · 54 code · 11 blank · 57 comment · 5 complexity · b61ac0d63a826c931aa995356a14f263 MD5 · raw file

  1. // Timeout exception type.
  2. // Copyright (C) 2008-2010 Malcolm Crowe, Lex Li, and other contributors.
  3. //
  4. // This library is free software; you can redistribute it and/or
  5. // modify it under the terms of the GNU Lesser General Public
  6. // License as published by the Free Software Foundation; either
  7. // version 2.1 of the License, or (at your option) any later version.
  8. //
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. // Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public
  15. // License along with this library; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. /*
  18. * Created by SharpDevelop.
  19. * User: lextm
  20. * Date: 2008/4/23
  21. * Time: 19:40
  22. *
  23. * To change this template use Tools | Options | Coding | Edit Standard Headers.
  24. */
  25. using System;
  26. using System.Globalization;
  27. using System.Net;
  28. #if (!SILVERLIGHT)
  29. using System.Runtime.Serialization;
  30. using System.Security.Permissions;
  31. #endif
  32. namespace Lextm.SharpSnmpLib.Messaging
  33. {
  34. /// <summary>
  35. /// Timeout exception type of #SNMP.
  36. /// </summary>
  37. [Serializable]
  38. public sealed class TimeoutException : OperationException
  39. {
  40. /// <summary>
  41. /// The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.
  42. /// </summary>
  43. public int Timeout { get; private set; }
  44. /// <summary>
  45. /// Creates a <see cref="TimeoutException"/> instance.
  46. /// </summary>
  47. public TimeoutException()
  48. {
  49. }
  50. /// <summary>
  51. /// Creates a <see cref="TimeoutException"/> instance with a specific <see cref="string"/>.
  52. /// </summary>
  53. /// <param name="message">Message</param>
  54. public TimeoutException(string message) : base(message)
  55. {
  56. }
  57. /// <summary>
  58. /// Creates a <see cref="TimeoutException"/> instance with a specific <see cref="string"/> and an <see cref="Exception"/> instance.
  59. /// </summary>
  60. /// <param name="message">Message</param>
  61. /// <param name="inner">Inner exception</param>
  62. public TimeoutException(string message, Exception inner) : base(message, inner)
  63. {
  64. }
  65. #if (!SILVERLIGHT && !CF)
  66. private TimeoutException(SerializationInfo info, StreamingContext context)
  67. : base(info, context)
  68. {
  69. if (info == null)
  70. {
  71. throw new ArgumentNullException("info");
  72. }
  73. Timeout = info.GetInt32("Timeout");
  74. }
  75. /// <summary>
  76. /// Gets object data.
  77. /// </summary>
  78. /// <param name="info">Info</param>
  79. /// <param name="context">Context</param>
  80. [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
  81. public override void GetObjectData(SerializationInfo info, StreamingContext context)
  82. {
  83. base.GetObjectData(info, context);
  84. info.AddValue("Timeout", Timeout);
  85. }
  86. #endif
  87. /// <summary>
  88. /// Returns a <see cref="String"/> that represents this <see cref="TimeoutException"/>.
  89. /// </summary>
  90. /// <returns></returns>
  91. public override string ToString()
  92. {
  93. return string.Format(CultureInfo.InvariantCulture, "TimeoutException: timeout: {0}", Timeout.ToString(CultureInfo.InvariantCulture));
  94. }
  95. /// <summary>
  96. /// Creates a <see cref="TimeoutException"/>.
  97. /// </summary>
  98. /// <param name="agent">Agent address</param>
  99. /// <param name="timeout">Timeout</param>
  100. /// <returns></returns>
  101. public static TimeoutException Create(IPAddress agent, int timeout)
  102. {
  103. if (agent == null)
  104. {
  105. throw new ArgumentNullException("agent");
  106. }
  107. var ex = new TimeoutException { Agent = agent, Timeout = timeout };
  108. return ex;
  109. }
  110. }
  111. }