예제 #1
0
        private void OnDownloaderDoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker     = sender as BackgroundWorker;
            TaskParameters2  parameters = e.Argument as TaskParameters2;

            using (WebClient client = new WebClient())
            {
                for (int i = 0; i < parameters.TotalCount; i++)
                {
                    TaskNode node = parameters.TaskNodes[i];
                    node.State = TaskNodeState.Downloading;
                    worker.ReportProgress(0, node);
                    string path = Program.GetLocalPath(node.Source, parameters.Destination);

                    if (Program.Download(client, node.Source, path))
                    {
                        node.State = TaskNodeState.Completed;
                    }
                    else
                    {
                        node.State = TaskNodeState.Failed;
                    }
                    worker.ReportProgress(0, node);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Initialize the task parameters, call before the form is loaded
        /// </summary>
        public void InitializeParameters(string[] sources, string destination)
        {
            Parameters = new TaskParameters2();

            int it = 0;
            foreach (var item in sources)
            {
                if (IsAvailableSource(item))
                {
                    TaskNode node = new TaskNode()
                    {
                        Index = it,
                        Source = item,
                        State = TaskNodeState.Ready
                    };
                    Parameters.TaskNodes.Add(node);
                    it++;
                }
            }

            Parameters.Destination = destination;
            Parameters.TotalCount = Parameters.TaskNodes.Count;
        }
예제 #3
0
        /// <summary>
        /// Initialize the task parameters, call before the form is loaded
        /// </summary>
        public void InitializeParameters(string[] sources, string destination)
        {
            Parameters = new TaskParameters2();

            int it = 0;

            foreach (var item in sources)
            {
                if (IsAvailableSource(item))
                {
                    TaskNode node = new TaskNode()
                    {
                        Index  = it,
                        Source = item,
                        State  = TaskNodeState.Ready
                    };
                    Parameters.TaskNodes.Add(node);
                    it++;
                }
            }

            Parameters.Destination = destination;
            Parameters.TotalCount  = Parameters.TaskNodes.Count;
        }