public ExtractorSet(IArtifactQueries artifactQueries, IServicesMgr servicesMgr, ExecutionIdentity executionIdentity, Int32 workspaceArtifactId, ExtractorSetReporting extractorSetReporting, RDO extractorSetRdo)
        {
            ServicesMgr           = servicesMgr;
            ExtractorSetReporting = extractorSetReporting;
            ArtifactQueries       = artifactQueries;
            WorkspaceArtifactId   = workspaceArtifactId;
            ExecutionIdentity     = executionIdentity;

            SetMyProperties(extractorSetRdo);
        }
        public WorkerQueue(ISqlQueryHelper sqlQueryHelper, IArtifactQueries artifactQueries, ArtifactFactory artifactFactory, IDBContext eddsDbContext, IServicesMgr servicesMgr, ExecutionIdentity executionIdentity, Int32 agentId, Int32 resourceServerId, String batchTableName, TextExtractorLog textExtractorLog, ExtractorSetReporting textExtractorJobReporting)
        {
            InitializeDefaults();

            SqlQueryHelper            = sqlQueryHelper;
            ArtifactQueries           = artifactQueries;
            EddsDbContext             = eddsDbContext;
            ServicesMgr               = servicesMgr;
            ExecutionIdentity         = executionIdentity;
            AgentId                   = agentId;
            ResourceServerId          = resourceServerId;
            BatchTableName            = batchTableName;
            TextExtractorLog          = textExtractorLog;
            Records                   = GetWorkerQueueRecords(textExtractorJobReporting, artifactFactory);
            TextExtractorJobReporting = textExtractorJobReporting;
            ArtifactFactory           = artifactFactory;
            ErrorLogModel             = new ErrorLogModel(sqlQueryHelper, eddsDbContext, agentId, QueueTableName);
        }
        public WorkerQueueRecord(ISqlQueryHelper sqlSqlQueryHelper, IArtifactQueries artifactArtifactQueries, IDBContext eddsDbContext, IServicesMgr servicesMgr, ArtifactFactory artifactArtifactFactory, ExecutionIdentity executionExecutionIdentity, Int32 queueId, Int32 workspaceArtifactId, Int32 queueStatus, Int32 agentId, Int32 extractorSetArtifactId, Int32 documentArtifactId, Int32 extractorProfileArtifactId, Int32 sourceLongTextFieldArtifactId, ExtractorSetReporting textExtractorJobReporting, ExtractorSet extractorSet, ExtractorProfile extractorProfile)
        {
            SqlQueryHelper  = sqlSqlQueryHelper;
            ArtifactQueries = artifactArtifactQueries;

            QueueId                       = queueId;
            WorkspaceArtifactId           = workspaceArtifactId;
            QueueStatus                   = queueStatus;
            AgentId                       = agentId;
            ExtractorSetArtifactId        = extractorSetArtifactId;
            DocumentArtifactId            = documentArtifactId;
            ExtractorProfileArtifactId    = extractorProfileArtifactId;
            SourceLongTextFieldArtifactId = sourceLongTextFieldArtifactId;
            TextExtractorJobReporting     = textExtractorJobReporting;
            ArtifactFactory               = artifactArtifactFactory;

            QueueTableName    = Constant.Tables.WorkerQueue;
            EddsDbContext     = eddsDbContext;
            ServicesMgr       = servicesMgr;
            ExecutionIdentity = executionExecutionIdentity;

            ExtractorSet     = extractorSet;
            ExtractorProfile = extractorProfile;
        }
        private IEnumerable <WorkerQueueRecord> GetWorkerQueueRecords(ExtractorSetReporting textExtractorJobReporting, ArtifactFactory artifactFactory)
        {
            var records = new List <WorkerQueueRecord>();

            try
            {
                //reset unfinished jobs
                TextExtractorLog.RaiseUpdate(String.Format("Resetting records which failed. [Table = {0}]", QueueTableName));
                ResetUnfinishedJobs();

                //Retrieve records for worker queue
                var workerQueueBatch = SqlQueryHelper.RetrieveNextBatchInWorkerQueue(EddsDbContext, AgentId, BatchSize, BatchTableName, ResourceServerId);
                if (workerQueueBatch != null && workerQueueBatch.Rows.Count > 0)
                {
                    HasRecords = true;
                    TextExtractorLog.RaiseUpdate("Retrieved record(s) in the worker queue.");

                    //Extracting WorkspaceArtifactId and ExtractorSetArtifactID because our worker batch will contain documents only from a unique workspace and TextExtractorJob combination
                    WorkspaceArtifactId        = Convert.ToInt32(workerQueueBatch.Rows[0]["WorkspaceArtifactID"]);
                    ExtractorSetArtifactId     = Convert.ToInt32(workerQueueBatch.Rows[0]["ExtractorSetArtifactID"]);
                    ExtractorProfileArtifactId = Convert.ToInt32(workerQueueBatch.Rows[0]["ExtractorProfileArtifactID"]);

                    foreach (DataRow dataRow in workerQueueBatch.Rows)
                    {
                        var queueId                       = Convert.ToInt32(dataRow["QueueID"]);
                        var queueStatus                   = Convert.ToInt32(dataRow["QueueStatus"]);
                        var agentId                       = Convert.ToInt32(dataRow["AgentID"]);
                        var documentArtifactId            = Convert.ToInt32(dataRow["DocumentArtifactID"]);
                        var sourceLongTextFieldArtifactId = Convert.ToInt32(dataRow["SourceLongTextFieldArtifactID"]);

                        try
                        {
                            var extractorSet     = artifactFactory.GetInstanceOfExtractorSet(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, ExtractorSetArtifactId);
                            var extractorProfile = artifactFactory.GetInstanceOfExtractorProfile(ExecutionIdentity.CurrentUser, WorkspaceArtifactId, ExtractorProfileArtifactId);

                            var workerQueueRecord = new WorkerQueueRecord(SqlQueryHelper, ArtifactQueries, EddsDbContext, ServicesMgr, artifactFactory, ExecutionIdentity, queueId, WorkspaceArtifactId, queueStatus, agentId, ExtractorSetArtifactId, documentArtifactId, ExtractorProfileArtifactId, sourceLongTextFieldArtifactId, textExtractorJobReporting, extractorSet, extractorProfile);
                            records.Add(workerQueueRecord);
                        }
                        catch (Exception)
                        {
                            //Update ExtractorSet details
                            ArtifactQueries.UpdateExtractorSetDetails(ServicesMgr, ExecutionIdentity, WorkspaceArtifactId, ExtractorSetArtifactId, Constant.ErrorMessages.REQUIRED_FIELDS_ARE_MISSING);

                            //delete current record from worker queue
                            SqlQueryHelper.RemoveRecordFromWorkerQueue(EddsDbContext, Constant.Tables.WorkerQueue, queueId);

                            //delete any record for this Extractor Set in Worker Queue where Agents are not assigned
                            SqlQueryHelper.DeleteRecordsInWorkerQueueForCancelledExtractorSet(EddsDbContext, WorkspaceArtifactId, ExtractorSetArtifactId);
                        }
                    }
                }
                else
                {
                    HasRecords = false;
                    TextExtractorLog.RaiseUpdate("No records in the worker queue.");
                }
            }
            catch (Exception ex)
            {
                throw new CustomExceptions.TextExtractorException("An error occured when retrieving records in the worker queue.", ex);
            }

            return(records);
        }