private async Task CreateAuditRecordAsync(string fileGuid, MarkupUtilityImportJob markupUtilityImportJob, int documentArtifactId, int redactionId) { RaiseMessage($"creating audit record. {_errorContext}"); await AuditRecordHelper.CreateRedactionAuditRecordAsync( AgentHelper.GetDBContext(WorkspaceArtifactId), Constant.AuditRecord.AuditAction.REDACTION_CREATED, documentArtifactId, markupUtilityImportJob.CreatedBy, _importWorkerQueueRecord, markupUtilityImportJob.MarkupSetArtifactId, redactionId, fileGuid); }
public async Task ExecuteAsync() { IQuery queryHelper = new Query(); var resourceGroupIds = GetResourceGroupIDs(); IErrorQueries errorQueries = new ErrorQueries(); IArtifactQueries artifactQueries = new ArtifactQueries(); IAuditRecordHelper auditRecordHelper = new AuditRecordHelper(queryHelper); IMarkupTypeHelper markupTypeHelper = new MarkupTypeHelper(); var job = new ImportWorkerJob(AgentID, Helper, queryHelper, DateTime.Now, resourceGroupIds, errorQueries, artifactQueries, auditRecordHelper, markupTypeHelper); job.OnMessage += MessageRaised; try { RaiseMessage(string.Empty, 10); RaiseMessage("Enter Agent", 10); await job.ExecuteAsync(); RaiseMessage("Exit Agent", 10); RaiseMessage(string.Empty, 10); } catch (Exception ex) { //Raise an error on the agents tab and event viewer RaiseError(ex.ToString(), ex.ToString()); //Add the error to our custom Errors table queryHelper.InsertRowIntoImportErrorLogAsync(Helper.GetDBContext(-1), job.WorkspaceArtifactId, Constant.Tables.ImportWorkerQueue, job.RecordId, job.AgentId, ex.ToString()).Wait(); //Add the error to the Relativity Errors tab //this second try catch is in case we have a problem connecting to the RSAPI try { errorQueries.WriteError(Helper.GetServicesManager(), ExecutionIdentity.System, job.WorkspaceArtifactId, ex); } catch (Exception rsapiException) { RaiseError(rsapiException.ToString(), rsapiException.ToString()); } //Set the status in the queue to error queryHelper.UpdateStatusInImportWorkerQueueAsync(Helper.GetDBContext(-1), Constant.Status.Queue.Error, job.BatchTableName).Wait(); } }
public void CreateRedactionAuditRecordAsyncTestFailiure() { var mock = new Mock <IQuery>(); mock .Setup(x => x.CreateAuditRecordAsync(It.IsAny <IDBContext>(), It.IsAny <RedactionAuditRecord>())) .Throws <MarkupUtilityException>() .Verifiable(); var auditRecordHelper = new AuditRecordHelper(mock.Object); var task = auditRecordHelper.CreateRedactionAuditRecordAsync(_mockDbContext.Object, 1, 2, 3, "4", 5, 6, 7); var aggregateException = Assert.Throws <AggregateException>(() => { task.Wait(); }); string errorContext = $"{Constant.ErrorMessages.CREATE_REDACTION_AUDIT_RECORD_ERROR} [AuditActionId = {1}, ArtifactId = {2}, UserId = {3}, MarkupSetArtifactId = {6}, RedactionId = {5}, FileGuid = {"4"}]"; var actualException = aggregateException.InnerExceptions.First(x => x.GetType() == typeof(MarkupUtilityException)) as MarkupUtilityException; Assert.That(actualException, Is.Not.Null); if (actualException != null) { Assert.AreEqual(errorContext, actualException.Message); } }
public async Task CreateRedactionAuditRecordAsyncTestSuccess() { var mock = new Mock <IQuery>(); mock .Setup(x => x.CreateAuditRecordAsync(It.IsAny <IDBContext>(), It.IsAny <RedactionAuditRecord>())) .Returns(Task.FromResult(default(Task))) .Verifiable(); var auditRecordHelper = new AuditRecordHelper(mock.Object); await auditRecordHelper.CreateRedactionAuditRecordAsync(_mockDbContext.Object, 1, 2, 3, "4", 5, 6, 7); mock.Verify(x => x.CreateAuditRecordAsync(It.IsAny <IDBContext>(), It.Is <RedactionAuditRecord>(arg => arg.ArtifactId == 2 && arg.Action == 1 && arg.UserId == 3 && arg.Details == $@"<auditElement><imageMarkup id=""5"" pageNumber=""7"" markupSetArtifactID=""6"" /></auditElement>" && arg.RequestOrigination == $@"<auditElement><RequestOrigination><IP /><Prefix /><Page>{Constant.AuditRecord.APPLICATION_NAME}</Page></RequestOrigination></auditElement>" && arg.RecordOrigination == $@"<auditElement><RecordOrigination><MAC /><IP /><Server /></RecordOrigination></auditElement>")), Times.Exactly(1)); }