DiscoveredSsdpDevice.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Net.Http.Headers;
  3. namespace Rssdp
  4. {
  5. /// <summary>
  6. /// Represents a discovered device, containing basic information about the device and the location of it's full device description document. Also provides convenience methods for retrieving the device description document.
  7. /// </summary>
  8. /// <seealso cref="SsdpDevice"/>
  9. /// <seealso cref="Infrastructure.ISsdpDeviceLocator"/>
  10. public sealed class DiscoveredSsdpDevice
  11. {
  12. #region Fields
  13. private DateTimeOffset _AsAt;
  14. #endregion
  15. #region Public Properties
  16. /// <summary>
  17. /// Sets or returns the type of notification, being either a uuid, device type, service type or upnp:rootdevice.
  18. /// </summary>
  19. public string NotificationType { get; set; }
  20. /// <summary>
  21. /// Sets or returns the universal service name (USN) of the device.
  22. /// </summary>
  23. public string Usn { get; set; }
  24. /// <summary>
  25. /// Sets or returns a URL pointing to the device description document for this device.
  26. /// </summary>
  27. public Uri DescriptionLocation { get; set; }
  28. /// <summary>
  29. /// Sets or returns the length of time this information is valid for (from the <see cref="AsAt"/> time).
  30. /// </summary>
  31. public TimeSpan CacheLifetime { get; set; }
  32. /// <summary>
  33. /// Sets or returns the date and time this information was received.
  34. /// </summary>
  35. public DateTimeOffset AsAt
  36. {
  37. get { return _AsAt; }
  38. set
  39. {
  40. if (_AsAt != value)
  41. {
  42. _AsAt = value;
  43. }
  44. }
  45. }
  46. /// <summary>
  47. /// Returns the headers from the SSDP device response message
  48. /// </summary>
  49. public HttpHeaders ResponseHeaders { get; set; }
  50. #endregion
  51. #region Public Methods
  52. /// <summary>
  53. /// Returns true if this device information has expired, based on the current date/time, and the <see cref="CacheLifetime"/> &amp; <see cref="AsAt"/> properties.
  54. /// </summary>
  55. /// <returns></returns>
  56. public bool IsExpired()
  57. {
  58. return this.CacheLifetime == TimeSpan.Zero || this.AsAt.Add(this.CacheLifetime) <= DateTimeOffset.Now;
  59. }
  60. #endregion
  61. #region Overrides
  62. /// <summary>
  63. /// Returns the device's <see cref="Usn"/> value.
  64. /// </summary>
  65. /// <returns>A string containing the device's universal service name.</returns>
  66. public override string ToString()
  67. {
  68. return this.Usn;
  69. }
  70. #endregion
  71. }
  72. }