Ejemplo n.º 1
0
        public RedisStageDirectory(RedisConnectionFactory connectionFactory, ILogger <RedisStageDirectory> logger, IOptions <NanoServiceOptions> serviceOptions, ITransportSerializer serializer)
        {
            _connectionFactory = connectionFactory;
            _serviceOptions    = serviceOptions.Value;
            _serializer        = serializer;
            _logger            = logger;

            var cacheOptions = Microsoft.Extensions.Options.Options.Create <MemoryCacheOptions>(new MemoryCacheOptions()
            {
            });

            _memoryCache = new MemoryCache(cacheOptions);

            _updateTask = Task.Run(async() => {
                while (true)
                {
                    try
                    {
                        await GetAllStages(true);
                        await Task.Delay(TimeSpan.FromSeconds(1));
                    }
                    catch {
                        await Task.Delay(TimeSpan.FromSeconds(2));
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public RemoteStageClient(
            IServiceProvider services,
            IActorDirectory actorDirectory,
            IStageDirectory stageDirectory,
            LocalStage localStage,
            ISocketClient socketClient,
            ITransportSerializer serializer,
            RemoteStageServer stageServer,
            ITelemetry telemetry
            )
        {
            _services = services;

            _actorDirectory = actorDirectory;

            _stageDirectory = stageDirectory;

            _localStage = localStage;

            _socketClient = socketClient;

            _serializer = serializer;

            _stageServer = stageServer;

            _telemetry = telemetry;

            ProcessServerInput();
        }
Ejemplo n.º 3
0
        protected ConnectionSettingsBase(
            IConnectionPool connectionPool,
            IConnection connection,
            ConnectionSettings.SourceSerializerFactory sourceSerializerFactory,
            IPropertyMappingProvider propertyMappingProvider
            )
            : base(connectionPool, connection, null, NestElasticsearchProductRegistration.DefaultForNest)
        {
            var formatterResolver           = new NestFormatterResolver(this);
            var defaultSerializer           = new DefaultHighLevelSerializer(formatterResolver);
            var sourceSerializer            = sourceSerializerFactory?.Invoke(defaultSerializer, this) ?? defaultSerializer;
            var serializerAsMappingProvider = sourceSerializer as IPropertyMappingProvider;

            _propertyMappingProvider = propertyMappingProvider ?? serializerAsMappingProvider ?? new PropertyMappingProvider();

            //We wrap these in an internal proxy to facilitate serialization diagnostics
            _sourceSerializer = new JsonFormatterAwareDiagnosticsSerializerProxy(sourceSerializer, "source");
            UseThisRequestResponseSerializer = new JsonFormatterAwareDiagnosticsSerializerProxy(defaultSerializer);
            _defaultFieldNameInferrer        = p => p.ToCamelCase();
            _defaultIndices       = new FluentDictionary <Type, string>();
            _defaultRelationNames = new FluentDictionary <Type, string>();
            _inferrer             = new Inferrer(this);

            UserAgent(ConnectionSettings.DefaultUserAgent);
        }
Ejemplo n.º 4
0
        public RemoteStageServer(
            IServiceProvider services,
            IActorDirectory actorDirectory,
            IStageDirectory stageDirectory,
            LocalStage localStage,
            ILogger <RemoteStageServer> logger,
            ISocketServer socketServer,
            ITransportSerializer serializer,
            ITelemetry telemetry

            )
        {
            _services = services;

            _actorDirectory = actorDirectory;

            _stageDirectory = stageDirectory;

            _localStage = localStage;

            _socketServer = socketServer;

            _serializer = serializer;

            _logger = logger;

            _telemetry = telemetry;

            _remoteClient = new Lazy <RemoteStageClient>(() => {
                return(_services.GetRequiredService <RemoteStageClient>());
            });

            ProcessServerInput();
        }
Ejemplo n.º 5
0
 public JsonFormatterAwareDiagnosticsSerializerProxy(ITransportSerializer serializer, string purpose = "request/response")
     : base(serializer, purpose)
 {
     if (serializer is IInternalSerializer s && s.TryGetJsonFormatter(out var formatterResolver))
     {
         _formatterResolver       = formatterResolver;
         _wrapsUtf8JsonSerializer = true;
     }
Ejemplo n.º 6
0
        public override object DeserializeResponse(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream) =>
        response.Success
                                ? new PreviewDatafeedResponse <TDocument>
        {
            Data = builtInSerializer.Deserialize <IReadOnlyCollection <TDocument> >(stream)
        }

                                : new PreviewDatafeedResponse <TDocument>();
        public override object DeserializeResponse(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream) =>
        response.Success
                                ? new GetCertificatesResponse
        {
            Certificates = builtInSerializer.Deserialize <ClusterCertificateInformation[]>(stream)
        }

                                : new GetCertificatesResponse();
 /// <summary> <inheritdoc cref="TransportConfiguration"/></summary>
 /// <param name="connectionPool"><inheritdoc cref="IConnectionPool"/></param>
 /// <param name="connection"><inheritdoc cref="IConnection"/></param>
 /// <param name="serializer"><inheritdoc cref="ITransportSerializer"/></param>
 /// <param name="productRegistration"><inheritdoc cref="IProductRegistration"/></param>
 public TransportConfiguration(
     IConnectionPool connectionPool,
     IConnection connection                   = null,
     ITransportSerializer serializer          = null,
     IProductRegistration productRegistration = null)
     : base(connectionPool, connection, serializer, productRegistration)
 {
 }
Ejemplo n.º 9
0
 public void WriteSerialized <T>(T value, ITransportSerializer serializer, IConnectionConfigurationValues settings,
                                 SerializationFormatting formatting = SerializationFormatting.None
                                 )
 {
     using var ms = settings.MemoryStreamFactory.Create();
     serializer.Serialize(value, ms, formatting);
     WriteRaw(ms);
 }
        public FractionalNumbers()
        {
            var pool     = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
            var settings = new ConnectionSettings(pool, new InMemoryConnection());
            var client   = new ElasticClient(settings);

            _serializer = client.RequestResponseSerializer;
        }
Ejemplo n.º 11
0
        public override object DeserializeResponse(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream) =>
        response.Success
                                ? new TranslateSqlResponse
        {
            Result = builtInSerializer.Deserialize <ISearchRequest>(stream)
        }

                                : new TranslateSqlResponse();
Ejemplo n.º 12
0
 public RabbitPublisher(
     ITransportSerializer encoder,
     ILogger <RabbitPublisher> logger,
     IPublisherChannelFactory publisherChannelFactory)
 {
     _encoder = encoder ?? throw new ArgumentNullException(nameof(encoder));
     _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
     _publisherChannelFactory = publisherChannelFactory ?? throw new ArgumentNullException(nameof(publisherChannelFactory));
 }
        public ExceptionSerializationTests()
        {
            var pool           = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
            var connection     = new InMemoryConnection();
            var values         = new ConnectionConfiguration(pool, connection);
            var lowlevelClient = new ElasticLowLevelClient(values);

            _transportNetSerializer = lowlevelClient.Serializer;
        }
Ejemplo n.º 14
0
        internal LazyDocument(byte[] bytes, IJsonFormatterResolver formatterResolver)
        {
            Bytes = bytes;
            var settings = formatterResolver.GetConnectionSettings();

            _sourceSerializer          = settings.SourceSerializer;
            _requestResponseSerializer = settings.RequestResponseSerializer;
            _memoryStreamFactory       = settings.MemoryStreamFactory;
        }
Ejemplo n.º 15
0
 public ServiceBusPublisher(IServiceBusSenderFactory senderFactory,
                            ITransportSerializer serializer,
                            ILogger <ServiceBusPublisher> logger, SystemInfo systemInfo)
 {
     _senderFactory = senderFactory ?? throw new ArgumentNullException(nameof(senderFactory));
     _serializer    = serializer ?? throw new ArgumentNullException(nameof(serializer));
     _logger        = logger ?? throw new ArgumentNullException(nameof(logger));
     _systemInfo    = systemInfo ?? throw new ArgumentNullException(nameof(systemInfo));
 }
Ejemplo n.º 16
0
 public MyClientConfiguration(
     IConnectionPool connectionPool = null,
     IConnection connection         = null,
     ITransportSerializer requestResponseSerializer = null,
     IProductRegistration productRegistration       = null)
     : base(
         connectionPool ?? new SingleNodeConnectionPool(new Uri("http://default-endpoint.example"))
         , connection, requestResponseSerializer, productRegistration)
 {
 }
Ejemplo n.º 17
0
 public JsonNetSerializer(
     ITransportSerializer builtinSerializer,
     IConnectionSettingsValues connectionSettings,
     Func <JsonSerializerSettings> jsonSerializerSettingsFactory             = null,
     Action <ConnectionSettingsAwareContractResolver> modifyContractResolver = null,
     IEnumerable <JsonConverter> contractJsonConverters = null
     )
     : base(builtinSerializer, connectionSettings, jsonSerializerSettingsFactory, modifyContractResolver, contractJsonConverters)
 {
 }
Ejemplo n.º 18
0
 public override async Task <object> DeserializeResponseAsync(
     ITransportSerializer builtInSerializer,
     IApiCallDetails response,
     Stream stream,
     CancellationToken ctx = default
     ) =>
 response.Success
                         ? await builtInSerializer.CreateStateful(Formatter)
 .DeserializeAsync <MultiSearchResponse>(stream, ctx)
 .ConfigureAwait(false)
                         : new MultiSearchResponse();
Ejemplo n.º 19
0
        public static DefaultHighLevelSerializer CreateStateful <T>(this ITransportSerializer serializer, IJsonFormatter <T> formatter)
        {
            if (!(serializer is IInternalSerializer s) || !s.TryGetJsonFormatter(out var currentFormatterResolver))
            {
                throw new Exception($"Can not create a stateful serializer because {serializer.GetType()} does not yield a json formatter");
            }

            var formatterResolver = new StatefulFormatterResolver <T>(formatter, currentFormatterResolver);

            return(new DefaultHighLevelSerializer(formatterResolver));
        }
        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.º 21
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>();
        internal static void SerializeUsingWriter <T>(this ITransportSerializer serializer, ref JsonWriter writer, T body, IConnectionConfigurationValues settings, SerializationFormatting formatting)
        {
            if (serializer is IInternalSerializer s && s.TryGetJsonFormatter(out var formatterResolver))
            {
                JsonSerializer.Serialize(ref writer, body, formatterResolver);
                return;
            }

            var memoryStreamFactory = settings.MemoryStreamFactory;
            var bodyBytes           = serializer.SerializeToBytes(body, memoryStreamFactory, formatting);

            writer.WriteRaw(bodyBytes);
        }
Ejemplo n.º 23
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();
Ejemplo n.º 24
0
        public override object DeserializeResponse(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream)
        {
            if (!response.Success || response.HttpStatusCode == 404)
            {
                return(builtInSerializer.Deserialize <CatResponse <TCatRecord> >(stream));
            }

            var catResponse = new CatResponse <TCatRecord>();
            var records     = builtInSerializer.Deserialize <IReadOnlyCollection <TCatRecord> >(stream);

            catResponse.Records = records;
            return(catResponse);
        }
Ejemplo n.º 25
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);
        }
 /// <summary>
 /// Extension method that serializes an instance of <typeparamref name="T"/> to a string.
 /// </summary>
 /// <param name="memoryStreamFactory">
 /// A factory yielding MemoryStream instances, defaults to <see cref="RecyclableMemoryStreamFactory"/>
 /// that yields memory streams backed by pooled byte arrays.
 /// </param>
 public static string SerializeToString <T>(
     this ITransportSerializer serializer,
     T data,
     IMemoryStreamFactory memoryStreamFactory,
     SerializationFormatting formatting = SerializationFormatting.None
     )
 {
     memoryStreamFactory ??= TransportConfiguration.DefaultMemoryStreamFactory;
     using (var ms = memoryStreamFactory.Create())
     {
         serializer.Serialize(data, ms, formatting);
         return(ms.Utf8String());
     }
 }
        public override object DeserializeResponse(ITransportSerializer builtInSerializer, IApiCallDetails response, Stream stream)
        {
            if (!response.Success)
            {
                return(new NodesHotThreadsResponse());
            }

            using (stream)
                using (var sr = new StreamReader(stream, Encoding.UTF8))
                {
                    var plainTextResponse = sr.ReadToEnd();
                    return(Parse(plainTextResponse));
                }
        }
Ejemplo n.º 28
0
        public TypedHyperSocket(TypedSocketOptions options, ITypedHandlerFactory handlerFactory, ITransportSerializer serializer)
        {
            _options = options;
            _socket  = new HyperSocket(options.Socket);
            HookEvents();

            _handlerFactory = handlerFactory;

            _cleanUpTimer          = new Timer(options.AnswerTimeout.TotalMilliseconds / 4);
            _cleanUpTimer.Elapsed += CleanUp;
            _cleanUpTimer.Start();

            Serializer = serializer;
        }
Ejemplo n.º 29
0
        public void Configure()
        {
            ConfigureDefaults();

            _serviceProvider = _serviceCollection.BuildServiceProvider();

            _remoteClient = _serviceProvider.GetRequiredService <RemoteStageClient>();

            _stageDirectory = _serviceProvider.GetRequiredService <IStageDirectory>();

            _serializer = _serviceProvider.GetRequiredService <ITransportSerializer>();

            _telemetry = _serviceProvider.GetRequiredService <ITelemetry>();

            _configured = true;
        }
Ejemplo n.º 30
0
        public ServiceBusSubscriber(IQueueReferenceFactory queueReferenceFactory,
                                    ServiceBusClient serviceBusClient,
                                    ITransportSerializer messageParser,
                                    IMessageProcessor messageProcessor,
                                    ILogger <ServiceBusSubscriber <TM> > logger, SystemInfo systemInfo)
        {
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _messageParser    = messageParser ?? throw new ArgumentNullException(nameof(messageParser));
            _messageProcessor = messageProcessor ?? throw new ArgumentNullException(nameof(messageProcessor));
            _systemInfo       = systemInfo ?? throw new ArgumentNullException(nameof(systemInfo));

            var references = queueReferenceFactory.Create <TM>();

            _processor = serviceBusClient.CreateProcessor(references.TopicName, references.SubscriptionName);
            _processor.ProcessMessageAsync += MessageHandler;
            _processor.ProcessErrorAsync   += ProcessErrorAsync;
        }