private void ProcessJob(IServicesMgr servicesMgr, int workspaceArtifactId, int jobArtifactId)
        {
            try
            {
                //Update job status to In Progress
                _apiChooser.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.IN_PROGRESS);

                //Update job metrics
                if (selectedApiType == Helpers.Constants.ApiType.Rsapi)
                {
                    RDO jobRdo = _apiChooser.RetrieveJob(servicesMgr, workspaceArtifactId, jobArtifactId);
                    RaiseMessage("Calculating metrics for the job", 10);
                    ProcessAllMetrics(servicesMgr, workspaceArtifactId, jobArtifactId, jobRdo);
                    RaiseMessage("Calculated metrics for the job", 10);
                }
                else if (selectedApiType == Helpers.Constants.ApiType.Gravity)
                {
                }

                //Update job status to Completed
                _apiChooser.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.COMPLETED);
            }
            catch (Exception ex)
            {
                //Update job status to Error
                string errorMessage = ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex);
                _apiChooser.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.ERROR);
                _apiChooser.UpdateJobField(servicesMgr, workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Errors_LongText, errorMessage);
            }
        }
        /// <summary>Constructor</summary>
        /// <param name="obj">Untyped object.</param>
        /// <param name="errors">Validation errors.</param>
        public ValidationException(object obj, IReadOnlyCollection <ValidationError> errors)
            : base(ExceptionMessageFormatter.CreateExceptionMessage(obj, errors))
        {
            Check.ArgumentIsNull(obj, "obj");
            Check.ArgumentIsNull(errors, "errors");
            Check.Argument(errors.Count > 0, "errors.Count > 0");

            Object = obj;
            Errors = errors;
        }
        public void GetEntireExceptionStack_returns_single_message_when_only_one_exception()
        {
            var formatter = new ExceptionMessageFormatter();

            var exception = new Exception("test");

            var result = formatter.GetEntireExceptionStack(exception);

            Assert.AreEqual(exception.Message, result);
        }
        public void GetEntireExceptionStack_returns_single_message_when_only_one_exception()
        {
            var formatter = new ExceptionMessageFormatter();

            var exception = new Exception("test");

            var result = formatter.GetEntireExceptionStack(exception);

            Assert.AreEqual(exception.Message, result);
        }
Beispiel #5
0
        public void GetFormattedMessage_WitInnerException_ShouldReturnMessage()
        {
            // Arrange
            var exception = new Exception(string.Empty, new AggregateException());
            var formatter = new ExceptionMessageFormatter();

            // Act
            var msg = formatter.GetFormattedMessage(exception);

            // Assert
            Assert.Pass("Handled exception without exception");
        }
        public void GetEntireExceptionStack_returns_all_messages_when_three_exceptions()
        {
            var formatter = new ExceptionMessageFormatter();

            var exception3 = new Exception("three");
            var exception2 = new Exception("two", exception3);
            var exception1 = new Exception("one", exception2);

            var result = formatter.GetEntireExceptionStack(exception1);

            Assert.AreEqual("one --> two --> three", result);
        }
        public void GetEntireExceptionStack_returns_all_messages_when_three_exceptions()
        {
            var formatter = new ExceptionMessageFormatter();

            var exception3 = new Exception("three");
            var exception2 = new Exception("two", exception3);
            var exception1 = new Exception("one", exception2);

            var result = formatter.GetEntireExceptionStack(exception1);

            Assert.AreEqual("one --> two --> three", result);
        }
Beispiel #8
0
        public void GetFormattedMessage_WithMessageAndNoInnerException_ShouldReturnMessage()
        {
            string message = Guid.NewGuid().ToString();

            // Arrange
            var exception = new Exception(message);
            var formatter = new ExceptionMessageFormatter();

            // Act
            var msg = formatter.GetFormattedMessage(exception);

            // Assert
            Assert.IsTrue(msg.Contains(message));
        }
Beispiel #9
0
        public async Task ProcessSingleUserAsync(Int32 workspaceArtifactID, Int32 jobArtifactID, ExportWorkerQueueRecord exportWorkerQueueRecord)
        {
            try
            {
                RaiseAndLogDebugMessage($"Processing a single user in export worker batch. [{nameof(exportWorkerQueueRecord.ArtifactId)}] = {exportWorkerQueueRecord.ArtifactId}");

                kCura.Relativity.Client.DTOs.User userRDO = await ArtifactQueries.RetrieveUserAsync(RsapiApiOptions, RsapiRepositoryGroup.UserRepository, exportWorkerQueueRecord.ArtifactId);

                //query user Auth data
                LoginProfile userLoginProfile = await AuthenticationHelper.RetrieveExistingUserLoginProfileAsync(userRDO.ArtifactID);

                //query keywords and notes for user
                KeywordsNotesModel userKeywordsNotesModel = await SqlQueryHelper.RetrieveKeywordsAndNotesForUserAsync(
                    eddsDbContext : AgentHelper.GetDBContext(-1),
                    userArtifactId : userRDO.ArtifactID);

                //query groups user is part of
                IEnumerable <String> userGroupNameList = await QueryGroupsNamesUserIsPartOfAsync(userRDO);

                UserAdminObject userAdminObject = await ConvertUserResultToUserAdminObjectAsync(userRDO);

                //add keywords and notes, auth and groups data to UserAdminObject
                await AddKeywordsNotesAuthInfoAndGroupsToUserAdminObjectAsync(userAdminObject, userKeywordsNotesModel, userGroupNameList, userLoginProfile);

                //insert user data info into the export worker results table
                await InsertUserDataIntoExportWorkerResultsTableAsync(exportWorkerQueueRecord, userAdminObject);

                RaiseAndLogDebugMessage($"Processed a single user in export worker batch. [{nameof(exportWorkerQueueRecord.ArtifactId)}] = {exportWorkerQueueRecord.ArtifactId}");
            }
            catch (Exception ex)
            {
                //create export job error record
                String details = ExceptionMessageFormatter.GetExceptionMessageIncludingAllInnerExceptions(ex);
                await CreateExportJobErrorRecordAsync(workspaceArtifactID, jobArtifactID, exportWorkerQueueRecord.ObjectType, Constant.Status.JobErrors.ERROR, details);
            }
        }
        private void ProcessJob(int workspaceArtifactId, int jobArtifactId)
        {
            try
            {
                //Update job status to In Progress
                _rsapiHelper.UpdateJobField(workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.IN_PROGRESS);

                //Update job metrics
                RDO jobRdo = _rsapiHelper.RetrieveJob(workspaceArtifactId, jobArtifactId);
                RaiseMessage("Calculating metrics for the job", 10);
                ProcessAllMetrics(workspaceArtifactId, jobArtifactId, jobRdo);
                RaiseMessage("Calculated metrics for the job", 10);

                //Update job status to Completed
                _rsapiHelper.UpdateJobField(workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.COMPLETED);
            }
            catch (Exception ex)
            {
                //Update job status to Error
                string errorMessage = ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex);
                _rsapiHelper.UpdateJobField(workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Status_LongText, Constants.JobStatus.ERROR);
                _rsapiHelper.UpdateJobField(workspaceArtifactId, jobArtifactId, Constants.Guids.Fields.InstanceMetricsJob.Errors_LongText, errorMessage);
            }
        }
 public void Setup()
 {
     this.formatter = new ExceptionMessageFormatter();
 }
        private void SetMyProperties(RDO extractorSetRdo)
        {
            if (extractorSetRdo == null)
            {
                Exists = false;
                return;
            }

            try
            {
                var savedSearchArtifact         = extractorSetRdo.Fields.Get(Constant.Guids.Fields.ExtractorSet.SavedSearch).ValueAsSingleObject;
                var extractorProfileArtifact    = extractorSetRdo.Fields.Get(Constant.Guids.Fields.ExtractorSet.ExtractorProfile).ValueAsSingleObject;
                var sourceLongTextFieldArtifact = extractorSetRdo.Fields.Get(Constant.Guids.Fields.ExtractorSet.SourceLongTextField).ValueAsSingleObject;

                String emailRecepients = extractorSetRdo.Fields.Get(Constant.Guids.Fields.ExtractorSet.EmailNotificationRecipients).ValueAsLongText;
                EmailRecepients = (String.IsNullOrWhiteSpace(emailRecepients) == true) ? null : emailRecepients.Split(';');

                SetName                       = extractorSetRdo.Fields.Get(Constant.Guids.Fields.ExtractorSet.SetName).ValueAsFixedLengthText;
                ArtifactId                    = extractorSetRdo.ArtifactID;
                Status                        = extractorSetRdo.Fields.Get(Constant.Guids.Fields.ExtractorSet.Status).ValueAsFixedLengthText;
                SavedSearchArtifactId         = savedSearchArtifact.ArtifactID;
                ExtractorProfileArtifactId    = extractorProfileArtifact.ArtifactID;
                SourceLongTextFieldArtifactId = sourceLongTextFieldArtifact.ArtifactID;
                Exists                        = true;
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.DEFAULT_CONVERT_TO_EXTRACTOR_SET_ERROR_MESSAGE + ". " + ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex), ex);
            }
        }
Beispiel #13
0
        private void SetMyProperties(RDO extractorProfileRdo)
        {
            try
            {
                ProfileName = extractorProfileRdo.Fields.Get(Constant.Guids.Fields.ExtractorProfile.ProfileName).ValueAsFixedLengthText;
                if (ProfileName == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.EXTRACTOR_PROFILE_PROFILE_NAME_IS_EMPTY);
                }

                ArtifactId = extractorProfileRdo.ArtifactID;
                if (ArtifactId < 1)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.EXTRACTOR_PROFILE_ARTIFACT_ID_CANNOT_BE_LESS_THAN_OR_EQUAL_TO_ZERO);
                }

                var targetTextArtifacts = extractorProfileRdo.Fields.Get(Constant.Guids.Fields.ExtractorProfile.TargetText).GetValueAsMultipleObject <Artifact>();
                if (targetTextArtifacts == null || targetTextArtifacts.Count == 0)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.EXTRACTOR_PROFILE_TARGET_TEXT_IS_EMPTY);
                }

                foreach (var targetTextArtifact in targetTextArtifacts)
                {
                    var targetText = ArtifactFactory.GetInstanceOfExtractorTargetText(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, targetTextArtifact.ArtifactID);

                    ExtractorTargetTexts.Add(targetText);
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.DEFAULT_CONVERT_TO_EXTRACTOR_PROFILE_ERROR_MESSAGE + ". " + ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex), ex);
            }
        }
        // Virtual for testing purpose
        public virtual Boolean Process(ExtractorSetDocument extractorSetDocument, ExtractorSet extractorSet)
        {
            if (extractorSetDocument == null)
            {
                throw new ArgumentNullException("extractorSetDocument");
            }
            if (extractorSetDocument.TextSource == null)
            {
                throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.EXTRACTOR_SET_SOURCE_LONG_TEXT_FIELD_IS_EMPTY);
            }

            var documentUpdatedWithExtractedText = false;

            ExtractorSetHistory extractorSetHistory = null;

            var errorContext = String.Format("An error occured when extracting text for field. [WorkspaceArtifactId: {0}, DocumentArtifactId: {1}, TextExtractorFieldArtifactId: {2}]", WorkspaceArtifactId, extractorSetDocument.ArtifactId, ArtifactId);

            try
            {
                string historyStartMarkerName = null;
                string historyStopMarkerName  = null;
                string historyMarkerType      = null;

                switch (TargetRule.MarkerEnum)
                {
                case Constant.MarkerEnum.RegEx:
                    historyStartMarkerName = RegExStartMarker.Name;
                    historyStopMarkerName  = (RegExStopMarker == null) ? null : RegExStopMarker.Name;
                    historyMarkerType      = "Regular Expression";
                    break;

                case Constant.MarkerEnum.PlainText:
                    historyStartMarkerName = StartMarker;
                    historyStopMarkerName  = StopMarker;
                    historyMarkerType      = "Plain Text";
                    break;
                }

                extractorSetHistory = new ExtractorSetHistory(ServicesMgr, ExecutionIdentity, ArtifactQueries, extractorSet.ArtifactId, extractorSetDocument.ArtifactId, DestinationField.ArtifactID, WorkspaceArtifactId, TargetName, historyStartMarkerName, historyStopMarkerName, historyMarkerType);

                if (!String.IsNullOrEmpty(this.StopMarker))
                {
                    TextExtractionUtility.StopMarker = this.StopMarker;
                }

                var extractedText = TextExtractionUtility.ExtractText(extractorSetDocument.TextSource, StartMarker, StopMarker, TargetRule);

                if (TextExtractionUtility.IsMarkerFound == false)
                {
                    //create extractor set history record
                    extractorSetHistory.CreateRecord(Constant.ExtractionSetHistoryStatus.COMPLETE_MARKER_NOT_FOUND);
                }
                else
                {
                    if (String.IsNullOrEmpty(extractedText))
                    {
                        //create extractor set history record
                        extractorSetHistory.CreateRecord(Constant.ExtractionSetHistoryStatus.COMPLETE_TEXT_NOT_FOUND);
                    }
                    else
                    {
                        //update Document field with extracted text
                        ArtifactQueries.UpdateDocumentTextFieldValue(ServicesMgr, ExecutionIdentity.CurrentUser, WorkspaceArtifactId, extractorSetDocument.ArtifactId, DestinationField.ArtifactID, extractedText);

                        //check if text is truncated
                        if (TextExtractionUtility.IsTextTruncated)
                        {
                            //Update TextExtractorDetails field on the Document object if extracted text is truncated
                            var fieldValue = String.Format(Constant.TextExtractorDetailsMessages.TRUNCATED, ArtifactQueries.GetFieldNameForArtifactId(ServicesMgr, ExecutionIdentity, WorkspaceArtifactId, DestinationField.ArtifactID));

                            ArtifactQueries.AppendToDocumentLongTextFieldValue(ServicesMgr, ExecutionIdentity, WorkspaceArtifactId, extractorSetDocument.ArtifactId, Constant.Guids.Fields.Document.TextExtractorDetails, fieldValue);
                        }

                        //create extractor set history record
                        extractorSetHistory.CreateRecord(Constant.ExtractionSetHistoryStatus.COMPLETE_TEXT_EXTRACTED);
                        documentUpdatedWithExtractedText = true;
                    }
                }
            }
            catch (Exception ex)
            {
                //create extractor set history record
                if (extractorSetHistory != null)
                {
                    extractorSetHistory.CreateRecord(Constant.ExtractionSetHistoryStatus.ERROR, ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex));
                }
                else
                {
                    throw new Exception("An error occured when creating Extractor Set History record.");
                }

                //log error message to ErrorLog table
                ErrorLogModel.InsertRecord(errorContext, ex, ArtifactId, WorkspaceArtifactId);
            }

            return(documentUpdatedWithExtractedText);
        }
        public void SetMyProperties(RDO extractorTargetTextRdo)
        {
            try
            {
                ArtifactId = extractorTargetTextRdo.ArtifactID;
                if (ArtifactId < 1)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_ARTIFACT_ID_CANNOT_BE_LESS_THAN_OR_EQUAL_TO_ZERO);
                }

                TargetName = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.TargetName).ValueAsFixedLengthText;
                if (TargetName == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_TARGET_NAME_IS_EMPTY);
                }

                switch (TargetRule.MarkerEnum)
                {
                case Constant.MarkerEnum.RegEx:
                    RegeExStartMarkerArtifact = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.RegularExpressionStartMarker).ValueAsSingleObject;
                    if (RegeExStartMarkerArtifact == null)
                    {
                        throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_REGULAR_EXPRESSION_IS_EMPTY);
                    }

                    ArtifactFactory artifactFactory = new ArtifactFactory(ArtifactQueries, ServicesMgr, ErrorLogModel);
                    RegExStartMarker = artifactFactory.GetInstanceOfExtractorRegullarExpression(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, RegeExStartMarkerArtifact.ArtifactID);

                    StartMarker = RegExStartMarker.RegularExpression;

                    RegeExStopMarkerArtifact = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.RegularExpressionStopMarker).ValueAsSingleObject;
                    if (RegeExStopMarkerArtifact == null || RegeExStopMarkerArtifact.ArtifactID < 1)
                    {
                        RegExStopMarker = null;
                    }
                    else
                    {
                        RegExStopMarker = artifactFactory.GetInstanceOfExtractorRegullarExpression(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, RegeExStopMarkerArtifact.ArtifactID);

                        StopMarker = RegExStopMarker.RegularExpression;
                    }
                    break;

                case Constant.MarkerEnum.PlainText:
                    PlainTextStartMarker = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.PlainTextStartMarker).ValueAsFixedLengthText;
                    if (PlainTextStartMarker == null)
                    {
                        throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_PLAIN_TEXT_MARKER_IS_EMPTY);
                    }

                    StartMarker = PlainTextStartMarker;

                    PlainTextStopMarker = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.PlainTextStopMarker).ValueAsFixedLengthText;
                    StopMarker          = PlainTextStopMarker;
                    break;
                }

                if (StartMarker == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_START_MARKER_IS_EMPTY);
                }

                if (StopMarker != null)
                {
                    TargetRule.DirectionEnum = Constant.DirectionEnum.RightToStopMarker;
                }

                DestinationField = extractorTargetTextRdo.Fields.Get(Constant.Guids.Fields.ExtractorTargetText.DestinationField).ValueAsSingleObject;
                if (DestinationField == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.TARGET_TEXT_DESTINATION_FIELD_IS_EMPTY);
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.DEFAULT_CONVERT_TO_EXTRACTOR_TARGET_TEXT_ERROR_MESSAGE + ". " + ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex), ex);
            }
        }
        public async Task ProcessNewRecordAsync(String delimitedListOfResourceGroupIds)
        {
            if (delimitedListOfResourceGroupIds != String.Empty)
            {
                DataTable dataTable = await RetrieveNextRecordInExportManagerQueueTableAsync(delimitedListOfResourceGroupIds);

                if (TableIsNotEmpty(dataTable))
                {
                    ExportManagerQueueRecord exportManagerQueueRecord = new ExportManagerQueueRecord(dataTable.Rows[0]);

                    SetJobProperties(exportManagerQueueRecord);

                    String context = $"[Table = {QueueTable}, ID = {TableRowId}, Workspace Artifact ID = {WorkspaceArtifactId}, Export Job Artifact ID = {ExportJobArtifactId}]";
                    RaiseAndLogDebugMessage($"Processing record(s). {context}");

                    try
                    {
                        Int32 numberOfExpectedExports;

                        //update export job status to in progress
                        await UpdateExportJobStatus(Constant.Status.Job.IN_PROGRESS_MANAGER, exportManagerQueueRecord);

                        //update export manager queue record with export results table name
                        String exportResultsTableName = $"{Constant.Names.ExportWorkerResultsTablePrefix}{Guid.NewGuid()}";
                        await SqlQueryHelper.UpdateResultsTableNameInExportManagerQueueAsync(AgentHelper.GetDBContext(-1), exportManagerQueueRecord.TableRowId, exportResultsTableName);

                        // Add specific logic for other types of objects here #DifferentObject
                        Constant.Enums.SupportedObjects migrationObjectType = (Constant.Enums.SupportedObjects)Enum.Parse(typeof(Constant.Enums.SupportedObjects), exportManagerQueueRecord.ObjectType);
                        switch (migrationObjectType)
                        {
                        case Constant.Enums.SupportedObjects.User:
                            numberOfExpectedExports = await ProcessUsers(exportManagerQueueRecord, exportResultsTableName);

                            break;

                        default:
                            throw new AdminMigrationUtilityException(Constant.ErrorMessages.InvalidAdminObjectTypeError);
                        }

                        //Update status and statistics long as cancellation is not requested
                        if (!await CancellationRequestedAsync(exportManagerQueueRecord))
                        {
                            await SqlQueryHelper.UpdateStatusInExportManagerQueueByWorkspaceJobIdAsync(
                                eddsDbContext : AgentHelper.GetDBContext(-1),
                                workspaceArtifactId : exportManagerQueueRecord.WorkspaceArtifactId,
                                exportJobArtifactId : exportManagerQueueRecord.ExportJobArtifactId,
                                queueStatus : Constant.Status.Queue.WAITING_FOR_WORKERS_TO_FINISH);

                            await UpdateExportJobStatus(Constant.Status.Job.COMPLETED_MANAGER, exportManagerQueueRecord);

                            await UpdateExportJobExpectedNumberOfExports(numberOfExpectedExports, exportManagerQueueRecord);
                        }
                    }
                    catch (Exception ex)
                    {
                        //update export job status to error
                        await UpdateExportJobStatus(Constant.Status.Job.ERROR, exportManagerQueueRecord);

                        String details = ExceptionMessageFormatter.GetExceptionMessageIncludingAllInnerExceptions(ex);
                        RaiseAndLogDebugMessage(details);

                        //remove record from export manager queue table
                        await ClearRecordsFromQueueTables(exportManagerQueueRecord);
                    }
                }
            }
        }
        public void ProcessAllRecords()
        {
            string[] emailRecepients = null;

            try
            {
                if (HasRecords)
                {
                    //update job status to worker - in progress
                    TextExtractorLog.RaiseUpdate(String.Format("Updating record status to {0}. [WorkspaceArtifactId: {1}, ExtractorSetArtifactID: {2}]", Constant.ExtractorSetStatus.IN_PROGRESS_WORKER_PROCESSING, WorkspaceArtifactId, ExtractorSetArtifactId));
                    ArtifactQueries.UpdateRdoStringFieldValue(ServicesMgr, ExecutionIdentity.CurrentUser, WorkspaceArtifactId, Constant.Guids.ObjectType.ExtractorSet, Constant.Guids.Fields.ExtractorSet.Status, ExtractorSetArtifactId, Constant.ExtractorSetStatus.IN_PROGRESS_WORKER_PROCESSING);

                    var countForLogging = 1;
                    foreach (var workerQueueRecord in Records)
                    {
                        TextExtractorLog.RaiseUpdate(String.Format("Processing record - {0}. [WorkspaceArtifactId: {1}, ExtractorSetArtifactID: {2}, DocumentArtifactId: {3}]", countForLogging++, WorkspaceArtifactId, ExtractorSetArtifactId, workerQueueRecord.DocumentArtifactId));

                        //check for ExtractorSet cancellation
                        var extractorSet = ArtifactFactory.GetInstanceOfExtractorSet(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, ExtractorSetArtifactId);
                        emailRecepients = extractorSet.EmailRecepients;

                        if (extractorSet.IsCancellationRequested())
                        {
                            TextExtractorLog.RaiseUpdate("Cancellation Requested.");

                            //delete all remaining records in current batch worker queue because the ExtractorSet is cancelled
                            TextExtractorLog.RaiseUpdate("Deleting all the remaining records in current worker queue batch.");
                            SqlQueryHelper.RemoveBatchFromQueue(EddsDbContext, BatchTableName);

                            return;
                        }

                        try
                        {
                            workerQueueRecord.Process();
                        }
                        catch (Exception ex)
                        {
                            var errorContext = String.Format("An error occured when processing the document. [WorkspaceArtifactId: {0}, ExtractorSetArtifactId: {1}, DocumentArtifactId: {2}]", workerQueueRecord.WorkspaceArtifactId, workerQueueRecord.ExtractorSetArtifactId, workerQueueRecord.DocumentArtifactId);

                            //log error message to ErrorLog table
                            ErrorLogModel.InsertRecord(errorContext, ex, workerQueueRecord.QueueId, workerQueueRecord.WorkspaceArtifactId);

                            //Update TextExtractorErrors field on the Document object incase of error
                            var    exceptionMessage = ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex);
                            String extractorSetName = ArtifactQueries.GetExtractorSetNameForArtifactId(ServicesMgr, ExecutionIdentity, WorkspaceArtifactId, workerQueueRecord.ExtractorSetArtifactId);
                            var    fieldValue       = String.Format(Constant.ErrorMessages.DOCUMENT_ERROR_ENCOUNTERED, exceptionMessage, extractorSetName);
                            ArtifactQueries.AppendToDocumentLongTextFieldValue(ServicesMgr, ExecutionIdentity, workerQueueRecord.WorkspaceArtifactId, workerQueueRecord.DocumentArtifactId, Constant.Guids.Fields.Document.TextExtractorErrors, fieldValue);

                            //Update ExtractorSet Details field
                            ArtifactQueries.UpdateExtractorSetDetails(ServicesMgr, ExecutionIdentity, workerQueueRecord.WorkspaceArtifactId, workerQueueRecord.ExtractorSetArtifactId, Constant.ExtractorSetStatus.DetailMessages.COMPLETE_WITH_ERRORS_DETAILS);
                        }
                        finally
                        {
                            //delete current record from worker queue
                            SqlQueryHelper.RemoveRecordFromWorkerQueue(EddsDbContext, workerQueueRecord.QueueTableName, workerQueueRecord.QueueId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException("An error occured when processing records in the worker queue.", ex);
            }
            finally
            {
                VerifyAndUpdateWorkerStatusToComplete();
                if (emailRecepients != null)
                {
                    VerifyAndSendEmailForExtractorSetComplete(emailRecepients);
                }
            }
        }
Beispiel #18
0
        public void SetMyProperties(RDO extractorRegullarExpressionRdo)
        {
            try
            {
                ArtifactId = extractorRegullarExpressionRdo.ArtifactID;
                if (ArtifactId < 1)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.REGULAR_EXPRESSION_ARTIFACT_ID_CANNOT_BE_LESS_THAN_OR_EQUAL_TO_ZERO);
                }

                Name = extractorRegullarExpressionRdo.Fields.Get(Constant.Guids.Fields.ExtractorRegularExpression.Name).ValueAsFixedLengthText;
                if (Name == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.REGULAR_EXPRESSION_NAME_IS_EMPTY);
                }

                RegularExpression = extractorRegullarExpressionRdo.Fields.Get(Constant.Guids.Fields.ExtractorRegularExpression.RegularExpression).ValueAsFixedLengthText;
                if (RegularExpression == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.REGULAR_EXPRESSION_REGULAR_EXPRESSION_IS_EMPTY);
                }

                Description = extractorRegullarExpressionRdo.Fields.Get(Constant.Guids.Fields.ExtractorRegularExpression.Description).ValueAsFixedLengthText;
                if (Description == null)
                {
                    throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.REGULAR_EXPRESSION_DESCRIPTION_IS_EMPTY);
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException(Constant.ErrorMessages.DEFAULT_CONVERT_TO_EXTRACTOR_REGULAR_EXPRESSION_ERROR_MESSAGE + ". " + ExceptionMessageFormatter.GetInnerMostExceptionMessage(ex), ex);
            }
        }