Пример #1
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Node_Common    node = e.Argument as Node_Common;
            DownloaderInfo info = new DownloaderInfo(m_worker, e, null);

            node.ParsePage(info);
        }
Пример #2
0
        private void DownloadWorker_DoWork(object sender, DoWorkEventArgs workArgs)
        {
            errorFolders.Clear();
            errorSongs.Clear();

            List <Node_Common> downloadNodes = new List <Node_Common>();

            foreach (Node_Common node in (workArgs.Argument as ObservableCollection <Node_Common>))
            {
                downloadNodes.Add(node);
            }

            downloadNodes.Reverse();

            if (m_downloadWorker.CancellationPending)
            {
                workArgs.Cancel = true;
                return;
            }

            ReportProgressPrimary("Starting downloads.", 0);

            Stack <Node_Common> nodesToProcess = new Stack <Node_Common>();

            foreach (Node_Common node in downloadNodes)
            {
                if (m_downloadWorker.CancellationPending)
                {
                    workArgs.Cancel = true;
                    return;
                }

                m_logger.Addtext("Got download node - " + node.Name + " (" + node.URL + ")\n");
                nodesToProcess.Push(node);
            }

            if (m_downloadWorker.CancellationPending)
            {
                workArgs.Cancel = true;
                return;
            }

            double count = 0;
            double total = nodesToProcess.Count;

            while (nodesToProcess.Count > 0)
            {
                Node_Common node = nodesToProcess.Pop();

                if (m_downloadWorker.CancellationPending)
                {
                    workArgs.Cancel = true;
                    return;
                }

                if ((node.NodeType == Node_Common.Type.T_SONG) && (node.IsParsed))
                {
                    Node_Song song = node as Node_Song;
                    m_logger.Addtext("Downloading song - " + song.Name + " (" + song.Mp3Path + ")\n");
                    ReportProgressPrimary("Downloading Song - " + song.Name, 10 + ((count / total) * 90));
                    count++;

                    try
                    {
                        DownloaderInfo info = new DownloaderInfo(m_downloadWorker, workArgs, ReportProgressSecondary);
                        song.Download(m_destinationPath, info);
                        RemoveNodeFromUIList(song);
                    }
                    catch (Exception exp)
                    {
                        AddFailureNode(song, exp.Message);
                        continue;
                    }
                }
                else
                {
                    m_logger.Addtext("Processing subnodes of - " + node.Name + "\n");
                    ReportProgressPrimary("Gathering song list - " + node.Name, 10 + ((count / total) * 90));
                    count++;

                    try
                    {
                        DownloaderInfo info = new DownloaderInfo(m_downloadWorker, workArgs, ReportProgressSecondary);
                        node.ParsePage(info);
                        RemoveNodeFromUIList(node);
                    }
                    catch (Exception exp)
                    {
                        AddFailureNode(node, exp.Message);
                        continue;
                    }

                    if (node.NodeType == Node_Common.Type.T_DIR)
                    {
                        List <Node_Common> subNodes = new List <Node_Common>();
                        foreach (Node_Common subnode in (node as Node_Directory).Children)
                        {
                            if (m_downloadWorker.CancellationPending)
                            {
                                workArgs.Cancel = true;
                                return;
                            }

                            m_logger.Addtext("Added subnode for download - " + subnode.Name + " (" + subnode.URL + ")\n");
                            subNodes.Add(subnode);
                        }

                        subNodes.Reverse();
                        foreach (Node_Common subnode in subNodes)
                        {
                            nodesToProcess.Push(subnode);
                            AddNodeToUIList(subnode);
                        }

                        total += subNodes.Count;
                    }
                    else if (node.NodeType == Node_Common.Type.T_SONG)
                    {
                        m_logger.Addtext("Added song for download - " + node.Name + " (" + (node as Node_Song).Mp3Path + ")\n");
                        nodesToProcess.Push(node);
                        AddNodeToUIList(node);
                        total++;
                    }
                }
            }

            ReportProgressPrimary("Done downloading songs.", 100);
            workArgs.Result = true;
        }