/// <summary> /// Tests if one can login /// </summary> /// <returns></returns> public bool TestLogin() { try { IRSAPIClient client = GetRsapiClient(); client.Dispose(); return(true); } catch (Exception) { return(false); } }
public async Task ExecuteAsync() { ISqlQueryHelper sqlQueryHelper = new SqlQueryHelper(); IEnumerable <Int32> resourceGroupIds = GetResourceGroupIDs(); _logger = Helper.GetLoggerFactory().GetLogger(); IArtifactQueries artifactQueries = new ArtifactQueries(); //Setup RSAPI repositories APIOptions rsapiApiOptions = new APIOptions { WorkspaceID = -1 }; IRSAPIClient rsapiClient = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.CurrentUser); rsapiClient.APIOptions = rsapiApiOptions; IRsapiRepositoryGroup rsapiRepositoryGroup = new RSAPIiRepositoryGroup(rsapiClient); ILoginProfileManager loginProfileManager = Helper.GetServicesManager().CreateProxy <ILoginProfileManager>(ExecutionIdentity.CurrentUser); IAuthenticationHelper authenticationHelper = new AuthenticationHelper(loginProfileManager); ISerializationHelper serializationHelper = new SerializationHelper(); ExportWorkerJob job = new ExportWorkerJob( agentId: AgentID, agentHelper: Helper, sqlQueryHelper: sqlQueryHelper, processedOnDateTime: DateTime.Now, resourceGroupIds: resourceGroupIds, logger: _logger, artifactQueries: artifactQueries, rsapiApiOptions: rsapiApiOptions, rsapiRepositoryGroup: rsapiRepositoryGroup, authenticationHelper: authenticationHelper, serializationHelper: serializationHelper); job.OnMessage += MessageRaised; try { RaiseMessage("Enter Agent", 10); await job.ExecuteAsync(); RaiseMessage("Exit Agent", 10); } catch (Exception ex) { //Raise an error on the agents tab and event viewer RaiseError(ex.ToString(), ex.ToString()); _logger.LogError(ex, $"{Constant.Names.ApplicationName} - {ex}"); //Add the error to our custom Errors table sqlQueryHelper.InsertRowIntoExportErrorLogAsync(Helper.GetDBContext(-1), job.WorkspaceArtifactId, Constant.Tables.ExportWorkerQueue, job.TableRowId, job.AgentId, ex.ToString()).Wait(); //Add the error to the Relativity Errors tab //this second try catch is in case we have a problem connecting to the RSAPI try { ErrorQueries.WriteError(Helper.GetServicesManager(), ExecutionIdentity.System, job.WorkspaceArtifactId, ex); } catch (Exception rsapiException) { RaiseError(rsapiException.ToString(), rsapiException.ToString()); _logger.LogError(rsapiException, $"{Constant.Names.ApplicationName} - {rsapiException}"); } //Set the status in the queue to error sqlQueryHelper.UpdateStatusInExportWorkerQueueAsync(Helper.GetDBContext(-1), Constant.Status.Queue.ERROR, job.BatchTableName).Wait(); } finally { rsapiClient.Dispose(); } }