private async Task <TransportCommands> GetRenderingProtocolAsync(CancellationToken cancellationToken) { var rendererCommands = RendererCommands; if (rendererCommands != null) { return(rendererCommands); } if (_disposed) { throw new ObjectDisposedException(GetType().Name); } var avService = GetServiceRenderingControl(); if (avService == null) { throw new ArgumentException("Device AvService is null"); } string url = NormalizeUrl(Properties.BaseUrl, avService.ScpdUrl); var httpClient = new SsdpHttpClient(_httpClient, _config); _logger.LogDebug("Dlna Device.GetRenderingProtocolAsync"); var document = await httpClient.GetDataAsync(url, cancellationToken).ConfigureAwait(false); rendererCommands = TransportCommands.Create(document); RendererCommands = rendererCommands; return(rendererCommands); }
private async Task <TransportCommands> GetAVProtocolAsync(CancellationToken cancellationToken) { var avCommands = AvCommands; if (avCommands != null) { return(avCommands); } if (_disposed) { throw new ObjectDisposedException(GetType().Name); } var avService = GetAvTransportService(); if (avService == null) { return(null); } string url = NormalizeUrl(Properties.BaseUrl, avService.ScpdUrl); var httpClient = new SsdpHttpClient(_httpClient, _config); var document = await httpClient.GetDataAsync(url, cancellationToken).ConfigureAwait(false); avCommands = TransportCommands.Create(document); AvCommands = avCommands; return(avCommands); }
private async Task GetRenderingProtocolAsync() { var avService = GetServiceRenderingControl(); if (avService == null) { return; } string url = NormalizeUrl(Properties.BaseUrl, avService.ScpdUrl); var httpClient = new SsdpHttpClient(_httpClient, _config); var document = await httpClient.GetDataAsync(url).ConfigureAwait(false); RendererCommands = TransportCommands.Create(document); }
private async Task GetAVProtocolAsync() { if (_disposed) { return; } var avService = GetAvTransportService(); if (avService == null) { return; } string url = NormalizeUrl(Properties.BaseUrl, avService.ScpdUrl); var httpClient = new SsdpHttpClient(_httpClient, _config); var document = await httpClient.GetDataAsync(url).ConfigureAwait(false); AvCommands = TransportCommands.Create(document); }
public static async Task <Device> CreateuPnpDeviceAsync(Uri url, IHttpClient httpClient, IServerConfigurationManager config, ILogger logger, ITimerFactory timerFactory, CancellationToken cancellationToken) { var ssdpHttpClient = new SsdpHttpClient(httpClient, config); var document = await ssdpHttpClient.GetDataAsync(url.ToString(), cancellationToken).ConfigureAwait(false); var deviceProperties = new DeviceInfo(); var friendlyNames = new List <string>(); var name = document.Descendants(uPnpNamespaces.ud.GetName("friendlyName")).FirstOrDefault(); if (name != null && !string.IsNullOrWhiteSpace(name.Value)) { friendlyNames.Add(name.Value); } var room = document.Descendants(uPnpNamespaces.ud.GetName("roomName")).FirstOrDefault(); if (room != null && !string.IsNullOrWhiteSpace(room.Value)) { friendlyNames.Add(room.Value); } deviceProperties.Name = string.Join(" ", friendlyNames.ToArray()); var model = document.Descendants(uPnpNamespaces.ud.GetName("modelName")).FirstOrDefault(); if (model != null) { deviceProperties.ModelName = model.Value; } var modelNumber = document.Descendants(uPnpNamespaces.ud.GetName("modelNumber")).FirstOrDefault(); if (modelNumber != null) { deviceProperties.ModelNumber = modelNumber.Value; } var uuid = document.Descendants(uPnpNamespaces.ud.GetName("UDN")).FirstOrDefault(); if (uuid != null) { deviceProperties.UUID = uuid.Value; } var manufacturer = document.Descendants(uPnpNamespaces.ud.GetName("manufacturer")).FirstOrDefault(); if (manufacturer != null) { deviceProperties.Manufacturer = manufacturer.Value; } var manufacturerUrl = document.Descendants(uPnpNamespaces.ud.GetName("manufacturerURL")).FirstOrDefault(); if (manufacturerUrl != null) { deviceProperties.ManufacturerUrl = manufacturerUrl.Value; } var presentationUrl = document.Descendants(uPnpNamespaces.ud.GetName("presentationURL")).FirstOrDefault(); if (presentationUrl != null) { deviceProperties.PresentationUrl = presentationUrl.Value; } var modelUrl = document.Descendants(uPnpNamespaces.ud.GetName("modelURL")).FirstOrDefault(); if (modelUrl != null) { deviceProperties.ModelUrl = modelUrl.Value; } var serialNumber = document.Descendants(uPnpNamespaces.ud.GetName("serialNumber")).FirstOrDefault(); if (serialNumber != null) { deviceProperties.SerialNumber = serialNumber.Value; } var modelDescription = document.Descendants(uPnpNamespaces.ud.GetName("modelDescription")).FirstOrDefault(); if (modelDescription != null) { deviceProperties.ModelDescription = modelDescription.Value; } deviceProperties.BaseUrl = string.Format("http://{0}:{1}", url.Host, url.Port); var icon = document.Descendants(uPnpNamespaces.ud.GetName("icon")).FirstOrDefault(); if (icon != null) { deviceProperties.Icon = CreateIcon(icon); } foreach (var services in document.Descendants(uPnpNamespaces.ud.GetName("serviceList"))) { if (services == null) { continue; } var servicesList = services.Descendants(uPnpNamespaces.ud.GetName("service")); if (servicesList == null) { continue; } foreach (var element in servicesList) { var service = Create(element); if (service != null) { deviceProperties.Services.Add(service); } } } var device = new Device(deviceProperties, httpClient, logger, config, timerFactory); return(device); }