/// <summary>
        /// Initializes the DocumentDbStorage form the url auth secret provide.
        /// </summary>
        /// <param name="url">The url string to DocumentDb Database</param>
        /// <param name="authSecret">The secret key for the DocumentDb Database</param>
        /// <param name="database">The name of the database to connect with</param>
        /// <param name="collection">The name of the collection on the database</param>
        /// <param name="options">The DocumentDbStorageOptions object to override any of the options</param>
        public DocumentDbStorage(string url, string authSecret, string database, string collection, DocumentDbStorageOptions options = null)
        {
            Options = options ?? new DocumentDbStorageOptions();
            Options.DatabaseName   = database;
            Options.CollectionName = collection;

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                NullValueHandling    = NullValueHandling.Ignore,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                ContractResolver     = new CamelCasePropertyNamesContractResolver
                {
                    NamingStrategy = new CamelCaseNamingStrategy(false, false)
                }
            };

            ConnectionPolicy connectionPolicy = ConnectionPolicy.Default;

            connectionPolicy.ConnectionMode     = ConnectionMode.Direct;
            connectionPolicy.ConnectionProtocol = Protocol.Tcp;
            connectionPolicy.RequestTimeout     = Options.RequestTimeout;
            connectionPolicy.RetryOptions       = new RetryOptions
            {
                MaxRetryWaitTimeInSeconds           = 10,
                MaxRetryAttemptsOnThrottledRequests = 5
            };

            Client = new DocumentClient(new Uri(url), authSecret, settings, connectionPolicy);
            Task task         = Client.OpenAsync();
            Task continueTask = task.ContinueWith(t => Initialize(), TaskContinuationOptions.OnlyOnRanToCompletion);

            continueTask.Wait();

            JobQueueProvider provider = new JobQueueProvider(this);

            QueueProviders = new PersistentJobQueueProviderCollection(provider);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes the DocumentDbStorage form the url auth secret provide.
        /// </summary>
        /// <param name="url">The url string to DocumentDb Database</param>
        /// <param name="authSecret">The secret key for the DocumentDb Database</param>
        /// <param name="database">The name of the database to connect with</param>
        /// <param name="collection">The name of the collection on the database</param>
        /// <param name="options">The DocumentDbStorageOptions object to override any of the options</param>
        public DocumentDbStorage(string url, string authSecret, string database, string collection, DocumentDbStorageOptions options = null)
        {
            Options = options ?? new DocumentDbStorageOptions();
            Options.DatabaseName   = database;
            Options.CollectionName = collection;

            // set the partitioning flag on the client helper
            ClientHelper.enablePartition = Options.EnablePartition;

            JsonSerializerSettings settings = new JsonSerializerSettings
            {
                NullValueHandling    = NullValueHandling.Ignore,
                DateTimeZoneHandling = DateTimeZoneHandling.Utc,
                ContractResolver     = new DocumentContractResolver()
            };

            ConnectionPolicy connectionPolicy = ConnectionPolicy.Default;

            connectionPolicy.ConnectionMode     = Options.ConnectionMode;
            connectionPolicy.ConnectionProtocol = Options.ConnectionProtocol;
            connectionPolicy.RequestTimeout     = Options.RequestTimeout;
            connectionPolicy.RetryOptions       = new RetryOptions
            {
                MaxRetryWaitTimeInSeconds           = 10,
                MaxRetryAttemptsOnThrottledRequests = 5
            };

            Client = new DocumentClient(new Uri(url), authSecret, settings, connectionPolicy);
            Task task         = Client.OpenAsync();
            Task continueTask = task.ContinueWith(t => Initialize(), TaskContinuationOptions.OnlyOnRanToCompletion);

            continueTask.Wait();

            StoredprocedureHelper.Setup(database, collection);

            JobQueueProvider provider = new JobQueueProvider(this);

            QueueProviders = new PersistentJobQueueProviderCollection(provider);
        }