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; ...@@ -23,10 +23,10 @@ using Microsoft.VisualStudio.TestTools.LoadTesting;
23 23
24 namespace LIL_VSTT_Plugins 24 namespace LIL_VSTT_Plugins
25 { 25 {
26 [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.")] 26 [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.")]
27 public class ZipFileUploadBeforePost : WebTestRequestPlugin 27 public class ZipFileUploadBeforePost : WebTestRequestPlugin
28 { 28 {
29 String tempDir = null; 29 Queue<String> deleteDirs = new Queue<string>();
30 public override void PreRequest(object sender, PreRequestEventArgs e) 30 public override void PreRequest(object sender, PreRequestEventArgs e)
31 { 31 {
32 if (e.Request.Body.GetType() == typeof(FormPostHttpBody)) { 32 if (e.Request.Body.GetType() == typeof(FormPostHttpBody)) {
...@@ -35,8 +35,9 @@ namespace LIL_VSTT_Plugins ...@@ -35,8 +35,9 @@ namespace LIL_VSTT_Plugins
35 if(param.GetType() == typeof(FileUploadParameter)) 35 if(param.GetType() == typeof(FileUploadParameter))
36 { 36 {
37 FileUploadParameter fparam = (FileUploadParameter)param; 37 FileUploadParameter fparam = (FileUploadParameter)param;
38 tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString(); 38 String tempDir = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString();
39 Directory.CreateDirectory(tempDir); 39 Directory.CreateDirectory(tempDir);
40 deleteDirs.Enqueue(tempDir);
40 Directory.CreateDirectory(tempDir + @"\ZipDir"); 41 Directory.CreateDirectory(tempDir + @"\ZipDir");
41 File.Copy(fparam.FileName, tempDir + @"\ZipDir\" + Path.GetFileName(fparam.FileName)); 42 File.Copy(fparam.FileName, tempDir + @"\ZipDir\" + Path.GetFileName(fparam.FileName));
42 ZipFile.CreateFromDirectory(tempDir + @"\ZipDir", tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip"); 43 ZipFile.CreateFromDirectory(tempDir + @"\ZipDir", tempDir + "\\" + Path.GetFileName(fparam.FileName) + ".zip");
...@@ -51,7 +52,8 @@ namespace LIL_VSTT_Plugins ...@@ -51,7 +52,8 @@ namespace LIL_VSTT_Plugins
51 52
52 public override void PostRequest(object sender, PostRequestEventArgs e) 53 public override void PostRequest(object sender, PostRequestEventArgs e)
53 { 54 {
54 if (tempDir != null) Directory.Delete(tempDir, true); 55 foreach (String dir in deleteDirs) Directory.Delete(dir, true);
56 deleteDirs.Clear();
55 base.PostRequest(sender, e); 57 base.PostRequest(sender, e);
56 } 58 }
57 } 59 }
......