Ejemplo n.º 1
0
        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 "";
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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("");
        }
Ejemplo n.º 4
0
        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;
        }
 public static void getPythonStringTargetFile(string fileToProcess, string targetFolder, bool processJarFiles)
 {
     //if (Directory.Exists(fileOrFolderToProcess))
     //    return fileOrFolderToProcess;
     if (File.Exists(fileToProcess))
     {
         var extension = Path.GetExtension(fileToProcess).ToLower();
         switch (extension)
         {
             case ".zip":
             case ".jar":
             case ".war":
                 if (extension == ".jar" && false == processJarFiles)     // handle the case where we don't want to process the Jar files
                     return;
                 targetFolder = Path.Combine(targetFolder, Path.GetFileName(fileToProcess).Replace(".", "_"));
                 var unzipedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(fileToProcess, targetFolder);
                 foreach (var unzipedFile in unzipedFiles)
                     getPythonStringTargetFile(unzipedFile, targetFolder, processJarFiles);
                 break;
             case ".class":
                 var targetFile = fileToProcess.Replace(':','_').Replace('/','_').Replace('\\','_');
                 Files.copy(fileToProcess, Path.Combine(targetFolder, targetFile));
                 break;
         }
     }
 }
        public static Dictionary<string, List<string>> mapAvailableJars(List<string> jarPaths)
        {
            DI.log.info("Search recursively for all *.jar files");
            var availableJars = new List<string>();
            foreach (var jarSearchPath in jarPaths)
                availableJars.AddRange(Files.getFilesFromDir_returnFullPath(jarSearchPath, "*.jar", true));

            DI.log.info("Found {0} jar files", availableJars.Count);

            var mappedClasses = new Dictionary<string, List<string>>();
            foreach (var jarFile in availableJars)
            {
                var filesInJar = new zipUtils().getListOfFilesInZip(jarFile);
                foreach (var fileInJar in filesInJar)
                    if (Path.GetExtension(fileInJar) == ".class")
                    {
                        if (false == mappedClasses.ContainsKey(fileInJar))
                            mappedClasses.Add(fileInJar, new List<string>());
                        mappedClasses[fileInJar].Add(jarFile);
                    }
            }
            DI.log.info("There are {0} classes mapped", mappedClasses.Keys.Count);
            return mappedClasses;
        }