public CosmosDBGrainStorage(string name, CosmosDBStorageOptions options, SerializationManager serializationManager,
                                    Providers.IProviderRuntime providerRuntime, IPartitionKeyProvider partitionKeyProvider,
                                    IOptions <ClusterOptions> clusterOptions, IGrainFactory grainFactory, ITypeResolver typeResolver, ILoggerFactory loggerFactory)
        {
            this._name = name;
            this._partitionKeyProvider = partitionKeyProvider;
            this._loggerFactory        = loggerFactory;
            var loggerName = $"{typeof(CosmosDBGrainStorage).FullName}.{name}";

            this._logger  = loggerFactory.CreateLogger(loggerName);
            this._options = options;
            this._serializationManager    = serializationManager;
            this._grainFactory            = grainFactory;
            this._typeResolver            = typeResolver;
            this._serviceId               = clusterOptions.Value.ServiceId;
            this._grainReferenceConverter = providerRuntime.ServiceProvider.GetRequiredService <IGrainReferenceConverter>();

            this._sprocFiles = new Dictionary <string, string>
            {
                { LOOKUP_INDEX_SPROC, $"{LOOKUP_INDEX_SPROC}.js" }
            };

            if (this._options.JsonSerializerSettings == null)
            {
                this._options.JsonSerializerSettings = OrleansJsonSerializer.UpdateSerializerSettings(OrleansJsonSerializer.GetDefaultSerializerSettings(this._typeResolver, this._grainFactory),
                                                                                                      this._options.UseFullAssemblyNames,
                                                                                                      this._options.IndentJson,
                                                                                                      this._options.TypeNameHandling);
                this._options.JsonSerializerSettings.DefaultValueHandling       = DefaultValueHandling.Include;
                this._options.JsonSerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Registers a command auditor that writes to an event hub
        /// </summary>
        /// <param name="resolver">Dependency resolver</param>
        /// <param name="eventHubClient">The event hub client</param>
        /// <param name="partitionKeyProvider">An optional partition key provider, if unspecified events will be sent unpartitioned</param>
        /// <param name="options">Options for the event hub auditor configuration</param>
        /// <returns>Dependency resolver</returns>
        public static ICommandingDependencyResolver UseEventHubCommandAuditing(this ICommandingDependencyResolver resolver,
                                                                               Microsoft.Azure.EventHubs.EventHubClient eventHubClient,
                                                                               IPartitionKeyProvider partitionKeyProvider = null,
                                                                               AzureEventHubAuditorOptions options        = null)
        {
            options = options ?? new AzureEventHubAuditorOptions();
            IEventHubClient client = new EventHubClient(eventHubClient);

            if (partitionKeyProvider == null)
            {
                partitionKeyProvider = new NullPartitionKeyProvider();
            }

            resolver.RegisterInstance(client);
            resolver.RegisterInstance(partitionKeyProvider);
            resolver.TypeMapping <IAuditItemMapper, AuditItemMapper>();
            resolver.TypeMapping <IEventHubSerializer, EventHubSerializer>();
            if (options.UsePreDispatchAuditor)
            {
                resolver.UsePreDispatchCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditPreDispatchRootOnly);
            }
            if (options.UsePostDispatchAuditor)
            {
                resolver.UsePostDispatchCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditPostDispatchRootOnly);
            }
            if (options.UseExecutionAuditor)
            {
                resolver.UseExecutionCommandingAuditor <AzureEventHubCommandAuditor>(options.AuditExecuteDispatchRootOnly);
            }
            return(resolver);
        }
Beispiel #3
0
 /// <summary>
 /// Registers a command auditor that writes to an event hub
 /// </summary>
 /// <param name="resolver">Dependency resolver</param>
 /// <param name="connectionString">Connection string to an event hub. This needs to also supply the EntityPath e.g.:
 /// Endpoint=sb://myeventhub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=mysharedaccesskey;EntityPath=myeventhub
 /// </param>
 /// <param name="partitionKeyProvider">An optional partition key provider, if unspecified events will be sent unpartitioned</param>
 /// <param name="options">Options for the event hub auditor configuration</param>
 /// <returns>Dependency resolver</returns>
 public static ICommandingDependencyResolver UseEventHubCommandAuditing(this ICommandingDependencyResolver resolver,
                                                                        string connectionString,
                                                                        IPartitionKeyProvider partitionKeyProvider = null,
                                                                        AzureEventHubAuditorOptions options        = null)
 {
     Microsoft.Azure.EventHubs.EventHubClient client = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(connectionString);
     return(UseEventHubCommandAuditing(resolver, client, partitionKeyProvider, options));
 }
        /// <summary>
        /// Initializes an instance of the PartitionProxy class with specified IPartitionKeyProvider and IPartitionConnectionProvider implantations.
        /// </summary>
        /// <param name="partitionKeyProvider">Current partition key provider.</param>
        /// <param name="partitionProvider">Partition provider.</param>
        public PartitionProxy(IPartitionKeyProvider partitionKeyProvider, IPartitionConnectionProvider partitionProvider)
        {
            if(partitionKeyProvider == null)
                throw new ArgumentNullException("partitionKeyProvider");

            if(partitionProvider == null)
                throw new ArgumentNullException("partitionProvider");

            PartitionKeyProvider = partitionKeyProvider;
            PartitionConnectionProvider = partitionProvider;
        }
Beispiel #5
0
        /// <summary>
        /// Registers a command auditor that writes to an event hub
        /// </summary>
        /// <param name="resolver">Dependency resolver</param>
        /// <param name="connectionString">Connection string to an event hub e.g.:
        /// Endpoint=sb://myeventhub.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=mysharedaccesskey
        /// </param>
        /// <param name="entityPath">The path to the event hub (usually just the event hub name</param>
        /// <param name="partitionKeyProvider">An optional partition key provider, if unspecified events will be sent unpartitioned</param>
        /// <param name="options">Options for the event hub auditor configuration</param>
        /// <returns>Dependency resolver</returns>
        public static ICommandingDependencyResolver UseEventHubCommandAuditing(this ICommandingDependencyResolver resolver,
                                                                               string connectionString,
                                                                               string entityPath,
                                                                               IPartitionKeyProvider partitionKeyProvider = null,
                                                                               AzureEventHubAuditorOptions options        = null)
        {
            EventHubsConnectionStringBuilder builder = new EventHubsConnectionStringBuilder(connectionString);

            builder.EntityPath = entityPath;
            Microsoft.Azure.EventHubs.EventHubClient client = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(builder.ToString());
            return(UseEventHubCommandAuditing(resolver, client, partitionKeyProvider, options));
        }
Beispiel #6
0
 public AzureEventHubCommandAuditor(IEventHubClient client, IEventHubSerializer serializer, IPartitionKeyProvider partitionKeyProvider)
 {
     _client               = client;
     _serializer           = serializer;
     _partitionKeyProvider = partitionKeyProvider;
 }