This is the root documentdb connection object.
Ejemplo n.º 1
0
        /// <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 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);
 }
Ejemplo n.º 3
0
 /// <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
            )
 {
 }
Ejemplo n.º 4
0
 public Collection(DocumentDbConnection connection, string databaseId, string collectionId, TimeSpan?defaultTimeout = null)
     : base(connection, defaultTimeout)
 {
     DatabaseId      = databaseId;
     CollectionId    = collectionId;
     mDefaultTimeout = mDefaultTimeout ?? TimeSpan.FromSeconds(10);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns a Direct TCP DocumentClient from a connection.
 /// </summary>
 /// <param name="conn">The documentDB connection.</param>
 /// <param name="policy">The policy.</param>
 /// <param name="level">The consistency level.></param>
 /// <returns></returns>
 public static DocumentClient ToDocumentClient(this DocumentDbConnection conn, ConnectionPolicy policy = null, ConsistencyLevel?level = null)
 {
     return(new DocumentClient(conn.Account, conn.AccountKey, policy ?? new ConnectionPolicy
     {
         ConnectionMode = ConnectionMode.Direct,
         ConnectionProtocol = Protocol.Tcp
     }, level));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// This is the document db persistence agent.
        /// </summary>
        /// <param name="account">This is the documentdb id</param>
        /// <param name="base64key">This is the base64 encoded access key</param>
        /// <param name="databaseName">The is the databaseId name. If the Db does not exist it will be created.</param>
        /// <param name="collectionName">The is the collection name. If the collection does it exist it will be created.</param>
        public CollectionHolder(DocumentDbConnection connection, string databaseName, string collectionName, TimeSpan?defaultTimeout = null, bool create = true)
        {
            Account = connection.ToAccount(defaultTimeout);

            Database = Account.ToDatabase(databaseName, create: create);

            Collection = Database.ToCollection(collectionName, create: create);
        }
        /// <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);
        }
Ejemplo n.º 8
0
 public static CollectionHolder ToCollectionHolder(this DocumentDbConnection conn, string databaseName, string collectionName, TimeSpan?defaultTimeout = null, bool create = true)
 {
     return(new CollectionHolder(conn, databaseName, collectionName, defaultTimeout, create));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// This method converts a DocumentDb connection in to an account.
 /// </summary>
 /// <param name="conn">The connection.</param>
 /// <param name="defaultTimeout">The default timeout.</param>
 /// <returns></returns>
 public static Account ToAccount(this DocumentDbConnection conn, TimeSpan?defaultTimeout = null)
 {
     return(new Account(conn, defaultTimeout));
 }
Ejemplo n.º 10
0
 public Collection(string account, string base64key, string databaseId, string collectionId, TimeSpan?defaultTimeout = null)
     : this(DocumentDbConnection.ToConnection(account, base64key), databaseId, collectionId, defaultTimeout)
 {
 }
Ejemplo n.º 11
0
 protected RestBase(DocumentDbConnection connection, TimeSpan?defaultTimeout = null)
 {
     mDefaultTimeout = defaultTimeout;
     Connection      = connection;
 }
Ejemplo n.º 12
0
 public static DocumentDbConnection DocDBConnection(this IEnvironmentConfiguration config) => DocumentDbConnection.ToConnection(config.DocDBAccountName(), config.DocDBAccountAccessKey());
 public static DocumentDbConnection DocDBConnection(this IEnvironmentConfiguration config, bool throwExceptionIfNotFound = false)
 => DocumentDbConnection.ToConnection(config.DocDBAccountName(throwExceptionIfNotFound), config.DocDBAccountAccessKey(throwExceptionIfNotFound));
Ejemplo n.º 14
0
        /// <summary>
        /// This is the document db persistence agent.
        /// </summary>
        /// <param name="accountName">This is the documentdb id</param>
        /// <param name="base64key">This is the base64 encoded access key</param>
        /// <param name="databaseName">The is the databaseId name. If the Db does not exist it will be created.</param>
        /// <param name="collectionName">The is the collection name. If the collection does it exist it will be created.</param>

        public CollectionHolder(string accountName, string base64key, string databaseName, string collectionName, TimeSpan?defaultTimeout = null, bool create = true) :
            this(DocumentDbConnection.ToConnection(accountName, base64key), databaseName, collectionName, defaultTimeout, create)
        {
        }
Ejemplo n.º 15
0
 public Account(DocumentDbConnection connection, TimeSpan?defaultTimeout = null) : base(connection, defaultTimeout)
 {
     Name            = connection.AccountName;
     mDefaultTimeout = mDefaultTimeout ?? TimeSpan.FromSeconds(30);
 }
Ejemplo n.º 16
0
 public Account(string account, string base64key, TimeSpan?defaultTimeout = null)
     : this(DocumentDbConnection.ToConnection(account, base64key), defaultTimeout)
 {
 }