using IRaCIS.Application.Interfaces;
using System.Text;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using IRaCIS.Core.Infrastructure;
using IRaCIS.Core.Application.Helper;
using Microsoft.AspNetCore.Hosting;

namespace IRaCIS.Application.Services
{
    public class FileService : IFileService
    {


        private readonly IWebHostEnvironment _hostEnvironment;
        private string defaultUploadFilePath = string.Empty;
        private readonly ILogger<FileService> _logger;
        public FileService(
            IWebHostEnvironment hostEnvironment, ILogger<FileService> logger)
        {
       
            _hostEnvironment = hostEnvironment;

            defaultUploadFilePath = FileStoreHelper.GetIRaCISRootPath(_hostEnvironment);
            _logger = logger;
        }

    



      

        private static void CopyDirectory(string srcPath, string destPath)
        {

            DirectoryInfo dir = new DirectoryInfo(srcPath);
            FileSystemInfo[] fileInfoArray = dir.GetFileSystemInfos();  //获取目录下（不包含子目录）的文件和子目录
            foreach (FileSystemInfo fileInfo in fileInfoArray)
            {
                if (fileInfo is DirectoryInfo)     //判断是否文件夹
                {
                    if (!Directory.Exists(destPath + "\\" + fileInfo.Name))
                    {
                        Directory.CreateDirectory(destPath + "\\" + fileInfo.Name);   //目标目录下不存在此文件夹即创建子文件夹
                    }
                    CopyDirectory(fileInfo.FullName, destPath + "\\" + fileInfo.Name);    //递归调用复制子文件夹
                }
                else
                {
                    File.Copy(fileInfo.FullName, destPath + "\\" + fileInfo.Name, true);      //不是文件夹即复制文件，true表示可以覆盖同名文件
                }
            }

        }
    }
}
