Beispiel #1
0
        public static void UploadDirectory(string sourceDirectory, string targetFileName)
        {
            string tempPath = ConfigReader.GetSettingsValue("UploadWorkingDirectory", Path.GetTempPath());
            string tempDir  = DirectoryHelper.CreateTempDirectory(tempPath);

            RetryVoidExecutor.Do(() =>
            {
                try
                {
                    if (!Directory.Exists(tempDir))
                    {
                        Directory.CreateDirectory(tempDir);
                    }

                    string zipPath = Path.Combine(tempDir, targetFileName);

                    ZipFile.CreateFromDirectory(sourceDirectory, zipPath);

                    using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(zipPath)))
                    {
                        BlobUtility blobUtility = new BlobUtility();
                        blobUtility.Upload(ms, targetFileName);
                    }
                }

                catch (Exception)
                {
                    throw;
                }

                finally
                {
                    if (Directory.Exists(tempDir))
                    {
                        DirectoryHelper.DeleteDirectory(tempDir);
                    }
                }
            })
            .Try(RetryCount)
            .Wait(RetryTimeInterval)
            .Start();
        }
Beispiel #2
0
        public static void DownloadFiles(string path, string fileName)
        {
            RetryVoidExecutor.Do(() =>
            {
                BlobUtility utility = new BlobUtility();
                MemoryStream ms     = utility.GetBlob(fileName);

                if (ms == null)
                {
                    throw new Exception(string.Format("File download failed for stream '{0}'", fileName));
                }

                using (ZipArchive archive = new ZipArchive(ms))
                {
                    foreach (ZipArchiveEntry file in archive.Entries)
                    {
                        string completeFileName = Path.Combine(path, file.FullName);
                        //create subdirectory if not exists
                        string fileDir = Path.GetDirectoryName(completeFileName);
                        if (!Directory.Exists(fileDir))
                        {
                            Directory.CreateDirectory(fileDir);
                        }

                        // if the file being extracted is an empty directory, don't try to extract since it is invalid
                        if (!string.IsNullOrWhiteSpace(Path.GetFileName(completeFileName)))
                        {
                            file.ExtractToFile(completeFileName, true);
                        }
                    }
                }
            })
            .Try(RetryCount)
            .Wait(RetryTimeInterval)
            .Start();
        }