DiscoveredSsdpDevice.cs 2.5 KB

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