// Searches for content within module m and adding it. public void PopulateModuleContent(BbModule m) { populateProgress.ReportStatus("Populating content for " + m.Name); try { if (!m.Initialized) { CreateMainContentDirectory(m); } PopulateContentDirectory(m.Content); } catch (Exception e) { populateProgress.ReportStatus("Error populating content for module: " + m.Name); populateProgress.ReportError("Error populating content for module: " + m.Name); log.Write("Content population error for: " + m.Name); log.WriteException(e); log.Write(e.StackTrace); } }
// Downloads a BbContentItem file and saves it to directory. public void DownloadFile(BbContentItem file, string directory) { string shortDir = directory.Substring(outputDirectory.Length, directory.Length - outputDirectory.Length); try { if (file.LinkType == "onedrive") { file.Url = OneDriveURL(file.Url); } if (file.LinkType == "dropbox") { file.Url = DropboxURL(file.Url); } else if (file.LinkType == "website") { log.Write("Linking to website " + file.Url.AbsoluteUri); downloadProgress.ReportStatus("Creating shortcut: " + shortDir + file.Name + file.Url.AbsoluteUri); CreateUrlShortcut(file, directory); return; } else if (file.LinkType == "email") { return; // Don't try to download e-mail } downloadProgress.ReportStatus("Downloading file (" + file.LinkType + "): " + shortDir + file.Name); Directory.CreateDirectory(directory); //Create directory if it doesn't exist already DetectFileName(file); http.DownloadFile(file.Url.AbsoluteUri, directory + file.Filename); } catch (WebException e) { log.WriteException(e); log.Write("ERROR: Cannot download file " + file); log.Write(shortDir); downloadProgress.ReportError("ERROR: Cannot download file " + file); } downloadProgress.IncWorkCounter(); }