コード例 #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);
        }