/// <summary>
        /// Initializes the AzureDocumentDbStorage form the url auth secret provide.
        /// </summary>
        /// <param name="options">The AzureDocumentDbStorageOptions object to override any of the options</param>
        /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception>
        private AzureDocumentDbStorage(AzureDocumentDbStorageOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            Options = options;

            ConnectionPolicy connectionPolicy = ConnectionPolicy.Default;

            connectionPolicy.RequestTimeout = options.RequestTimeout;
            Client = new DocumentClient(options.Endpoint, options.AuthSecret, connectionPolicy);
            Client.OpenAsync().GetAwaiter().GetResult();

            Collections = new DocumentCollections(options.DatabaseName, options.CollectionPrefix, options.DefaultCollectionName);
            Initialize();

            Newtonsoft.Json.JsonConvert.DefaultSettings = () => new Newtonsoft.Json.JsonSerializerSettings
            {
                NullValueHandling    = Newtonsoft.Json.NullValueHandling.Ignore,
                DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore,
                DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc,
                TypeNameHandling     = Newtonsoft.Json.TypeNameHandling.All
            };

            JobQueueProvider provider = new JobQueueProvider(this);

            QueueProviders = new PersistentJobQueueProviderCollection(provider);
        }
        private static AzureDocumentDbStorageOptions Transform(string url, string authSecret, string database, AzureDocumentDbStorageOptions options)
        {
            if (options == null)
            {
                options = new AzureDocumentDbStorageOptions();
            }

            options.Endpoint     = new Uri(url);
            options.AuthSecret   = authSecret;
            options.DatabaseName = database;

            if (!string.IsNullOrEmpty(options.CollectionPrefix))
            {
                options.CollectionPrefix = $"{options.CollectionPrefix}_";
            }

            if (string.IsNullOrEmpty(options.DefaultCollectionName))
            {
                options.DefaultCollectionName = null;
            }

            return(options);
        }
 /// <summary>
 /// Initializes the AzureDocumentDbStorage 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="options">The AzureDocumentDbStorageOptions object to override any of the options</param>
 /// <exception cref="ArgumentNullException"><paramref name="url"/> argument is null.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="authSecret"/> argument is null.</exception>
 public AzureDocumentDbStorage(string url, string authSecret, string database, AzureDocumentDbStorageOptions options) : this(Transform(url, authSecret, database, options))
 {
 }