Commit e90b96d6 e90b96d63f08ed994820e4744ef8be77695bbbc3 by Christian Gerdes

Zip File Upload: Added support for multiple files

1 parent f71a32c4
......@@ -23,10 +23,10 @@ using Microsoft.VisualStudio.TestTools.LoadTesting;
namespace LIL_VSTT_Plugins
{
[DisplayName("Zip File Upload"), Description("Creates an ZIP archive of the file to be uploaded using the files name and adding .zip. Warning, uses %TEMP% for temp storage.")]
[DisplayName("Zip File Upload"), Description("Creates an ZIP archive of each of the files to be uploaded using the files name and adding .zip. Warning, uses %TEMP% for temp storage.")]
public class ZipFileUploadBeforePost : WebTestRequestPlugin
{
String tempDir = null;
Queue<String> deleteDirs = new Queue<string>();
public override void PreRequest(object sender, PreRequestEventArgs e)
{
if (e.Request.Body.GetType() == typeof(FormPostHttpBody)) {
......@@ -35,8 +35,9 @@ namespace LIL_VSTT_Plugins
if(param.GetType() == typeof(FileUploadParameter))
{
FileUploadParameter fparam = (FileUploadParameter)param;
tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString();
String tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString();
Directory.CreateDirectory(tempDir);
deleteDirs.Enqueue(tempDir);
Directory.CreateDirectory(tempDir + @"\ZipDir");
File.Copy(fparam.FileName, tempDir + @"\ZipDir\" + Path.GetFileName(fparam.FileName));
ZipFile.CreateFromDirectory(tempDir + @"\ZipDir", tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip");
......@@ -51,7 +52,8 @@ namespace LIL_VSTT_Plugins
public override void PostRequest(object sender, PostRequestEventArgs e)
{
if (tempDir != null) Directory.Delete(tempDir, true);
foreach (String dir in deleteDirs) Directory.Delete(dir, true);
deleteDirs.Clear();
base.PostRequest(sender, e);
}
}
......