コード例 #1
0
        public async void FreeSlot(FreeSlot freeslot)
        {
            Console.WriteLine("[Downloadanager] FreeSlot");

            int downloading = _repo.CountByState(State.Downloading);

            if (downloading >= _maxdownload)
            {
                await _bus.SendAsync <QueueFull> (new QueueFull {
                    Downloading = downloading,
                    MaxDownload = _maxdownload
                });

                return;
            }

            Download waiting;
            bool     dequeued = _repo.FirstByState(State.Waiting, out waiting);

            if (!dequeued)
            {
                await _bus.SendAsync <QueueEmpty> (new QueueEmpty());

                return;
            }

            bool resumed = waiting.TryResume();

            if (!resumed)
            {
                await _bus.SendAsync <DownloadError> (new DownloadError {
                    Id    = waiting.Id,
                    State = waiting.State,
                    Error = ErrorEnum.FreeSlot_InvalidState
                });

                return;
            }
            _repo.Update(waiting);

            var queuedownload = new QueueDownload {
                Download = waiting
            };
            await _bus.SendAsync <QueueDownload> (queuedownload);
        }
コード例 #2
0
        public void QueueDownload_Received(QueueDownload queuedownload)
        {
            Console.WriteLine("[NSUrlSessionManager] QueueDownload");

            var download = queuedownload.Download;

            Console.WriteLine("[NSUrlSessionManager] QueueDownload Url           : {0}", download.Url);
            Console.WriteLine("[NSUrlSessionManager] QueueDownload Total         : {0}", download.Total);
            Console.WriteLine("[NSUrlSessionManager] QueueDownload Written       : {0}", download.Written);
            Console.WriteLine("[NSUrlSessionManager] QueueDownload DownloadState : {0}", download.DownloadState);
            Console.WriteLine("[NSUrlSessionManager] QueueDownload State         : {0}", download.State);
            Console.WriteLine("[NSUrlSessionManager] QueueDownload LastModified  : {0}", download.LastModified);

            NSUrlSession.GetTasks2((dataTasks, uploadTasks, downloadTasks) => {
                int free = _maxdownloads - downloadTasks.Length;

                Console.WriteLine("[NSUrlSessionManager] QueueDownload GetTasks2");
                Console.WriteLine("[NSUrlSessionManager] QueueDownload GetTasks2 Maxdownloads : {0}", _maxdownloads);
                Console.WriteLine("[NSUrlSessionManager] QueueDownload GetTasks2 Length       : {0}", downloadTasks.Length);
                Console.WriteLine("[NSUrlSessionManager] QueueDownload GetTasks2 Free         : {0}", free);

                if (free <= 0)
                {
                    _bus.SendAsync <DownloadRejected> (new DownloadRejected {
                        Id     = download.Id,
                        Reason = RejectionEnum.QueueFull
                    });
                    return;
                }

                using (var url = NSUrl.FromString(download.Url))
                    using (var request = NSUrlRequest.FromUrl(url)) {
                        var task             = NSUrlSession.CreateDownloadTask(request);
                        task.TaskDescription = download.Id.ToString();
                        task.Resume();
                    }
            });
        }