public void Handle(SonarrEvent type) { Program.LogMsg($"Waiting lock for {type.EventType} | {typeof(SonarrEvent)}", Discord.LogSeverity.Info, "OnGrab"); Lock.WaitOne(); Program.LogMsg($"Received lock for {type.EventType}", Discord.LogSeverity.Info, "OnGrab"); try { if (type is OnTestSonarrEvent t) { OnTest?.Invoke(this, t); } else if (type is OnGrabSonarrEvent g) { Program.LogMsg($"Invoking event for OnGrab", Discord.LogSeverity.Info, "OnGrab"); Program.LogMsg($"{OnGrab?.GetInvocationList().Length} listeners #4", LogSeverity.Info, "OnGrab"); OnGrab?.Invoke(this, g); } else if (type is OnDownloadSonarrEvent d) { OnDownload?.Invoke(this, d); } } finally { Lock.Release(); Program.LogMsg($"Released lock for {type.EventType}", Discord.LogSeverity.Info, "OnGrab"); } }
private IEnumerator DownloadAsync() { long downloadedSize = 0; for (int i = 0; i < updateKeys.Count; i++) { var downloadSizeHandle = Addressables.GetDownloadSizeAsync(updateKeys[i]); yield return(downloadSizeHandle); long size = downloadSizeHandle.Result; Addressables.Release(downloadSizeHandle); if (size <= 0) { continue; } var downloadHandle = Addressables.DownloadDependenciesAsync(updateKeys[i]); while (downloadHandle.PercentComplete < 1 && !downloadHandle.IsDone) { OnDownload?.Invoke(downloadedSize + (long)(downloadHandle.PercentComplete * size), downloadSize); #if UNITY_EDITOR Debug.Log(string.Format("Download Size: {0}/{1}", downloadedSize + (long)(downloadHandle.PercentComplete * size), downloadSize)); #endif yield return(null); } downloadedSize += size; Addressables.Release(downloadHandle); if (downloadedSize >= downloadSize) { break; } } }
public void Get() { var tdNow = DateTime.Now; string nowFolder = $"{tdNow.Year}-{tdNow.Month:00}-{tdNow.Day:00}-{tdNow.Hour:00}-{tdNow.Minute:00}"; foreach (var myVideo in MyVideos) { IEnumerable <VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(VideoBaseUrl + myVideo.Id); VideoInfo video = videoInfos .First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360); if (video.RequiresDecryption) { DownloadUrlResolver.DecryptDownloadUrl(video); } var savePath = Path.Combine(VideoDownloadDir, nowFolder); if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } var videoDownloader = new VideoDownloader(video, Path.Combine(savePath, GetValidDirectoryName(video.Title + video.VideoExtension))); videoDownloader.DownloadProgressChanged += (sender, args) => { OnDownload?.Invoke(myVideo.Id, args.ProgressPercentage); }; videoDownloader.Execute(); } }
private void DownloadItem_Click(object sender, EventArgs e) { var dialog = new FolderBrowserDialog(); if (dialog.ShowDialog() == DialogResult.OK) { OnDownload?.Invoke(dialog.SelectedPath, item); } }
public override void OnClick(Popup popup, Vector2 mousePosition) { if (needDownload) { needDownload = false; OnDownload?.Invoke(this); } popup.Goto(this, false); }
/// <summary> /// Creates a new instance of an <see cref="AudioPlayer"/> /// </summary> /// <param name="autoPlay">Whether to autoplay media.</param> /// <param name="defaultVolume">Default volume to set. Min-0, Max=1</param> /// <param name="tickIntervalMs">After how many milliseconds to update/call OnPlaying event.</param> public AudioPlayer(bool autoPlay = false, double defaultVolume = 1, double tickIntervalMs = 100) { _autoPlay = autoPlay; _volume = defaultVolume; Timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(tickIntervalMs) }; Timer.Tick += Timer_Tick; MediaPlayer = new MediaPlayer(); MediaPlayer.PlaybackSession.PlaybackStateChanged += (s, e) => OnStateChanged?.Invoke(s); MediaPlayer.MediaEnded += (s, e) => OnMediaEnded?.Invoke(); MediaPlayer.Volume = defaultVolume; MediaPlayer.AutoPlay = autoPlay; MediaPlayer.AudioCategory = MediaPlayerAudioCategory.Media; MediaPlayer.MediaFailed += (s, e) => OnError?.Invoke(e); MediaPlayer.MediaOpened += (s, e) => OnOpened?.Invoke(s.PlaybackSession); MediaPlayer.PlaybackSession.BufferingProgressChanged += (s, e) => OnBuffer?.Invoke(s.BufferingProgress); MediaPlayer.PlaybackSession.DownloadProgressChanged += (s, e) => OnDownload?.Invoke(s.DownloadProgress); }