예제 #1
0
        public void TestEndpoints(string mqValue)
        {
            using (var scope = _serviceScopeFactory.CreateScope())
            {
                //var _resourceService = scope.ServiceProvider.GetService<IResourceService>();
                IResourceService _resourceService          = null;
                List <DistributionEndpointsTest> endPoints = JsonConvert.DeserializeObject <List <DistributionEndpointsTest> >(mqValue, _serializerSettings);

                List <(DistributionEndpointsTest endPoint, bool result)> endpoint_test_result = new List <(DistributionEndpointsTest, bool)>();

                foreach (var endpoint in endPoints)
                {
                    endpoint_test_result.Add(TestSingleEndpoint(endpoint));
                }

                var checkSuccessful   = endpoint_test_result.FindAll(x => x.result);
                var checkUnsuccessful = endpoint_test_result.FindAll(x => !x.result);

                _remoteAppDataService.DeleteByAdditionalInfoAsync(checkSuccessful.Select(x => x.endPoint.DistributionEndpointPidUri).ToList())
                .Wait();

                var distributionEndpointPidURIs = _remoteAppDataService.GetByAdditionalInfoAsync(
                    checkUnsuccessful.Select(x => x.endPoint.DistributionEndpointPidUri).ToList()
                    ).Result;

                foreach (var result in checkUnsuccessful)
                {
                    if (distributionEndpointPidURIs.Any(x => x.pidUri.Equals(result.endPoint.DistributionEndpointPidUri)))
                    {
                        var endpointFromAds = distributionEndpointPidURIs.Single(x => x.pidUri.Equals(result.endPoint.DistributionEndpointPidUri));
                        if (endpointFromAds.createdAt.AddDays(21) < DateTime.UtcNow) //check for 3 week period
                        {
                            _resourceService.MarkDistributionEndpointAsDeprecated(new Uri(result.endPoint.PidUri));
                        }
                    }
                    else
                    {
                        var invalidDistributionEndpointMessage = new InvalidDistributionEndpointMessage()
                        {
                            ColidEntryPidUri           = result.endPoint.PidUri,
                            UserEmail                  = result.endPoint.Author,
                            ResourceLabel              = result.endPoint.ResourceLabel,
                            DistributionEndpoint       = new Uri(result.endPoint.NetworkAddress),
                            DistributionEndpointPidUri = result.endPoint.DistributionEndpointPidUri
                        };
                        _remoteAppDataService.NotifyInvalidDistributionEndpoint(invalidDistributionEndpointMessage).Wait();
                    }
                }
            }
        }
예제 #2
0
        public async Task NotifyInvalidDistributionEndpoint(InvalidDistributionEndpointMessage message)
        {
            using (var httpClient = _clientFactory.CreateClient())
            {
                _logger.LogWarning($"TargetURL:Sending request to {AppDataServiceNotifyInvalidDistributionEndpointApi}");
                var response = await AquireTokenAndSendToAppDataService(
                    httpClient,
                    HttpMethod.Post,
                    AppDataServiceNotifyInvalidDistributionEndpointApi,
                    message);

                CheckResponseStatus(response, "Something went wrong while notifying user about invalid distribution endpoint(s)");
            }
        }