//Zkratka pro vyvolání údalosti při chybě private void CallError(string message) { State = States.Error; operation.Post(new SendOrPostCallback(delegate(object state) { OnDownloadError?.Invoke(this, message); }), null); }
private void NetworkStateChanged(Object sender, ConnectivityChangedEventArgs e) { OnDownloadError.Invoke(this, e); if (!_webClient.IsBusy && e.NetworkAccess == Xamarin.Essentials.NetworkAccess.Internet) { _webClient.DownloadFileAsync(new Uri(url), pathToNewFile); } }
/// <summary> /// 根据解析出来的模型进行下载 /// </summary> /// <param name="basicModel"></param> /// <returns></returns> public async Task <bool> DownloadAsync(BasicMusicInfoModel basicModel) { return(await Task.Run(async() => { var obj = (QqMusicInfoModel)basicModel; try { OnBeforeDownload?.Invoke($"{basicModel.SongName}_{basicModel.SingerName}"); var vkeyInfo = await GetVkeyInfo(obj.SongId, obj.MediaMid); var url = new Uri(string.Format(_downloadUrl, obj.MediaMid, vkeyInfo.data.items[0].vkey)); var saveName = $"{obj.SongName}_{obj.SingerName}"; await _requests.SaveFileAsync(url, $"{saveName}.m4a"); OnAfterDownload?.Invoke($"{basicModel.SongName}_{basicModel.SingerName}"); return true; } catch (Exception e) { OnDownloadError?.Invoke(e, $"{basicModel.SongName}_{basicModel.SingerName}"); return false; } })); }
private void OnError(ResultCode code) { OnDownloadError?.Invoke(code); }