/// <summary>
        /// Acknowledges a notification as having been processed.
        /// </summary>
        /// <param name="factorySettings"></param>
        /// <param name="authenticationSettings"></param>
        /// <param name="acknowledgement"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task AcknowledgeNotification(ApiClientFactorySettings factorySettings,
                                                  AuthenticationHelperSettings authenticationSettings,
                                                  ConnectorNotificationAcknowledgeModel acknowledgement,
                                                  CancellationToken cancellationToken = default(CancellationToken))
        {
            var client = _apiClientFactory.CreateApiClient(factorySettings);

            var policy = ApiClientRetryPolicy.GetPolicy(MaxRetryAttempts, cancellationToken);

            var acknowledgementResponse = await policy.ExecuteAsync(
                async() =>
            {
                var authHelper = _apiClientFactory.CreateAuthenticationHelper();
                var headers    = await authHelper.GetHttpRequestHeaders(authenticationSettings).ConfigureAwait(false);
                var response   = await client.ApiNotificationsPostWithHttpMessagesAsync(acknowledgement, customHeaders: headers, cancellationToken: cancellationToken).ConfigureAwait(false);
                return(response);
            }
                ).ConfigureAwait(false);

            if (acknowledgementResponse.Response.StatusCode == HttpStatusCode.NotFound)
            {
                throw new ResourceNotFoundException($"Notification with ID [{acknowledgement.NotificationId}] was not found. It may have already been acknowledged.");
            }

            // TODO: add more comprehensive handling of the response codes
        }
        /// <summary>
        /// Queries for all connector notifications for a given connector instance that are pending acknowledgement.
        /// </summary>
        /// <param name="factorySettings"></param>
        /// <param name="authenticationSettings"></param>
        /// <param name="connectorConfigId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <IList <ConnectorNotificationModel> > GetAllPendingConnectorNotifications(ApiClientFactorySettings factorySettings,
                                                                                                    AuthenticationHelperSettings authenticationSettings,
                                                                                                    string connectorConfigId,
                                                                                                    CancellationToken cancellationToken = default(CancellationToken))
        {
            // Get Notifications
            var client = _apiClientFactory.CreateApiClient(factorySettings);

            var policy = ApiClientRetryPolicy.GetPolicy(MaxRetryAttempts, cancellationToken);

            var notificationQueryResponse = await policy.ExecuteAsync(
                async (ct) =>
            {
                var authHelper = _apiClientFactory.CreateAuthenticationHelper();
                var headers    = await authHelper.GetHttpRequestHeaders(authenticationSettings).ConfigureAwait(false);
                var response   = await client.ApiNotificationsByConnectorIdGetWithHttpMessagesAsync(
                    connectorConfigId,
                    customHeaders: headers,
                    cancellationToken: ct
                    ).ConfigureAwait(false);

                return(response);
            },
                cancellationToken
                ).ConfigureAwait(false);

            // TODO: add more comprehensive handling of the response codes

            var notifications = notificationQueryResponse.Body;

            return(notifications);
        }
Пример #3
0
        /// <summary>
        /// Gets the ConnectorConfigModel from the Records365 Connector API.
        /// </summary>
        /// <param name="connectorConfigId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ConnectorConfigModel> GetConnectorConfig(Guid connectorConfigId, CancellationToken cancellationToken)
        {
            var client = ApiClientFactory.CreateApiClient(ApiClientFactorySettings);
            var policy = ApiClientRetryPolicy.GetPolicy(4, cancellationToken);

            var connectorConfig = await policy.ExecuteAsync(
                async (ct) =>
            {
                var authHelper = ApiClientFactory.CreateAuthenticationHelper();
                var headers    = await authHelper.GetHttpRequestHeaders(AuthenticationHelperSettings).ConfigureAwait(false);
                var response   = await client.ApiConnectorConfigurationsByIdGetWithHttpMessagesAsync(
                    connectorConfigId,
                    customHeaders: headers,
                    cancellationToken: ct
                    ).ConfigureAwait(false);

                return(response.Body);
            },
                cancellationToken
                ).ConfigureAwait(false);

            return(connectorConfig);
        }
Пример #4
0
        public async Task RetryPolicy_Logs(Exception exception)
        {
            var           externalId    = Guid.NewGuid().ToString();
            SubmitContext submitContext = new BinarySubmitContext
            {
                ExternalId = externalId
            };

            var policy = ApiClientRetryPolicy.GetPolicy(
                _mockLog.Object,
                typeof(HttpSubmitBinaryPipelineElement),
                nameof(HttpSubmitBinaryPipelineElement.Submit),
                2,
                CancellationToken.None,
                submitContext.LogPrefix()
                );

            Type expectedExceptionType = exception.GetType();

            await Assert.ThrowsAsync(expectedExceptionType, async() =>
            {
                await policy.ExecuteAsync(
                    async(ct) =>
                {
                    throw exception;
                },
                    CancellationToken.None
                    );
            });

            _mockLog.Verify(x => x.LogMessage(
                                It.Is <Type>(t => t == typeof(HttpSubmitBinaryPipelineElement)),
                                It.Is <string>(m => m == "Submit_Retry"),
                                It.Is <string>(l => l.Contains(externalId)),
                                It.IsAny <long?>()
                                ), Times.Exactly(2));
        }
Пример #5
0
 /// <summary>
 /// Gets a retry policy which can be used for communicating with Records365
 /// </summary>
 /// <returns></returns>
 protected Policy GetRetryPolicy(SubmitContext submitContext, string methodName = nameof(Submit))
 {
     return(ApiClientRetryPolicy.GetPolicy(Log, GetType(), methodName, MaxRetryAttempts, submitContext.CancellationToken, submitContext.LogPrefix()));
 }