예제 #1
0
        public async Task <ActionResult> DownloadLog(long cookieToReturn)
        {
            FlushLog();
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                string filename = dataProvider.GetLogFileName();
                if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename))
                {
                    throw new Error(this.__ResStr("logNotFound", "The log file '{0}' cannot be located", filename));
                }
#if MVC6
                Response.Headers.Remove("Cookie");
                Response.Cookies.Append(Basics.CookieDone, cookieToReturn.ToString(), new Microsoft.AspNetCore.Http.CookieOptions {
                    HttpOnly = false, Path = "/"
                });
#else
                HttpCookie cookie = new HttpCookie(Basics.CookieDone, cookieToReturn.ToString());
                Response.Cookies.Remove(Basics.CookieDone);
                Response.SetCookie(cookie);
#endif

                string contentType = "application/octet-stream";
#if MVC6
                return(new PhysicalFileResult(filename, contentType)
                {
                    FileDownloadName = "Logfile.txt"
                });
#else
                FilePathResult result = new FilePathResult(filename, contentType);
                result.FileDownloadName = "Logfile.txt";
                return(result);
#endif
            }
        }
예제 #2
0
        public async Task <ActionResult> DownloadZippedLog(long cookieToReturn)
        {
            FlushLog();
            using (LogRecordDataProvider dataProvider = LogRecordDataProvider.GetLogRecordDataProvider()) {
                string filename = dataProvider.GetLogFileName();
                if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename))
                {
                    throw new Error(this.__ResStr("logNotFound", "The log file '{0}' cannot be located", filename));
                }
#if MVC6
#else
                HttpCookie cookie = new HttpCookie(Basics.CookieDone, cookieToReturn.ToString());
                Response.Cookies.Remove(Basics.CookieDone);
                Response.SetCookie(cookie);
#endif
                string        zipName = "Logfile.zip";
                YetaWFZipFile zipFile = new YetaWFZipFile {
                    FileName = zipName,
                };
                zipFile.AddFile(filename, "Logfile.txt");
                return(new ZippedFileResult(zipFile, cookieToReturn));
            }
        }