]> insang Git - ZipProject.git/commitdiff
압축하기 진행률, 다운로드까지 완벽하게 완료. 끝.
authorjoinsang <dhkq92@icloud.com>
Thu, 28 Mar 2019 05:04:16 +0000 (14:04 +0900)
committerjoinsang <dhkq92@icloud.com>
Thu, 28 Mar 2019 05:04:16 +0000 (14:04 +0900)
ZipProject/Controllers/WebZipController.cs
ZipProject/Models/SimpleLongPolling.cs
ZipProject/Models/ZipModel.cs
ZipProject/Views/WebZip/partial_zip.cshtml
ZipProject/_publish/ZipProject.Views.dll
ZipProject/_publish/ZipProject.Views.pdb
ZipProject/_publish/ZipProject.dll
ZipProject/_publish/ZipProject.pdb
ZipProject/_publish/wwwroot/js/Zip/partial_zip.js
ZipProject/wwwroot/js/Zip/partial_zip.js

index 7cfb06596851d2243418e0c6bb54ff78192ff475..0a4aee54f42ee36985fff26c88ae99c7198a9452 100644 (file)
@@ -63,14 +63,14 @@ namespace ZipProject.Controllers {
     public async Task<ActionResult> FileUploadProgress (string uuid) {
       SimpleLongPolling longPolling = new SimpleLongPolling (uuid);
       var msg = await longPolling.WaitAsync ();
-      return Json (msg == null ? "-2" : msg);
+      return Json (msg);
     }
 
-    public ActionResult DownloadZip(string uuid){
-      string path= Environment.CurrentDirectory+"/wwwroot/zipfiles/"+uuid+".zip";
-      byte[] file= System.IO.File.ReadAllBytes(path);
-      System.IO.File.Delete(path);
-      return File(file, "application/zip");
+    public ActionResult DownloadZip (string uuid) {
+      string path = Environment.CurrentDirectory + "/wwwroot/zipfiles/" + uuid + ".zip";
+      byte[] file = System.IO.File.ReadAllBytes (path);
+      System.IO.File.Delete (path);
+      return File (file, "application/zip");
     }
 
     public ActionResult Error () {
index e1789811580a06c892ca43abe52b25d08f7e9f58..aa1bf4755d562a565de52fea52308a6b811ce7bf 100644 (file)
@@ -33,7 +33,7 @@ public class SimpleLongPolling {
   }
 
   public async Task<string> WaitAsync () {
-    await Task.WhenAny (_TaskCompleteion.Task, Task.Delay (100)); // blocking wait until event occurs or timeout
+    await Task.WhenAny (_TaskCompleteion.Task, Task.Delay (1200000)); // blocking wait until event occurs or timeout
     lock (_sSubscribers) {
       _sSubscribers.Remove (this);
     }
index 2f192afc09b6ad0298193169803c305103fdc879..76f11d940e4ca2e8bdefd8650bff8c11c3dea827 100644 (file)
@@ -20,6 +20,7 @@ namespace ZipProject {
     private JObject keypair;
     private string[] dirList;
     private List<IFormFile> files;
+    private int now;
     private string zipname;
     public ZipModel () { }
 
@@ -52,8 +53,8 @@ namespace ZipProject {
           zip.AddEntry (dir + filename, file.OpenReadStream ());
         }
 
-        if (!Directory.Exists(Environment.CurrentDirectory+"/wwwroot/zipfiles/")){
-          Directory.CreateDirectory(Environment.CurrentDirectory+"/wwwroot/zipfiles/");
+        if (!Directory.Exists (Environment.CurrentDirectory + "/wwwroot/zipfiles/")) {
+          Directory.CreateDirectory (Environment.CurrentDirectory + "/wwwroot/zipfiles/");
         }
 
         zip.Save (path);
@@ -62,7 +63,10 @@ namespace ZipProject {
 
     public void SaveProgress (object sender, SaveProgressEventArgs e) {
       if (e.EventType == ZipProgressEventType.Saving_BeforeWriteEntry) {
-        SimpleLongPolling.Publish (uuid, (e.EntriesSaved + 1) + "");
+        if (now != e.EntriesSaved + 1) {
+          now = e.EntriesSaved + 1;
+          SimpleLongPolling.Publish (uuid, (e.EntriesSaved + 1) + "");
+        }
       } else if (e.EventType == ZipProgressEventType.Saving_Completed) {
         SimpleLongPolling.Publish (uuid, "-1");
       }
index 437a3865748817d1ba60ab4b5484b0c135c3cbdb..31d6ac19a186c4575f02babc3347c2492886cfb0 100644 (file)
@@ -77,7 +77,7 @@
     <span>@LanguagePack.GetText(lang, "pleasewait") <div><progress value="0" max="1"></progress></div></span>\r
   </div>\r
   <div class="webzip-btn-complate">\r
-    <div class="webzip-btn" onclick="RequestCompress();">\r
+    <div class="webzip-btn" onclick="$('.modal').css('display', 'table');RequestCompress();">\r
       @LanguagePack.GetText(lang, "complate")\r
     </div>\r
   </div>\r
index 085567c61cd421e77776b60c060eae968722241e..6da3caa5a2f2dbf316a7a4dc24d3ff3b3264fafb 100644 (file)
Binary files a/ZipProject/_publish/ZipProject.Views.dll and b/ZipProject/_publish/ZipProject.Views.dll differ
index 274b147e93d790cecf51be1e96bf4be58f38ecc8..497df2cc72a9dfec25be90b683b2694937c43e8f 100644 (file)
Binary files a/ZipProject/_publish/ZipProject.Views.pdb and b/ZipProject/_publish/ZipProject.Views.pdb differ
index 61f976e83269906e5110372f5c23224328c70f10..29ed26c183a078f5ee6ae01fea79a661ff4f96ec 100644 (file)
Binary files a/ZipProject/_publish/ZipProject.dll and b/ZipProject/_publish/ZipProject.dll differ
index 9e5729cc7cba50e8eaec695187f2f456a0f91aa2..0e2a1c860c126909f5758dc541906a780075d6fb 100644 (file)
Binary files a/ZipProject/_publish/ZipProject.pdb and b/ZipProject/_publish/ZipProject.pdb differ
index 3ec805759a20ae30ee70196bc6d8160f90f9ac4b..b5be10a2876c536605edb362e93db4c8f6b5a146 100644 (file)
@@ -306,7 +306,6 @@ function RequestCompress() {
   if (confirm(_Language["iscompress"] + size)) {
     var filelength = files.keys().length;
     $("progress").attr("max", filelength);
-    $(".modal").css("display", "table");
     //디렉토리 리스트
     var dirList = new Array();
     for (var i = 0; i < directories.keys().length; i++) {
@@ -330,7 +329,7 @@ function RequestCompress() {
 
     //데이터 폼 생성후 파일들과 각종 정포 담기
     var formdata = new FormData();
-    var uuid= GetUUID();
+    var uuid = GetUUID();
     for (var i = 0; i < files.keys().length; i++) {
       formdata.append("files", files.get(i).get("file"));
     }
@@ -339,44 +338,41 @@ function RequestCompress() {
     formdata.append("format", format);
     formdata.append("uuid", uuid);
 
-    //압축요청, 압축이 완료되면 다운로드창 띄우기
+    //압축요청
     $.ajax({
       type: "post",
       url: "/webzip/fileupload",
       data: formdata,
       processData: false,
-      contentType: false,
+      contentType: false
     });
 
-    var progress = setInterval(() => {
-        $.ajax({
-          type: "post",
-          url: "/webzip/fileuploadprogress",
-          data: "uuid="+uuid
-        }).done(function(data2) {
-          var iscomplate = false;
-          if (data2 == "-1" && iscomplate == false){
-            clearInterval(progress);
+    var Getprogress = function() {
+      $.ajax({
+        type: "post",
+        url: "/webzip/fileuploadprogress",
+        data: "uuid=" + uuid,
+        timeout: 1200000,
+        success: function(data2) {
+          $("progress").attr("value", data2);
+          if (data2 != "-1") {
+            Getprogress();
+          } else {
+            //modal display none바꾸고
             $(".modal").css("display", "none");
+            //파일다운로드 요청.
             var a = document.createElement("a");
-            var url = "/webzip/DownloadZip?uuid="+uuid;
+            var url = "/webzip/DownloadZip?uuid=" + uuid;
             a.href = url;
             a.download = directories.get(0) + "." + format;
             a.click();
             window.URL.revokeObjectURL(url);
-            $("progress").attr("value", "0");
-            iscomplate == true;
           }
-          else {
-            if (data2 != "-2"){
-              $("progress").attr("value", data2);
-            }
-          }
-        });
-        req;
-    }, 100);
-    progress;
+        }
+      });
+    };
 
+    Getprogress();
   }
 }
 
@@ -472,6 +468,7 @@ SetBulletIcon();
 SetSortable();
 directories.put(0, "example");
 
+//웹소켓(안씀)
 // var protocol = location.protocol === "https:" ? "wss:" : "ws:";
 // var wsUri = protocol + "//" + window.location.host + "/ws";
 // var socket = new WebSocket(wsUri);
index 3ec805759a20ae30ee70196bc6d8160f90f9ac4b..b5be10a2876c536605edb362e93db4c8f6b5a146 100644 (file)
@@ -306,7 +306,6 @@ function RequestCompress() {
   if (confirm(_Language["iscompress"] + size)) {
     var filelength = files.keys().length;
     $("progress").attr("max", filelength);
-    $(".modal").css("display", "table");
     //디렉토리 리스트
     var dirList = new Array();
     for (var i = 0; i < directories.keys().length; i++) {
@@ -330,7 +329,7 @@ function RequestCompress() {
 
     //데이터 폼 생성후 파일들과 각종 정포 담기
     var formdata = new FormData();
-    var uuid= GetUUID();
+    var uuid = GetUUID();
     for (var i = 0; i < files.keys().length; i++) {
       formdata.append("files", files.get(i).get("file"));
     }
@@ -339,44 +338,41 @@ function RequestCompress() {
     formdata.append("format", format);
     formdata.append("uuid", uuid);
 
-    //압축요청, 압축이 완료되면 다운로드창 띄우기
+    //압축요청
     $.ajax({
       type: "post",
       url: "/webzip/fileupload",
       data: formdata,
       processData: false,
-      contentType: false,
+      contentType: false
     });
 
-    var progress = setInterval(() => {
-        $.ajax({
-          type: "post",
-          url: "/webzip/fileuploadprogress",
-          data: "uuid="+uuid
-        }).done(function(data2) {
-          var iscomplate = false;
-          if (data2 == "-1" && iscomplate == false){
-            clearInterval(progress);
+    var Getprogress = function() {
+      $.ajax({
+        type: "post",
+        url: "/webzip/fileuploadprogress",
+        data: "uuid=" + uuid,
+        timeout: 1200000,
+        success: function(data2) {
+          $("progress").attr("value", data2);
+          if (data2 != "-1") {
+            Getprogress();
+          } else {
+            //modal display none바꾸고
             $(".modal").css("display", "none");
+            //파일다운로드 요청.
             var a = document.createElement("a");
-            var url = "/webzip/DownloadZip?uuid="+uuid;
+            var url = "/webzip/DownloadZip?uuid=" + uuid;
             a.href = url;
             a.download = directories.get(0) + "." + format;
             a.click();
             window.URL.revokeObjectURL(url);
-            $("progress").attr("value", "0");
-            iscomplate == true;
           }
-          else {
-            if (data2 != "-2"){
-              $("progress").attr("value", data2);
-            }
-          }
-        });
-        req;
-    }, 100);
-    progress;
+        }
+      });
+    };
 
+    Getprogress();
   }
 }
 
@@ -472,6 +468,7 @@ SetBulletIcon();
 SetSortable();
 directories.put(0, "example");
 
+//웹소켓(안씀)
 // var protocol = location.protocol === "https:" ? "wss:" : "ws:";
 // var wsUri = protocol + "//" + window.location.host + "/ws";
 // var socket = new WebSocket(wsUri);