Esempio n. 1
0
        public string downloadBinaryFile(string urlOfFileToFetch, string targetFileOrFolder)
        {
            var targetFile = targetFileOrFolder;

            if (Directory.Exists(targetFileOrFolder))
            {
                targetFile = Path.Combine(targetFileOrFolder, Path.GetFileName(urlOfFileToFetch));
            }

            PublicDI.log.debug("Downloading Binary File {0}", urlOfFileToFetch);
            lock (this)
            {
                using (WebClient webClient = new WebClient())
                {
                    try
                    {
                        byte[] pageData = webClient.DownloadData(urlOfFileToFetch);
                        O2Kernel_Files.WriteFileContent(targetFile, pageData);
                        PublicDI.log.debug("Downloaded File saved to: {0}", targetFile);

                        webClient.Dispose();

                        GC.Collect();       // because of WebClient().GetRequestStream prob
                        return(targetFile);
                    }
                    catch (Exception ex)
                    {
                        PublicDI.log.ex(ex);
                    }
                }
            }
            GC.Collect();       // because of WebClient().GetRequestStream prob
            return(null);
        }
 public static void createOrSetLocalConfigFile(string pathToLocalConfigFile)
 {
     if (File.Exists(pathToLocalConfigFile))
     {
         DI.config.O2ConfigFile = pathToLocalConfigFile;
         saveO2ConfigFile();
     }
     else
     {
         var newO2ConfigDirectory = Path.GetDirectoryName(pathToLocalConfigFile);
         O2Kernel_Files.checkIfDirectoryExistsAndCreateIfNot(newO2ConfigDirectory);
         saveO2ConfigFile((KO2Config)DI.config, pathToLocalConfigFile);     // create local config file from current O2Configfile
         //createO2ConfigFile(pathToLocalConfigFile);
         DI.config.O2ConfigFile = pathToLocalConfigFile;
     }
 }