Exemplo n.º 1
0
 private void RemoveTask(DownloadTaskControl downloadTaskControl)
 {
     Controls.Remove(downloadTaskControl);
     _taskerList.Remove(downloadTaskControl);
     downloadTaskControl.Dispose();
     GC.Collect();
 }
Exemplo n.º 2
0
        private void UpdateTaskPosition()
        {
            SuspendLayout();
            for (Int32 id = 0; id < _taskerList.Count; id++)
            {
                DownloadTaskControl item = _taskerList[id];
                item.Location = new Point(id < 3 ? 0 : item.Size.Width, id % 3 * item.Size.Height);
            }

            ResumeLayout();
        }
Exemplo n.º 3
0
        private void AddRequest(DownloadRequest request)
        {
            if (CurrentTasks >= MaximumTasks)
            {
                DownloadTaskControl completedTask = _taskerList.FirstOrDefault(TaskRemovable);

                if (completedTask == null)
                {
                    return;
                }

                RemoveTask(completedTask);
            }

            AddDownloadTaskControl(request);
            _form.RemoveRequest(request);
        }
Exemplo n.º 4
0
        public void AddDownloadTaskControl(DownloadRequest downloadRequest = null)
        {
            if (CurrentTasks >= MaximumTasks)
            {
                if (downloadRequest != null)
                {
                    _form.AddRequest(downloadRequest);
                }

                return;
            }

            downloadRequest ??= new DownloadRequest(String.Empty, Globals.CurrentDownloadPath, false);
            SuspendLayout();
            DownloadTaskControl downloadTaskControl = new DownloadTaskControl(downloadRequest)
            {
                Size = new Size(LayoutGUI.DownloadTaskControlWidth, LayoutGUI.DownloadTaskControlHeight)
            };

            downloadTaskControl.Completed += () =>
            {
                if (Globals.QueueAutoDownload.GetValue() && _form.GetRequests().Any())
                {
                    downloadTaskControl.Close();
                }
            };
            downloadTaskControl.NeedClosing += () =>
            {
                RemoveTask(downloadTaskControl);
            };
            downloadTaskControl.NeedClosing += () =>
            {
                List <Object>          invalidRequests = new List <Object>();
                List <DownloadRequest> requests        = new List <DownloadRequest>();
                foreach (Object obj in _form.GetRequests())
                {
                    if (!(obj is DownloadRequest request))
                    {
                        invalidRequests.Add(obj);
                        continue;
                    }

                    if (requests.Count < MaximumTasks - CurrentTasks)
                    {
                        requests.Add(request);
                    }
                }

                foreach (Object obj in invalidRequests)
                {
                    _form.RemoveRequest(obj);
                }

                foreach (DownloadRequest request in requests.TakeWhile(request => CurrentTasks < MaximumTasks))
                {
                    _form.RemoveRequest(request);
                    AddDownloadTaskControl(request);
                }

                if (Globals.APIKey.IsValid && CurrentTasks <= 0)
                {
                    AddDownloadTaskControl();
                }
            };
            AddTask(downloadTaskControl);

            ResumeLayout();
        }
Exemplo n.º 5
0
 private static Boolean TaskRemovable(DownloadTaskControl task)
 {
     return(task.Task?.IsCompleted == true && task.IsFullDownload ||
            task.Task?.IsStarted != true && task.EmptySearchRequest);
 }
Exemplo n.º 6
0
 private void UpdateTaskPosition(ref DownloadTaskControl control)
 {
     UpdateTaskPosition();
 }
Exemplo n.º 7
0
 private void AddTask(DownloadTaskControl downloadTaskControl)
 {
     _taskerList.Add(downloadTaskControl);
     Controls.Add(downloadTaskControl);
 }