コード例 #1
0
 protected AllStreamSubscriptionService(
     StreamStoreBase streamStreamStoreClient,
     string subscriptionName,
     ICheckpointStore checkpointStore,
     IJsonEventSerializer eventSerializer,
     IEnumerable <IEventHandler> projections,
     ILoggerFactory?loggerFactory = null,
     ProjectionGapMeasure?measure = null
     ) : base(
         streamStreamStoreClient,
         subscriptionName,
         checkpointStore,
         eventSerializer,
         projections,
         loggerFactory,
         measure
         )
 {
 }
コード例 #2
0
 /// <summary>
 /// Creates EventStoreDB catch-up subscription service for a given stream
 /// </summary>
 /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param>
 /// <param name="streamName">Name of the stream to receive events from</param>
 /// <param name="subscriptionId">Subscription ID</param>
 /// <param name="checkpointStore">Checkpoint store instance</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="measure">Optional: gap measurement for metrics</param>
 public StreamSubscription(
     EventStoreClient eventStoreClient,
     string streamName,
     string subscriptionId,
     ICheckpointStore checkpointStore,
     IEventSerializer eventSerializer,
     IEnumerable <IEventHandler> eventHandlers,
     ILoggerFactory?loggerFactory   = null,
     SubscriptionGapMeasure?measure = null
     ) : base(
         eventStoreClient,
         subscriptionId,
         checkpointStore,
         eventSerializer,
         eventHandlers,
         loggerFactory,
         measure
         )
     => _streamName = Ensure.NotEmptyString(streamName, nameof(streamName));
コード例 #3
0
 public StreamSubscriptionService(
     EventStoreClient eventEventStoreClient,
     string streamName,
     string subscriptionName,
     ICheckpointStore checkpointStore,
     IEventSerializer eventSerializer,
     IEnumerable <IEventHandler> projections,
     ILoggerFactory?loggerFactory = null,
     ProjectionGapMeasure?measure = null
     ) : base(
         eventEventStoreClient,
         subscriptionName,
         checkpointStore,
         eventSerializer,
         projections,
         loggerFactory,
         measure
         )
     => _streamName = streamName;
コード例 #4
0
        protected InterceptorBase(
            Options options,
            IServiceProvider serviceProvider,
            ILoggerFactory?loggerFactory = null)
        {
            LoggerFactory           = loggerFactory ??= NullLoggerFactory.Instance;
            Log                     = LoggerFactory.CreateLogger(GetType());
            LogLevel                = options.LogLevel;
            ValidationLogLevel      = options.ValidationLogLevel;
            ServiceProvider         = serviceProvider;
            ArgumentHandlerProvider = options.ArgumentHandlerProvider
                                      ?? serviceProvider.GetRequiredService <IArgumentHandlerProvider>();

            _createHandler            = CreateHandler;
            _createInterceptedMethod  = CreateInterceptedMethod;
            _createTypedHandlerMethod = GetType()
                                        .GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
                                        .Single(m => m.Name == nameof(CreateTypedHandler));
        }
コード例 #5
0
        /// <summary>
        ///     Instance a new HassClient
        /// </summary>
        /// <param name="logFactory">The LogFactory to use for logging, null uses default values from config.</param>
        /// <param name="wsFactory">The factory to use for websockets, mainly for testing purposes</param>
        /// <param name="httpMessageHandler">httpMessage handler (used for mocking)</param>
        internal HassClient(
            ILoggerFactory?logFactory,
            ITransportPipelineFactory <HassMessage>?pipelineFactory,
            IClientWebSocketFactory?wsFactory,
            HttpMessageHandler?httpMessageHandler)
        {
            logFactory ??= _getDefaultLoggerFactory;
            wsFactory ??= new ClientWebSocketFactory();

            var bypassCertificateErrorsForHash = Environment.GetEnvironmentVariable("HASSCLIENT_BYPASS_CERT_ERR");

            if (httpMessageHandler is null && bypassCertificateErrorsForHash is object)
            {
                _httpClientHandler = new HttpClientHandler();
                _httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) =>
                {
                    if (sslPolicyErrors == SslPolicyErrors.None)
                    {
                        return(true); //Is valid
                    }

                    if (cert.GetCertHashString() == bypassCertificateErrorsForHash.ToUpperInvariant())
                    {
                        return(true);
                    }
                    return(false);
                };

                httpMessageHandler = _httpClientHandler;
            }

            _httpClient = httpMessageHandler != null ?
                          new HttpClient(httpMessageHandler) : new HttpClient();

            _wsFactory       = wsFactory;
            _pipelineFactory = pipelineFactory;

            _loggerFactory = logFactory;
            _logger        = logFactory.CreateLogger <HassClient>();

            _messageLogLevel = Environment.GetEnvironmentVariable("HASSCLIENT_MSGLOGLEVEL") ?? "Default";
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UaTcpSessionChannel"/> class.
 /// </summary>
 /// <param name="localDescription">The <see cref="ApplicationDescription"/> of the local application.</param>
 /// <param name="certificateStore">The local certificate store.</param>
 /// <param name="userIdentity">The user identity. Provide an <see cref="AnonymousIdentity"/>, <see cref="UserNameIdentity"/>, <see cref="IssuedIdentity"/> or <see cref="X509Identity"/>.</param>
 /// <param name="remoteEndpoint">The <see cref="EndpointDescription"/> of the remote application. Obtained from a prior call to UaTcpDiscoveryClient.GetEndpoints.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="options">The session channel options.</param>
 /// <param name="additionalTypes">Any additional types to be registered with encoder.</param>
 public UaTcpSessionChannel(
     ApplicationDescription localDescription,
     ICertificateStore?certificateStore,
     IUserIdentity userIdentity,
     EndpointDescription remoteEndpoint,
     ILoggerFactory?loggerFactory       = null,
     UaTcpSessionChannelOptions?options = null,
     IEnumerable <Type>?additionalTypes = null)
     : base(localDescription, certificateStore, remoteEndpoint, loggerFactory, options, additionalTypes)
 {
     this.UserIdentity     = userIdentity;
     this.options          = options ?? new UaTcpSessionChannelOptions();
     this.loggerFactory    = loggerFactory;
     this.logger           = loggerFactory?.CreateLogger <UaTcpSessionChannel>();
     this.actionBlock      = new ActionBlock <PublishResponse>(pr => this.OnPublishResponse(pr));
     this.stateMachineCts  = new CancellationTokenSource();
     this.publishResponses = new BroadcastBlock <PublishResponse>(null, new DataflowBlockOptions {
         CancellationToken = this.stateMachineCts.Token
     });
 }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientSessionChannel"/> class.
 /// </summary>
 /// <param name="localDescription">The <see cref="ApplicationDescription"/> of the local application.</param>
 /// <param name="certificateStore">The local certificate store.</param>
 /// <param name="userIdentity">The user identity. Provide an <see cref="AnonymousIdentity"/>, <see cref="UserNameIdentity"/>, <see cref="IssuedIdentity"/> or <see cref="X509Identity"/>.</param>
 /// <param name="remoteEndpoint">The <see cref="EndpointDescription"/> of the remote application. Obtained from a prior call to <see cref="DiscoveryService.GetEndpointsAsync(GetEndpointsRequest, ILoggerFactory?, UaApplicationOptions?, StackProfile?)"/>.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="options">The session channel options.</param>
 public ClientSessionChannel(
     ApplicationDescription localDescription,
     ICertificateStore?certificateStore,
     IUserIdentity userIdentity,
     EndpointDescription remoteEndpoint,
     ILoggerFactory?loggerFactory        = null,
     ClientSessionChannelOptions?options = null,
     StackProfile?stackProfile           = null)
     : base(localDescription, certificateStore, remoteEndpoint, loggerFactory, options, stackProfile)
 {
     UserIdentity      = userIdentity;
     _options          = options ?? new ClientSessionChannelOptions();
     _loggerFactory    = loggerFactory;
     _logger           = loggerFactory?.CreateLogger <ClientSessionChannel>();
     _actionBlock      = new ActionBlock <PublishResponse>(pr => OnPublishResponse(pr));
     _stateMachineCts  = new CancellationTokenSource();
     _publishResponses = new BroadcastBlock <PublishResponse>(null, new DataflowBlockOptions {
         CancellationToken = _stateMachineCts.Token
     });
 }
コード例 #8
0
        public static HttpClientCallInvoker Create(
            HttpClient httpClient,
            ILoggerFactory?loggerFactory          = null,
            ISystemClock?systemClock              = null,
            Action <GrpcChannelOptions>?configure = null)
        {
            var channelOptions = new GrpcChannelOptions
            {
                LoggerFactory = loggerFactory,
                HttpClient    = httpClient
            };

            configure?.Invoke(channelOptions);

            var channel = GrpcChannel.ForAddress(httpClient.BaseAddress, channelOptions);

            channel.Clock = systemClock ?? SystemClock.Instance;

            return(new HttpClientCallInvoker(channel));
        }
コード例 #9
0
 /// <summary>
 /// Creates EventStoreDB persistent subscription service for a given stream
 /// </summary>
 /// <param name="clientSettings">EventStoreDB gRPC client settings</param>
 /// <param name="subscriptionId">Subscription ID</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="measure">Optional: gap measurement for metrics</param>
 public StreamPersistentSubscription(
     EventStoreClientSettings clientSettings,
     string streamName,
     string subscriptionId,
     IEventSerializer eventSerializer,
     IEnumerable <IEventHandler> eventHandlers,
     ILoggerFactory?loggerFactory   = null,
     SubscriptionGapMeasure?measure = null
     ) : this(
         new EventStoreClient(Ensure.NotNull(clientSettings, nameof(clientSettings))),
         new EventStorePersistentSubscriptionsClient(clientSettings),
         streamName,
         subscriptionId,
         eventSerializer,
         eventHandlers,
         loggerFactory,
         measure
         )
 {
 }
コード例 #10
0
        /// <summary>
        /// Creates a Google PubSub subscription service
        /// </summary>
        /// <param name="options">Subscription options <see cref="PubSubSubscriptionOptions"/></param>
        /// <param name="eventHandlers">Collection of event handlers</param>
        /// <param name="eventSerializer">Event serializer instance</param>
        /// <param name="loggerFactory">Optional: logger factory</param>
        /// <param name="measure">Callback for measuring the subscription gap</param>
        public GooglePubSubSubscription(
            PubSubSubscriptionOptions options,
            IEnumerable <IEventHandler> eventHandlers,
            IEventSerializer?eventSerializer = null,
            ILoggerFactory?loggerFactory     = null,
            ISubscriptionGapMeasure?measure  = null
            ) : base(
                options,
                new NoOpCheckpointStore(),
                eventHandlers,
                eventSerializer ?? DefaultEventSerializer.Instance,
                loggerFactory,
                measure
                )
        {
            _failureHandler = Ensure.NotNull(options, nameof(options)).FailureHandler
                              ?? DefaultEventProcessingErrorHandler;

            _subscriptionName = SubscriptionName.FromProjectSubscription(
                Ensure.NotEmptyString(options.ProjectId, nameof(options.ProjectId)),
                Ensure.NotEmptyString(options.SubscriptionId, nameof(options.SubscriptionId))
                );

            _topicName = TopicName.FromProjectTopic(
                options.ProjectId,
                Ensure.NotEmptyString(options.TopicId, nameof(options.TopicId))
                );

            _undeliveredCountRequest = GetFilteredRequest(PubSubMetricUndeliveredMessagesCount);
            _oldestAgeRequest        = GetFilteredRequest(PubSubMetricOldestUnackedMessageAge);

            ListTimeSeriesRequest GetFilteredRequest(string metric)
            => new()
            {
                Name   = $"projects/{options.ProjectId}",
                Filter = $"metric.type = \"pubsub.googleapis.com/subscription/{metric}\" "
                         + $"AND resource.label.subscription_id = \"{options.SubscriptionId}\""
            };
        }

        Task _subscriberTask = null !;
コード例 #11
0
 /// <summary>
 /// Creates EventStoreDB persistent subscription service for a given stream
 /// </summary>
 /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param>
 /// <param name="streamName">Name of the stream to receive events from</param>
 /// <param name="subscriptionId">Subscription ID</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="measure">Optional: gap measurement for metrics</param>
 public StreamPersistentSubscription(
     EventStoreClient eventStoreClient,
     string streamName,
     string subscriptionId,
     IEnumerable <IEventHandler> eventHandlers,
     IEventSerializer?eventSerializer = null,
     ILoggerFactory?loggerFactory     = null,
     ISubscriptionGapMeasure?measure  = null
     ) : this(
         eventStoreClient,
         new StreamPersistentSubscriptionOptions {
     Stream = streamName,
     SubscriptionId = subscriptionId
 },
         eventHandlers,
         eventSerializer,
         loggerFactory,
         measure
         )
 {
 }
コード例 #12
0
        public RabbitMqBus(RabbitMqConnectionOptions rabbitMqConnectionOptions,
                           AnabasisAppContext appContext,
                           ISerializer serializer,
                           ILoggerFactory?loggerFactory = null,
                           IKillSwitch?killSwitch       = null,
                           RetryPolicy?retryPolicy      = null)
        {
            BusId = $"{nameof(RabbitMqBus)}_{Guid.NewGuid()}";

            _logger     = loggerFactory?.CreateLogger <RabbitMqBus>();
            _serializer = serializer;
            _defaultPublishConfirmTimeout = TimeSpan.FromSeconds(10);
            _existingSubscriptions        = new Dictionary <string, IRabbitMqSubscription>();
            _ensureExchangeCreated        = new List <string>();
            _rabbitMqConnectionOptions    = rabbitMqConnectionOptions;
            _killSwitch = killSwitch ?? new KillSwitch();
            _appContext = appContext;

            RabbitMqConnection      = new RabbitMqConnection(rabbitMqConnectionOptions, appContext, loggerFactory, retryPolicy);
            ConnectionStatusMonitor = new RabbitMqConnectionStatusMonitor(RabbitMqConnection, loggerFactory);
        }
コード例 #13
0
ファイル: EFEventStore.cs プロジェクト: nozzle-1/CQELight
        public EFEventStore(EFEventStoreOptions options, ILoggerFactory?loggerFactory = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _dbContextOptions         = options.DbContextOptions;
            _logger                   = (loggerFactory ?? new LoggerFactory(new[] { new DebugLoggerProvider() })).CreateLogger <EFEventStore>();
            _snapshotBehaviorProvider = options.SnapshotBehaviorProvider;

            _bufferInfo      = options.BufferInfo;
            _archiveBehavior = options.ArchiveBehavior;
            _archiveBehaviorDbContextOptions = options.ArchiveDbContextOptions;

            if (_bufferInfo != null)
            {
                s_SlidingTimer  = new Timer(TreatBufferEvents, null, Timeout.Infinite, Timeout.Infinite);
                s_AbsoluteTimer = new Timer(TreatBufferEvents, null, Timeout.Infinite, Timeout.Infinite);
            }
        }
コード例 #14
0
        public static IConfigurationBuilder AddConsul(
            this IConfigurationBuilder builder,
            ConfigurationOptions configurationOptions,
            IConsulHandler consulHandler,
            ILoggerFactory?loggerFactory
            )
        {
            var consulBuilder  = new ConsulBuilder(consulHandler);
            var consulEndpoint = new ConsulKvEndpoint(consulBuilder, loggerFactory.CreateLogger <ConsulKvEndpoint>())
            {
                WatchExceptionHandler = async(kv, e, key, logger, ct) =>
                {
                    await Task.Delay(10000, ct);

                    logger.LogWarning($"Restart watching {key}");
                    return(true);
                }
            };

            return(builder.AddConsul(configurationOptions, consulHandler, consulEndpoint));
        }
コード例 #15
0
        protected SubscriptionService(
            EventStoreClient           eventStoreClient,
            string                     subscriptionId,
            ICheckpointStore           checkpointStore,
            IEventSerializer           eventSerializer,
            IEnumerable<IEventHandler> eventHandlers,
            ILoggerFactory?            loggerFactory = null,
            SubscriptionGapMeasure?    measure       = null
        ) {
            EventStoreClient = eventStoreClient;
            _checkpointStore = checkpointStore;
            _eventSerializer = eventSerializer;
            _subscriptionId  = subscriptionId;
            _measure         = measure;

            _projections = eventHandlers.Where(x => x.SubscriptionId == subscriptionId).ToArray();

            _log = loggerFactory?.CreateLogger($"StreamSubscription-{subscriptionId}");

            _debugLog = _log?.IsEnabled(LogLevel.Debug) == true ? _log.LogDebug : null;
        }
コード例 #16
0
        /// <summary>
        /// Creates new instance of <see cref="FluentValidationSchemaProcessor"/>
        /// </summary>
        /// <param name="validatorFactory">Validator factory.</param>
        /// <param name="rules">External FluentValidation rules. Rule with the same name replaces default rule.</param>
        /// <param name="loggerFactory"><see cref="ILoggerFactory"/> for logging. Can be null.</param>
        public FluentValidationSchemaProcessor(IValidatorFactory validatorFactory,
                                               IEnumerable <FluentValidationRule>?rules = null,
                                               ILoggerFactory?loggerFactory             = null)
        {
            _validatorFactory = validatorFactory;
            _logger           = loggerFactory?.CreateLogger(typeof(FluentValidationSchemaProcessor)) ?? NullLogger.Instance;
            _rules            = CreateDefaultRules();

            if (rules != null)
            {
                var ruleMap = _rules.ToDictionary(rule => rule.Name, rule => rule);

                foreach (var rule in rules)
                {
                    // Add or replace rule
                    ruleMap[rule.Name] = rule;
                }

                _rules = ruleMap.Values.ToList();
            }
        }
コード例 #17
0
 /// <summary>
 /// Creates a Google PubSub subscription service
 /// </summary>
 /// <param name="projectId">GCP project ID</param>
 /// <param name="topicId"></param>
 /// <param name="subscriptionId">Google PubSub subscription ID (within the project), which must already exist</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="measure">Callback for measuring the subscription gap</param>
 public GooglePubSubSubscription(
     string projectId,
     string topicId,
     string subscriptionId,
     IEnumerable <IEventHandler> eventHandlers,
     IEventSerializer?eventSerializer = null,
     ILoggerFactory?loggerFactory     = null,
     ISubscriptionGapMeasure?measure  = null
     ) : this(
         new PubSubSubscriptionOptions {
     SubscriptionId = subscriptionId,
     ProjectId = projectId,
     TopicId = topicId
 },
         eventHandlers,
         eventSerializer,
         loggerFactory,
         measure
         )
 {
 }
コード例 #18
0
 /// <summary>
 /// Creates RabbitMQ subscription service instance
 /// </summary>
 /// <param name="connectionFactory">RabbitMQ connection factory</param>
 /// <param name="subscriptionQueue">Subscription queue, will be created it doesn't exist</param>
 /// <param name="exchange">Exchange to consume events from, the queue will get bound to this exchange</param>
 /// <param name="subscriptionId">Subscription ID</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logging factory</param>
 public RabbitMqSubscriptionService(
     ConnectionFactory connectionFactory,
     string subscriptionQueue,
     string exchange,
     string subscriptionId,
     IEnumerable <IEventHandler> eventHandlers,
     IEventSerializer?eventSerializer = null,
     ILoggerFactory?loggerFactory     = null
     ) : this(
         connectionFactory,
         new RabbitMqSubscriptionOptions {
     SubscriptionQueue = subscriptionQueue,
     Exchange = exchange,
     SubscriptionId = subscriptionId
 },
         eventHandlers,
         eventSerializer,
         loggerFactory
         )
 {
 }
コード例 #19
0
        protected SubscriptionService(
            string subscriptionId,
            ICheckpointStore checkpointStore,
            IEventSerializer eventSerializer,
            IEnumerable <IEventHandler> eventHandlers,
            ILoggerFactory?loggerFactory    = null,
            ISubscriptionGapMeasure?measure = null
            )
        {
            _checkpointStore = Ensure.NotNull(checkpointStore, nameof(checkpointStore));
            _eventSerializer = Ensure.NotNull(eventSerializer, nameof(eventSerializer));
            SubscriptionId   = Ensure.NotEmptyString(subscriptionId, subscriptionId);
            _measure         = measure;

            _eventHandlers = Ensure.NotNull(eventHandlers, nameof(eventHandlers))
                             .Where(x => x.SubscriptionId == subscriptionId)
                             .ToArray();

            _log = loggerFactory?.CreateLogger($"StreamSubscription-{subscriptionId}");

            _debugLog = _log?.IsEnabled(LogLevel.Debug) == true ? _log.LogDebug : null;
        }
コード例 #20
0
ファイル: ShovelService.cs プロジェクト: paulopez78/eventuous
        /// <summary>
        /// Creates a shovel service instance, which must be registered as a hosted service
        /// </summary>
        /// <param name="subscriptionId">Shovel subscription id</param>
        /// <param name="eventSerializer">Event serializer</param>
        /// <param name="createSubscription">Function to create a subscription</param>
        /// <param name="producer">Producer instance</param>
        /// <param name="routeAndTransform">Routing and transformation function</param>
        /// <param name="loggerFactory">Logger factory</param>
        /// <param name="measure">Subscription gap measurement</param>
        public ShovelService(
            string subscriptionId,
            IEventSerializer eventSerializer,
            CreateSubscription createSubscription,
            TProducer producer,
            RouteAndTransform routeAndTransform,
            ILoggerFactory?loggerFactory   = null,
            SubscriptionGapMeasure?measure = null
            )
        {
            _producer = Ensure.NotNull(producer, nameof(producer));

            _subscription = createSubscription(
                Ensure.NotEmptyString(subscriptionId, nameof(subscriptionId)),
                Ensure.NotNull(eventSerializer, nameof(eventSerializer)),
                new[] {
                new ShovelHandler <TProducer>(subscriptionId, producer, Ensure.NotNull(routeAndTransform, nameof(routeAndTransform)))
            },
                loggerFactory,
                measure
                );
        }
コード例 #21
0
 /// <summary>
 /// Creates EventStoreDB catch-up subscription service for $all
 /// </summary>
 /// <param name="eventStoreClient"></param>
 /// <param name="options"></param>
 /// <param name="checkpointStore">Checkpoint store instance</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="eventFilter">Optional: server-side event filter</param>
 /// <param name="measure">Optional: gap measurement for metrics</param>
 public AllStreamSubscription(
     EventStoreClient eventStoreClient,
     AllStreamSubscriptionOptions options,
     ICheckpointStore checkpointStore,
     IEnumerable <IEventHandler> eventHandlers,
     IEventSerializer?eventSerializer = null,
     ILoggerFactory?loggerFactory     = null,
     IEventFilter?eventFilter         = null,
     ISubscriptionGapMeasure?measure  = null
     ) : base(
         eventStoreClient,
         options,
         checkpointStore,
         eventHandlers,
         eventSerializer,
         loggerFactory,
         measure
         )
 {
     _eventFilter = eventFilter ?? EventTypeFilter.ExcludeSystemEvents();
     _options     = options;
 }
コード例 #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UaTcpSessionChannel"/> class.
 /// </summary>
 /// <param name="localDescription">The <see cref="ApplicationDescription"/> of the local application.</param>
 /// <param name="certificateStore">The local certificate store.</param>
 /// <param name="userIdentity">The user identity. Provide an <see cref="AnonymousIdentity"/>, <see cref="UserNameIdentity"/>, <see cref="IssuedIdentity"/> or <see cref="X509Identity"/>.</param>
 /// <param name="endpointUrl">The url of the endpoint of the remote application</param>
 /// <param name="securityPolicyUri">Optionally, filter by SecurityPolicyUri.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="options">The session channel options.</param>
 public UaTcpSessionChannel(
     ApplicationDescription localDescription,
     ICertificateStore?certificateStore,
     IUserIdentity?userIdentity,
     string endpointUrl,
     string?securityPolicyUri           = null,
     ILoggerFactory?loggerFactory       = null,
     UaTcpSessionChannelOptions?options = null)
     : base(localDescription, certificateStore, new EndpointDescription {
     EndpointUrl = endpointUrl, SecurityPolicyUri = securityPolicyUri
 }, loggerFactory, options)
 {
     UserIdentity      = userIdentity;
     _options          = options ?? new UaTcpSessionChannelOptions();
     _loggerFactory    = loggerFactory;
     _logger           = loggerFactory?.CreateLogger <UaTcpSessionChannel>();
     _actionBlock      = new ActionBlock <PublishResponse>(pr => OnPublishResponse(pr));
     _stateMachineCts  = new CancellationTokenSource();
     _publishResponses = new BroadcastBlock <PublishResponse>(null, new DataflowBlockOptions {
         CancellationToken = _stateMachineCts.Token
     });
 }
コード例 #23
0
 /// <summary>
 /// Creates EventStoreDB persistent subscription service for a given stream
 /// </summary>
 /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param>
 /// <param name="subscriptionId">Subscription ID</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="measure">Optional: gap measurement for metrics</param>
 public StreamPersistentSubscription(
     EventStoreClient eventStoreClient,
     EventStorePersistentSubscriptionsClient persistentSubscriptionsClient,
     string streamName,
     string subscriptionId,
     IEventSerializer eventSerializer,
     IEnumerable <IEventHandler> eventHandlers,
     ILoggerFactory?loggerFactory   = null,
     SubscriptionGapMeasure?measure = null
     ) : base(
         eventStoreClient,
         subscriptionId,
         new NoOpCheckpointStore(),
         eventSerializer,
         eventHandlers,
         loggerFactory,
         measure
         )
 {
     _persistentSubscriptionsClient = persistentSubscriptionsClient;
     _stream = streamName;
 }
コード例 #24
0
 /// <summary>
 /// Creates EventStoreDB catch-up subscription service for $all
 /// </summary>
 /// <param name="eventStoreClient">EventStoreDB gRPC client instance</param>
 /// <param name="subscriptionId">Subscription ID</param>
 /// <param name="checkpointStore">Checkpoint store instance</param>
 /// <param name="eventSerializer">Event serializer instance</param>
 /// <param name="eventHandlers">Collection of event handlers</param>
 /// <param name="loggerFactory">Optional: logger factory</param>
 /// <param name="eventFilter">Optional: server-side event filter</param>
 /// <param name="measure">Optional: gap measurement for metrics</param>
 public AllStreamSubscription(
     EventStoreClient eventStoreClient,
     string subscriptionId,
     ICheckpointStore checkpointStore,
     IEnumerable <IEventHandler> eventHandlers,
     IEventSerializer?eventSerializer = null,
     ILoggerFactory?loggerFactory     = null,
     IEventFilter?eventFilter         = null,
     ISubscriptionGapMeasure?measure  = null
     ) : this(
         eventStoreClient,
         new AllStreamSubscriptionOptions {
     SubscriptionId = subscriptionId
 },
         checkpointStore,
         eventHandlers,
         eventSerializer,
         loggerFactory,
         eventFilter,
         measure
         )
 {
 }
コード例 #25
0
        public static HttpClientCallInvoker Create(
            HttpClient httpClient,
            ILoggerFactory?loggerFactory          = null,
            ISystemClock?systemClock              = null,
            Action <GrpcChannelOptions>?configure = null,
            bool?disableClientDeadline            = null,
            long?maxTimerPeriod = null,
            IOperatingSystem?operatingSystem = null)
        {
            var channelOptions = new GrpcChannelOptions
            {
                LoggerFactory = loggerFactory,
                HttpClient    = httpClient
            };

            configure?.Invoke(channelOptions);

            var channel = GrpcChannel.ForAddress(httpClient.BaseAddress !, channelOptions);

            ConfigureChannel(systemClock, disableClientDeadline, maxTimerPeriod, operatingSystem, channel);

            return(new HttpClientCallInvoker(channel));
        }
コード例 #26
0
        public static ICommandHandlerBuilder <T> Log <T>(this ICommandHandlerBuilder <T> builder,
                                                         ILoggerFactory?loggerFactory = null) where T : class
        {
            var log = loggerFactory?.CreateLogger <T>() ?? new NullLogger <T>();

            return(builder.Pipe(next => async(m, ct) => {
                if (log.IsEnabled(LogLevel.Information))
                {
                    log.LogInformation(m.ToString());
                }

                try {
                    return await next(m, ct);
                } catch (Exception ex) {
                    if (log.IsEnabled(LogLevel.Error))
                    {
                        log.LogError(ex.ToString());
                    }

                    throw;
                }
            }));
        }
コード例 #27
0
        /// <summary>
        /// Registers DAL services in <see cref="IServiceCollection"/>.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
        /// <param name="connectionString">SQL Server connection string.</param>
        /// <param name="loggerFactory">Logger factory.</param>
        /// <param name="logSensitiveData">Specifies whether to log data transferring in SQL queries.</param>
        /// <returns>The same service collection so that multiple calls can be chained.</returns>
        public static IServiceCollection AddDataAccessLayer(this IServiceCollection services,
                                                            string connectionString, ILoggerFactory?loggerFactory, bool logSensitiveData = false)
        {
            services.AddDbContextFactory <ApplicationContext>(builder =>
            {
                builder = builder.UseSqlServer(connectionString);
                if (loggerFactory != null)
                {
                    builder.UseLoggerFactory(loggerFactory);
                }
                if (logSensitiveData)
                {
                    builder.EnableSensitiveDataLogging();
                }
            });

            services.AddScoped <ICrudRepository <Course>, CourseRepository>();
            services.AddScoped <ICrudRepository <JournalRecord>, JournalRecordRepository>();
            services.AddScoped <ICrudRepository <Lecturer>, LecturerRepository>();
            services.AddScoped <ICrudRepository <Lecture>, LectureRepository>();
            services.AddScoped <ICrudRepository <Student>, StudentRepository>();
            return(services);
        }
コード例 #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UaTcpSessionChannel"/> class.
 /// </summary>
 /// <param name="localDescription">The <see cref="ApplicationDescription"/> of the local application.</param>
 /// <param name="certificateStore">The local certificate store.</param>
 /// <param name="userIdentityProvider">An asynchronous function that provides the user identity. Provide an <see cref="AnonymousIdentity"/>, <see cref="UserNameIdentity"/>, <see cref="IssuedIdentity"/> or <see cref="X509Identity"/>.</param>
 /// <param name="endpointUrl">The url of the endpoint of the remote application</param>
 /// <param name="securityPolicyUri">Optionally, filter by SecurityPolicyUri.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="options">The session channel options.</param>
 /// <param name="additionalTypes">Any additional types to be registered with encoder.</param>
 public UaTcpSessionChannel(
     ApplicationDescription localDescription,
     ICertificateStore certificateStore,
     Func <EndpointDescription, Task <IUserIdentity> > userIdentityProvider,
     string endpointUrl,
     string?securityPolicyUri           = null,
     ILoggerFactory?loggerFactory       = null,
     UaTcpSessionChannelOptions?options = null,
     IEnumerable <Type>?additionalTypes = null)
     : base(localDescription, certificateStore, new EndpointDescription {
     EndpointUrl = endpointUrl, SecurityPolicyUri = securityPolicyUri
 }, loggerFactory, options, additionalTypes)
 {
     this.UserIdentityProvider = userIdentityProvider;
     this.options          = options ?? new UaTcpSessionChannelOptions();
     this.loggerFactory    = loggerFactory;
     this.logger           = loggerFactory?.CreateLogger <UaTcpSessionChannel>();
     this.actionBlock      = new ActionBlock <PublishResponse>(pr => this.OnPublishResponse(pr));
     this.stateMachineCts  = new CancellationTokenSource();
     this.publishResponses = new BroadcastBlock <PublishResponse>(null, new DataflowBlockOptions {
         CancellationToken = this.stateMachineCts.Token
     });
 }
コード例 #29
0
    public BodyModelBinder(
        IList <IInputFormatter> formatters,
        IHttpRequestStreamReaderFactory readerFactory,
        ILoggerFactory?loggerFactory,
        MvcOptions?options)
    {
        if (formatters == null)
        {
            throw new ArgumentNullException(nameof(formatters));
        }

        if (readerFactory == null)
        {
            throw new ArgumentNullException(nameof(readerFactory));
        }

        _formatters    = formatters;
        _readerFactory = readerFactory.CreateReader;

        _logger = loggerFactory?.CreateLogger <BodyModelBinder>() ?? NullLogger <BodyModelBinder> .Instance;

        _options = options;
    }
コード例 #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClientSessionChannel"/> class.
 /// </summary>
 /// <param name="localDescription">The <see cref="ApplicationDescription"/> of the local application.</param>
 /// <param name="certificateStore">The local certificate store.</param>
 /// <param name="userIdentityProvider">An asynchronous function that provides the user identity. Provide an <see cref="AnonymousIdentity"/>, <see cref="UserNameIdentity"/>, <see cref="IssuedIdentity"/> or <see cref="X509Identity"/>.</param>
 /// <param name="endpointUrl">The url of the endpoint of the remote application</param>
 /// <param name="securityPolicyUri">Optionally, filter by SecurityPolicyUri.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 /// <param name="options">The session channel options.</param>
 public ClientSessionChannel(
     ApplicationDescription localDescription,
     ICertificateStore certificateStore,
     Func <EndpointDescription, Task <IUserIdentity> > userIdentityProvider,
     string endpointUrl,
     string?securityPolicyUri            = null,
     ILoggerFactory?loggerFactory        = null,
     ClientSessionChannelOptions?options = null,
     StackProfile?stackProfile           = null)
     : base(localDescription, certificateStore, new EndpointDescription {
     EndpointUrl = endpointUrl, SecurityPolicyUri = securityPolicyUri
 }, loggerFactory, options, stackProfile)
 {
     UserIdentityProvider = userIdentityProvider;
     _options             = options ?? new ClientSessionChannelOptions();
     _loggerFactory       = loggerFactory;
     _logger           = loggerFactory?.CreateLogger <ClientSessionChannel>();
     _actionBlock      = new ActionBlock <PublishResponse>(pr => OnPublishResponse(pr));
     _stateMachineCts  = new CancellationTokenSource();
     _publishResponses = new BroadcastBlock <PublishResponse>(null, new DataflowBlockOptions {
         CancellationToken = _stateMachineCts.Token
     });
 }