I went through most of the questions about this exception, but none of them gave me hints on how to solve the problem that I encountered:
timeouts are not supported in this thread
Here is the code:
[ValidateAntiForgeryToken]
[HttpPost]
public async Task<ActionResult> Upload(TemplateOutputModel input)
{
var result = await Command.ApplyAsync(new UploadDocumentTemplateCommand
{
DocumentType = input.DocumentType,
InputStream = input.File.InputStream,
ContentLength = input.File.ContentLength,
FileExtension = ".docx"
});
if (result == Command.CommandResult.Succeeded)
return RedirectToAction("List");
throw new Exception("Template not uploaded");
}
public class UploadDocumentTemplateCommand:ICommand
{
public DocumentType DocumentType { get; set;}
public Stream InputStream { get; set; }
public int ContentLength { get; set; }
public string FileExtension { get; set; }
}
public async Task<Command.CommandResult> Apply(UploadDocumentTemplateCommand command)
{
if (command.ContentLength <= 0) return Command.CommandResult.Failed;
switch (command.FileExtension)
{
case ".pdf":
documentService.SaveStaticDocument(command.DocumentType, command.InputStream);
break;
case ".docx":
var versionNumber = documentRepository.GetDocumentTemplateVersion(command.DocumentType);
documentRepository.QuickTemplateUpload(command.DocumentType, command.InputStream, versionNumber + 1);
break;
}
return Command.CommandResult.Succeeded;
}
Any help is much appreciated.
source
share