private void Initialize(ClientConfiguration configuration, string defaultBucket, CouchbaseStorageOptions options) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (string.IsNullOrEmpty(defaultBucket)) { throw new ArgumentNullException(nameof(defaultBucket)); } Options = options ?? new CouchbaseStorageOptions(); Options.DefaultBucket = defaultBucket; configuration.Serializer = () => new DocumentDefaultSerializer(); Client = new Cluster(configuration); string indexPrefix = $"IDX_{defaultBucket}"; IBucket bucket = Client.OpenBucket(Options.DefaultBucket); { IBucketManager manager = bucket.CreateManager(bucket.Configuration.Username, bucket.Configuration.Password); manager.CreateN1qlPrimaryIndex($"{indexPrefix}_Primary", false); manager.CreateN1qlIndex($"{indexPrefix}_Type", false, "type"); manager.CreateN1qlIndex($"{indexPrefix}_Id", false, "id"); manager.CreateN1qlIndex($"{indexPrefix}_Expire", false, "expire_on"); manager.CreateN1qlIndex($"{indexPrefix}_Name", false, "name"); } JobQueueProvider provider = new JobQueueProvider(this); QueueProviders = new PersistentJobQueueProviderCollection(provider); }
/// <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); }
/// <summary> /// Initializes the FirebaseStorage form the url & auth secret provide. /// </summary> /// <param name="url">The url string to Firebase Database</param> /// <param name="authSecret">The secret key for the Firebase Database</param> /// <param name="options">The FirebaseStorage 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> /// <exception cref="ArgumentNullException"><paramref name="options"/> argument is null.</exception> public FirebaseStorage(string url, string authSecret, FirebaseStorageOptions options) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(nameof(url)); } if (string.IsNullOrEmpty(authSecret)) { throw new ArgumentNullException(nameof(authSecret)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } Config = new FirebaseConfig { AuthSecret = authSecret, BasePath = url, RequestTimeout = options.RequestTimeout, Serializer = new Json.JsonSerializer() }; this.url = url; Options = options; JobQueueProvider provider = new JobQueueProvider(this); QueueProviders = new PersistentJobQueueProviderCollection(provider); }
/// <summary> /// Initializes the CosmosDbStorage form the url auth secret provide. /// </summary> /// <param name="url">The url string to Cosmos Database</param> /// <param name="authSecret">The secret key for the Cosmos Database</param> /// <param name="database">The name of the database to connect with</param> /// <param name="collection">The name of the collection/container on the database</param> /// <param name="options">The CosmosDbStorageOptions object to override any of the options</param> /// <param name="storageOptions"></param> public CosmosDbStorage(string url, string authSecret, string database, string collection, CosmosClientOptions options = null, CosmosDbStorageOptions storageOptions = null) { this.database = database; this.collection = collection; StorageOptions ??= new CosmosDbStorageOptions(); JobQueueProvider provider = new JobQueueProvider(this); QueueProviders = new PersistentJobQueueProviderCollection(provider); options ??= new CosmosClientOptions(); options.ApplicationName = "Hangfire"; options.Serializer = new CosmosJsonSerializer(settings); Client = new CosmosClient(url, authSecret, options); Initialize(); }
/// <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 = 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); }