public InProgressDocument(DocumentIdentity id, string fileName, InProcessDocumentState state, DateTimeOffset lastStatusUpdateTime, string errorInfo = null) { Id = id ?? throw new ArgumentNullException(nameof(id)); FileName = fileName ?? throw new ArgumentNullException(nameof(fileName)); State = state; ErrorInfo = errorInfo; LastStatusUpdateTime = lastStatusUpdateTime; }
private async Task UpdateStateInternal(DocumentInfo document, InProcessDocumentState newState, string errorInfo, CancellationToken cancellationToken) { InProgressDocumentDbItem inProgressDocument = null; await ResilientTransaction.New(context).ExecuteAsync(async() => { var(id, userIdentity) = document.Id; inProgressDocument = await context.InProgressDocuments.FindAsync(new object[] { id, userIdentity }, cancellationToken); if (inProgressDocument != null) { context.InProgressDocuments.Update(inProgressDocument); } else { inProgressDocument = new InProgressDocumentDbItem { Id = id, UserIdentity = userIdentity, }; context.InProgressDocuments.Add(inProgressDocument); } inProgressDocument.ErrorInfo = errorInfo; inProgressDocument.FileName = document.FileName; inProgressDocument.State = newState; inProgressDocument.LastStatusUpdateTime = DateTimeOffset.UtcNow; await context.SaveChangesAsync(cancellationToken); }); if (inProgressDocument.State == newState) { await mediator.Publish( new InProgressDocumentStateChanged( new InProgressDocument( document.Id, inProgressDocument.FileName, inProgressDocument.State, inProgressDocument.LastStatusUpdateTime, inProgressDocument.ErrorInfo)), cancellationToken); } }
public Task UpdateState(DocumentInfo document, InProcessDocumentState newState, CancellationToken cancellationToken) { return(UpdateStateInternal(document, newState, null, cancellationToken)); }