DiscoveredSsdpDevice.cs 2.8 KB

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