DiscoveredSsdpDevice.cs 2.4 KB

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