/// <summary> /// Services the device found asynchronous. /// </summary> /// <param name="sender">The sender.</param> /// <param name="device">The device.</param> private async void Service_DeviceFoundAsync(object sender, MusicCastDevice device) { await DispatcherHelper.ExecuteOnUIThreadAsync(() => { IsLoading = false; if (Devices.Where(w => w != null).Select(s => s.Id).Contains(device.Id)) { return; } Devices.Add(new Device() { Id = device.Id, BaseUri = device.BaseUri.ToString(), Zone = device.Zone, FriendlyName = device.FriendlyName, ImageUri = UriHelper.ResolvePath(device.Location, device.ImagePath), ImageSize = device.ImageSize, Power = device.Power, Input = device.Input.ToString(), SubTitle = device.NowPlayingInformation, IsAlive = true }); }); await SaveDevicesInStorageAsync(Devices.ToList()).ConfigureAwait(false); }
/// <summary> /// Refreshes the device asynchronous. /// </summary> /// <param name="id">The identifier.</param> /// <param name="baseUri">The base URI.</param> /// <param name="zone">The zone.</param> /// <returns></returns> public async Task <MusicCastDevice> RefreshDeviceAsync(string id, Uri baseUri, string zone) { try { var status = await this.GetDeviceStatusAsync(baseUri, zone).ConfigureAwait(false); var distributionInfo = await this.GetDistributionInfoAsync(baseUri).ConfigureAwait(false); var temp = new MusicCastDevice() { Id = id, Power = status.power, Input = (status.input), Volume = status.volume, MaxVolume = status.max_volume }; if (status.input == Inputs.tuner) { var tuner = await this.GetTunerPlayInfoAsync(baseUri).ConfigureAwait(false); temp.NowPlayingInformation = tuner.NowPlayingSummary; } else { var tuner = await this.GetNetRadioInfoAsync(baseUri).ConfigureAwait(false); temp.NowPlayingInformation = tuner.NowPlayingSummary; } if (distributionInfo.client_list.Count > 0 && !string.IsNullOrEmpty(distributionInfo.group_name)) { temp.FriendlyName = distributionInfo.group_name; } return(temp); } catch (Exception) { return(null); } }