public static void GetFile(OAIDataProvider dataProvider, RecordQueryResult record) { if (dataProvider == null || record == null) { return; } string basePath = Properties.directoryForHarvestedFiles + "\\"; basePath += new Uri(dataProvider.BaseURL).Host + "\\"; if (Properties.overwriteHarvestedFiles ? true : string.IsNullOrEmpty(record.Header.FilePath)) { if (!Directory.Exists(basePath)) { Directory.CreateDirectory(basePath); } string filePath = null; switch (dataProvider.Function) { case "FromPageOnly": filePath = FromPageOnly(record, basePath, dataProvider.FirstSource); break; case "FromSourceTag": filePath = FromSourceTag(record, dataProvider, basePath); break; default: break; } if (!string.IsNullOrEmpty(filePath)) { record.Header.FilePath = filePath; } } }
public static string FromSourceTag( RecordQueryResult record, OAIDataProvider dataProvider, string basePath) { try { if (record == null || dataProvider == null || string.IsNullOrEmpty(basePath)) { return(null); } string files = string.Empty; foreach (var sourceItem in GetAllSources(record, dataProvider.FirstSource)) { var fileName = string.IsNullOrEmpty(sourceItem.Name) ? sourceItem.AlternateName : sourceItem.Name; string filePath = CreateUniqueFileName(basePath, fileName); if (DownloadFile(filePath, sourceItem.AbsoluteUri)) { files += filePath + "]["; } } if (!string.IsNullOrEmpty(files)) { return(files.Substring(0, files.Length - 2)); } return(FromPageOnly(record, basePath, string.IsNullOrEmpty(dataProvider.SecondSource) ? dataProvider.FirstSource : dataProvider.SecondSource)); } catch (Exception e) { /* for debugging purpose only */ string msg = e.Message; } return(null); }