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 { /* * * //Setting up an RSAPI Client * using (IRSAPIClient proxy = * Helper.GetServicesManager().CreateProxy<IRSAPIClient>(ExecutionIdentity.System)) * { * //Add code for working with RSAPIClient * } * */ } catch (System.Exception ex) { //Your Agent caught an exception this.RaiseError(ex.Message, ex.Message); } }
public static void CleanQueueTable(Relativity.API.IDBContext eddsDBContext) { string sql = @" DELETE FROM [EDDS].[eddsdbo].[ExtensionFixerQueue] WHERE [Status] = 4"; eddsDBContext.ExecuteNonQuerySQLStatement(sql); }
public static Int32 JobQueueDepth(Relativity.API.IDBContext eddsDBContext) { string sql = @" SELECT COUNT(*) FROM [EDDS].[eddsdbo].[ExtensionFixerQueue]"; return(Int32.Parse(eddsDBContext.ExecuteSqlStatementAsScalar(sql).ToString())); }
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); } }
public static void UpdateJobStatus(Relativity.API.IDBContext eddsDBContext, Int32 agentArtifactID, Int32 workspaceArtifactID, Int32 jobArtifactID, Int32 statusCode) { string sql = String.Format(@" UPDATE [EDDS].[eddsdbo].[ExtensionFixerQueue] SET [Status] = {0} WHERE [WorkspaceArtifactID] = {1} AND [JobArtifactID] = {2} AND [AgentArtifactID] = {3}", statusCode, workspaceArtifactID, jobArtifactID, agentArtifactID); eddsDBContext.ExecuteNonQuerySQLStatement(sql); }
public static void UpdateJobTable(Relativity.API.IDBContext workspaceDBContext, DataTable completedBatch, Int32 jobArtifactID) { foreach (DataRow row in completedBatch.Rows) { string sql = String.Format(@" UPDATE [EDDSDBO].[REF_POP_{0}] SET [Filename] = '{1}', [Status] = 3 WHERE FileID = {2}", jobArtifactID.ToString(), row["Filename"].ToString(), row["FileID"].ToString()); workspaceDBContext.ExecuteNonQuerySQLStatement(sql); } }
public static void CreatePopTable(Relativity.API.IDBContext workspaceDBContext, int jobArtifactID, List <int> searchArtifacts, bool imagesOnly) { string sql = String.Format(@" IF OBJECT_ID('[REF_POP_{0}]') IS NULL CREATE TABLE [REF_POP_{0}]( [FileID] [int] NOT NULL, [Filename] [nvarchar](200) NOT NULL, [Location] [nvarchar](2000) NOT NULL, [Status] [int] NOT NULL);" , jobArtifactID.ToString()); workspaceDBContext.ExecuteNonQuerySQLStatement(sql); foreach (int documentArtifactID in searchArtifacts) { if (imagesOnly) { sql = String.Format(@" INSERT INTO [REF_POP_{0}] SELECT F.[FileID] , F.[Filename] , F.[Location] , 0 FROM [File] AS F LEFT JOIN [REF_POP_{0}] AS REF ON REF.[FileID] = F.[FileID] WHERE F.[Type] IN (1,3) AND F.[Filename] NOT LIKE '%.%' AND REF.[FileID] IS NULL AND F.[DocumentArtifactID] = {1}", jobArtifactID.ToString(), documentArtifactID.ToString()); } else { sql = String.Format(@" INSERT INTO [REF_POP_{0}] SELECT F.[FileID] , F.[Filename] , F.[Location] , 0 FROM [File] AS F LEFT JOIN [REF_POP_{0}] AS REF ON REF.[FileID] = F.[FileID] WHERE F.[Filename] NOT LIKE '%.%' AND REF.[FileID] IS NULL AND F.[DocumentArtifactID] = {1}", jobArtifactID.ToString(), documentArtifactID.ToString()); } workspaceDBContext.ExecuteNonQuerySQLStatement(sql); } }
public static Boolean DoesAgentHaveJob(Relativity.API.IDBContext eddsDBContext, Int32 agentArtifactID) { string sql = String.Format(@" SELECT COUNT(*) FROM [EDDS].[eddsdbo].[ExtensionFixerQueue] WHERE [AgentArtifactID] = {0}", agentArtifactID.ToString()); Int32 jobCount = Int32.Parse(eddsDBContext.ExecuteSqlStatementAsScalar(sql).ToString()); if (jobCount > 0) { return(true); } else { return(false); } }
private static int GetTemplateCase(Relativity.API.IDBContext context) { string getTemplate = "SELECT TOP 1 [CaseTemplateID] " + "FROM [CaseEventHandlerHistory] " + "WHERE [CaseTemplateID] IS NOT NULL"; SqlDataReader result = context.ExecuteSQLStatementAsReader(getTemplate); if (result.HasRows) { result.Read(); return(result.GetInt32(0)); } return(0); }
public override Response Execute() { //Construct a response object with default values. kCura.EventHandler.Response retVal = new kCura.EventHandler.Response(); retVal.Success = true; retVal.Message = string.Empty; try { Int32 currentWorkspaceArtifactID = Helper.GetActiveCaseID(); //The Object Manager is the newest and preferred way to interact with Relativity instead of the Relativity Services API(RSAPI). //The RSAPI will be scheduled for depreciation after the Object Manager reaches feature party with it. using (IObjectManager objectManager = this.Helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.System)) { retVal.Success = false; retVal.Message = "FirstTime"; } //Setting up an RSAPI Client using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System)) { //Set the proxy to use the current workspace proxy.APIOptions.WorkspaceID = currentWorkspaceArtifactID; //Add code for working with RSAPIClient } Relativity.API.IDBContext workspaceContext = Helper.GetDBContext(currentWorkspaceArtifactID); //Get a dbContext for the EDDS database Relativity.API.IDBContext eddsDBContext = Helper.GetDBContext(-1); IAPILog logger = Helper.GetLoggerFactory().GetLogger(); logger.LogVerbose("Log information throughout execution."); } catch (Exception ex) { //Change the response Success property to false to let the user know an error occurred retVal.Success = false; retVal.Message = ex.ToString(); } return(retVal); }
public static void UpdateFileTable(Relativity.API.IDBContext workspaceDBContext, Int32 jobArtifactID) { string sql = String.Format(@" UPDATE F SET F.[Filename] = REF.[Filename] FROM [EDDSDBO].[File] AS F INNER JOIN [EDDSDBO].[REF_POP_{0}] AS REF ON F.[FileID] = REF.[FileID] WHERE [REF].[Status] = 3; UPDATE [EDDSDBO].[REF_POP_{0}] SET [Status] = 4 WHERE [Status] = 3; DELETE FROM [EDDSDBO].[REF_POP_{0}] WHERE [Status] = 4;", jobArtifactID); workspaceDBContext.ExecuteNonQuerySQLStatement(sql); }
public override kCura.EventHandler.Response Execute() { //Construct a response object with default values. kCura.EventHandler.Response retVal = new kCura.EventHandler.Response(); retVal.Success = true; retVal.Message = String.Empty; try { Int32 currentWorkspaceArtifactID = this.Helper.GetActiveCaseID(); /* * //Setting up an RSAPI Client * using (IRSAPIClient proxy = * Helper.GetServicesManager().CreateProxy<IRSAPIClient>(ExecutionIdentity.System)) * { * //Set the proxy to use the current workspace * proxy.APIOptions.WorkspaceID = currentWorkspaceArtifactID; * //Add code for working with RSAPIClient * } */ workspaceContext = this.Helper.GetDBContext(currentWorkspaceArtifactID); //Start the transaction workspaceContext.BeginTransaction(); //Get a dbContext for the EDDS database Relativity.API.IDBContext eddsDBContext = this.Helper.GetDBContext(-1); } catch (System.Exception ex) { //Change the response Success property to false to let the user know an error occurred retVal.Success = false; retVal.Message = ex.ToString(); } return(retVal); }
public static Dictionary <string, int> GetJob(Relativity.API.IDBContext eddsDBContext, Int32 agentArtifactID) { Int32 workspaceArtifactID; Int32 jobArtifactID; Int32 sourceSearchArtifactID; if (DoesAgentHaveJob(eddsDBContext, agentArtifactID)) { string sql = String.Format(@" SELECT TOP 1 [JobArtifactID], [WorkspaceArtifactID], [SourceSearchArtifactID] FROM [EDDS].[eddsdbo].[ExtensionFixerQueue] WHERE AgentArtifactID = {0} AND [Status] NOT IN (4, 5)", agentArtifactID); DataTable jobInfo = eddsDBContext.ExecuteSqlStatementAsDataTable(sql); DataRow row = jobInfo.Rows[0]; workspaceArtifactID = Int32.Parse(row["WorkspaceArtifactID"].ToString()); jobArtifactID = Int32.Parse(row["JobArtifactID"].ToString()); sourceSearchArtifactID = Int32.Parse(row["SourceSearchArtifactID"].ToString()); Dictionary <string, int> outputDict = new Dictionary <string, int> { { "WorkspaceArtifactID", workspaceArtifactID }, { "JobArtifactID", jobArtifactID }, { "SourceSearchArtifactID", sourceSearchArtifactID } }; return(outputDict); } else if (JobQueueDepth(eddsDBContext) > 0) { string sql = @" SELECT TOP 1 [JobArtifactID], [WorkspaceArtifactID], [SourceSearchArtifactID] FROM [EDDS].[eddsdbo].[ExtensionFixerQueue] WHERE [Status] = 0"; DataTable jobInfo = eddsDBContext.ExecuteSqlStatementAsDataTable(sql); DataRow row = jobInfo.Rows[0]; workspaceArtifactID = Int32.Parse(row["WorkspaceArtifactID"].ToString()); jobArtifactID = Int32.Parse(row["JobArtifactID"].ToString()); sourceSearchArtifactID = Int32.Parse(row["SourceSearchArtifactID"].ToString()); sql = String.Format(@" UPDATE [EDDS].[eddsdbo].[ExtensionFixerQueue] SET [Status] = 2, [AgentArtifactID] = {0} WHERE [WorkspaceArtifactID] = {1} AND [JobArtifactID] = {2}", agentArtifactID, workspaceArtifactID, jobArtifactID); eddsDBContext.ExecuteNonQuerySQLStatement(sql); Dictionary <string, int> outputDict = new Dictionary <string, int> { { "WorkspaceArtifactID", workspaceArtifactID }, { "JobArtifactID", jobArtifactID }, { "SourceSearchArtifactID", sourceSearchArtifactID } }; return(outputDict); } else { return(null); } }
private async Task SubmitDocuments(ConsoleButton consoleButton) { try { switch (consoleButton.Name) { //Handle each Button's functionality case "Submit Documents": int workspaceId = this.Helper.GetActiveCaseID(); int modelId = this.ActiveArtifact.ArtifactID; Model model = new Model(); //Get Documents In SavedSearch int savedSearchId = (int)this.ActiveArtifact.Fields[Guids.Model.SAVED_SEARCH_FIELD.ToString()].Value.Value; await model.ReadDocumentsInSavedSeach(Helper.GetServicesManager(), workspaceId, savedSearchId); //Could have made function shared with the other event handler but left here for demo Relativity.API.IDBContext workspaceContext = Helper.GetDBContext(workspaceId); string documentLocation = string.Empty; List <string> documentLocations = new List <string>(); foreach (int documentArtifactId in model.DocsInSearch) { string sql = @"SELECT [Location] FROM [file] WITH(NOLOCK) WHERE [DocumentArtifactId] = @documentArtifactID AND [Type] = 0"; SqlParameter documentArtifactIdParam = new SqlParameter("@documentArtifactID", SqlDbType.Int); documentArtifactIdParam.Value = documentArtifactId; documentLocation = workspaceContext.ExecuteSqlStatementAsScalar <String>(sql, new SqlParameter[] { documentArtifactIdParam }); documentLocations.Add(documentLocation); } //get secrets AzureSettings azureSettings = new AzureSettings(); ISecretStore secretStore = this.Helper.GetSecretStore(); Secret secret = secretStore.Get(azureSettings.SecretPath); string congnitiveServicesKey = secret.Data[azureSettings.CognitiveServicesKeySecretName]; string congnitiveServicesEndPoint = secret.Data[azureSettings.CognitiveServicesEndpointSecretName]; string storageAccountKey = secret.Data[azureSettings.StorageAccountKeySecretName]; string storageAccountName = secret.Data[azureSettings.StorageAccountNameSecretName]; //upload documents to New Container AzureStorageService azureStorageService = new FormRecognition.AzureStorageService(storageAccountKey, storageAccountName); Microsoft.Azure.Storage.Blob.CloudBlobClient client = azureStorageService.GetClient(); string containerPrefix = workspaceId.ToString() + "-" + modelId.ToString(); string sasUrl = azureStorageService.UploadFiles(client, documentLocations, containerPrefix); string containerName = azureStorageService.ContainerName; //Train model AzureFormRecognitionService azureFormRecognitionService = new FormRecognition.AzureFormRecognitionService(congnitiveServicesKey, congnitiveServicesEndPoint, Helper); Guid modeld = await azureFormRecognitionService.TrainModelAsync(azureFormRecognitionService.GetClient(), sasUrl); model.ModelGuid = modeld; model.SasUrl = sasUrl; //Update Relativity with data returned await model.UpdateRelativity(Helper.GetServicesManager(), workspaceId, modelId); break; } } catch (Exception e) { Helper.GetLoggerFactory().GetLogger().LogError(e, "Submit Documents Error"); throw; } }