Exemplo n.º 1
0
        private void SaveFile(Domain.File file)
        {
            var shadowFile = _shadowFileService.LoadShadowFile(file.FilePath);

            shadowFile.TagNames = file.Tags.Select(f => f.Name).ToList();
            _shadowFileService.SaveShadowFile(file.FilePath, shadowFile);
        }
Exemplo n.º 2
0
        public FileResponseDTO Update(UpdateFileRequestDTO requestDTO)
        {
            if (this.FindOneByUUID(requestDTO.uuid) == null)
            {
                throw new EntityNotFoundException($"File with uuid {requestDTO.uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
            }

            Domain.File file = new Domain.File()
            {
                uuid = requestDTO.uuid
            };

            file.filePath = CreateRelativeFilePath(file.uuid, requestDTO.fileExtension);
            DeleteFile(file.filePath);
            SaveFile(requestDTO.fileData, file.filePath);

            file = this._queryExecutor.Execute <Domain.File>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.UPDATE_FILE(file), this._modelMapper.MapToFile);
            try
            {
                var mat = this._httpClientService.SendRequest <object>(HttpMethod.Put, "http://localhost:40008/api/sections/material/", new UserPrincipal(_httpContextAccessor.HttpContext).token, file).Result;
            } catch {}

            try
            {
                var message = this._httpClientService.SendRequest <object>(HttpMethod.Put, "http://localhost:40002/api/messaging/file/", new UserPrincipal(_httpContextAccessor.HttpContext).token, file).Result;
            }
            catch { }
            return(this._autoMapper.Map <FileResponseDTO>(file));
        }
Exemplo n.º 3
0
        [HttpPost] // Authorize
        public async Task <IActionResult> Post(string resource, Guid referenceId, ICollection <IFormFile> file)
        {
            foreach (var f in file)
            {
                using (var memoryStream = new MemoryStream())
                {
                    await f.CopyToAsync(memoryStream);

                    var create = new Domain.File
                    {
                        Resource    = resource,
                        ReferenceId = referenceId,
                        Name        = f.FileName,
                        FileType    = f.ContentType,
                        ContentType = f.ContentType,
                        Size        = f.Length,
                        Content     = new Domain.FileContent(memoryStream.ToArray())
                    };

                    context.Add(create);
                    await context.SaveChangesAsync();
                }
            }

            return(Accepted());
        }
        public static int GetPartsAmount(this File file, int partSize)
        {
            var parts      = file?.SizeInBytes / partSize;
            var totalParts = parts * partSize == file?.SizeInBytes ? parts : parts + 1;

            return(totalParts ?? -1);
        }
Exemplo n.º 5
0
        public async Task SaveFileAsync(Domain.File file, Stream content)
        {
            Assert.NotNull(file, nameof(file));
            Assert.NotNull(content, nameof(content));

            var destinationFilePath = Path.Combine(_path, file.Path);

            EnsureDirectoryExists(destinationFilePath);
            await SaveFile(destinationFilePath, content);
        }
Exemplo n.º 6
0
 public PostFileRequest(Domain.Configuration configuration, Domain.File file)
 {
     LocationKey   = configuration.LocationKey;
     SequenceId    = configuration.SequenceId;
     FileContent   = file.Content;
     FileSizeBytes = file.SizeBytes;
     Name          = file.Name;
     FileTimeStamp = file.TimeStampUtc;
     SequenceId    = configuration.SequenceId;
 }
Exemplo n.º 7
0
 public FileResponseDTO Delete(string uuid)
 {
     Domain.File toDelete = this.FindOneByUUID(uuid);
     if (toDelete == null)
     {
         throw new EntityNotFoundException($"File with uuid {uuid} doesn't exist!", GeneralConsts.MICROSERVICE_NAME);
     }
     this._queryExecutor.Execute(DatabaseConsts.USER_SCHEMA, this._sqlCommands.DELETE_FILE(uuid), this._modelMapper.MapToFile);
     DeleteFile(toDelete.filePath);
     return(this._autoMapper.Map <FileResponseDTO>(toDelete));
 }
        public async Task StoreFileAsync(File file)
        {
            EnsureDirectory();
            var now = DateTime.Now;

            file.Name       = $"{file.Name}_{now:yyMMddHHmmss}";
            file.UploadDate = now;
            var path = Path.Join(DIRECTORY, file.Name);

            await System.IO.File.WriteAllBytesAsync(path, file.Data);
        }
Exemplo n.º 9
0
        public Stream GetFileContent(Domain.File file)
        {
            Assert.NotNull(file, nameof(file));

            var filePath = Path.Combine(_path, file.Path);

            if (!System.IO.File.Exists(filePath))
            {
                throw new ArgumentException("File does not exist in the storage");
            }
            return(ReadFile(filePath));
        }
Exemplo n.º 10
0
        public FileResponseDTO Create(CreateFileRequestDTO requestDTO)
        {
            Domain.File file = new Domain.File();
            file.filePath = CreateRelativeFilePath(file.uuid, requestDTO.fileExtension);
            SaveFile(requestDTO.fileData, file.filePath);

            file = this._queryExecutor.Execute <Domain.File>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.CREATE_FILE(file), this._modelMapper.MapToFileAfterInsert);
            file = this._queryExecutor.Execute <Domain.File>(DatabaseConsts.USER_SCHEMA, this._sqlCommands.GET_FILE_BY_UUID(file.uuid), this._modelMapper.MapToFile);
            var r = this._httpClientService.SendRequest <object>(HttpMethod.Put, "http://localhost:40008/api/sections/material/", new UserPrincipal(_httpContextAccessor.HttpContext).token, file).Result;

            return(this._autoMapper.Map <FileResponseDTO>(file));
        }
Exemplo n.º 11
0
 public void SaveFile(Domain.File file)
 {
     //TODO: fileservice is using repository (bypassing operation logic)
     if (file.Id > 0)
     {
         _repository.Update(file);
     }
     else
     {
         _repository.Create(file);
     }
 }
Exemplo n.º 12
0
        private async Task <Domain.File> BuildFileAsync(string fileName)
        {
            var file = new Domain.File();

            file.Id        = Guid.NewGuid();
            file.Name      = fileName;
            file.Extension = ".jpg";
            file.MimeType  = "image/jpeg";
            file.Data      = new byte[1];

            await this.filesRepository.AddAsync(file);

            return(file);
        }
        private void DeleteFilesInOs(Domain.File oldFile)
        {
            var fileInfo = new FileInfo(Path.Combine(GetDocumentsDirectory(), oldFile.Name));

            if (fileInfo.Exists)
            {
                fileInfo.Delete();
            }

            var fileInfoText = new FileInfo(Path.Combine(GetTextDirectory(), oldFile.Name + ".txt"));

            if (fileInfoText.Exists)
            {
                fileInfoText.Delete();
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// The process of registering the file information in the database
        /// </summary>
        /// <param name="entityList"></param>
        /// <param name="userID"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        public async Task Add(IList <FileDto> modelList, Guid userID, bool isCommit = true)
        {
            foreach (var model in modelList)
            {
                Domain.File entity = Mapper.Map <Domain.File>(model);
                entity.ID       = Guid.NewGuid();
                entity.CreateBy = userID;
                entity.CreateDT = DateTime.Now;

                uow.Repository <Domain.File>().Add(entity);
            }

            if (isCommit)
            {
                await uow.SaveChangesAsync();
            }
        }
        public async Task <string> SaveFileAsync(IFormFile file)
        {
            var createdOn         = DateTime.UtcNow;
            var rootPath          = settings.FileRootPath;
            var uploadsRootFolder = Path.Combine(rootPath, _uploadCatalog, userIdentityContext.ExternalId.ToString(), createdOn.Year.ToString(), createdOn.Month.ToString());

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

            var id = Guid.NewGuid();

            var fileEntity = new Domain.File
            {
                ContentType = file.ContentType,
                FileName    = file.FileName,
                UserId      = userIdentityContext.ExternalId,
                CreatedOn   = createdOn,
                ExternalId  = id,
                Id          = id,
                ModifiedOn  = createdOn,
                IsDeleted   = false,
            };

            this.Context.Files.Add(fileEntity);
            await this.Context.SaveChangesAsync();

            fileEntity.ExternalId = fileEntity.Id;
            await this.Context.SaveChangesAsync();

            var filePath = Path.Combine(uploadsRootFolder, fileEntity.Id.ToString());

            using (var fileStream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(fileStream).ConfigureAwait(false);
            }

            return(fileEntity.Id.ToString());
        }