/// <summary> /// Devices the found asynchronous. /// </summary> /// <param name="sender">The sender.</param> /// <param name="device">The device.</param> /// <returns></returns> private async void DeviceFoundAsync(object sender, DLNADescription device) { if (device == null || device.X_device == null) { return; } var baseUri = new Uri(device.X_device.X_URLBase); var info = await this.GetDeviceInfo(baseUri).ConfigureAwait(false); await this.GetNetworkStatus(baseUri).ConfigureAwait(false); var location = await this.GetDeviceLocationInfoAsync(baseUri).ConfigureAwait(false); var distributionInfo = await this.GetDistributionInfoAsync(baseUri).ConfigureAwait(false); foreach (var zone in location.zone_list.ValidZones) { var status = await this.GetDeviceStatusAsync(baseUri, zone).ConfigureAwait(false); var friendlyName = distributionInfo.client_list.Count() > 0 ? distributionInfo.group_name : string.Empty; if (string.IsNullOrEmpty(friendlyName)) { var temp = await this.GetDeviceZoneFriendlyNameAsync(baseUri, zone).ConfigureAwait(false); friendlyName = temp.text; } var convertedModel = ConvertApiDeviceToDevice(baseUri, zone, friendlyName, device, status, info); if (status.input == Inputs.tuner) { var tuner = await this.GetTunerPlayInfoAsync(baseUri).ConfigureAwait(false); convertedModel.NowPlayingInformation = tuner.NowPlayingSummary; } if (DeviceFound != null) { DeviceFound(this, convertedModel); } } }
/// <summary> /// Renders the device asynchronous. /// </summary> /// <param name="location">The location.</param> /// <returns></returns> private async Task <DLNADescription> RenderDeviceAsync(string location) { try { XmlSerializer reader = new XmlSerializer(typeof(DLNADescription)); using (var client = _httpClientFactory.CreateClient()) { var stream = await client.GetStreamAsync(location).ConfigureAwait(false); StreamReader file = new StreamReader(stream); DLNADescription device = (DLNADescription)reader.Deserialize(file); file.Close(); device.Location = location; return(device); } } catch (Exception e) { Debug.WriteLine(e); return(null); } }
/// <summary> /// Converts the API device to device. /// </summary> /// <param name="baseUri">The base URI.</param> /// <param name="zone">The zone.</param> /// <param name="device">The device.</param> /// <param name="status">The status.</param> /// <param name="info">The information.</param> /// <returns></returns> private MusicCastDevice ConvertApiDeviceToDevice(Uri baseUri, string zone, string friendlyName, DLNADescription device, GetStatusResponse status, GetDeviceInfoResponse info) { return(new MusicCastDevice() { Id = info.device_id, BaseUri = baseUri, Zone = zone, ModelName = info.model_name, FriendlyName = friendlyName, Location = (device.Location), ImagePath = (device.device.iconList.Last().url), ImageSize = device.device.iconList.Last().width, Power = status.power, Input = (status.input) }); }