|
@@ -13,9 +13,6 @@ namespace Rssdp.Infrastructure
|
|
/// </summary>
|
|
/// </summary>
|
|
public class SsdpDeviceLocator : DisposableManagedObjectBase
|
|
public class SsdpDeviceLocator : DisposableManagedObjectBase
|
|
{
|
|
{
|
|
-
|
|
|
|
- #region Fields & Constants
|
|
|
|
-
|
|
|
|
private List<DiscoveredSsdpDevice> _Devices;
|
|
private List<DiscoveredSsdpDevice> _Devices;
|
|
private ISsdpCommunicationsServer _CommunicationsServer;
|
|
private ISsdpCommunicationsServer _CommunicationsServer;
|
|
|
|
|
|
@@ -25,10 +22,6 @@ namespace Rssdp.Infrastructure
|
|
private readonly TimeSpan DefaultSearchWaitTime = TimeSpan.FromSeconds(4);
|
|
private readonly TimeSpan DefaultSearchWaitTime = TimeSpan.FromSeconds(4);
|
|
private readonly TimeSpan OneSecond = TimeSpan.FromSeconds(1);
|
|
private readonly TimeSpan OneSecond = TimeSpan.FromSeconds(1);
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Constructors
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Default constructor.
|
|
/// Default constructor.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -42,10 +35,6 @@ namespace Rssdp.Infrastructure
|
|
_Devices = new List<DiscoveredSsdpDevice>();
|
|
_Devices = new List<DiscoveredSsdpDevice>();
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Events
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Raised for when
|
|
/// Raised for when
|
|
/// <list type="bullet">
|
|
/// <list type="bullet">
|
|
@@ -76,12 +65,6 @@ namespace Rssdp.Infrastructure
|
|
/// <seealso cref="StopListeningForNotifications"/>
|
|
/// <seealso cref="StopListeningForNotifications"/>
|
|
public event EventHandler<DeviceUnavailableEventArgs> DeviceUnavailable;
|
|
public event EventHandler<DeviceUnavailableEventArgs> DeviceUnavailable;
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Public Methods
|
|
|
|
-
|
|
|
|
- #region Search Overloads
|
|
|
|
-
|
|
|
|
public void RestartBroadcastTimer(TimeSpan dueTime, TimeSpan period)
|
|
public void RestartBroadcastTimer(TimeSpan dueTime, TimeSpan period)
|
|
{
|
|
{
|
|
lock (_timerLock)
|
|
lock (_timerLock)
|
|
@@ -167,8 +150,6 @@ namespace Rssdp.Infrastructure
|
|
return BroadcastDiscoverMessage(searchTarget, SearchTimeToMXValue(searchWaitTime), cancellationToken);
|
|
return BroadcastDiscoverMessage(searchTarget, SearchTimeToMXValue(searchWaitTime), cancellationToken);
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Starts listening for broadcast notifications of service availability.
|
|
/// Starts listening for broadcast notifications of service availability.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -236,10 +217,6 @@ namespace Rssdp.Infrastructure
|
|
handlers(this, new DeviceUnavailableEventArgs(device, expired));
|
|
handlers(this, new DeviceUnavailableEventArgs(device, expired));
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Public Properties
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Sets or returns a string containing the filter for notifications. Notifications not matching the filter will not raise the <see cref="ISsdpDeviceLocator.DeviceAvailable"/> or <see cref="ISsdpDeviceLocator.DeviceUnavailable"/> events.
|
|
/// Sets or returns a string containing the filter for notifications. Notifications not matching the filter will not raise the <see cref="ISsdpDeviceLocator.DeviceAvailable"/> or <see cref="ISsdpDeviceLocator.DeviceUnavailable"/> events.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -261,10 +238,6 @@ namespace Rssdp.Infrastructure
|
|
set;
|
|
set;
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Overrides
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Disposes this object and all internal resources. Stops listening for all network messages.
|
|
/// Disposes this object and all internal resources. Stops listening for all network messages.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -285,12 +258,6 @@ namespace Rssdp.Infrastructure
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Private Methods
|
|
|
|
-
|
|
|
|
- #region Discovery/Device Add
|
|
|
|
-
|
|
|
|
private void AddOrUpdateDiscoveredDevice(DiscoveredSsdpDevice device, IPAddress localIpAddress)
|
|
private void AddOrUpdateDiscoveredDevice(DiscoveredSsdpDevice device, IPAddress localIpAddress)
|
|
{
|
|
{
|
|
bool isNewDevice = false;
|
|
bool isNewDevice = false;
|
|
@@ -326,10 +293,6 @@ namespace Rssdp.Infrastructure
|
|
|| device.NotificationType == this.NotificationFilter;
|
|
|| device.NotificationType == this.NotificationFilter;
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Network Message Processing
|
|
|
|
-
|
|
|
|
private Task BroadcastDiscoverMessage(string serviceType, TimeSpan mxValue, CancellationToken cancellationToken)
|
|
private Task BroadcastDiscoverMessage(string serviceType, TimeSpan mxValue, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
var values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
@@ -429,8 +392,6 @@ namespace Rssdp.Infrastructure
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- #region Header/Message Processing Utilities
|
|
|
|
-
|
|
|
|
private string GetFirstHeaderStringValue(string headerName, HttpResponseMessage message)
|
|
private string GetFirstHeaderStringValue(string headerName, HttpResponseMessage message)
|
|
{
|
|
{
|
|
string retVal = null;
|
|
string retVal = null;
|
|
@@ -498,12 +459,6 @@ namespace Rssdp.Infrastructure
|
|
return (TimeSpan)(headerValue.MaxAge ?? headerValue.SharedMaxAge ?? TimeSpan.Zero);
|
|
return (TimeSpan)(headerValue.MaxAge ?? headerValue.SharedMaxAge ?? TimeSpan.Zero);
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Expiry and Device Removal
|
|
|
|
-
|
|
|
|
private void RemoveExpiredDevicesFromCache()
|
|
private void RemoveExpiredDevicesFromCache()
|
|
{
|
|
{
|
|
if (this.IsDisposed) return;
|
|
if (this.IsDisposed) return;
|
|
@@ -560,8 +515,6 @@ namespace Rssdp.Infrastructure
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
private TimeSpan SearchTimeToMXValue(TimeSpan searchWaitTime)
|
|
private TimeSpan SearchTimeToMXValue(TimeSpan searchWaitTime)
|
|
{
|
|
{
|
|
if (searchWaitTime.TotalSeconds < 2 || searchWaitTime == TimeSpan.Zero)
|
|
if (searchWaitTime.TotalSeconds < 2 || searchWaitTime == TimeSpan.Zero)
|
|
@@ -598,10 +551,6 @@ namespace Rssdp.Infrastructure
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region Event Handlers
|
|
|
|
-
|
|
|
|
private void CommsServer_ResponseReceived(object sender, ResponseReceivedEventArgs e)
|
|
private void CommsServer_ResponseReceived(object sender, ResponseReceivedEventArgs e)
|
|
{
|
|
{
|
|
ProcessSearchResponseMessage(e.Message, e.LocalIpAddress);
|
|
ProcessSearchResponseMessage(e.Message, e.LocalIpAddress);
|
|
@@ -611,7 +560,5 @@ namespace Rssdp.Infrastructure
|
|
{
|
|
{
|
|
ProcessNotificationMessage(e.Message, e.LocalIpAddress);
|
|
ProcessNotificationMessage(e.Message, e.LocalIpAddress);
|
|
}
|
|
}
|
|
-
|
|
|
|
- #endregion
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|