private static dynamic GetResult(FileContainer fileContainer, bool error = false) { switch (fileContainer.TypeContainer) { case TypeContainer.Video: return(new { finished = fileContainer.Finished(), debugInfo = error ? DebugInfo(fileContainer) : null, sourceAudioCpuEncoding = AudioCpuEncodeResultJson(fileContainer.SourceFileItem, error), sourceVideoGpuEncoding = VideoGpuEncodeResultJson(fileContainer.SourceFileItem, error), ipfsAddSourceVideo = IpfsResultJson(fileContainer.SourceFileItem, error), sprite = fileContainer.SpriteVideoFileItem == null ? null : new { spriteCreation = SpriteResultJson(fileContainer.SpriteVideoFileItem, error), ipfsAddSprite = IpfsResultJson(fileContainer.SpriteVideoFileItem, error) }, encodedVideos = !fileContainer.EncodedFileItems.Any() ? null : fileContainer.EncodedFileItems.Select(e => new { encode = AudioVideoCpuEncodeResultJson(e, error), ipfsAddEncodeVideo = IpfsResultJson(e, error) }) .ToArray() }); case TypeContainer.Image: return(new { ipfsAddSource = IpfsResultJson(fileContainer.SnapFileItem, error), ipfsAddOverlay = IpfsResultJson(fileContainer.OverlayFileItem, error) }); case TypeContainer.Subtitle: return(new { ipfsAddSource = IpfsResultJson(fileContainer.SubtitleFileItem, error) }); } LogManager.AddGeneralMessage(LogLevel.Critical, "Type container non géré " + fileContainer.TypeContainer, "Error"); throw new InvalidOperationException("type container non géré"); }
private async Task <string> GetFileToTemp() { // Copy file to temp location string sourceFilePath = TempFileManager.GetNewTempFilePath(); FormValueProvider formModel; try { // Récupération du fichier using (System.IO.FileStream stream = System.IO.File.Create(sourceFilePath)) { formModel = await Request.StreamFile(stream); } } catch (Exception ex) { LogManager.AddGeneralMessage(LogLevel.Critical, $"Exception Download File : {ex}", "Exception"); TempFileManager.SafeDeleteTempFile(sourceFilePath); throw; } try { ValueProviderResult fileName = formModel.GetValue("qqFileName"); if (fileName.Length == 1) { var extension = System.IO.Path.GetExtension(fileName.FirstValue); if (!string.IsNullOrWhiteSpace(extension)) { string newFilePath = System.IO.Path.ChangeExtension(sourceFilePath, extension); System.IO.File.Move(sourceFilePath, newFilePath); sourceFilePath = newFilePath; } } } catch {} return(sourceFilePath); }