public async Task AFileIsDownloadedOnFileDownload()
        {
            var          url          = "https://m.media-amazon.com/images/I/61-gczrW31L._AC_UY218_.jpg";
            FileDownload fileDownload = new FileDownload();
            var          file         = await fileDownload.Download(url);

            Assert.True(file.Length > 0);
        }
Exemple #2
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     _downloadService = new FileDownload();
     _fileIOservice   = new FileIOService(PATH);
     _downloadService.Download();
     _view = _fileIOservice.LoadData();
     if (_view != null)
     {
         thrList.ItemsSource = _view;
     }
 }
Exemple #3
0
        public static object PublishFile(string template, string report, dynamic dy, bool isDownload = true)
        {
            var result = new ReportTable
            {
                ErrCode = 0,
                ErrMsg  = "ok"
            };

            try
            {
                var appSettings     = new AppSettings();
                var contentRootPath = appSettings.Get("HostingEnvironment.ContentRootPath", HostContext.AppHost.MapProjectPath("~/"));
                var templatePath    = HostContext.AppHost.MapProjectPath($"{ Path.Combine(contentRootPath, "template")}");
                var reportPath      = HostContext.AppHost.MapProjectPath($"{ Path.Combine(contentRootPath, "report")}");

                if (!Directory.Exists(templatePath))
                {
                    Directory.CreateDirectory(templatePath);
                }

                if (!Directory.Exists(reportPath))
                {
                    Directory.CreateDirectory(reportPath);
                }

                var templateFilePath = Path.Combine(templatePath, template);
                var reportFilePath   = Path.Combine(reportPath, report);

                Console.WriteLine("templateFilePath:" + templateFilePath);
                Console.WriteLine("reportFilePath:" + reportFilePath);

                FileInfo templateFile = new FileInfo(templateFilePath);

                //将现有文件复制到新文件,不允许覆盖现有文件
                templateFile.CopyTo(reportFilePath);

                if (Report(reportFilePath, dy))
                {
                    result.FilePath = reportFilePath;
                    if (isDownload)
                    {
                        var obj = FileDownload.Download(report, "report");
                        return(obj);
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                Console.WriteLine("PublishFile报错:" + ex.Message);

                return(result);
            }
        }