public BeerSample() : this(ClusterHelper.GetBucket("beer-sample")) { }
public static void Cleanup() { ClusterHelper.Close(); }
static void OpenBucket() { var bucket1 = ClusterHelper.GetBucket("default"); TwoThreadsCompleted.Signal(); }
public BookingService() { _bucket = ClusterHelper.GetBucket("lawyermanagementdb"); }
private Task <IBucket> GetDefaultBucket() { return(ClusterHelper.GetBucketAsync(_bucketName)); }
public NavigationController() { _bucket = ClusterHelper.GetBucket(ConfigurationDefaults.COUCHBASE_COLLECTIONNAME); }
public void When_GetBucket_Is_Called_And_NotInitialized_ThrowInitializationException() { Assert.Throws <InitializationException>(() => ClusterHelper.GetBucket("default")); }
public IQueryResult <dynamic> ExecuteQuery(IQueryRequest query) { return(ClusterHelper .GetBucket(CouchbaseConfigHelper.Instance.Bucket) .Query <dynamic>(query)); }
public IOperationResult <dynamic> Upsert(string id, object model, string bucket) { return(ClusterHelper .GetBucket(bucket) .Upsert <dynamic>(id, model)); }
public ProfileRepository() { _bucket = ClusterHelper.GetBucket("hello-couchbase"); }
public IBucket Bucket(string bucketName) { return(ClusterHelper.GetBucket(bucketName)); }
public void Setup() { ClusterHelper.Initialize(Utils.TestConfiguration.GetCurrentConfiguration()); }
private static IQueryResult <dynamic> ExecuteSql(string sql) { return(ClusterHelper .GetBucket("default") .Query <dynamic>(new QueryRequest(sql).Timeout(TimeSpan.FromMinutes(5)))); }
public static void CloseCouchbaseConnection() { ClusterHelper.Close(); }
private static void CleanupCouchbase() { ClusterHelper.Close(); }
public IOperationResult <dynamic> Get(string id, string bucket) { return(ClusterHelper .GetBucket(bucket) .Get <dynamic>(id)); }
public TemperatureController(IOptions <CouchbaseOptions> couchbaseOptions, TemperatureHub temperatureHub) { _temperatureHub = temperatureHub; _bucket = ClusterHelper.GetBucket(couchbaseOptions.Value.CouchbaseBucket); }
public bool Exists(string id, string bucket) { return(ClusterHelper .GetBucket(bucket) .Exists(id)); }
public void When_Get_Called_Without_Calling_Initialize_InitializationException_Is_Thrown() { ClusterHelper.Close(); var ex = Assert.Throws <InitializationException>(() => ClusterHelper.Get()); }
public UserController(IUserService userService) { _bucket = ClusterHelper.GetBucket("lawyermanagementdb"); _userService = userService; }
public HomeController() { _bucket = ClusterHelper.GetBucket("mybucket"); }
static void Main(string[] args) { var _dbContext = new UserBehaviorDbContext(); var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); ClusterHelper.Initialize(new ClientConfiguration { Servers = new List <Uri> { new Uri(configuration.GetSlnConfig("CouchbaseEndpoint")) } }, new PasswordAuthenticator(configuration.GetSlnConfig("CouchbaseUserName"), configuration.GetSlnConfig("CouchbasePassword"))); var factory = new ConnectionFactory() { HostName = configuration.GetSlnConfig("RabbitMQEndpoint") }; IBucket _bucket = ClusterHelper.GetBucket("TesteViajaNetUserBehavior"); try { using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { channel.QueueDeclare(queue: "UserBehavior", durable: false, exclusive: false, autoDelete: false, arguments: null); var consumer = new EventingBasicConsumer(channel); consumer.Received += (model, ea) => { var body = ea.Body; var message = Encoding.UTF8.GetString(body); PageAccess pageAccess = JsonConvert.DeserializeObject <PageAccess>(message); pageAccess.Id = Guid.NewGuid(); pageAccess.DateCreated = DateTime.Now; _dbContext.PageAccesses.Add(pageAccess); _dbContext.SaveChanges(); _bucket.Insert <PageAccess>(pageAccess.Id.ToString(), pageAccess); }; channel.BasicConsume(queue: "UserBehavior", autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } } catch (Exception e) { Console.Write(e.Message); } finally { ClusterHelper.Close(); } }
public TestController() { _bucket = ClusterHelper.GetBucket("default"); }
public CrudController() { bucket = ClusterHelper.GetBucket("Test"); }
protected void Application_End() { ClusterHelper.Close(); }
private void OnShutdown() { ClusterHelper.Close(); }
public CouchBaseDBExtension(ExtendedActorSystem system) { if (system == null) { throw new ArgumentNullException("system"); } // Initialize fallback configuration defaults system.Settings.InjectTopLevelFallback(CouchBaseDBPersistence.DefaultConfiguration()); var HOCON_CB_JournalConfig = system.Settings.Config.GetConfig("akka.persistence.journal.couchbase"); JournalSettings = new CouchBaseJournalSettings(HOCON_CB_JournalConfig); if (JournalSettings.UseClusterHelper) { JournalCBBucket = ClusterHelper.GetBucket(JournalSettings.BucketName); JournalCBCluster = JournalCBBucket.Cluster; } else { // Instantiate the connection to the cluster JournalCBCluster = new Cluster(JournalSettings.CBClientConfiguration); //Open the bucket and make a reference to the CB Client Configuration JournalCBBucket = (CouchbaseBucket)JournalCBCluster.OpenBucket(JournalSettings.BucketName); } // Throw an exception if we reach this point without a CB Cluster, CB Config, or Bucket if (JournalCBCluster == null) { throw new Exception("CouchBase Journal Cluster could not initialized."); } // Had to do it this way since by default CB always initializes the default bucket. if (JournalCBBucket.Name != JournalSettings.BucketName) { throw new Exception("CouchBase Journal bucket could not initialized."); } // Add Journal Indexes // Add here to create Global Secondary Indexes that cover (See covering Indexes in Couchbase website) to improve performance // First check if the index exists // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr' // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId' // Create using these: // CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `SSA` (PersistenceId,SequenceNr,DocumentType) USING GSI // CREATE INDEX idxDocumentType_PersistenceId on `SSA` (DocumentType,PersistenceId) USING GSI //string N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'"; //var result = JournalCBBucket.Query<dynamic>(N1QLQueryString); //if (result.Rows.Count == 0 && result.Success == true) //{ // N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `" + JournalCBBucket.Name + "` (PersistenceId,SequenceNr,DocumentType) USING GSI"; // result = JournalCBBucket.Query<dynamic>(N1QLQueryString); // //if (result.Success != true) // // Debug.Write("Could not create index:idxDocumentType_PersistenceId_SequenceNr"); //} //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId"; //result = JournalCBBucket.Query<dynamic>(N1QLQueryString); //if (result.Rows.Count == 0 && result.Success == true) //{ // N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId on `" + JournalCBBucket.Name + "` (PersistenceId,DocumentType) USING GSI"; // result = JournalCBBucket.Query<dynamic>(N1QLQueryString); // //if (result.Success != true) // // Debug.Write("Could not create index:idxDocumentType_PersistenceId"); //} var HOCON_CB_SnapshotConfig = system.Settings.Config.GetConfig("akka.persistence.snapshot-store.couchbase"); SnapShotStoreSettings = new CouchbaseSnapshotSettings(HOCON_CB_SnapshotConfig); if (SnapShotStoreSettings.UseClusterHelper) { SnapShotStoreCBBucket = ClusterHelper.GetBucket(SnapShotStoreSettings.BucketName); SnapShotStoreCBCluster = SnapShotStoreCBBucket.Cluster; } else { // Are we using the same cluster as the journal? if (SnapShotStoreSettings.CBClientConfiguration.Servers.All(JournalSettings.CBClientConfiguration.Servers.Contains)) { SnapShotStoreCBCluster = JournalCBCluster; // Since we are using the same cluster are we using the same bucket? if (SnapShotStoreSettings.BucketName == JournalSettings.BucketName) { SnapShotStoreCBBucket = JournalCBBucket; } } else // Instantiate the connection to the new cluster { SnapShotStoreCBCluster = new Cluster(SnapShotStoreSettings.CBClientConfiguration); //Open the bucket and make a reference to the CB Client Configuration SnapShotStoreCBBucket = (CouchbaseBucket)JournalCBCluster.OpenBucket(SnapShotStoreSettings.BucketName); } } // Throw an exception if we reach this point without a CB Cluster, CB Config, or Bucket if (SnapShotStoreCBCluster == null) { throw new Exception("CouchBase Snapshot Store Cluster could not initialized."); } if (SnapShotStoreCBBucket == null) { throw new Exception("CouchBase Snapshot Store bucket could not initialized."); } // Add Snapshot indexes // Add here to create Global Secondary Indexes that cover (See covering Indexes in Couchbase website) to improve performance // First check if the index exists // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr' // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp' // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId' // Create it if it does not // CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `SSA` (PersistenceId,SequenceNr,DocumentType) USING GSI // CREATE INDEX idxDocumentType_PersistenceId_Timestamp on `SSA` (PersistenceId,Timestamp,DocumentType) USING GSI // CREATE INDEX idxDocumentType_PersistenceId on `SSA` (DocumentType,PersistenceId) USING GSI //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'"; //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString); //if (result.Rows.Count == 0 && result.Success == true) //{ // N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `" + SnapShotStoreCBBucket.Name + "` (PersistenceId,SequenceNr,DocumentType) USING GSI"; // result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString); // //if (result.Success != true) // // Debug.Write("Could not create index:idxDocumentType_PersistenceId_SequenceNr"); //} //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp"; //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString); //if (result.Rows.Count == 0 && result.Success == true) //{ // N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_Timestamp on `" + SnapShotStoreCBBucket.Name + "` (PersistenceId,Timestamp,DocumentType) USING GSI"; // result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString); // //if (result.Success != true) // // Debug.Write("Could not create index:idxDocumentType_PersistenceId_Timestamp"); //} //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp"; //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString); //if (result.Rows.Count == 0 && result.Success == true) //{ // N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId on `" + SnapShotStoreCBBucket.Name + "` (DocumentType,PersistenceId) USING GSI"; // result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString); // //if (result.Success != true) // // Debug.Write("Could not create index:idxDocumentType_PersistenceId"); //} }
public ApplicationDbContext() : base(ClusterHelper.GetBucket("default")) { }
public void When_Get_Called_Without_Calling_Initialize_InitializationException_Is_Thrown() { ClusterHelper.Close(); var cluster = ClusterHelper.Get(); }
public async Task Initialise() { try { if (string.IsNullOrWhiteSpace(this.BucketName)) { throw new ArgumentException("BucketName can not be null or empty"); } if (this.ClientConfig == null) { throw new ArgumentException("You must supply a configuration to connect to Couchbase"); } if (this.ClientConfig.BucketConfigs.All(a => a.Key != this.BucketName)) { throw new BucketConfigMissingFromConfigurationException($"The requested bucket is named '{this.BucketName}' however the provided Couchbase configuration has no bucket configuration"); } if (!ClusterHelper.Initialized) { ClusterHelper.Initialize(this.ClientConfig); } else { foreach (var conf in this.ClientConfig.BucketConfigs) { if (ClusterHelper.Get().Configuration.BucketConfigs.ContainsKey(conf.Key)) { ClusterHelper.Get().Configuration.BucketConfigs.Remove(conf.Key); } ClusterHelper.Get().Configuration.BucketConfigs.Add(conf.Key, conf.Value); } } var timeoutPolicy = Policy.TimeoutAsync(30, TimeoutStrategy.Pessimistic); this.bucket = await timeoutPolicy.ExecuteAsync(async() => this.bucket = await ClusterHelper.GetBucketAsync(this.BucketName)); } catch (Exception e) { await Task.FromException(e); } }