From: joinsang Date: Thu, 28 Mar 2019 05:04:16 +0000 (+0900) Subject: 압축하기 진행률, 다운로드까지 완벽하게 완료. 끝. X-Git-Url: https://git.insang.kr/gitweb/?a=commitdiff_plain;h=ef7089598a9d31a043e79cd3066096ed45897d82;p=ZipProject.git 압축하기 진행률, 다운로드까지 완벽하게 완료. 끝. --- diff --git a/ZipProject/Controllers/WebZipController.cs b/ZipProject/Controllers/WebZipController.cs index 7cfb065..0a4aee5 100644 --- a/ZipProject/Controllers/WebZipController.cs +++ b/ZipProject/Controllers/WebZipController.cs @@ -63,14 +63,14 @@ namespace ZipProject.Controllers { public async Task 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 () { diff --git a/ZipProject/Models/SimpleLongPolling.cs b/ZipProject/Models/SimpleLongPolling.cs index e178981..aa1bf47 100644 --- a/ZipProject/Models/SimpleLongPolling.cs +++ b/ZipProject/Models/SimpleLongPolling.cs @@ -33,7 +33,7 @@ public class SimpleLongPolling { } public async Task 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); } diff --git a/ZipProject/Models/ZipModel.cs b/ZipProject/Models/ZipModel.cs index 2f192af..76f11d9 100644 --- a/ZipProject/Models/ZipModel.cs +++ b/ZipProject/Models/ZipModel.cs @@ -20,6 +20,7 @@ namespace ZipProject { private JObject keypair; private string[] dirList; private List 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"); } diff --git a/ZipProject/Views/WebZip/partial_zip.cshtml b/ZipProject/Views/WebZip/partial_zip.cshtml index 437a386..31d6ac1 100644 --- a/ZipProject/Views/WebZip/partial_zip.cshtml +++ b/ZipProject/Views/WebZip/partial_zip.cshtml @@ -77,7 +77,7 @@ @LanguagePack.GetText(lang, "pleasewait")
-
+
@LanguagePack.GetText(lang, "complate")
diff --git a/ZipProject/_publish/ZipProject.Views.dll b/ZipProject/_publish/ZipProject.Views.dll index 085567c..6da3caa 100644 Binary files a/ZipProject/_publish/ZipProject.Views.dll and b/ZipProject/_publish/ZipProject.Views.dll differ diff --git a/ZipProject/_publish/ZipProject.Views.pdb b/ZipProject/_publish/ZipProject.Views.pdb index 274b147..497df2c 100644 Binary files a/ZipProject/_publish/ZipProject.Views.pdb and b/ZipProject/_publish/ZipProject.Views.pdb differ diff --git a/ZipProject/_publish/ZipProject.dll b/ZipProject/_publish/ZipProject.dll index 61f976e..29ed26c 100644 Binary files a/ZipProject/_publish/ZipProject.dll and b/ZipProject/_publish/ZipProject.dll differ diff --git a/ZipProject/_publish/ZipProject.pdb b/ZipProject/_publish/ZipProject.pdb index 9e5729c..0e2a1c8 100644 Binary files a/ZipProject/_publish/ZipProject.pdb and b/ZipProject/_publish/ZipProject.pdb differ diff --git a/ZipProject/_publish/wwwroot/js/Zip/partial_zip.js b/ZipProject/_publish/wwwroot/js/Zip/partial_zip.js index 3ec8057..b5be10a 100644 --- a/ZipProject/_publish/wwwroot/js/Zip/partial_zip.js +++ b/ZipProject/_publish/wwwroot/js/Zip/partial_zip.js @@ -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); diff --git a/ZipProject/wwwroot/js/Zip/partial_zip.js b/ZipProject/wwwroot/js/Zip/partial_zip.js index 3ec8057..b5be10a 100644 --- a/ZipProject/wwwroot/js/Zip/partial_zip.js +++ b/ZipProject/wwwroot/js/Zip/partial_zip.js @@ -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);