/// <summary> /// Call this function when a file parameter had come /// </summary> /// <param name="index">index of parameter</param> /// <param name="fileNo">file number (1, 2 or 3)</param> /// <param name="stream">file stream</param> /// <returns></returns> public async Task NextFile(int index, int fileNo, Stream stream) { await CheckIfChangedAndSave(index); if (fileNo < 1 || fileNo > 3) { _messages.AddLast($"Unexpected file parameter file{fileNo} was provided. The parameter was skipped."); return; } if (_files[fileNo - 1] != null) { _messages.AddLast($"file{fileNo}[{index}] was presented twice. The first occurance will be used."); } try { _files[fileNo - 1] = await _fileStore.CreateAsync(stream); } catch (Exception ex) { _messages.AddLast($"An error occured when saving file{fileNo}[{index}]."); _logger.LogError(ex.Message); } }
/// <summary> /// Adds the specified file. /// </summary> /// <param name="file">The file.</param> /// <param name="stream">The binary stream.</param> /// <param name="cancellationToken">The <see cref="CancellationToken" /> used to propagate notifications that the operation should be canceled.</param> /// <returns></returns> public async Task <long> CreateAsync(File file, Stream stream, CancellationToken cancellationToken) { // use file guid instead name var id = await FileStore.CreateAsync(file, cancellationToken); var reference = BinaryProvider.InitUpload(id.ToString(CultureInfo.CurrentCulture)); await FileStore.InitAsync(id, BinaryProvider.AssemblyQualifiedName, reference, cancellationToken); await BinaryProvider.FinalizeUploadAsync(reference, stream, cancellationToken); await FileStore.FinalizeAsync(id, cancellationToken); return(id); }