public async Task <MediaFileProcessingResult> Process(MediaFileInfo file, RssFeedDto feed, CancellationToken ct) { string tempDirectory = null; try { tempDirectory = _tempDirectoryService.Create(feed.Id.ToString()); var alternativeFileName = Guid.NewGuid().ToString(); var downloadService = _fileDownloadResolver(feed.Type); var tempFile = await downloadService .DownloadMediaFile(file.Url, tempDirectory, alternativeFileName, ct) .ConfigureAwait(false); var fileResult = await ProcessFile(tempFile, tempDirectory, ct); var newEntry = new MediaFileDto { FeedId = feed.Id, Title = file.Name, FileName = fileResult, Url = file.VideoId }; _context.MediaFiles.Add(newEntry); await _context.SaveChangesAsync(); return(new MediaFileSuccessResult(feed.Url, newEntry.Id)); } catch (Exception ex) { return(new MediaFileErrorResult(feed.Url, ex)); } }
public IMediaFile CreateMediaFile(string filePath) { var exifData = _exifDataService.Read(filePath); var size = _fileService.GetSizeInMb(filePath); var mediaType = _extensionsProvider.GetMediaType(filePath); var dto = new MediaFileDto(filePath, exifData.IsExif, exifData.CreationDateTime, size, mediaType, exifData.CameraModel); return(_mediaFileFactory(dto)); }
public int AddFile(MediaFileDto model) { try { var entity = _mediaFileMapper.Map(model); _unitOfWork.MediaFileRepository.Add(entity); _unitOfWork.SaveChanges(); return(entity.Id); } catch (Exception) { throw; } }
public Task <string> SaveUserAvatar(MediaFileDto file) { try { //先删除默认头像 _mediaService.DeleteMediaFileAsync(file.UserId, file.BusinessType, true); //再新增 var result = _mediaService.AddMediaFileAsync(file); return(result); } catch (Exception ex) { throw ex; } }
public Task CreateAsync(AccountDto dto) { var account = _orchardService.ContentManager.New <AccountPart>("Account"); account.Sex = dto.Sex; account.UserId = dto.AccountId; account.MobilePhone = dto.MobilePhone; account.LoginWay = dto.LoginWay; account.ActiveState = ActiveState.Normal;//默认正常 var employeeResult = HasEmployee(dto.MobilePhone); if (employeeResult.Result != null) { account.IsEmployee = true; account.Sex = employeeResult.Result.Sex; account.MobilePhone = dto.MobilePhone; } account.CreateOn = DateTime.Now; _orchardService.ContentManager.Create(account, VersionOptions.Published);//创建账号 var defFileStream = _mediaService.GetDefaultMediaFile(Constant.DefaultAvatarName); if (defFileStream.Result != null) { //初次创建时使用默认头像 var defaultFile = new MediaFileDto { UserId = dto.AccountId, UserName = dto.AccountName, Stream = defFileStream.Result, BusinessType = Constant.DefaultAvatar, FileName = Constant.DefaultAvatarName }; SaveUserAvatar(defaultFile); } ClearCache(); return(Task.FromResult <object>(null)); }
public async Task <PhysicalFileResult> GetFile(int id, string fileName) { try { if (id != 0) { MediaFileDto file = await _fileManager.GetAsync(id); var filePath = $@"{_hostingEnv.WebRootPath}\{file.Path}"; return(new PhysicalFileResult(filePath, file.ContentType)); } else { IEnumerable <MediaFileDto> file = await _fileManager.GetAsync(fileName); var filePath = $@"{_hostingEnv.WebRootPath}\{file.FirstOrDefault().Path}"; return(new PhysicalFileResult(filePath, file.FirstOrDefault().ContentType)); } } catch (Exception) { throw; } }
public Task <int> AddFileAsync(MediaFileDto model) { return(Task.Run(() => AddFile(model))); }