Beispiel #1
0
        public async Task UpdateSearchParameterStatusAsync(IReadOnlyCollection <string> searchParameterUris, SearchParameterStatus status)
        {
            var searchParameterStatusList = new List <ResourceSearchParameterStatus>();
            var updated = new List <SearchParameterInfo>();

            foreach (string uri in searchParameterUris)
            {
                var searchParamUri = new Uri(uri);

                var paramInfo = _searchParameterDefinitionManager.GetSearchParameter(searchParamUri);
                updated.Add(paramInfo);
                paramInfo.IsSearchable = status == SearchParameterStatus.Enabled;
                paramInfo.IsSupported  = status == SearchParameterStatus.Supported || status == SearchParameterStatus.Enabled;

                searchParameterStatusList.Add(new ResourceSearchParameterStatus()
                {
                    LastUpdated = Clock.UtcNow,
                    Status      = status,
                    Uri         = searchParamUri,
                });
            }

            await _searchParameterStatusDataStore.UpsertStatuses(searchParameterStatusList);

            await _mediator.Publish(new SearchParametersUpdated(updated));
        }
        public async Task UpdateSearchParameterStatusAsync(IReadOnlyCollection <string> searchParameterUris, SearchParameterStatus status, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(searchParameterUris);

            if (searchParameterUris.Count == 0)
            {
                return;
            }

            var searchParameterStatusList = new List <ResourceSearchParameterStatus>();
            var updated    = new List <SearchParameterInfo>();
            var parameters = (await _searchParameterStatusDataStore.GetSearchParameterStatuses(cancellationToken))
                             .ToDictionary(x => x.Uri.OriginalString);

            foreach (string uri in searchParameterUris)
            {
                _logger.LogTrace("Setting the search parameter status of '{uri}' to '{newStatus}'", uri, status.ToString());

                SearchParameterInfo paramInfo = _searchParameterDefinitionManager.GetSearchParameter(uri);
                updated.Add(paramInfo);
                paramInfo.IsSearchable = status == SearchParameterStatus.Enabled;
                paramInfo.IsSupported  = status == SearchParameterStatus.Supported || status == SearchParameterStatus.Enabled;

                if (parameters.TryGetValue(uri, out var existingStatus))
                {
                    existingStatus.LastUpdated = Clock.UtcNow;
                    existingStatus.Status      = status;

                    if (paramInfo.IsSearchable && existingStatus.SortStatus == SortParameterStatus.Supported)
                    {
                        existingStatus.SortStatus = SortParameterStatus.Enabled;
                        paramInfo.SortStatus      = SortParameterStatus.Enabled;
                    }

                    searchParameterStatusList.Add(existingStatus);
                }
                else
                {
                    searchParameterStatusList.Add(new ResourceSearchParameterStatus
                    {
                        LastUpdated = Clock.UtcNow,
                        Status      = status,
                        Uri         = new Uri(uri),
                    });
                }
            }

            await _searchParameterStatusDataStore.UpsertStatuses(searchParameterStatusList, cancellationToken);

            await _mediator.Publish(new SearchParametersUpdatedNotification(updated), cancellationToken);
        }
        public async Task UpdateSearchParameterStatusAsync(IReadOnlyCollection <string> searchParameterUris, SearchParameterStatus status)
        {
            var searchParameterStatusList = new List <ResourceSearchParameterStatus>();
            var updated    = new List <SearchParameterInfo>();
            var parameters = (await _searchParameterStatusDataStore.GetSearchParameterStatuses())
                             .ToDictionary(x => x.Uri);

            foreach (string uri in searchParameterUris)
            {
                var searchParamUri = new Uri(uri);

                var paramInfo = _searchParameterDefinitionManager.GetSearchParameter(searchParamUri);
                updated.Add(paramInfo);
                paramInfo.IsSearchable = status == SearchParameterStatus.Enabled;
                paramInfo.IsSupported  = status == SearchParameterStatus.Supported || status == SearchParameterStatus.Enabled;

                if (parameters.TryGetValue(searchParamUri, out var existingStatus))
                {
                    existingStatus.LastUpdated = Clock.UtcNow;
                    existingStatus.Status      = status;

                    if (paramInfo.IsSearchable && existingStatus.SortStatus == SortParameterStatus.Supported)
                    {
                        existingStatus.SortStatus = SortParameterStatus.Enabled;
                        paramInfo.SortStatus      = SortParameterStatus.Enabled;
                    }

                    searchParameterStatusList.Add(existingStatus);
                }
                else
                {
                    searchParameterStatusList.Add(new ResourceSearchParameterStatus
                    {
                        LastUpdated = Clock.UtcNow,
                        Status      = status,
                        Uri         = searchParamUri,
                    });
                }
            }

            await _searchParameterStatusDataStore.UpsertStatuses(searchParameterStatusList);

            await _mediator.Publish(new SearchParametersUpdated(updated));
        }