public async static Task <int> GetFieldArtifactID(string fieldName, IEHHelper helper, IAPILog logger) { int fieldArtifactId = 0; using (IObjectManager objectManager = helper.GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.System)) { var queryRequest = new QueryRequest() { ObjectType = new ObjectTypeRef() { Name = "Field" }, Condition = $"'Name' == '{fieldName}' AND 'Object Type' == 'Document'" }; var queryResult = await objectManager.QuerySlimAsync(helper.GetActiveCaseID(), queryRequest, 0, 1); if (queryResult.TotalCount > 0) { fieldArtifactId = queryResult.Objects.Select(x => x.ArtifactID).FirstOrDefault(); logger.LogVerbose("Alert field artifactID: {fieldArtifactID}", fieldArtifactId); } } return(fieldArtifactId); }
/// <summary> /// Agent logic goes here /// </summary> public override void Execute() { IAPILog logger = Helper.GetLoggerFactory().GetLogger(); try { //Get a dbContext for the workspace database int workspaceArtifactId = Helpers.Constants.WORKSPACE_ID; //Setting up an RSAPI Client using (IRSAPIClient rsapiClient = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.CurrentUser)) { //Set the proxy to use the current workspace rsapiClient.APIOptions.WorkspaceID = workspaceArtifactId; var counter = 0; while (counter < 10) { var imageRDO = new RDO(); imageRDO.ArtifactTypeGuids.Add(Helpers.Constants.IMAGE_OBJECT_GUID); imageRDO.Fields.Add(new FieldValue(Helpers.Constants.IMAGE_NAME_FIELD_GUID, DateTime.Now.ToLongTimeString() + " " + counter.ToString())); rsapiClient.Repositories.RDO.Create(imageRDO); counter++; } } logger.LogVerbose("Log information throughout execution."); } catch (Exception ex) { //Your Agent caught an exception logger.LogError(ex, "There was an exception."); RaiseError(ex.Message, ex.Message); } }
// GET: Home public ActionResult Index() { IAPILog logger = Relativity.CustomPages.ConnectionHelper.Helper().GetLoggerFactory().GetLogger(); try { //Gets the user ID. int userArtifactId = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.ArtifactID; //Gets the user ID to use for auditing purposes. int userAuditArtifactId = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.AuditArtifactID; //Gets the user workspace artifact ID to use for auditing purposes. int userAuditWorkspaceUserArtifactId = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.AuditWorkspaceUserArtifactID; //Gets the email address of the current user. string userEmailAddress = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.EmailAddress; //Gets the first name of the current user. string firstName = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.FirstName; //Gets the last name of the current user. string lastName = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.LastName; //Gets the full name of the current user. string fullName = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.FullName; //Gets the current user workspace artifact ID. int currentUserWorkspaceArtifactId = Relativity.CustomPages.ConnectionHelper.Helper().GetAuthenticationManager().UserInfo.WorkspaceUserArtifactID; //Get GUID for an artifact int testArtifactId = 1234567; Guid guidForTestArtifactId = Relativity.CustomPages.ConnectionHelper.Helper().GetGuid(currentUserWorkspaceArtifactId, testArtifactId); //Get a dbContext for the EDDS database IDBContext eddsDbContext = Relativity.CustomPages.ConnectionHelper.Helper().GetDBContext(-1); //Get a dbContext for the workspace database IDBContext workspaceDbContext = Relativity.CustomPages.ConnectionHelper.Helper().GetDBContext(currentUserWorkspaceArtifactId); //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 = Relativity.CustomPages.ConnectionHelper.Helper().GetServicesManager().CreateProxy <IObjectManager>(ExecutionIdentity.CurrentUser)) { } //Setting up an RSAPI Client using (IRSAPIClient rsapiClient = Relativity.CustomPages.ConnectionHelper.Helper().GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.CurrentUser)) { //Set the proxy to use the current workspace rsapiClient.APIOptions.WorkspaceID = currentUserWorkspaceArtifactId; //Add code for working with RSAPIClient } logger.LogVerbose("Log information throughout execution."); } catch (Exception ex) { //Your custom page caught an exception logger.LogError(ex, "There was an exception."); } return(View()); }
/// <summary> /// Agent logic goes here /// </summary> public override void Execute() { IAPILog logger = Helper.GetLoggerFactory().GetLogger(); try { // Update Security Protocol ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //Get the current Agent artifactID int agentArtifactId = AgentID; //Get a dbContext for the EDDS database IDBContext eddsDbContext = Helper.GetDBContext(-1); //Get a dbContext for the workspace database //int workspaceArtifactId = 01010101; // Update it with the real //IDBContext workspaceDbContext = Helper.GetDBContext(workspaceArtifactId); //Get GUID for an artifact //int testArtifactId = 10101010; //Guid guidForTestArtifactId = Helper.GetGuid(workspaceArtifactId, testArtifactId); //Display a message in Agents Tab and Windows Event Viewer RaiseMessage("The current time is: " + DateTime.Now.ToLongTimeString(), 1); //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 (IWorkspaceName workspaceName = this.Helper.GetServicesManager().CreateProxy <IWorkspaceName>(ExecutionIdentity.CurrentUser)) { String name = workspaceName.GetWorkspaceNameAsync(1017759).Result.Name; RaiseMessage("The worksapce name is" + name, 1); } //Setting up an RSAPI Client using (IRSAPIClient rsapiClient = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.CurrentUser)) { //Set the proxy to use the current workspace //rsapiClient.APIOptions.WorkspaceID = workspaceArtifactId; //Add code for working with RSAPIClient } logger.LogVerbose("Log information throughout execution."); } catch (Exception ex) { //Your Agent caught an exception logger.LogError(ex, "There was an exception."); RaiseError(ex.Message, ex.Message); } }
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 override Response Execute() { IAPILog logger = Helper.GetLoggerFactory().GetLogger(); logger.LogVerbose("Log information throughout execution."); ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; Response retVal = new Response(); retVal.Success = true; retVal.Message = string.Empty; try { Int32 currentWorkspaceArtifactID = this.Helper.GetActiveCaseID(); using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System)) { proxy.APIOptions.WorkspaceID = currentWorkspaceArtifactID; //Add code for working with RSAPIClient int fieldMatchCount = QueryForArticleTitleField(proxy, currentWorkspaceArtifactID); if (fieldMatchCount < 1) { int createSuccess = CreateDocumentFieldArticleTitle(proxy, currentWorkspaceArtifactID); if (createSuccess <= 0) { retVal.Success = false; retVal.Message = "Failed to create the field!"; logger.LogInformation("Failed to create"); } } } } catch (Exception ex) { retVal.Success = false; retVal.Message = ex.ToString(); } return(retVal); }
public override Response Execute() { Helper.GetLoggerFactory().GetLogger(); //Construct a response object with default values. Response retVal = new Response(); retVal.Success = true; retVal.Message = String.Empty; //Get the logger from the helper IAPILog logger = Helper.GetLoggerFactory().GetLogger(); logger.LogVerbose("Log information throughout execution."); try { IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System); //Set the proxy to use the current workspace proxy.APIOptions.WorkspaceID = -1; //Get a dbContext for the EDDS database IDBContext dbContext = Helper.GetDBContext(-1); Boolean isValidSandbox = false; //Check to see if its an R1 instance logger.LogDebug($"DAPI - {nameof(DynamicApiPreInstallEventHandler)} - {nameof(Execute)} - Checking to see if the relativity instance is a cloud instance."); int doesCloudInstanceSettingExist = DoesInstanceSettingExists(dbContext, RELATIVITY_URL_SECTION_NAME, RELATIVITY_CLOUD_INSTANCE_SETTING); string cloudInstanceSetting = GetInstanceSetting(dbContext, RELATIVITY_URL_SECTION_NAME, RELATIVITY_CLOUD_INSTANCE_SETTING); if (!string.IsNullOrWhiteSpace(cloudInstanceSetting)) { if (cloudInstanceSetting.ToLower().Equals("true")) { logger.LogDebug($"DAPI - {nameof(DynamicApiPreInstallEventHandler)} - {nameof(Execute)} - Relativity instance is a cloud instance."); //Get the URL for the Relativity Instance URL string relativityInstance = GetInstanceSetting(dbContext, RELATIVITY_URL_SECTION_NAME, RELATIVITY_URL_NAME); if (string.IsNullOrWhiteSpace(relativityInstance)) { isValidSandbox = false; } else { //If Relativity instance ends with sandbox.relativity.one then install the application if (relativityInstance.ToLower().EndsWith(SandboxString1.ToLower()) || relativityInstance.ToLower().EndsWith(SandboxString2.ToLower())) { isValidSandbox = true; } } } else { isValidSandbox = true; } } // If on-prem or sandbox RelOne if (doesCloudInstanceSettingExist == 0 || isValidSandbox) { logger.LogDebug($"DAPI - {nameof(DynamicApiPreInstallEventHandler)} - {nameof(Execute)} - Application installation was successful."); retVal.Success = true; retVal.Message = String.Empty; } else { logger.LogDebug($"DAPI - {nameof(DynamicApiPreInstallEventHandler)} - {nameof(Execute)} - Relativity instance is not an RelOne Developer Sandbox or On-Prem, installation has been stopped."); retVal.Success = false; retVal.Message = "Application is only allowed to be installed in an RelOne Developer Sandbox or On-Prem Instance."; } } //If its an On-prem instance do nothing 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 override Response PopulateScriptBlocks() { Response retVal = new Response() { Success = true, Message = string.Empty }; int currentWorkspaceArtifactID = Helper.GetActiveCaseID(); int currentLayoutArtifactID = this.ActiveLayout.ArtifactID; int currentDocumentArtifactID = this.ActiveArtifact.ArtifactID; IAPILog logger = Helper.GetLoggerFactory().GetLogger(); int fieldArtifactID = RelativityAlertPIEH.Helper.GetFieldArtifactID(_fieldName, Helper, logger).GetAwaiter().GetResult(); if (fieldArtifactID < 1) { logger.LogDebug("Alert field {fieldName} not found in workspace {caseArtifactID}", _fieldName, currentWorkspaceArtifactID); return(retVal); } IDBContext workspaceDbContext = this.Helper.GetDBContext(currentWorkspaceArtifactID); bool fieldExists = RelativityAlertPIEH.Helper.FindFieldOnLayout(workspaceDbContext, fieldArtifactID, currentLayoutArtifactID, logger); if (!fieldExists) { logger.LogVerbose("Alert NOT fired because {fieldName} field not present on workspace {caseArtifactID}, layout {layoutArtifactID}", _fieldName, currentWorkspaceArtifactID, currentLayoutArtifactID); return(retVal); } string alertFieldText = ""; if (!this.ActiveArtifact.Fields[_fieldName].Value.IsNull) { alertFieldText = RelativityAlertPIEH.Helper.SanitizeAlertText(this.ActiveArtifact.Fields[_fieldName].Value.Value.ToString()); } if (!String.IsNullOrEmpty(alertFieldText)) { string alert = $"<script type=\"text/javascript\"> alert(\"{ alertFieldText }\"); </script>"; this.RegisterClientScriptBlock(new ScriptBlock() { Key = "alertKey", Script = alert }); logger.LogDebug("Alert fired on workspace {caseArtifactID}, layout {layoutArtifactID}, and document {documentArtifactID}", currentWorkspaceArtifactID, currentLayoutArtifactID, currentDocumentArtifactID); } else { logger.LogVerbose("Alert NOT fired on workspace {caseArtifactID}, layout {layoutArtifactID}, and document {documentArtifactID}", currentWorkspaceArtifactID, currentLayoutArtifactID, currentDocumentArtifactID); } logger.LogVerbose("Alert text detected: {alertFieldText}", alertFieldText); return(retVal); }
public override void Execute() { IAPILog logger = Helper.GetLoggerFactory().GetLogger(); try { /* Adding message so time of last check-in updates */ RaiseMessage("Managing the agents.", 10); /* Resource Pool ArtifactID is hard coded for now (Default pool) * Will eventually make this accessible in the UI */ int poolId = 1015040; /* Agent Server Adjustment factor. * Will eventually make this accessible in the UI */ int adjFactor = 10; /* This switch tells Agent Agent to not create any agents on a server containing the dtSearch search agent. * Will eventually make this accessible in the UI*/ bool ignoreSearchServer = true; /*Use API to create/delete agents instead of manually creating in SQL*/ bool useApiCreate = true; bool useApiDelete = true; /* Making stuff */ logger.LogVerbose("Creating new {objectName}", "Agent Helper"); IAgentHelper agentHelper = Helper; logger.LogVerbose("Creating new {objectName}", "EDDS DB Context"); IDBContext eddsDbContext = agentHelper.GetDBContext(-1); logger.LogVerbose("Creating new {objectName}", "Environment Helper"); EnvironmentHelper environment = new EnvironmentHelper(eddsDbContext); logger.LogVerbose("Creating new {objectName}", "Desired Agents List"); List <AgentsDesired> desiredAgentsList = new GetAgentsDesiredList(agentHelper, environment, poolId, IsOffHours()).AgentsPerServerObjectList; logger.LogVerbose("Creating new {objectName}", "Compared List"); List <AgentsDesired> comparedList = new CompareDesiredAgentsToExisting(desiredAgentsList, poolId, environment, logger).Compare(); logger.LogVerbose("Creating new {objectName}", "List Helper"); AgentsDesiredListHelper listHelper = new AgentsDesiredListHelper(comparedList); logger.LogVerbose("Creating new {objectName}", "Create List"); List <AgentsDesired> createList = listHelper.GetAgentCreateList(); logger.LogVerbose("Creating new {objectName}", "Delete List"); List <AgentsDesired> deleteList = listHelper.GetAgentDeleteList(); logger.LogVerbose("Creating new {objectName}", "Spots Per Server List"); List <SpotsPerServer> spotsPerServerList = new GetSpotsPerServerList(eddsDbContext, environment, adjFactor, poolId, ignoreSearchServer).SpotsPerServerList; logger.LogVerbose("Creating {objectName}", "Agent Create"); ICreateAgent createAgent = new CreateAgentSql(eddsDbContext, environment); if (useApiCreate) { createAgent = new CreateAgentApi(eddsDbContext, environment, agentHelper); } logger.LogVerbose("Creating {objectName}", "Agent Delete"); IDeleteAgent deleteAgent = new DeleteAgent(eddsDbContext); if (useApiDelete) { deleteAgent = new DeleteAgentApi(eddsDbContext, agentHelper); } /* Log createList, deleteList, and spotsPerServerList contents */ string createListString = ""; string deleteListString = ""; string spotsPerServerListString = ""; foreach (AgentsDesired cL in createList) { createListString += string.Format("{0} - {1} - {2}\r\n", cL.Guid, cL.Count, cL.RespectsResourcePool); } foreach (AgentsDesired dL in deleteList) { deleteListString += string.Format("{0} - {1} - {2}\r\n", dL.Guid, dL.Count, dL.RespectsResourcePool); } foreach (SpotsPerServer sP in spotsPerServerList) { spotsPerServerListString += string.Format("{0} - {1}\r\n", sP.AgentServerArtifactId, sP.Spots); } logger.LogDebug("Delete List : {deleteList}", deleteListString); logger.LogDebug("Create List: {createList}", createListString); logger.LogDebug("Spots Per Server List = {spotsPerServerList}", spotsPerServerListString); /* Create */ RunAgentCreate agentCreate = new RunAgentCreate(eddsDbContext, environment, createAgent, createList, spotsPerServerList, logger); logger.LogVerbose("Running {objectName}", "Agent Create"); agentCreate.Run(); logger.LogVerbose("Completed {objectName}", "Agent Create"); /* Delete */ RunAgentDelete agentDelete = new RunAgentDelete(eddsDbContext, environment, deleteAgent, poolId, deleteList, logger); logger.LogVerbose("Running {objectName}", "Agent Delete"); agentDelete.Run(); logger.LogVerbose("Completed {objectName}", "Agent Delete"); } catch (Exception ex) { RaiseError(ex.Message, ex.StackTrace); logger.LogError("Exception during agent Execute(): {ex}", ex); RaiseMessage("There has been an error. See log for more details", 1); } }