/// <summary>
        ///
        /// </summary>
        /// <param name="updateFileDto"></param>
        /// <returns></returns>
        public async Task <List <SysFileDto> > UploadFileAsync(UpdateFileDto updateFileDto)
        {
            List <SysFileDto> dtoList = new List <SysFileDto>();

            if (!object.Equals(updateFileDto.files, null) && updateFileDto.files.Any())
            {
                foreach (var item in updateFileDto.files)
                {
                    var dto = new SysFileDto();
                    dto.B_ID      = updateFileDto.B_ID;
                    dto.FileName  = item.FileName;
                    dto.FilePath  = Filehelp.GetFilePath(_webAppOptions.FileSaveBasePath);
                    dto.Extension = System.IO.Path.GetExtension(item.FileName);
                    dto.Size      = item.Length;
                    dto.Type      = "UUID";
                    dto.IDate     = DateTime.Now;
                    dto.UDate     = DateTime.Now;

                    await Filehelp.WriteFileAsync(item.OpenReadStream(), dto.FilePath);


                    var retDot = await InsertAsync(dto, false);

                    dtoList.Add(retDot);
                }
                await _repository.SaveAsync();
            }
            return(dtoList);
        }
예제 #2
0
        public async Task <IActionResult> UploadFileAsync(UpdateFileDto files)
        {
            var uploadFileDtoList = await _service.UploadFileAsync(files);

            if (uploadFileDtoList != null && uploadFileDtoList.Any())
            {
                return(this.JsonSuccess());
            }
            else
            {
                return(this.JsonFaild());
            }
        }
        public async Task <IActionResult> UpdateFile([FromBody] UpdateFileDto fileDto)
        {
            if (!IsAvailableOperation())
            {
                return(BadRequest());
            }



            await _fileStorageService.UpdateFile(fileDto, UserId, ClientId);

            AddLog(Enums.LogType.Update, LogMessage.CreateSuccessByIdMessage(LogMessage.FileEntityName, fileDto.Id, LogMessage.UpdateAction, UserId));
            return(Ok());
        }
예제 #4
0
        public async Task <string> UpdateFiles(int id, [FromBody] UpdateFileDto updateFileDto)
        {
            var file = await _unitOfWork.FileRepository.GetById(id);

            if (file == null)
            {
                throw new Exception("Not Found... ");
            }

            file = _mapper.Map(updateFileDto, file);
            await _unitOfWork.CompleteAsync();

            _mapper.Map <Entities.File, UpdateFileDto>(file);
            return("File was updated... ");
        }
예제 #5
0
 public async Task <IActionResult> UpdateFiles(int id, [FromBody] UpdateFileDto updateFileDto) => Ok(await _fileService.UpdateFiles(id, updateFileDto));
예제 #6
0
        /// <summary>
        /// 确认更新 ==》更新操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAllCheck_Click(object sender, EventArgs e)
        {
            try
            {
                handZip = true;
                if (File.Exists(downFile))
                {
                    FileInfo fileInfo = new FileInfo(downFile);
                    fileSize = fileInfo.Length / 1024;
                }

                //文件进行创建和覆盖操作
                //所有的文件路径
                Dictionary <string, UpdateFileDto> allFilePath = new Dictionary <string, UpdateFileDto>();
                //系统路径
                string rootFolder = AppDomain.CurrentDomain.BaseDirectory;
                string fullPath   = "";

                string parentFolder = null;


                using (Stream stream = File.OpenRead(downFile))
                {
                    var           reader = ReaderFactory.Open(stream);
                    UpdateFileDto dto    = null;
                    while (reader.MoveToNextEntry())
                    {
                        dto             = new UpdateFileDto();
                        dto.IsDirectory = reader.Entry.IsDirectory;

                        Console.WriteLine(reader.Entry);
                        int  loc      = reader.Entry.ToString().LastIndexOf("/");
                        bool noParent = !reader.Entry.ToString().Contains("/");//没有父节点

                        string name = loc > 0 ? reader.Entry.ToString().Substring(0, loc) : reader.Entry.ToString();

                        string relativePath = "";

                        //文件
                        if (!reader.Entry.IsDirectory)
                        {
                            Console.WriteLine("文件名:" + reader.Entry);
                            parentFolder = noParent ? pathToSaveDirectory : Path.Combine(pathToSaveDirectory, name);
                            reader.WriteEntryToDirectory(parentFolder);

                            if (@reader.Entry.ToString().Contains("Compressed Size"))
                            {
                                relativePath = @reader.Entry.ToString().Substring(0, @reader.Entry.ToString().IndexOf(" Compressed Size"));
                            }
                            else
                            {
                                relativePath = @reader.Entry.ToString();
                            }

                            //文件路径
                            fullPath = Path.Combine(rootFolder, relativePath);

                            dto.FullPath = fullPath;
                            if (!allFilePath.ContainsKey(fullPath))
                            {
                                dto.IsExist = File.Exists(dto.FullPath);
                                allFilePath.Add(fullPath, dto);
                            }

                            //跳过这部分文件==》数据库 版本信息  日志 附件 必须的dll文件
                            if (relativePath.Contains("zbfz.sqlite") ||
                                relativePath.Contains("version.info.txt") ||
                                relativePath.Contains("wcfLog.txt") ||
                                relativePath.Contains("fujian/") ||
                                relativePath.Contains("System.Buffers.") ||
                                relativePath.Contains("System.Memory.") ||
                                relativePath.Contains("System.Runtime.CompilerServices.Unsafe.") ||
                                relativePath.Contains("updated_version.exe") ||
                                relativePath.Contains("SharpCompress.")
                                )
                            {
                                continue;
                            }

                            if (File.Exists(dto.FullPath))
                            {
                                File.Delete(dto.FullPath);
                            }


                            //FileStream fs = File.Open(Path.Combine(pathToSaveDirectory, relativePath), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                            File.Copy(Path.Combine(pathToSaveDirectory, relativePath), dto.FullPath, true);
                        }
                        else//文件夹
                        {
                            Console.WriteLine("文件夹名:" + reader.Entry);
                            parentFolder = Path.Combine(pathToSaveDirectory, name);
                            Directory.CreateDirectory(parentFolder);

                            //文件夹路径
                            fullPath     = Path.Combine(rootFolder, name);
                            dto.FullPath = fullPath;
                            if (!allFilePath.ContainsKey(fullPath))
                            {
                                dto.IsExist = Directory.Exists(dto.FullPath);
                                allFilePath.Add(fullPath, dto);
                            }

                            if (!dto.IsExist)
                            {
                                Directory.CreateDirectory(dto.FullPath);
                            }
                        }
                    }
                    stream.Close();
                    this.labelProcess.Text       = "100%";//进度条满了
                    this.progressBarUpdate.Value = 100;
                    this.buttonOver.Visible      = true;
                    //停止计时器
                    timer1.Stop();
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("解压的进程被占用," + ex.Message);

                MessageBox.Show("更新异常:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                DelectDir(pathToSaveDirectory);//删除下载的文件及该文件夹
            }
        }
예제 #7
0
        public async Task UpdateFile(UpdateFileDto fileDto, int userId, int clientId)
        {
            var fileStorageRepository = DataContextManager.CreateRepository <IFileStorageRepository>();
            var fileStorage           = await fileStorageRepository.GetById(fileDto.Id, userId, clientId);

            if (fileStorage == null || fileStorage != null && fileStorage.IsDirectory)
            {
                throw new NotFoundException("File storage", fileDto.Id);
            }

            var isAvailableToChange = await fileStorageRepository.IsAvailableToChange(fileStorage.Id, userId, clientId);

            if (!isAvailableToChange)
            {
                throw new UnavailableOperationException("update file", "File storage", fileStorage.Id, userId);
            }

            var fileName      = Path.GetFileNameWithoutExtension(fileDto.Name);
            var fileExtension = Path.GetExtension(fileDto.Name);

            if (fileStorage.ParentFileStorageId.HasValue)
            {
                var fileStorages = await fileStorageRepository.GetByParentId(fileStorage.ParentFileStorageId.Value, userId, clientId);

                if (fileStorages.Any(x => !x.IsDirectory && x.Name.Equals(fileName) && x.Files.Any(y => y.IsActive && y.Extension.Equals(fileExtension))))
                {
                    throw new FoundSameObjectException("File storage", fileName);
                }
            }

            fileStorage.Name       = fileName;
            fileStorage.UpdateDate = DateTime.UtcNow;
            fileStorage.UpdateById = userId;

            if (!String.IsNullOrEmpty(fileDto.Content))
            {
                fileStorage.Files.ToList().ForEach(file =>
                {
                    file.IsActive = false;
                });

                var sizeInfo = fileDto.Size.Value.ToPrettySize();
                var blobName = Guid.NewGuid();

                var newFile = new Models.File
                {
                    Extension        = fileExtension,
                    Size             = sizeInfo.Size,
                    SizeType         = sizeInfo.SizeType,
                    CreateById       = userId,
                    IsActive         = true,
                    CreateDate       = DateTime.UtcNow,
                    AzureBlobStorage = new AzureBlobStorage
                    {
                        BlobName = blobName
                    }
                };

                fileStorage.Files.Add(newFile);

                await _azureBlobClient.UploadFile(_blobSettings.ContainerName, blobName.ToString(), fileDto.Content.ToByteArray());
            }
            else
            {
                var activeFile = fileStorage.Files.FirstOrDefault();

                if (activeFile == null)
                {
                    throw new NotFoundDependencyObjectException("File");
                }

                activeFile.Extension  = fileExtension;
                activeFile.UpdateById = userId;
                activeFile.UpdateDate = DateTime.UtcNow;
            }

            await fileStorageRepository.Update(fileStorage);
        }