Пример #1
0
        public async Task <IActionResult> Delete(string serviceCode, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(serviceCode))
            {
                throw new ArgumentNullException(nameof(serviceCode));
            }

            var entity = await Task.Run(() => _service.Get(serviceCode), cancellationToken);

            if (entity == null)
            {
                throw new HttpNotFoundException($"No service definition found for '{serviceCode}'");
            }

            var result = await Task.Run(() => _service.Delete(serviceCode), cancellationToken);

            if (result)
            {
                // remove from cache
                await DropServiceCacheAsync(serviceCode, cancellationToken);

                // stop recording
                await _actionApiService.StopRecordingAsync(serviceCode, cancellationToken);

                _logger.LogInformation($"Service '{serviceCode}' removed");
                return(Ok());
            }
            else
            {
                return(StatusCode(500));
            }
        }
Пример #2
0
        public async Task <ActionResult <List <ActionApiCallResultDTO> > > StopRecordingAsync(string serviceCode, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(serviceCode))
            {
                throw new ArgumentNullException(nameof(serviceCode));
            }

            var actionResult = await _actionApiService.StopRecordingAsync(serviceCode, cancellationToken);

            // save captured routes
            var cachekey       = KakaduConstants.GetFoundRoutesKey(serviceCode);
            var capturedRoutes = await _cache.GetAsync <List <KnownRouteDTO> >(cachekey, token : cancellationToken);

            if (capturedRoutes != null && capturedRoutes.Any())
            {
                var entities = _mapper.Map <List <KnownRouteModel> >(capturedRoutes);

                // TODO: go through replies, if compressed, store them in a raw form and make sure they're encoded when sending back from cache

                /*
                 * if (contentEncoding == "gzip")
                 * {
                 *  content = DecompressGZip(content);
                 *  if (msg.Content?.Headers?.Contains("Content-Encoding") ?? false)
                 *  {
                 *      msg.Content?.Headers?.Remove("Content-Encoding");
                 *      contentEncoding = string.Empty;
                 *  }
                 * }
                 */

                _serviceService.AddKnownRoutes(serviceCode, entities);
            }

            // clear cache
            await _cache.RemoveAsync(KakaduConstants.GetServiceKey(serviceCode), cancellationToken);

            return(Ok(actionResult));
        }