Ejemplo n.º 1
0
        public async Task ExecuteAsync()
        {
            var sqlQueryHelper   = new SqlQueryHelper();
            var resourceGroupIds = GetResourceGroupIDs();

            _logger = Helper.GetLoggerFactory().GetLogger();
            var rsapiApiOptions = new APIOptions {
                WorkspaceID = -1
            };
            var rsapiClient = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.CurrentUser);

            rsapiClient.APIOptions = rsapiApiOptions;
            var rsapiGroupRepository = new RSAPIiRepositoryGroup(rsapiClient);
            var artifactQueries      = new ArtifactQueries();

            var job = new ImportWorkerJob(AgentID, Helper, sqlQueryHelper, artifactQueries, DateTime.Now, rsapiGroupRepository, resourceGroupIds, _logger, rsapiApiOptions, new 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.InsertRowIntoImportErrorLogAsync(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}");
                }
            }
            finally
            {
                rsapiClient.Dispose();
            }
        }
Ejemplo n.º 2
0
        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();
            }
        }