aboutsummaryrefslogtreecommitdiff
path: root/RSSDP/SsdpDevice.cs
diff options
context:
space:
mode:
Diffstat (limited to 'RSSDP/SsdpDevice.cs')
-rw-r--r--RSSDP/SsdpDevice.cs61
1 files changed, 32 insertions, 29 deletions
diff --git a/RSSDP/SsdpDevice.cs b/RSSDP/SsdpDevice.cs
index f89bafb19..4005d836d 100644
--- a/RSSDP/SsdpDevice.cs
+++ b/RSSDP/SsdpDevice.cs
@@ -15,9 +15,6 @@ namespace Rssdp
/// <seealso cref="SsdpEmbeddedDevice"/>
public abstract class SsdpDevice
{
-
- #region Fields
-
private string _Udn;
private string _DeviceType;
private string _DeviceTypeNamespace;
@@ -25,10 +22,6 @@ namespace Rssdp
private IList<SsdpDevice> _Devices;
- #endregion
-
- #region Events
-
/// <summary>
/// Raised when a new child device is added.
/// </summary>
@@ -43,10 +36,6 @@ namespace Rssdp
/// <seealso cref="DeviceRemoved"/>
public event EventHandler<DeviceEventArgs> DeviceRemoved;
- #endregion
-
- #region Constructors
-
/// <summary>
/// Derived type constructor, allows constructing a device with no parent. Should only be used from derived types that are or inherit from <see cref="SsdpRootDevice"/>.
/// </summary>
@@ -60,23 +49,19 @@ namespace Rssdp
this.Devices = new ReadOnlyCollection<SsdpDevice>(_Devices);
}
- #endregion
-
public SsdpRootDevice ToRootDevice()
{
var device = this;
var rootDevice = device as SsdpRootDevice;
if (rootDevice == null)
+ {
rootDevice = ((SsdpEmbeddedDevice)device).RootDevice;
+ }
return rootDevice;
}
- #region Public Properties
-
- #region UPnP Device Description Properties
-
/// <summary>
/// Sets or returns the core device type (not including namespace, version etc.). Required.
/// </summary>
@@ -180,9 +165,13 @@ namespace Rssdp
get
{
if (String.IsNullOrEmpty(_Udn) && !String.IsNullOrEmpty(this.Uuid))
+ {
return "uuid:" + this.Uuid;
+ }
else
+ {
return _Udn;
+ }
}
set
@@ -252,8 +241,6 @@ namespace Rssdp
/// </remarks>
public Uri PresentationUrl { get; set; }
- #endregion
-
/// <summary>
/// Returns a read-only enumerable set of <see cref="SsdpDevice"/> objects representing children of this device. Child devices are optional.
/// </summary>
@@ -265,10 +252,6 @@ namespace Rssdp
private set;
}
- #endregion
-
- #region Public Methods
-
/// <summary>
/// Adds a child device to the <see cref="Devices"/> collection.
/// </summary>
@@ -282,9 +265,20 @@ namespace Rssdp
/// <seealso cref="DeviceAdded"/>
public void AddDevice(SsdpEmbeddedDevice device)
{
- if (device == null) throw new ArgumentNullException(nameof(device));
- if (device.RootDevice != null && device.RootDevice != this.ToRootDevice()) throw new InvalidOperationException("This device is already associated with a different root device (has been added as a child in another branch).");
- if (device == this) throw new InvalidOperationException("Can't add device to itself.");
+ if (device == null)
+ {
+ throw new ArgumentNullException(nameof(device));
+ }
+
+ if (device.RootDevice != null && device.RootDevice != this.ToRootDevice())
+ {
+ throw new InvalidOperationException("This device is already associated with a different root device (has been added as a child in another branch).");
+ }
+
+ if (device == this)
+ {
+ throw new InvalidOperationException("Can't add device to itself.");
+ }
bool wasAdded = false;
lock (_Devices)
@@ -295,7 +289,9 @@ namespace Rssdp
}
if (wasAdded)
+ {
OnDeviceAdded(device);
+ }
}
/// <summary>
@@ -310,7 +306,10 @@ namespace Rssdp
/// <seealso cref="DeviceRemoved"/>
public void RemoveDevice(SsdpEmbeddedDevice device)
{
- if (device == null) throw new ArgumentNullException(nameof(device));
+ if (device == null)
+ {
+ throw new ArgumentNullException(nameof(device));
+ }
bool wasRemoved = false;
lock (_Devices)
@@ -323,7 +322,9 @@ namespace Rssdp
}
if (wasRemoved)
+ {
OnDeviceRemoved(device);
+ }
}
/// <summary>
@@ -336,7 +337,9 @@ namespace Rssdp
{
var handlers = this.DeviceAdded;
if (handlers != null)
+ {
handlers(this, new DeviceEventArgs(device));
+ }
}
/// <summary>
@@ -349,9 +352,9 @@ namespace Rssdp
{
var handlers = this.DeviceRemoved;
if (handlers != null)
+ {
handlers(this, new DeviceEventArgs(device));
+ }
}
-
- #endregion
}
}