/// <summary> /// Adds a device (and it's children) to the list of devices being published by this server, /// making them discoverable to SSDP clients. /// </summary> /// <param name="device">The <see cref="SsdpDevice"/> instance to add.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public async Task AddDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } if (_disposed) { return; } // Must be first, to ensure there will be sockets available. Server.AddEvent("M-SEARCH", RequestReceived); bool wasAdded = false; lock (_devices) { if (!_devices.Contains(device)) { _devices.Add(device); wasAdded = true; } } if (wasAdded) { _logger.LogInformation("DLNA server added {Device}", device); await SendAliveNotifications(device, true).ConfigureAwait(false); StartBroadcastingAliveMessages(_aliveMessageInterval); } }
public void DiscoveredDevice_GetDeviceInfo_DoesNotMakeHttpRequestIfDataCached() { var publishedDevice = new SsdpRootDevice() { Location = new Uri("http://192.168.1.100:1702/description"), CacheLifetime = TimeSpan.FromMinutes(1), DeviceType = "TestDeviceType", Uuid = System.Guid.NewGuid().ToString() }; var discoveredDevice = new DiscoveredSsdpDevice(); discoveredDevice.Usn = "test usn"; discoveredDevice.AsAt = DateTimeOffset.Now; discoveredDevice.CacheLifetime = publishedDevice.CacheLifetime; discoveredDevice.DescriptionLocation = publishedDevice.Location; var client = new MockHttpClient(publishedDevice.ToDescriptionDocument()); var device = discoveredDevice.GetDeviceInfo(client).GetAwaiter().GetResult(); client = new MockHttpClient(publishedDevice.ToDescriptionDocument()); device = discoveredDevice.GetDeviceInfo(client).GetAwaiter().GetResult(); Assert.IsNull(client.LastRequest); Assert.AreEqual(device.Uuid, publishedDevice.Uuid); Assert.AreEqual(device.DeviceType, publishedDevice.DeviceType); }
/// <summary> /// Removes a device (and it's children) from the list of devices being published by this server, making them indiscoverable. /// </summary> /// <param name="device">The <see cref="SsdpDevice"/> instance to add.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private async Task RemoveDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } bool wasRemoved = false; lock (_devices) { if (_devices.Contains(device)) { _devices.Remove(device); wasRemoved = true; } } if (wasRemoved) { _logger.LogInformation("Device {Device} removed.", device); Server.IncreaseBootId(); await SendByeByeNotifications(device, true).ConfigureAwait(false); } }
public void TestDevices() { asyncEvent = new AutoResetEvent(false); // Add a device var devices = new Devices(); devices.SetCallback(OnAddDeviceCallback); var discoveredSsdpDevice = new DiscoveredSsdpDevice { Usn = "usn", DescriptionLocation = new System.Uri("http://192.168.111.111") }; var ssdpDevice = new SsdpRootDevice { FriendlyName = "Device_Name" }; devices.OnDeviceAvailable(discoveredSsdpDevice, ssdpDevice); asyncEvent.WaitOne(100); Assert.AreEqual(ssdpDevice.FriendlyName, device.GetFriendlyName()); Assert.AreEqual(discoveredSsdpDevice.Usn, device.GetUsn()); Assert.AreEqual(discoveredSsdpDevice.DescriptionLocation.Host, device.GetHost()); // Not connected, volume messages are not send. TestMessagesWhenNotConnected(devices); // Connect and launch app TestConnectAndLoadMedia(devices); // Test the other messages TestMessages(devices); }
public void AddDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } ThrowIfDisposed(); bool wasAdded = false; lock (_Devices) { if (!_Devices.Contains(device)) { _Devices.Add(device); wasAdded = true; } } if (wasAdded) { WriteTrace("Device Added", device); SendAliveNotifications(device, true, CancellationToken.None); } }
/// <summary> /// Removes a device (and it's children) from the list of devices being published by this server, making them undiscoverable. /// </summary> /// <remarks> /// <para>Removing a device causes "byebye" notification messages to be sent immediately, advising clients of the device/service becoming unavailable. We recommend removing the device from the published list before shutting down the actual device/service, if possible.</para> /// <para>This method does nothing if the device was not found in the collection.</para> /// </remarks> /// <param name="device">The <see cref="SsdpDevice"/> instance to add.</param> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception> public async Task RemoveDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException("device"); } ThrowIfDisposed(); bool wasRemoved = false; TimeSpan minCacheTime = TimeSpan.Zero; lock (_Devices) { if (_Devices.Contains(device)) { _Devices.Remove(device); wasRemoved = true; minCacheTime = GetMinimumNonZeroCacheLifetime(); } } if (wasRemoved) { //_MinCacheTime = minCacheTime; DisconnectFromDeviceEvents(device); WriteTrace("Device Removed", device); await SendByeByeNotifications(device, true).ConfigureAwait(false); SetRebroadcastAliveNotificationsTimer(minCacheTime); } }
public void SsdpDevice_EmptyDeviceTypeReturnsEmpty() { var rootDevice = new SsdpRootDevice(); rootDevice.DeviceType = String.Empty; Assert.AreEqual(String.Empty, rootDevice.DeviceType); }
private static void PublishDevices() { if (_DevicePublisher != null) { Console.WriteLine("Stopping previous publisher."); _DevicePublisher.Dispose(); } // Create a device publisher _DevicePublisher = new SsdpDevicePublisher(); // Create the device(s) we want to publish. var rootDevice = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), FriendlyName = "Sample RSSDP Device", Manufacturer = "RSSDP", ModelNumber = "123", ModelName = "RSSDP Sample Device", SerialNumber = "123", Uuid = System.Guid.NewGuid().ToString() }; rootDevice.CustomResponseHeaders.Add(new CustomHttpHeader("X-MachineName", Environment.MachineName)); // Now publish by adding them to the publisher. _DevicePublisher.AddDevice(rootDevice); Console.WriteLine("Publishing devices: "); WriteOutDevices(rootDevice); Console.WriteLine(); }
public static void PublishThisDevice(string ip) { if (string.IsNullOrEmpty(ip)) { ConsoleLogger.Log("[rssdp] cannot publish device: ip address not valid"); return; } var appPort = Application.CurrentConfiguration.WebService.GuiWebServicePort; var deviceDefinition = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), Uuid = Application.CurrentConfiguration.Host.MachineUid.ToString(), Location = new Uri($"http://{ip}:{appPort}/device/description"), DeviceTypeNamespace = "antd", ModelUrl = new Uri($"http://{ip}:{appPort}/"), DeviceType = Application.CurrentConfiguration.Host.PartNumber.ToString(), FriendlyName = $"{ip} as {Application.CurrentConfiguration.Host.HostName}", Manufacturer = "Anthilla SRL", ModelName = Application.CurrentConfiguration.Host.SerialNumber.ToString().Replace("-", ""), SerialNumber = Application.CurrentConfiguration.Host.SerialNumber.ToString() }; _Publisher = new SsdpDevicePublisher(); _Publisher.AddDevice(deviceDefinition); ConsoleLogger.Log($"[rssdp] publishing this device on '{ip}'"); }
/// <summary> /// Removes a device (and it's children) from the list of devices being published by this server, making them undiscoverable. /// </summary> /// <remarks> /// <para>Removing a device causes "byebye" notification messages to be sent immediately, advising clients of the device/service becoming unavailable. We recommend removing the device from the published list before shutting down the actual device/service, if possible.</para> /// <para>This method does nothing if the device was not found in the collection.</para> /// </remarks> /// <param name="device">The <see cref="SsdpDevice"/> instance to add.</param> /// <exception cref="ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception> public async Task RemoveDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException(nameof(device)); } bool wasRemoved = false; lock (_Devices) { if (_Devices.Contains(device)) { _Devices.Remove(device); wasRemoved = true; } } if (wasRemoved) { WriteTrace("Device Removed", device); await SendByeByeNotifications(device, true, CancellationToken.None).ConfigureAwait(false); } }
// Call this method from somewhere to actually do the publish. private static void PublishDevice() { var ip4 = GetLocalIp4Address(); var version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); var deviceDefinition4 = new SsdpRootDevice() { Location = new Uri($"http://{ip4}/home/service"), PresentationUrl = new Uri($"http://{ip4}/"), FriendlyName = "Milwaukee Makerspace Api", Manufacturer = "Milwaukee Makerspace", ModelName = "Milwaukee Makerspace Api", Uuid = "6111f321-2cee-455e-b203-4abfaf14b516", ManufacturerUrl = new Uri("https://milwaukeemakerspace.org/"), ModelUrl = new Uri("https://github.com/DanDude0/MilwaukeeMakerspaceApi/"), ModelNumber = version, }; // Have to bind to all addresses on Linux, or broadcasts don't work! if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { ip4 = IPAddress.Any.ToString(); } Console.WriteLine($"Publishing SSDP on {ip4}"); SsdpPublisher4 = new SsdpDevicePublisher(new SsdpCommunicationsServer(new SocketFactory(ip4))); SsdpPublisher4.StandardsMode = SsdpStandardsMode.Relaxed; SsdpPublisher4.AddDevice(deviceDefinition4); SsdpDescription = deviceDefinition4.ToDescriptionDocument(); }
public void AddDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException("device"); } ThrowIfDisposed(); TimeSpan minCacheTime = TimeSpan.Zero; bool wasAdded = false; lock (_Devices) { if (!_Devices.Contains(device)) { _Devices.Add(device); wasAdded = true; minCacheTime = GetMinimumNonZeroCacheLifetime(); } } if (wasAdded) { //_MinCacheTime = minCacheTime; WriteTrace("Device Added", device); SetRebroadcastAliveNotificationsTimer(minCacheTime); SendAliveNotifications(device, true, CancellationToken.None); } }
public void ToDescriptionDocument_DeserialiseServiceList() { var rootDevice = CreateSampleRootDevice(); rootDevice.AddDevice(CreateEmbeddedDevice(rootDevice)); rootDevice.AddDevice(CreateEmbeddedDevice(rootDevice)); var service = new SsdpService() { ControlUrl = new Uri("/test/control", UriKind.Relative), EventSubUrl = new Uri("/test/events", UriKind.Relative), ScpdUrl = new Uri("/test", UriKind.Relative), ServiceType = "mytestservicetype", ServiceTypeNamespace = "my-test-namespace", ServiceVersion = 1, Uuid = System.Guid.NewGuid().ToString() }; rootDevice.AddService(service); var service2 = new SsdpService() { ControlUrl = new Uri("/test/control", UriKind.Relative), EventSubUrl = new Uri("/test/events", UriKind.Relative), ScpdUrl = new Uri("/test", UriKind.Relative), ServiceType = "mytestservicetype", ServiceTypeNamespace = "my-test-namespace", ServiceVersion = 1, Uuid = System.Guid.NewGuid().ToString() }; rootDevice.AddService(service2); var service3 = new SsdpService() { ControlUrl = new Uri("/test/control", UriKind.Relative), EventSubUrl = new Uri("/test/events", UriKind.Relative), ScpdUrl = new Uri("/test", UriKind.Relative), ServiceType = "mytestservicetype", ServiceTypeNamespace = "my-test-namespace", ServiceVersion = 1, Uuid = System.Guid.NewGuid().ToString() }; rootDevice.Devices.First().AddService(service3); var descriptionDocument = rootDevice.ToDescriptionDocument(); var doc = XDocument.Parse(descriptionDocument); var deserialisedDevice = new SsdpRootDevice(rootDevice.Location, rootDevice.CacheLifetime, doc.ToString()); AssertDevicesAreSame(rootDevice.Devices.First(), deserialisedDevice.Devices.First()); AssertDevicesAreSame(rootDevice.Devices.Last(), deserialisedDevice.Devices.Last()); Assert.AreEqual(2, deserialisedDevice.Services.Count()); Assert.AreEqual(1, deserialisedDevice.Devices.First().Services.Count()); AssertServicesAreSame(service, deserialisedDevice.Services.First()); AssertServicesAreSame(service2, deserialisedDevice.Services.Last()); AssertServicesAreSame(service3, deserialisedDevice.Devices.First().Services.First()); Assert.AreEqual(descriptionDocument, deserialisedDevice.ToDescriptionDocument()); }
private async Task RegisterServerEndpoints() { var addresses = await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false); var udn = CreateUuid(_appHost.SystemId); foreach (var address in addresses) { if (address.AddressFamily == AddressFamily.InterNetworkV6) { // Not support IPv6 right now continue; } var fullService = "urn:schemas-upnp-org:device:MediaServer:1"; _logger.LogInformation("Registering publisher for {0} on {1}", fullService, address); var descriptorUri = "/dlna/" + udn + "/description.xml"; var uri = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri); var device = new SsdpRootDevice { CacheLifetime = TimeSpan.FromSeconds(1800), //How long SSDP clients can cache this info. Location = uri, // Must point to the URL that serves your devices UPnP description document. Address = address, SubnetMask = _networkManager.GetLocalIpSubnetMask(address), FriendlyName = "Veso", Manufacturer = "Veso", ModelName = "Veso Server", Uuid = udn // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc. }; SetProperies(device, fullService); _Publisher.AddDevice(device); var embeddedDevices = new[] { "urn:schemas-upnp-org:service:ContentDirectory:1", "urn:schemas-upnp-org:service:ConnectionManager:1", //"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1" }; foreach (var subDevice in embeddedDevices) { var embeddedDevice = new SsdpEmbeddedDevice { FriendlyName = device.FriendlyName, Manufacturer = device.Manufacturer, ModelName = device.ModelName, Uuid = udn // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc. }; SetProperies(embeddedDevice, subDevice); device.AddDevice(embeddedDevice); } } }
/// <summary> /// Removes a device (and it's children) from the list of devices being published by this server, making them undiscoverable. /// </summary> /// <remarks> /// <para>Removing a device causes "byebye" notification messages to be sent immediately, advising clients of the device/service becoming unavailable. We recommend removing the device from the published list before shutting down the actual device/service, if possible.</para> /// <para>This method does nothing if the device was not found in the collection.</para> /// </remarks> /// <param name="device">The <see cref="SsdpDevice"/> instance to add.</param> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception> public async Task RemoveDevice(SsdpRootDevice device) { if (device == null) { throw new ArgumentNullException("device"); } bool wasRemoved = false; TimeSpan minCacheTime = TimeSpan.Zero; lock (_Devices) { if (_Devices.Contains(device)) { _Devices.Remove(device); wasRemoved = true; minCacheTime = GetMinimumNonZeroCacheLifetime(); } } if (wasRemoved) { WriteTrace("Device Removed", device); await SendByeByeNotifications(device, true, CancellationToken.None).ConfigureAwait(false); } }
public void SsdpDevice_RootDeviceFromDeviceDescriptionXml() { var xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root xmlns=\"urn:schemas-upnp-org:device-1-0\"><specVersion><major>1</major><minor>0</minor></specVersion><URLBase>http://192.168.0.1:54243</URLBase><device><deviceType>urn:schemas-upnp-org:device:MediaRenderer:1</deviceType><friendlyName>Friendly Player</friendlyName><manufacturer>RSSDP</manufacturer><manufacturerURL>https://github.com/Yortw/RSSDP</manufacturerURL><modelDescription>UPnP Renderer</modelDescription><modelName>RSSDP</modelName><modelNumber>6</modelNumber><modelURL>https://github.com/Yortw/RSSDP</modelURL><serialNumber>0</serialNumber><UDN>uuid:uuid:4422acaa-c5b4-4a8e-a1ff-382656833d43</UDN><UPC>00000000</UPC><iconList><icon><mimetype>image/png</mimetype><url>/icons/sm.png</url><width>48</width><height>48</height><depth>24</depth></icon><icon><mimetype>image/png</mimetype><url>/icons/lrg.png</url><width>120</width><height>120</height><depth>24</depth></icon><icon><mimetype>image/jpeg</mimetype><url>/icons/sm.jpg</url><width>48</width><height>48</height><depth>24</depth></icon><icon><mimetype>image/jpeg</mimetype><url>/icons/lrg.jpg</url><width>120</width><height>120</height><depth>24</depth></icon></iconList><serviceList><service><serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType><serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId><controlURL>/service/ConnectionManager/control</controlURL><eventSubURL>/service/ConnectionManager/event</eventSubURL><SCPDURL>/service/ConnectionManager/scpd</SCPDURL></service><service><serviceType>urn:schemas-upnp-org:service:AVTransport:1</serviceType><serviceId>urn:upnp-org:serviceId:AVTransport</serviceId><controlURL>/service/AVTransport/control</controlURL><eventSubURL>/service/AVTransport/event</eventSubURL><SCPDURL>/service/AVTransport/scpd</SCPDURL></service><service><serviceType>urn:schemas-upnp-org:service:RenderingControl:1</serviceType><serviceId>urn:upnp-org:serviceId:RenderingControl</serviceId><controlURL>/service/RenderingControl/control</controlURL><eventSubURL>/service/RenderingControl/event</eventSubURL><SCPDURL>/service/RenderingControl/scpd</SCPDURL></service></serviceList></device></root>"; var rootDevice = new SsdpRootDevice(new Uri("http://192.168.0.1:54243/device.xml"), TimeSpan.FromSeconds(30), xml); Assert.AreEqual("Friendly Player", rootDevice.FriendlyName); }
public void SsdpDevice_NullDeviceTypeReturnsNull() { var rootDevice = new SsdpRootDevice(); rootDevice.DeviceType = null; Assert.AreEqual(null, rootDevice.DeviceType); }
private async Task RegisterServerEndpoints() { var cacheLength = _config.GetDlnaConfiguration().BlastAliveMessageIntervalSeconds; var addresses = (await _appHost.GetLocalIpAddresses(CancellationToken.None).ConfigureAwait(false)).ToList(); var udn = CreateUuid(_appHost.SystemId); foreach (var address in addresses) { // TODO: Remove this condition on platforms that support it //if (address.AddressFamily == IpAddressFamily.InterNetworkV6) //{ // continue; //} var fullService = "urn:schemas-upnp-org:device:MediaServer:1"; _logger.Info("Registering publisher for {0} on {1}", fullService, address.ToString()); var descriptorUri = "/dlna/" + udn + "/description.xml"; var uri = new Uri(_appHost.GetLocalApiUrl(address) + descriptorUri); var device = new SsdpRootDevice { CacheLifetime = TimeSpan.FromSeconds(cacheLength), //How long SSDP clients can cache this info. Location = uri, // Must point to the URL that serves your devices UPnP description document. FriendlyName = "Emby Server", Manufacturer = "Emby", ModelName = "Emby Server", Uuid = udn // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc. }; SetProperies(device, fullService); _Publisher.AddDevice(device); var embeddedDevices = new [] { "urn:schemas-upnp-org:service:ContentDirectory:1", "urn:schemas-upnp-org:service:ConnectionManager:1", //"urn:microsoft.com:service:X_MS_MediaReceiverRegistrar:1" }; foreach (var subDevice in embeddedDevices) { var embeddedDevice = new SsdpEmbeddedDevice { FriendlyName = device.FriendlyName, Manufacturer = device.Manufacturer, ModelName = device.ModelName, Uuid = udn // This must be a globally unique value that survives reboots etc. Get from storage or embedded hardware etc. }; SetProperies(embeddedDevice, subDevice); device.AddDevice(embeddedDevice); } } }
private void AssertDevicesAreSame(SsdpRootDevice originalDevice, SsdpRootDevice deserialisedDevice) { Assert.AreEqual(originalDevice.CacheLifetime, deserialisedDevice.CacheLifetime); Assert.AreEqual(originalDevice.Location, deserialisedDevice.Location); Assert.AreEqual(originalDevice.UrlBase, deserialisedDevice.UrlBase); AssertDevicesAreSame((SsdpDevice)originalDevice, (SsdpDevice)deserialisedDevice); }
public void SsdpDevice_FullDeviceTypesReturnsStringWithNullValues() { var rootDevice = new SsdpRootDevice(); rootDevice.DeviceType = null; rootDevice.DeviceTypeNamespace = null; Assert.AreEqual("urn::device::1", rootDevice.FullDeviceType); }
internal DeviceInfo(SsdpRootDevice dev, string usn) { Usn = usn; Uuid = dev.Uuid; Host = dev.Location.Host; FriendlyName = dev.FriendlyName; ModelName = dev.ModelNumber; }
public void Activate(NavigationEventArgs e) { Tuple <AccessPoint, Service, SsdpRootDevice> args = e.Parameter as Tuple <AccessPoint, Service, SsdpRootDevice>; AccessPoint = args.Item1; wifiSetupService = args.Item2; selectedDevice = args.Item3; }
public void SsdpDevice_DeviceToRootDeviceReturnsAssignedRootDevice() { var rootDevice = new SsdpRootDevice(); var device = new SsdpEmbeddedDevice(); rootDevice.AddDevice(device); Assert.AreEqual(rootDevice, device.RootDevice); }
public void SsdpDevice_AddService_DuplicateAddDoesNothing() { var rootDevice = new SsdpRootDevice(); var service = new SsdpService(); rootDevice.AddService(service); rootDevice.AddService(service); Assert.AreEqual(1, rootDevice.Services.Count()); }
public void SsdpDevice_Constructor_DeserialisesComplexDeviceDocumentAndSkipsComplexCustomProperties() { var device = new SsdpRootDevice(new Uri("http://192.168.1.2"), TimeSpan.FromMinutes(1), DocumentWithComplexCustomProperties); Assert.AreEqual(19, device.CustomProperties.Count); var subDevice = device.Devices.Last(); Assert.AreEqual("QPlay:2", subDevice.CustomProperties["qq:X_QPlay_SoftwareCapability"].Value); Assert.IsFalse(subDevice.CustomProperties.Contains("X_Rhapsody-Extension")); }
public void SsdpDevice_AddDevice_DuplicateAddDoesNothing() { var rootDevice = new SsdpRootDevice(); var embeddedDevice = new SsdpEmbeddedDevice(); rootDevice.AddDevice(embeddedDevice); rootDevice.AddDevice(embeddedDevice); Assert.AreEqual(1, rootDevice.Devices.Count()); }
public void SsdpDevice_AddDevice_ThrowsAddingDeviceToMultipleParents() { var rootDevice1 = new SsdpRootDevice(); var rootDevice2 = new SsdpRootDevice(); var embeddedDevice = new SsdpEmbeddedDevice(); rootDevice1.AddDevice(embeddedDevice); rootDevice2.AddDevice(embeddedDevice); }
private static string CacheControlHeaderFromTimeSpan(SsdpRootDevice device) { if (device.CacheLifetime == TimeSpan.Zero) { return("CACHE-CONTROL: no-cache"); } else { return(String.Format("CACHE-CONTROL: public, max-age={0}", device.CacheLifetime.TotalSeconds)); } }
public void ToDescriptionDocument_DeserialisesUrlBase() { var rootDevice = CreateSampleRootDevice(); rootDevice.Udn = "testudn"; var descriptionDocument = rootDevice.ToDescriptionDocument(); var deserialisedDevice = new SsdpRootDevice(rootDevice.Location, rootDevice.CacheLifetime, descriptionDocument); Assert.AreEqual(rootDevice.Udn, deserialisedDevice.Udn); }
public void ToDescriptionDocument_DeserialiseInvalidUdn() { var rootDevice = CreateSampleRootDevice(); rootDevice.UrlBase = new Uri("http://testdevice:1700/baseurl"); var descriptionDocument = rootDevice.ToDescriptionDocument(); var deserialisedDevice = new SsdpRootDevice(rootDevice.Location, rootDevice.CacheLifetime, descriptionDocument); Assert.AreEqual(rootDevice.UrlBase, deserialisedDevice.UrlBase); }
/// <summary> /// Removes a device (and it's children) from the list of devices being published by this server, making them undiscoverable. /// </summary> /// <remarks> /// <para>Removing a device causes "byebye" notification messages to be sent immediately, advising clients of the device/service becoming unavailable. We recommend removing the device from the published list before shutting down the actual device/service, if possible.</para> /// <para>This method does nothing if the device was not found in the collection.</para> /// </remarks> /// <param name="device">The <see cref="SsdpDevice"/> instance to add.</param> /// <exception cref="System.ArgumentNullException">Thrown if the <paramref name="device"/> argument is null.</exception> public void RemoveDevice(SsdpRootDevice device) { if (device == null) throw new ArgumentNullException("device"); ThrowIfDisposed(); bool wasRemoved = false; TimeSpan minCacheTime; lock (_Devices) { if (_Devices.Contains(device)) { _Devices.Remove(device); wasRemoved = true; minCacheTime = GetMinimumNonZeroCacheLifetime(); } } if (wasRemoved) { _MinCacheTime = minCacheTime; DisconnectFromDeviceEvents(device); WriteTrace("Device Removed", device); SendByeByeNotifications(device, true); SetRebroadcastAliveNotificationsTimer(minCacheTime); } }
private static void PublishDevices() { if (_DevicePublisher != null) { Console.WriteLine("Stopping previous publisher."); _DevicePublisher.Dispose(); } // Create a device publisher _DevicePublisher = new SsdpDevicePublisher(); // Create the device(s) we want to publish. var rootDevice = new SsdpRootDevice() { CacheLifetime = TimeSpan.FromMinutes(30), FriendlyName = "Sample RSSDP Device", Manufacturer = "RSSDP", ModelNumber = "123", ModelName = "RSSDP Sample Device", SerialNumber = "123", Uuid = System.Guid.NewGuid().ToString() }; // Now publish by adding them to the publisher. _DevicePublisher.AddDevice(rootDevice); Console.WriteLine("Publishing devices: "); WriteOutDevices(rootDevice); Console.WriteLine(); }
public void AddDevice(SsdpRootDevice device) { if (device == null) throw new ArgumentNullException("device"); ThrowIfDisposed(); _DeviceValidator.ThrowIfDeviceInvalid(device); TimeSpan minCacheTime; bool wasAdded = false; lock (_Devices){ if (!_Devices.Contains(device)) { _Devices.Add(device); wasAdded = true; minCacheTime = GetMinimumNonZeroCacheLifetime(); } } if (wasAdded) { _MinCacheTime = minCacheTime; ConnectToDeviceEvents(device); WriteTrace("Device Added", device); SetRebroadcastAliveNotificationsTimer(minCacheTime); SendAliveNotifications(device, true); } }
private static string CacheControlHeaderFromTimeSpan(SsdpRootDevice device) { if (device.CacheLifetime == TimeSpan.Zero) return "CACHE-CONTROL: no-cache"; else return String.Format("CACHE-CONTROL: public, max-age={0}", device.CacheLifetime.TotalSeconds); }