diff options
| author | Max Git <rotvel@gmail.com> | 2020-06-23 09:20:50 +0200 |
|---|---|---|
| committer | Max Git <rotvel@gmail.com> | 2020-06-23 09:20:50 +0200 |
| commit | c35c401d65e00fd539c5451fbb0391327af5c610 (patch) | |
| tree | 3c5275c8fe6842d18f2667afa8a9233c37867b05 /RSSDP/SsdpDevice.cs | |
| parent | cd8d04f0555c9041a5a2495025e587a2ed994c8a (diff) | |
| parent | 0be10db5a5ea5f284b310e55ee572016a177decd (diff) | |
Merge branch 'master' into feature/ffmpeg-version-check
Diffstat (limited to 'RSSDP/SsdpDevice.cs')
| -rw-r--r-- | RSSDP/SsdpDevice.cs | 61 |
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 } } |
