public override bool execute() { if (sourceObject == null) return false; var fileToUnzip = (string) sourceObject; if (fileToUnzip.IndexOf("http://") > -1) fileToUnzip = new Web().downloadBinaryFile(fileToUnzip); if (!File.Exists(fileToUnzip)) return false; folderToUnzipFiles = folderToUnzipFiles ?? DI.config.TempFolderInTempDirectory; List<string> unzipedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(fileToUnzip, folderToUnzipFiles); if (unzipedFiles.Count == 0) return false; resultsObject = unzipedFiles; return true; }
public string checkIfFileExistsAndDownloadIfNot(string file , string urlToDownloadFile) { if (File.Exists(file)) return file; if (file.valid().isFalse()) file = urlToDownloadFile.fileName(); var localTempFile = urlToDownloadFile.extension(".zip") ? PublicDI.config.getTempFileInTempDirectory(".zip") : Path.Combine(PublicDI.config.O2TempDir, file); if (File.Exists(localTempFile)) return localTempFile; downloadBinaryFile(urlToDownloadFile, localTempFile); //var downloadedFile = downloadBinaryFile(urlToDownloadFile, false /*saveUsingTempFileName*/); if (File.Exists(localTempFile)) { if (Path.GetExtension(localTempFile) != ".zip" && urlToDownloadFile.fileName().extension(".zip").isFalse()) return localTempFile; List<string> extractedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(localTempFile, PublicDI.config.O2TempDir); if (extractedFiles != null) foreach(var extractedFile in extractedFiles) if (Path.GetFileName(extractedFile) == file) return extractedFile; } return ""; }
public List<String> downloadZipFileAndExtractFiles(string urlOfFileToFetch) { var webClient = new WebClient(); try { //setup headers foreach (var header in Headers_Request) webClient.Headers.Add(header.Key, header.Value); string tempFileName = String.Format("{0}_{1}.zip", PublicDI.config.TempFileNameInTempDirectory, Path.GetFileNameWithoutExtension(urlOfFileToFetch)); byte[] pageData = webClient.DownloadData(urlOfFileToFetch); Files.WriteFileContent(tempFileName, pageData); List<string> extractedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(tempFileName); File.Delete(tempFileName); return extractedFiles; } catch (Exception ex) { PublicDI.log.ex(ex); } return null; }