Example #1
0
        public override void Execute()
        {
            //Get the current Agent artifactID
            Int32 agentArtifactID = this.AgentID;

            //Get a dbContext for the EDDS database
            Relativity.API.IDBContext eddsDBContext = this.Helper.GetDBContext(-1);

            try
            {
                //Check to see if there are any jobs in the queue that aren't assigned to a different agent
                Dictionary <string, int> jobInformation = GetJob(eddsDBContext, agentArtifactID);

                //If GetJob returns nothing raise a message saying that
                if (jobInformation is null)
                {
                    this.RaiseMessage("Queue is empty. Waiting for work.", 10);
                }
                //Otherwise get to work
                else
                {
                    //Set workspace and job artifactID from job dictionary
                    int workspaceArtifactID    = jobInformation["WorkspaceArtifactID"];
                    int jobArtifactID          = jobInformation["JobArtifactID"];
                    int sourceSearchArtifactID = jobInformation["SourceSearchArtifactID"];

                    //Get the workspace's DB context
                    Relativity.API.IDBContext workspaceDBContext = this.Helper.GetDBContext(workspaceArtifactID);

                    using (kCura.Relativity.Client.IRSAPIClient proxy = this.Helper.GetServicesManager().CreateProxy <kCura.Relativity.Client.IRSAPIClient>(Relativity.API.ExecutionIdentity.System))
                    {
                        proxy.APIOptions.WorkspaceID = workspaceArtifactID;
                        List <int> searchResults = RunSourceSearch(proxy, sourceSearchArtifactID);
                        CreatePopTable(workspaceDBContext, jobArtifactID, searchResults, true);
                    }

                    DataTable batch = GetJobBatch(workspaceDBContext, jobArtifactID, 5000);

                    if (batch is null)
                    {
                        UpdateJobStatus(eddsDBContext, agentArtifactID, workspaceArtifactID, jobArtifactID, 4);
                        CleanQueueTable(eddsDBContext);
                    }
                    else
                    {
                        UpdateJobStatus(eddsDBContext, agentArtifactID, workspaceArtifactID, jobArtifactID, 2);
                        DataTable updatedBatch = UpdateFilenameExtension(batch);
                        UpdateJobTable(workspaceDBContext, updatedBatch, jobArtifactID);
                        UpdateFileTable(workspaceDBContext, jobArtifactID);
                    }
                }
            }
            catch (System.Exception ex)
            {
                //Your Agent caught an exception
                this.RaiseError(ex.Message, ex.Message);
            }
        }
Example #2
0
        public static ICollection <JavaScriptBlock> GetAll(kCura.Relativity.Client.IRSAPIClient client)
        {
            var javaScriptBlocks = new List <JavaScriptBlock>();

            var qry = new kCura.Relativity.Client.DTOs.Query <kCura.Relativity.Client.DTOs.RDO>();

            qry.ArtifactTypeGuid = Helper.Constants.Javascripts.ObjectTypeGuid;
            //qry.Fields = kCura.Relativity.Client.DTOs.FieldValue.AllFields;
            qry.Fields = new List <kCura.Relativity.Client.DTOs.FieldValue> {
                new kCura.Relativity.Client.DTOs.FieldValue(Helper.Constants.Javascripts.Fields.Text)
                , new kCura.Relativity.Client.DTOs.FieldValue(Helper.Constants.Javascripts.Fields.ViewMode)
            };

            BooleanCondition onlyActiveJavaScript = new BooleanCondition(Helper.Constants.Javascripts.Fields.Disabled, BooleanConditionEnum.EqualTo, false);

            qry.Condition = onlyActiveJavaScript;


            try
            {
                var ActiveJavaScriptsResults = client.Repositories.RDO.Query(qry);

                if (ActiveJavaScriptsResults.Success)
                {
                    foreach (var result in ActiveJavaScriptsResults.Results)
                    {
                        var javaScript     = new JavaScriptBlock();
                        var resultArtifact = result.Artifact;
                        javaScript.Text       = resultArtifact.Fields.First(x => x.Guids.Contains(Helper.Constants.Javascripts.Fields.Text)).ValueAsLongText;
                        javaScript.ArtifactID = resultArtifact.ArtifactID;
                        var viewModeChoiceField = resultArtifact.Fields.First(x => x.Guids.Contains(Helper.Constants.Javascripts.Fields.ViewMode)).ValueAsSingleChoice;


                        javaScript.ViewMode = JavaScriptBlock.ViewModeValue.All;
                        if (viewModeChoiceField != null)
                        {
                            var viewModeChoice = client.Repositories.Choice.ReadSingle(viewModeChoiceField.ArtifactID);
                            if (viewModeChoice.Guids.Contains(Helper.Constants.Javascripts.Choices.ViewMode.ViewOnly))
                            {
                                javaScript.ViewMode = JavaScriptBlock.ViewModeValue.ViewOnly;
                            }
                            else if (viewModeChoice.Guids.Contains(Helper.Constants.Javascripts.Choices.ViewMode.EditOnly))
                            {
                                javaScript.ViewMode = JavaScriptBlock.ViewModeValue.EditOnly;
                            }
                        }
                        javaScriptBlocks.Add(javaScript);


                        //var jS = new JavaScripts();
                        //jS.text = text;
                    }
                }
                else
                {
                    Console.WriteLine(string.Format("An error occurred reading results: {0}", ActiveJavaScriptsResults.Message));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("An error occurred: {0}", ex.Message));
            }

            return(javaScriptBlocks);
        }