// DoWork event handler for the file download BackgroundWorker. // The selected TreeNode (either a module, folder, or file) is passed in the DoWorkEventArgs e private void DownloadBW_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; TreeNode selectedNode = e.Argument as TreeNode; scraper.DownloadProgress.BeginJob(worker); // -- DETERMINE TYPE OF NODE SELECTED -- // Module selected if (selectedNode.Tag.GetType() == typeof(BbModule)) { BbModule module = selectedNode.Tag as BbModule; scraper.DownloadProgress.TotalWork = module.Content.CountAllFiles(); scraper.DownloadModuleFiles(module); } // Single folder selected else if (selectedNode.Tag.GetType() == typeof(BbContentDirectory)) { BbContentDirectory folder = selectedNode.Tag as BbContentDirectory; scraper.DownloadProgress.TotalWork = folder.CountAllFiles(); scraper.DownloadFolder(folder, scraper.OutputDirectory + BbUtils.CleanDirectory(folder.Name) + @"\"); } // Single file selected else if (selectedNode.Tag.GetType() == typeof(BbContentItem)) { BbContentItem file = selectedNode.Tag as BbContentItem; scraper.DownloadProgress.TotalWork = 1; scraper.DownloadFile(file); } }
// Event Handler for the content treeview. Changes information displayed private void contentTree_AfterSelect(object sender, TreeViewEventArgs e) { ClearInfoBox(); // Change what's displayed in the Information Box depending on type of node selected // File selected if (contentTree.SelectedNode.Tag.GetType() == typeof(BbContentItem)) { BbContentItem file = contentTree.SelectedNode.Tag as BbContentItem; infoLabel1.Text = "Name"; infoText1.Text = file.Name; infoLabel2.Text = "Filename"; infoText2.Text = file.Filename; infoLabel3.Text = "Link Type"; infoText3.Text = file.LinkType; infoLabel4.Text = "URL"; infoTextLink.Text = file.Url.AbsoluteUri; } // Folder selected else if (contentTree.SelectedNode.Tag.GetType() == typeof(BbContentDirectory)) { BbContentDirectory folder = contentTree.SelectedNode.Tag as BbContentDirectory; infoLabel1.Text = "Name"; infoText1.Text = folder.Name; infoLabel2.Text = "Files"; infoText2.Text = folder.CountAllFiles().ToString(); infoLabel3.Text = "Subfolders"; infoText3.Text = folder.SubFolders.Count.ToString(); infoLabel4.Text = "URL"; infoTextLink.Text = folder.Url.AbsoluteUri; } // Module selected else if (contentTree.SelectedNode.Tag.GetType() == typeof(BbModule)) { BbModule module = contentTree.SelectedNode.Tag as BbModule; infoLabel1.Text = "Name"; infoText1.Text = module.Name; infoLabel2.Text = "Files"; infoText2.Text = module.Content.CountAllFiles().ToString(); infoLabel3.Text = "Subfolders"; infoText3.Text = module.Content.SubFolders.Count.ToString(); infoLabel4.Text = "URL"; infoTextLink.Text = module.Url.AbsoluteUri; } }