Ejemplo n.º 1
0
        public override async Task <object> DeserializeResponseAsync(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream, CancellationToken ctx = default)
        {
            if (!response.Success || response.HttpStatusCode == 404)
            {
                return(await builtInSerializer.DeserializeAsync <CatResponse <TCatRecord> >(stream, ctx).ConfigureAwait(false));
            }

            var catResponse = new CatResponse <TCatRecord>();
            var records     = await builtInSerializer.DeserializeAsync <IReadOnlyCollection <TCatRecord> >(stream, ctx).ConfigureAwait(false);

            catResponse.Records = records;
            return(catResponse);
        }
Ejemplo n.º 2
0
        private async Task MessageHandler(ProcessMessageEventArgs args)
        {
            try
            {
                _logger.LogInformation($"client '{_systemInfo.ClientId}' received message '{args.Message.MessageId}'. Processing...");

                var message = await _messageParser.DeserializeAsync <TM>(args.Message.Body);

                await _messageProcessor.ProcessAsync((dynamic)message, args.CancellationToken);

                await args.CompleteMessageAsync(args.Message).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"an error has occurred while processing message '{args.Message.MessageId}': {ex.Message}");
                if (args.Message.DeliveryCount > 3)
                {
                    await args.DeadLetterMessageAsync(args.Message).ConfigureAwait(false);
                }
                else
                {
                    await args.AbandonMessageAsync(args.Message).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 3
0
        public override async Task <object> DeserializeResponseAsync(
            ITransportSerializer builtInSerializer,
            IApiCallDetails response,
            Stream stream,
            CancellationToken ctx = default
            ) =>
        response.Success
                                ? new PreviewDatafeedResponse <TDocument>
        {
            Data = await builtInSerializer.DeserializeAsync <IReadOnlyCollection <TDocument> >(stream, ctx).ConfigureAwait(false)
        }

                                : new PreviewDatafeedResponse <TDocument>();
Ejemplo n.º 4
0
        public override async Task <object> DeserializeResponseAsync(
            ITransportSerializer builtInSerializer,
            IApiCallDetails response,
            Stream stream,
            CancellationToken ctx = default
            ) =>
        response.Success
                                ? new TranslateSqlResponse
        {
            Result = await builtInSerializer.DeserializeAsync <ISearchRequest>(stream, ctx).ConfigureAwait(false)
        }

                                : new TranslateSqlResponse();
        public override async Task <object> DeserializeResponseAsync(
            ITransportSerializer builtInSerializer,
            IApiCallDetails response,
            Stream stream,
            CancellationToken ctx = default
            ) =>
        response.Success
                                ? new GetCertificatesResponse
        {
            Certificates = await builtInSerializer.DeserializeAsync <ClusterCertificateInformation[]>(stream, ctx).ConfigureAwait(false)
        }

                                : new GetCertificatesResponse();
Ejemplo n.º 6
0
        public override async Task <object> DeserializeResponseAsync(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream, CancellationToken ctx = default)
        {
            if (response.Success)
            {
                if (builtInSerializer is IInternalSerializer internalSerializer &&
                    internalSerializer.TryGetJsonFormatter(out var formatter))
                {
                    var sourceSerializer = formatter.GetConnectionSettings().SourceSerializer;
                    return(new SourceResponse <TDocument>
                    {
                        Body = await sourceSerializer.DeserializeAsync <TDocument>(stream, ctx).ConfigureAwait(false)
                    });
                }

                return(new SourceResponse <TDocument>
                {
                    Body = await builtInSerializer.DeserializeAsync <TDocument>(stream, ctx).ConfigureAwait(false)
                });
            }

            return(new SourceResponse <TDocument>());
        }
Ejemplo n.º 7
0
 /// <inheritdoc />
 public Task <T> AsAsync <T>(CancellationToken ct = default)
 {
     using (var ms = _memoryStreamFactory.Create(Bytes))
         return(_sourceSerializer.DeserializeAsync <T>(ms, ct));
 }
Ejemplo n.º 8
0
 /// <inheritdoc cref="ITransportSerializer.DeserializeAsync"/>>
 public Task <object> DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default)
 {
     using (DiagnosticSource.Diagnose(DiagnosticSources.Serializer.Deserialize, _state))
         return(_serializer.DeserializeAsync(type, stream, cancellationToken));
 }