/// <summary> /// This constructor specifies whether the service should be registered as a shared service /// that can be called directly by other message handler and Microservice components. /// </summary> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="defaultTimeout"></param> /// <param name="entityName"></param> /// <param name="versionPolicy"></param> /// <param name="keyMaker"></param> /// <param name="persistenceEntitySerializer"></param> /// <param name="cachingEntitySerializer"></param> /// <param name="keySerializer"></param> /// <param name="keyDeserializer"></param> /// <param name="referenceMaker"></param> /// <param name="referenceHashMaker"></param> protected PersistenceCommandBase( PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , TimeSpan?defaultTimeout = null , string entityName = null , VersionPolicy <E> versionPolicy = null , Func <E, K> keyMaker = null , EntitySerializer <E> persistenceEntitySerializer = null , EntitySerializer <E> cachingEntitySerializer = null , Func <K, string> keySerializer = null , Func <string, K> keyDeserializer = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null ) { mTransform = EntityTransformCreate(entityName, versionPolicy, keyMaker , persistenceEntitySerializer, cachingEntitySerializer , keySerializer, keyDeserializer, referenceMaker, referenceHashMaker); mRequestsCurrent = new ConcurrentDictionary <Guid, IPersistenceRequestHolder>(); mPolicy.DefaultTimeout = defaultTimeout ?? TimeSpan.FromSeconds(10); mPolicy.PersistenceRetryPolicy = persistenceRetryPolicy ?? new PersistenceRetryPolicy(); mPolicy.ResourceProfile = resourceProfile; mCacheManager = cacheManager ?? new NullCacheManager <K, E>(); }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="C">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="cpipe">The incoming channel pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="credentials">This is the optional azure storage credentials. /// If this is not supplied, the method will try and extract this from configuration using the StorageAccountName and StorageAccountAccessKey keys.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="keySerializer">The key serializer function.</param> /// <returns>The pipeline.</returns> public static C AttachPersistenceManagerDocumentDbSdk <C, K, E>(this C cpipe , Func <E, K> keyMaker , Func <string, K> keyDeserializer , DocumentDbConnection connection = null , string database = null , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) where C : IPipelineChannelIncoming <IPipeline> where K : IEquatable <K> { cpipe.Pipeline.AddPersistenceManagerDocumentDbSdk(keyMaker, keyDeserializer, cpipe, connection, database, startupPriority , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , referenceMaker: referenceMaker , keySerializer: keySerializer); return(cpipe); }
/// <summary> /// This is the default constructor. /// </summary> /// <param name="credentials">The azure storage credentials.</param> /// <param name="keyMaker"></param> /// <param name="keyDeserializer"></param> /// <param name="storageIdMaker"></param> /// <param name="keySerializer"></param> /// <param name="entityName">The options entity name. If this is not presented then the entity name will be used.</param> /// <param name="versionPolicy">The versioning policy.</param> /// <param name="defaultTimeout">The default timeout for async requests.</param> /// <param name="accessType">The azure access type. BlobContainerPublicAccessType.Off is the default.</param> /// <param name="options">The optional blob request options.</param> /// <param name="context">The optional operation context.</param> /// <param name="persistenceRetryPolicy">Persistence retry policy</param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="referenceMaker"></param> /// <param name="encryption"></param> public PersistenceMessageHandlerAzureBlobStorageBase(StorageCredentials credentials , Func <E, K> keyMaker , Func <string, K> keyDeserializer , Func <K, string> storageIdMaker = null , Func <K, string> keySerializer = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , BlobContainerPublicAccessType accessType = BlobContainerPublicAccessType.Off , BlobRequestOptions options = null , OperationContext context = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , IServiceHandlerEncryption encryption = null ) : base(keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , keySerializer: keySerializer ) { mDirectory = entityName ?? typeof(E).Name; mStorage = new StorageServiceBase(credentials, "persistence", accessType, options, context, defaultTimeout: defaultTimeout, encryption: encryption); mStorageIdMaker = storageIdMaker ?? mTransform.KeySerializer; }
/// <summary> /// This is the document db persistence agent. /// </summary> /// <param name="connection">The documentDb connection.</param> /// <param name="database">The is the databaseId name. If the Db does not exist it will be created.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="jsonMaker">This function can be used to override the default JSON creation functions.</param> /// <param name="databaseCollection">The is the collection name. If the collection does it exist it will be created. This will be used by the sharding policy to create multiple collections.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionMaker">This function should be set to enforce optimistic locking.</param> /// <param name="defaultTimeout">This is the default timeout period to be used when connecting to documentDb.</param> /// <param name="shardingPolicy">This is sharding policy used to choose the appropriate collection from the key presented.</param> /// <param name="retryPolicy"></param> public PersistenceManagerHandlerDocumentDbBase( DocumentDbConnection connection , string database , Func <E, K> keyMaker , Func <string, K> keyDeserializer , string databaseCollection = null , ShardingPolicy <K> shardingPolicy = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) : base(entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , keyMaker: keyMaker , referenceMaker: referenceMaker , keySerializer: keySerializer , keyDeserializer: keyDeserializer ) { mConnection = connection; mDatabaseName = database; mCollectionName = databaseCollection ?? typeof(E).Name; mShardingPolicy = shardingPolicy ?? new ShardingPolicy <K>(mCollectionName, (k) => 0, 1, (i) => mCollectionName); }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="P">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="pipeline">The pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="cpipe">The incoming channel to listen for requests.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="prePopulate">The optional pre-population collection.</param> /// <returns>The pipeline.</returns> public static P AddPersistenceManagerHandlerMemory <P, K, E>(this P pipeline , Func <E, K> keyMaker , Func <string, K> keyDeserializer , IPipelineChannelIncoming <P> cpipe , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) where P : IPipeline where K : IEquatable <K> { PersistenceManagerHandlerMemory <K, E> pm = null; return(pipeline.AddPersistenceManagerHandlerMemory(keyMaker, keyDeserializer, cpipe, out pm , startupPriority , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer , prePopulate: prePopulate)); }
/// <summary> /// This is the default constructor for the memory persistence manager. /// This persistence manager is used to hold an in-memory JSON representation of the entity. /// It is primarily used for test purposes, but can be used in a production context. /// Please note that all data will be lost when the service is restarted. /// </summary> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="policy">The policy.</param> /// <param name="prePopulate">The optional pre-population collection.</param> public PersistenceManagerHandlerMemory(Func <E, K> keyMaker , Func <string, K> keyDeserializer , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , CommandPolicy policy = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) : base(keyMaker , keyDeserializer , entityName , versionPolicy , defaultTimeout , persistenceRetryPolicy , resourceProfile , cacheManager , referenceMaker , referenceHashMaker , keySerializer , policy , prePopulate ) { }
/// <summary> /// This is the default constructor with a manual connection string. /// </summary> /// <param name="connection">The sql datbase connection.</param> /// <param name="keyMaker">The key maker function.</param> /// <param name="keyDeserializer"></param> /// <param name="persistenceEntitySerializer">The entity serializer for persistence.</param> /// <param name="cachingEntitySerializer">The entity serializer for caching</param> /// <param name="xmlVersionMaker"></param> /// <param name="entityName"></param> /// <param name="versionPolicy"></param> /// <param name="defaultTimeout"></param> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="referenceMaker"></param> /// <param name="referenceHashMaker"></param> /// <param name="keySerializer"></param> protected PersistenceManagerHandlerSqlBase(string connection , Func <E, K> keyMaker , Func <string, K> keyDeserializer , EntitySerializer <E> persistenceEntitySerializer = null , EntitySerializer <E> cachingEntitySerializer = null , Func <XElement, Tuple <K, string> > xmlVersionMaker = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null ) : base(connection , keyMaker , keyDeserializer , persistenceEntitySerializer , cachingEntitySerializer , xmlVersionMaker: xmlVersionMaker , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer ) { }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="C">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="cpipe">The incoming channel pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="prePopulate">The optional pre-population collection.</param> /// <returns>The pipeline.</returns> public static C AttachPersistenceManagerHandlerFile <C, K, E>(this C cpipe , Func <E, K> keyMaker , Func <string, K> keyDeserializer , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) where C : IPipelineChannelIncoming <IPipeline> where K : IEquatable <K> { PersistenceManagerHandlerFile <K, E> pm = null; return(cpipe.AttachPersistenceManagerHandlerFile(keyMaker, keyDeserializer, out pm , startupPriority , entityName , versionPolicy , defaultTimeout , persistenceRetryPolicy , resourceProfile , cacheManager , referenceMaker , referenceHashMaker , keySerializer , prePopulate)); }
/// <summary> /// This is the document db persistence agent. /// </summary> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer"></param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy"></param> /// <param name="defaultTimeout">This is the default timeout period to be used when connecting to documentDb.</param> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="cacheManager"></param> /// <param name="referenceMaker"></param> /// <param name="referenceHashMaker"></param> /// <param name="keySerializer"></param> public PersistenceManagerHandlerMemory(Func <E, K> keyMaker , Func <string, K> keyDeserializer , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null ) : base(keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer ) { }
/// <summary> /// Adds an events hub data colletor to the pipeline /// </summary> /// <typeparam name="P">Type of IPipeline</typeparam> /// <param name="pipeline">Pipeline</param> /// <param name="connectionString">Event Hub Connection String</param> /// <param name="entityPath">Event Path</param> /// <param name="adjustPolicy">Adjust Policy Action</param> /// <param name="resourceProfile">Resource Profile</param> /// <param name="encryptionHandler">Encryption Handler</param> /// <param name="onCreate">Collector OnCreate Action</param> /// <returns></returns> public static P AddEventHubsDataCollector <P>(this P pipeline , string connectionString = null , string entityPath = null , Action <EventHubsDataCollectorPolicy> adjustPolicy = null , ResourceProfile resourceProfile = null , EncryptionHandlerId encryptionHandler = null , Action <EventHubsDataCollector> onCreate = null) where P : IPipeline { var policy = new EventHubsDataCollectorPolicy(); if (encryptionHandler != null && !pipeline.Service.Security.HasEncryptionHandler(encryptionHandler.Id)) { throw new EncryptionHandlerNotResolvedException(encryptionHandler.Id); } adjustPolicy?.Invoke(policy); if (connectionString == null) { connectionString = pipeline.Configuration.EventHubsConnection(); } var component = new EventHubsDataCollector(connectionString , entityPath , policy , resourceProfile , encryptionHandler); onCreate?.Invoke(component); pipeline.AddDataCollector(component); return(pipeline); }
/// <summary> /// This is the document db persistence agent. /// </summary> /// <param name="connection">The documentDb connection.</param> /// <param name="database">The is the databaseId name. If the Db does not exist it will be created.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="databaseCollection">The is the collection name. If the collection does it exist it will be created. This will be used by the sharding policy to create multiple collections.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionMaker">This function should be set to enforce optimistic locking.</param> /// <param name="defaultTimeout">This is the default timeout period to be used when connecting to documentDb.</param> /// <param name="shardingPolicy">This is sharding policy used to choose the appropriate collection from the key presented.</param> /// <param name="retryPolicy"></param> public PersistenceMessageHandlerDocumentDbSdk(DocumentDbConnection connection , string database , Func <E, K> keyMaker , Func <string, K> keyDeserializer , string databaseCollection = null , ShardingPolicy <K> shardingPolicy = null , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) : base(connection, database, keyMaker, keyDeserializer , databaseCollection: databaseCollection , shardingPolicy: shardingPolicy , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , keySerializer: keySerializer ) { }
/// <summary> /// This constructor passes in the support types for the collector. /// </summary> protected DataCollectorBase(EncryptionHandlerId encryptionId = null , ResourceProfile resourceProfile = null , DataCollectionSupport?supportMap = null , P policy = null) : base(policy) { mResourceProfile = resourceProfile; mSupportMapSubmitted = supportMap; mEncryption = encryptionId; }
/// <summary> /// This method adds a new resource statistic unless is already exists, in which case it returns the existing one. /// </summary> /// <param name="profile">The resource profile to return.</param> /// <returns>Returns the associated Resource Statistic.</returns> protected ResourceStatistics ResourceStatisticsCreateOrGet(ResourceProfile profile) { ResourceStatistics stats = mResources.GetOrAdd(profile.Id, new ResourceStatistics(signal: ResourceStatisticsSignal) { Name = profile.Id }); return(stats); }
/// <summary> /// /// </summary> /// <param name="policy">This is the default configuration policy.</param> /// <param name="resourceProfile">This is the optional resource profile that can be used to track and limit resources.</param> public EntityCacheAsyncBase(EntityCacheAsyncPolicy policy, ResourceProfile resourceProfile = null) : base(policy) { if (policy == null) { throw new ArgumentNullException("EntityCacheAsyncPolicy cannot be null"); } mResourceProfile = resourceProfile ?? new ResourceProfile(string.Format("Cache_{0}", typeof(E).Name)); mEntities = new ConcurrentDictionary <K, EntityCacheHolder <K, E> >(); }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="P">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="pipeline">The pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="cpipe">The incoming channel to listen for requests.</param> /// <param name="credentials">This is the optional azure storage credentials. /// If this is not supplied, the method will try and extract this from configuration using the StorageAccountName and StorageAccountAccessKey keys.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="keySerializer">The key serializer function.</param> /// <returns>The pipeline.</returns> public static P AddPersistenceManagerDocumentDbSdk <P, K, E>(this P pipeline , Func <E, K> keyMaker , Func <string, K> keyDeserializer , IPipelineChannelIncoming <P> cpipe , DocumentDbConnection connection = null , string database = null , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) where P : IPipeline where K : IEquatable <K> { if (keyMaker == null) { throw new ArgumentNullException("keyMaker", $"keyMaker cannot be null in {nameof(AddPersistenceManagerDocumentDbSdk)}"); } if (keyDeserializer == null) { throw new ArgumentNullException("keyDeserializer", $"keyDeserializer cannot be null in {nameof(AddPersistenceManagerDocumentDbSdk)}"); } if (cpipe == null) { throw new ArgumentNullException("cpipe", $"cpipe cannot be null in {nameof(AddPersistenceManagerDocumentDbSdk)}"); } if (connection == null) { connection = pipeline.Configuration.DocDBConnection(true); } if (database == null) { database = pipeline.Configuration.DocDBDatabaseName(false); } var pm = new PersistenceMessageHandlerDocumentDbSdk <K, E>(connection, database, keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , referenceMaker: referenceMaker , keySerializer: keySerializer ); pipeline.AddCommand(pm, startupPriority, channelIncoming: cpipe); return(pipeline); }
public static ChannelPipelineIncoming AppendResourceProfile(this ChannelPipelineIncoming cpipe , ResourceProfile profile , Action <ResourceProfile> action = null) { if (profile == null) { throw new ArgumentNullException("profile cannot be null"); } cpipe.AppendResourceProfile((c) => profile, action); return(cpipe); }
public static C AttachResourceProfile <C>(this C cpipe , ResourceProfile profile , Action <ResourceProfile> action = null) where C : IPipelineChannelIncoming <IPipeline> { if (profile == null) { throw new ArgumentNullException($"{nameof(AttachResourceProfile)}: profile cannot be null"); } cpipe.AttachResourceProfile((c) => profile, action); return(cpipe); }
/// <summary> /// This extension method attaches a memory persistence command to the incoming pipeline. /// </summary> /// <typeparam name="P">The incoming channel type.</typeparam> /// <typeparam name="K">The equatable key type.</typeparam> /// <typeparam name="E">The entity type.</typeparam> /// <param name="pipeline">The pipeline.</param> /// <param name="keyMaker">This function creates a key of type K from an entity of type E</param> /// <param name="keyDeserializer">The entity key deserializer.</param> /// <param name="cpipe">The incoming channel to listen for requests.</param> /// <param name="pm">An output parameter for the persistence manager.</param> /// <param name="startupPriority">The command start-up priority.</param> /// <param name="entityName">The entity name to be used in the collection. By default this will be set through reflection.</param> /// <param name="versionPolicy">The version policy. This is needed if you wish to support optimistic locking for updates.</param> /// <param name="defaultTimeout">The default timeout. This is used for testing to simulate timeouts.</param> /// <param name="persistenceRetryPolicy">The retry policy. This is used for testing purposes.</param> /// <param name="resourceProfile">The resource profile.</param> /// <param name="cacheManager">The cache manager.</param> /// <param name="referenceMaker">The reference maker. This is used for entities that support read by reference.</param> /// <param name="referenceHashMaker">The reference hash maker. This is used for fast lookup.</param> /// <param name="keySerializer">The key serializer function.</param> /// <param name="prePopulate">The optional pre-population collection.</param> /// <returns>The pipeline.</returns> public static P AddPersistenceManagerHandlerMemory <P, K, E>(this P pipeline , Func <E, K> keyMaker , Func <string, K> keyDeserializer , IPipelineChannelIncoming <P> cpipe , out PersistenceManagerHandlerMemory <K, E> pm , int startupPriority = 100 , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = default(TimeSpan?) , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <Tuple <string, string>, string> referenceHashMaker = null , Func <K, string> keySerializer = null , IEnumerable <KeyValuePair <K, E> > prePopulate = null ) where P : IPipeline where K : IEquatable <K> { if (keyMaker == null) { throw new ArgumentNullException("keyMaker", $"keyMaker cannot be null in {nameof(AddPersistenceManagerHandlerMemory)}"); } if (keyDeserializer == null) { throw new ArgumentNullException("keyDeserializer", $"keyDeserializer cannot be null in {nameof(AddPersistenceManagerHandlerMemory)}"); } if (cpipe == null) { throw new ArgumentNullException("cpipe", $"cpipe cannot be null in {nameof(AddPersistenceManagerHandlerMemory)}"); } pm = new PersistenceManagerHandlerMemory <K, E>(keyMaker, keyDeserializer , entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: cacheManager , referenceMaker: referenceMaker , referenceHashMaker: referenceHashMaker , keySerializer: keySerializer , prePopulate: prePopulate); pipeline.AddCommand(pm, startupPriority, channelIncoming: cpipe); return(pipeline); }
/// <summary> /// This method registers a consumer which can be used to track resource contention. /// </summary> /// <param name="name">The registration friendly name.</param> /// <param name="profile">The resource profile to connect to.</param> /// <returns>Returns the consumer used to track the resource.</returns> public IResourceConsumer RegisterConsumer(string name, ResourceProfile profile) { if (profile == null) { return(null); } var stats = ResourceStatisticsCreateOrGet(profile); var consumer = new ResourceConsumer(stats, name); mResourceResourceConsumer.TryAdd(consumer.ResourceId, consumer); return(consumer); }
/// <summary> /// /// </summary> /// <param name="credentials"></param> /// <param name="policy"></param> /// <param name="context"></param> /// <param name="resourceProfile"></param> /// <param name="encryptionId"></param> /// <param name="supportMap"></param> public AzureStorageDataCollector(StorageCredentials credentials , AzureStorageDataCollectorPolicy policy = null , OperationContext context = null , ResourceProfile resourceProfile = null , EncryptionHandlerId encryptionId = null , DataCollectionSupport?supportMap = null) : base(encryptionId, resourceProfile, supportMap, policy) { if (credentials == null) { throw new ArgumentNullException($"{nameof(AzureStorageDataCollector)}: credentials cannot be null."); } mCredentails = credentials; mContext = context; }
/// <summary> /// Constructor /// </summary> /// <param name="connection">Connection string to Event Hub including the entity path</param> /// <param name="entityPath">Entity path if not supplied in the connection string</param> /// <param name="policy">Policy</param> /// <param name="resourceProfile">Resource Profile</param> /// <param name="encryptionId">Encryption Id</param> /// <param name="supportMap">Support Map</param> public EventHubsDataCollector(string connection , string entityPath , EventHubsDataCollectorPolicy policy = null , ResourceProfile resourceProfile = null , EncryptionHandlerId encryptionId = null , DataCollectionSupport?supportMap = null) : base(encryptionId, resourceProfile, supportMap, policy) { var connectionStringBuilder = new EventHubsConnectionStringBuilder(connection); if (!string.IsNullOrWhiteSpace(entityPath)) { connectionStringBuilder.EntityPath = entityPath; } mConnection = connectionStringBuilder.ToString(); }
/// <summary> /// This is the default constructor. /// </summary> /// <param name="credentials">The azure storage credentials.</param> /// <param name="directoryMaker"></param> /// <param name="defaultTimeout">The default timeout for async requests.</param> /// <param name="accessType">The azure access type. BlobContainerPublicAccessType.Off is the default.</param> /// <param name="options">The optional blob request options.</param> /// <param name="context">The optional operation context.</param> /// <param name="containerName"></param> /// <param name="serviceName"></param> /// <param name="idMaker"></param> /// <param name="resourceProfile"></param> /// <param name="encryption"></param> protected AzureStorageLoggingBase(StorageCredentials credentials , string containerName , string serviceName , Func <E, string> idMaker = null , Func <E, string> directoryMaker = null , TimeSpan?defaultTimeout = null , BlobContainerPublicAccessType accessType = BlobContainerPublicAccessType.Off , BlobRequestOptions options = null , OperationContext context = null , ResourceProfile resourceProfile = null , IServiceHandlerEncryption encryption = null) { mStorage = new StorageServiceBase(credentials, containerName, accessType, options, context, defaultTimeout: defaultTimeout, encryption: encryption); mIdMaker = idMaker ?? IdMaker; mDirectoryMaker = directoryMaker ?? DirectoryMaker; mServiceName = serviceName; mResourceProfile = resourceProfile; }
/// <summary> /// This constructor specifies whether the service should be registered as a shared service /// that can be called directly by other message handler and Microservice components. /// </summary> protected PersistenceCommandBase( EntityTransformHolder <K, E> entityTransform , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , ICacheManager <K, E> cacheManager = null , TimeSpan?defaultTimeout = null ) { if (entityTransform == null) { throw new ArgumentNullException("entityTransform cannot be null"); } mTransform = entityTransform; mPolicy.DefaultTimeout = defaultTimeout ?? TimeSpan.FromSeconds(10); mPolicy.PersistenceRetryPolicy = persistenceRetryPolicy ?? new PersistenceRetryPolicy(); mPolicy.ResourceProfile = resourceProfile; mCacheManager = cacheManager ?? new NullCacheManager <K, E>(); }
/// <summary> /// This is the default constructor. /// </summary> /// <param name="keyDeserializer"></param> /// <param name="entityName">The entity name, derived from E if left null.</param> /// <param name="versionPolicy">The optional version and locking policy.</param> /// <param name="defaultTimeout">The default timeout when making requests.</param> /// <param name="redisConnection"></param> /// <param name="keyMaker"></param> /// <param name="persistenceRetryPolicy"></param> /// <param name="resourceProfile"></param> /// <param name="referenceMaker"></param> /// <param name="keySerializer"></param> public PersistenceMessageHandlerRedisCache(string redisConnection , Func <E, K> keyMaker , Func <string, K> keyDeserializer , string entityName = null , VersionPolicy <E> versionPolicy = null , TimeSpan?defaultTimeout = null , PersistenceRetryPolicy persistenceRetryPolicy = null , ResourceProfile resourceProfile = null , Func <E, IEnumerable <Tuple <string, string> > > referenceMaker = null , Func <K, string> keySerializer = null ) : base(entityName: entityName , versionPolicy: versionPolicy , defaultTimeout: defaultTimeout , persistenceRetryPolicy: persistenceRetryPolicy , resourceProfile: resourceProfile , cacheManager: RedisCacheHelper.Default <K, E>(redisConnection) , keyMaker: keyMaker , referenceMaker: referenceMaker , keySerializer: keySerializer , keyDeserializer: keyDeserializer) { }
public static P AddAzureStorageDataCollector <P>(this P pipeline , StorageCredentials creds = null , Action <AzureStorageDataCollectorPolicy> adjustPolicy = null , ResourceProfile resourceProfile = null , EncryptionHandlerId handler = null , Action <AzureStorageDataCollector> onCreate = null , OperationContext context = null ) where P : IPipeline { AzureStorageDataCollectorPolicy policy = new AzureStorageDataCollectorPolicy(); if (handler != null) { if (!pipeline.Service.Security.HasEncryptionHandler(handler.Id)) { throw new EncryptionHandlerNotResolvedException(handler.Id); } } adjustPolicy?.Invoke(policy); if (creds == null) { creds = pipeline.Configuration.AzureStorageCredentials(true); } var component = new AzureStorageDataCollector(creds, policy , context: context , encryptionId: handler); onCreate?.Invoke(component); pipeline.AddDataCollector(component); return(pipeline); }
public IResourceConsumer RegisterConsumer(string name, ResourceProfile profile) { return(mResourceContainer.RegisterConsumer(name, profile)); }
public AzureStorageEventSource(StorageCredentials credentials, string serviceName, string containerName = "eventsource", ResourceProfile resourceProfile = null, IServiceHandlerEncryption encryption = null) : base(credentials, containerName, serviceName, resourceProfile: resourceProfile, encryption: encryption) { }
public AzureStorageLogger(StorageCredentials credentials, string serviceName, string containerName = "log" , ResourceProfile resourceProfile = null, IEncryptionHandler encryption = null) : base(credentials, containerName, serviceName, resourceProfile: resourceProfile, encryption: encryption) { }