public Cluster(string connectionStr, string username, string password) { var connectionString = ConnectionString.Parse(connectionStr); _clusterOptions = new ClusterOptions() .WithServers(connectionString.Hosts.ToArray()) .WithCredentials(username, password); if (!_clusterOptions.Servers.Any()) { _clusterOptions = _clusterOptions.WithServers("couchbase://localhost"); } _couchbaseContext = new ConfigContext(_clusterOptions); _couchbaseContext.Start(_configTokenSource); if (_clusterOptions.EnableConfigPolling) { _couchbaseContext.Poll(_configTokenSource.Token); } _lazyQueryClient = new Lazy <IQueryClient>(() => new QueryClient(_clusterOptions)); _lazyAnalyticsClient = new Lazy <IAnalyticsClient>(() => new AnalyticsClient(_clusterOptions)); _lazySearchClient = new Lazy <ISearchClient>(() => new SearchClient(_clusterOptions)); _lazyQueryManager = new Lazy <IQueryIndexes>(() => new QueryIndexes(_lazyQueryClient.Value)); _lazyBucketManager = new Lazy <IBucketManager>(() => new BucketManager(_clusterOptions)); _lazyUserManager = new Lazy <IUserManager>(() => new UserManager(_clusterOptions)); }
public Cluster(string connectionString, ClusterOptions clusterOptions) { if (string.IsNullOrWhiteSpace(connectionString)) { throw new InvalidConfigurationException("The connectionString cannot be null, empty or only be whitesapce."); } if (clusterOptions == null) { throw new InvalidConfigurationException("ClusterOptions is null."); } if (string.IsNullOrWhiteSpace(clusterOptions.Password) || string.IsNullOrWhiteSpace(clusterOptions.UserName)) { throw new InvalidConfigurationException("Username and password are required."); } //TODO make connectionString function per the RFC: https://github.com/couchbaselabs/sdk-rfcs/blob/master/rfc/0011-connection-string.md clusterOptions.WithServers(connectionString); _configTokenSource = new CancellationTokenSource(); _clusterOptions = clusterOptions; _couchbaseContext = new ConfigContext(_clusterOptions); _couchbaseContext.Start(_configTokenSource); if (_clusterOptions.EnableConfigPolling) { _couchbaseContext.Poll(_configTokenSource.Token); } _lazyQueryClient = new Lazy <IQueryClient>(() => new QueryClient(_clusterOptions)); _lazyAnalyticsClient = new Lazy <IAnalyticsClient>(() => new AnalyticsClient(_clusterOptions)); _lazySearchClient = new Lazy <ISearchClient>(() => new SearchClient(_clusterOptions)); _lazyQueryManager = new Lazy <IQueryIndexes>(() => new QueryIndexes(_lazyQueryClient.Value)); _lazyBucketManager = new Lazy <IBucketManager>(() => new BucketManager(_clusterOptions)); _lazyUserManager = new Lazy <IUserManager>(() => new UserManager(_clusterOptions)); }