private void HandleToastActivatedEvent(object sender, object e) { RpToastNotificationActivatedEventArgs rpEvent; try { ToastActivatedEventArgs myEvent = (ToastActivatedEventArgs)e; rpEvent = JsonConvert .DeserializeObject <RpToastNotificationActivatedEventArgs>( JsonConvert.SerializeObject(myEvent) ); _log.Information(LogHelper.GetMethodName(this), "{ eventArguments}", rpEvent.Arguments); QueryString args = QueryString.Parse(rpEvent.Arguments); if (args["action"] == "LoginRequested") { ShowLoginToast(); } else if (args["action"] == "LoginDataSent") { var usr = rpEvent.UserInput["Username"]; var pwd = rpEvent.UserInput["Password"]; var response = _apiHandler.GetAuth(usr, pwd); LoginResponseToast(response); if (response.Status == "success") { Application.Restart(); } } else if (args["action"] == "RateSubmitted") { if (Int32.TryParse(rpEvent.UserInput["UserRate"], out int userRate) && 1 <= userRate && userRate <= 10 && Int32.TryParse(args["SongId"], out int songId)) { var ratingResponse = _apiHandler.GetRating(songId.ToString(), userRate); if (ratingResponse.Status == "success") { _config.State.Playback = new Playback(_apiHandler.GetNowplayingList()); } } } } catch (Exception ex) { _log.Error(LogHelper.GetMethodName(this), ex); } }
private void UpdateSongInfo() { string player_id = _config.IsRpPlayerTrackingChannel() ? _config.State.RpTrackingConfig.ActivePlayerId : null; var logMessageDetail = !string.IsNullOrEmpty(player_id) ? $"Player_ID: {player_id}" : $"Channel: {_config.ExternalConfig.Channel.ToString()}"; _log.Information(LogHelper.GetMethodName(this), $"Invoked - {logMessageDetail}"); var oldPlayback = _config.State.Playback; var nowPlayingList = _apiHandler.GetNowplayingList(); _config.State.Playback = new Playback(nowPlayingList); _log.Information(LogHelper.GetMethodName(this), "RP API call returned successfully - SongId: {@songId}", _config.State.Playback.SongInfo.SongId); // Update class attributes if (oldPlayback == null || _config.State.Playback.SongInfo.SongId != oldPlayback.SongInfo.SongId) { if (!_config.State.Playback.SameSongOnlyInternalUpdate) { _log.Information(LogHelper.GetMethodName(this), "New song - Start downloading album art - Song info: {@Songdata}", _config.State.Playback.SongInfo); // Download album art var tempFileName = $"{_config.StaticConfig.AlbumArtImagePath}.inprogress"; using (WebClient client = new WebClient()) { Retry.Do(() => { client.DownloadFile(new Uri($"{_config.StaticConfig.RpImageBaseUrl}/{_config.State.Playback.SongInfo.Cover}"), tempFileName); }, 500, 5); } if (File.Exists(_config.StaticConfig.AlbumArtImagePath)) { File.Delete(_config.StaticConfig.AlbumArtImagePath); } File.Move(tempFileName, _config.StaticConfig.AlbumArtImagePath); _log.Information(LogHelper.GetMethodName(this), "Albumart downloaded - Song expires: {@RefreshTimestamp} ({ExpirySeconds} seconds)", _config.State.Playback.SongInfoExpiration.ToString(), _config.State.Playback.NowplayingList.Refresh); } else { var newRatinText = _config.State.Playback.SongInfo.Rating != oldPlayback.SongInfo.Rating ? $" - New rating: {_config.State.Playback.SongInfo.Rating}" : null; var newExpirationText = _config.State.Playback.SongInfoExpiration != _config.State.Playback.SongInfoExpiration ? $" - New expiration: {_config.State.Playback.SongInfoExpiration.ToString()}" : null; _log.Information(LogHelper.GetMethodName(this), $"Same song - Only properties changed{newRatinText}{newExpirationText}"); } } else { _log.Information(LogHelper.GetMethodName(this), $"Same song: albumart and expiration is not updated - Seconds left: {nowPlayingList.Refresh}"); } _log.Information(LogHelper.GetMethodName(this), "Finished"); }