Пример #1
0
        public void RunPoller()
        {
            if (downloadPollerTask == null || downloadPollerTask.IsCompleted)
            {
                downloadPollerTask = Task.Run(async() =>
                {
                    while (HasWork())
                    {
                        try
                        {
                            await Task.Delay(1000);

                            DownloadHelper helper;
                            if (!string.IsNullOrWhiteSpace(currentId) && downloads.TryGetValue(currentId, out helper))
                            {
                                if (helper.State == DownloadHelper.DownloadState.Canceled)
                                {
                                    continue;
                                }
                                if (helper.State == DownloadHelper.DownloadState.Downloading)
                                {
                                    continue;
                                }
                                if (helper.State != DownloadHelper.DownloadState.Completed)
                                {
                                    await helper.StartDownload();
                                    continue;
                                }
                            }
                            var next = downloads.FirstOrDefault();
                            if (string.IsNullOrWhiteSpace(next.Key))
                            {
                                continue;
                            }
                            helper = next.Value;
                            if (helper.State == DownloadHelper.DownloadState.Canceled)
                            {
                                continue;
                            }
                            if (helper.State == DownloadHelper.DownloadState.Downloading)
                            {
                                continue;
                            }
                            if (helper.State != DownloadHelper.DownloadState.Completed)
                            {
                                await helper.StartDownload();
                            }
                        }
                        catch (Exception ex)
                        {
                            LogManager.Shared.Report(ex);
                        }
                    }
                });
            }
        }
Пример #2
0
        public void StopAllOthers(Song song)
        {
            var first = playerQueue.FirstOrDefault();

            if (first.Key != song.Id && !string.IsNullOrWhiteSpace(first.Key))
            {
                playerQueue.Remove(first.Key);
            }
            var items = playerQueue.ToList();

            foreach (var item in items)
            {
                if (item.Key != song.Id)
                {
                    item.Value.Stop();
                }
            }
        }