protected virtual void visitStudentModuleResourceDownloadsInFormat(OuStudentModule ouStudentModule, String formatName, String formatUriString) { if (cancellationRequestedChecker()) { return; } log.WriteLine("Inspecting module resource downloads in format: {0}", (Object)(formatName)); XmlDocument xmlDocument = ouSignedInWebSession.get(formatUriString); if (null == xmlDocument) { log.WriteLine("Error: failed to download: {0}", formatUriString); return; } xmlDocument.preserve(ouStudentModule.name + "_resource_downloads_in_" + formatName + ".xml"); visitStudentModuleResourceDownloadsInFormat(ouStudentModule, formatName, xmlDocument); }
protected virtual void visitStudentModuleResourceDownloads(OuStudentModule ouStudentModule, String downloadsUri) { if (cancellationRequestedChecker()) { return; } log.WriteLine("Inspecting module resource downloads"); XmlDocument xmlDocument = ouSignedInWebSession.get(downloadsUri); if (null == xmlDocument) { log.WriteLine("Error: failed to download: {0}", downloadsUri); return; } xmlDocument.preserve(ouStudentModule.name + "_resource_downloads.xml"); visitStudentModuleResourceDownloads(ouStudentModule, xmlDocument); }
protected virtual void visitStudentModuleResources(OuStudentModule ouStudentModule, XmlDocument xmlDocument) { if (cancellationRequestedChecker()) { return; } XmlNode downloadsAXmlNode = xmlDocument.SelectSingleNode(".//a[normalize-space(./span/span/span/text())='Downloads' and @href]"); if (null == downloadsAXmlNode) { onCouldNotLocateDownloadsLink(ouStudentModule); return; } String downloadsUri = downloadsAXmlNode.Attributes["href"].Value; using (new WritingIndentation(log)) { visitStudentModuleResourceDownloads(ouStudentModule, downloadsUri); } }
protected override void visitStudentModule(OuStudentModule ouStudentModule, XmlDocument xmlDocument) { if (cancellationRequestedChecker()) { return; } XmlNode resourcesAXmlNode = xmlDocument.SelectSingleNode(".//a[normalize-space(text())='Resources' and @href]"); if (null == resourcesAXmlNode) { onCouldNotLocateResourcesLink(ouStudentModule); return; } String resourcesUri = resourcesAXmlNode.Attributes["href"].Value; using (new WritingIndentation(log)) { visitStudentModuleResources(ouStudentModule, resourcesUri); } }
protected virtual void visitStudentModuleResourceDownloads(OuStudentModule ouStudentModule, XmlNodeList aXmlNodeList) { if (cancellationRequestedChecker()) { return; } using (new WritingIndentation(log)) { foreach (XmlNode aXmlNode in aXmlNodeList) { if (cancellationRequestedChecker()) { return; } String formatUriString = aXmlNode.Attributes["href"].Value; String formatName = aXmlNode.InnerText.Trim(); visitStudentModuleResourceDownloadsInFormat(ouStudentModule, formatName, formatUriString); } } }
protected virtual void visitStudentModuleResourceMediaDownloads(OuStudentModule ouStudentModule, XmlDocument xmlDocument) { if (cancellationRequestedChecker()) { return; } XmlNode mediaDownloadsUlXmlNode = xmlDocument.SelectSingleNode(".//h3[normalize-space(text())='Media downloads']/following-sibling::ul"); if (null == mediaDownloadsUlXmlNode) { onCouldNotLocateMediaDownloadsList(ouStudentModule); return; } XmlNodeList aXmlNodeList = mediaDownloadsUlXmlNode.SelectNodes(".//li//a[@href]"); if (0 == aXmlNodeList.Count) { onNoMediaFormatsAvailable(ouStudentModule); return; } visitStudentModuleResourceDownloads(ouStudentModule, aXmlNodeList); }
protected virtual void visitStudentModule(OuStudentModule ouStudentModule) { if (cancellationRequestedChecker()) { return; } log.WriteLine("Inspecting module: {0}", ouStudentModule); String uri = String.Format(moduleHomePatternUriString, ouStudentModule.shortName); try { XmlDocument xmlDocument = ouSignedInWebSession.get(uri); if (null == xmlDocument) { log.WriteLine("Error: failed to download: {0}", uri); return; } xmlDocument.preserve(ouStudentModule.name + ".xml"); visitStudentModule(ouStudentModule, xmlDocument); } catch (Exception exception) { log.WriteLine("Unable to access module: {0}, exception: {1}", ouStudentModule.shortName, exception); } }
protected override void visitStudentModuleResourceDownloadsInFormat(OuStudentModule ouStudentModule, String formatName, XmlDocument xmlDocument) { if (cancellationRequestedChecker()) { return; } XmlNodeList trXmlNodeList = xmlDocument.SelectNodes(".//table/tbody/tr"); if (0 == trXmlNodeList.Count) { onNoFilesAvailable(ouStudentModule, formatName); return; } using (new WritingIndentation(log)) { foreach (XmlNode trXmlNode in trXmlNodeList) { if (cancellationRequestedChecker()) { return; } visitStudentModuleResourceDownloadFile(ouStudentModule, formatName, trXmlNode); } } }
protected abstract void visitStudentModule(OuStudentModule ouStudentModule, XmlDocument xmlDocument);
protected virtual void onCouldNotLocateDownloadsLink(OuStudentModule ouStudentModule) { log.WriteLine("Error: could not locate 'Downloads' link"); }
protected virtual void onNoDocumentFormatsAvailable(OuStudentModule ouStudentModule) { Console.Out.WriteLine("Note: no document formats available"); }
protected abstract void visitStudentModuleResourceDownloadsInFormat(OuStudentModule ouStudentModule, String formatName, XmlDocument xmlDocument);
protected virtual void onNoMediaFormatsAvailable(OuStudentModule ouStudentModule) { Console.Out.WriteLine("Note: no media formats available"); }
protected virtual void onCouldNotLocateMediaDownloadsList(OuStudentModule ouStudentModule) { log.WriteLine("Warning: could not locate 'Media downloads' format list"); }
protected virtual void onNoFilesAvailable(OuStudentModule ouStudentModule, String formatName) { Console.Out.WriteLine("Note: no files available"); }
protected virtual void onCouldNotLocateResourcesLink(OuStudentModule ouStudentModule) { log.WriteLine("Error: could not locate 'Resources' link"); }
protected virtual void visitStudentModuleResourceDownloadFile(OuStudentModule ouStudentModule, String formatName, XmlNode trXmlNode) { if (cancellationRequestedChecker()) { return; } XmlNode uriAXmlNode = trXmlNode.SelectSingleNode("./td[2]//a[@href]"); if (null == uriAXmlNode) { log.WriteLine("Error: link missing"); return; } String name = uriAXmlNode.InnerText.Trim(); if (String.IsNullOrWhiteSpace(name)) { log.WriteLine("Error: name missing"); return; } XmlNode sizeTdXmlNode = trXmlNode.SelectSingleNode("./td[3]"); String sizeString = (null == sizeTdXmlNode) ? null : sizeTdXmlNode.InnerText.Trim(); if (String.IsNullOrWhiteSpace(sizeString)) { log.WriteLine("Error: size missing"); return; } long size; if (!SiByteMultiples.tryParse(sizeString, out size)) { log.WriteLine("Error: size invalid"); return; } XmlNode locationTdXmlNode = trXmlNode.SelectSingleNode("./td[4]"); String location = (null == locationTdXmlNode) ? null : locationTdXmlNode.InnerText.Trim(); if (String.IsNullOrWhiteSpace(location)) { // note: not all entries have locations location = null; } Uri downloadUri = new Uri(uriAXmlNode.Attributes["href"].Value); if (!hasFinalResourceDownloadExtension(downloadUri)) { downloadUri = ouSignedInWebSession.hit(downloadUri); } findings.getValueOrNew(ouStudentModule).Add( new DownloadableResourceFile( downloadUri: downloadUri, name: name, type: formatName, size: size, location: location ) ); }
protected virtual void visitStudentModuleResourceDownloads(OuStudentModule ouStudentModule, XmlDocument xmlDocument) { visitStudentModuleResourceDocumentDownloads(ouStudentModule, xmlDocument); visitStudentModuleResourceMediaDownloads(ouStudentModule, xmlDocument); }