Beispiel #1
0
 public CouncilController(ICouncilService councilService)
 {
     _bucket         = ClusterHelper.GetBucket("lawyermanagementdb");
     _councilService = councilService;
 }
Beispiel #2
0
 public BreweryController() :
     this(new BreweryRepository(ClusterHelper.GetBucket("beer-sample")))
 {
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Iniciando leitura da fila...");

            var couchbaseServer = "http://:8091";

            ClusterHelper.Initialize(new ClientConfiguration
            {
                Servers = new List <Uri> {
                    new Uri(couchbaseServer)
                }
            }, new PasswordAuthenticator("", ""));

            var _bucket = ClusterHelper.GetBucket("Coleta");
            var factory = new ConnectionFactory()
            {
                HostName = "",
                Port     = 5672,
                UserName = "",
                Password = ""
            };

            using (var dbContext = new viajanetContext())
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        //channel.ExchangeDeclare("exchange.name", ExchangeType.Direct);
                        channel.QueueDeclare(queue: "coletaqueue",
                                             durable: true,
                                             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);
                            var command = JsonConvert.DeserializeObject <ColetaCommand>(message);

                            Console.WriteLine("{2} Processando requisição da página {0}, IP {1}", command.Pagina, command.IP, command.Data);

                            // Insere no Couchbase
                            var ret = _bucket.Insert(Guid.NewGuid().ToString(), command);

                            // Insere no SQL Sever
                            var coleta = new tbColeta()
                            {
                                Ip         = command.IP,
                                Browser    = command.Browser,
                                Pagina     = command.Pagina,
                                Parametros = command.Pagina,
                                Data       = command.Data
                            };

                            dbContext.Add(coleta);
                            dbContext.SaveChanges();
                        };

                        channel.BasicConsume(queue: "coletaqueue",
                                             autoAck: true,
                                             consumer: consumer);

                        Console.WriteLine("Finalizado.");
                        Console.ReadLine();
                    }
        }
        static void OpenBucket()
        {
            var bucket1 = ClusterHelper.GetBucket("default");

            TwoThreadsCompleted.Signal();
        }
Beispiel #5
0
 public BookingController(IBookingService bookingService)
 {
     _bucket         = ClusterHelper.GetBucket("lawyermanagementdb");
     _bookingService = bookingService;
 }
 public void When_GetBucket_Is_Called_And_NotInitialized_ThrowInitializationException()
 {
     Assert.Throws <InitializationException>(() => ClusterHelper.GetBucket("default"));
 }
 public BookingService()
 {
     _bucket = ClusterHelper.GetBucket("lawyermanagementdb");
 }
Beispiel #8
0
 public IBucket Bucket(string bucketName)
 {
     return(ClusterHelper.GetBucket(bucketName));
 }
Beispiel #9
0
 public IQueryResult <dynamic> ExecuteQuery(IQueryRequest query)
 {
     return(ClusterHelper
            .GetBucket(CouchbaseConfigHelper.Instance.Bucket)
            .Query <dynamic>(query));
 }
Beispiel #10
0
 private static IQueryResult <dynamic> ExecuteSql(string sql)
 {
     return(ClusterHelper
            .GetBucket("default")
            .Query <dynamic>(new QueryRequest(sql).Timeout(TimeSpan.FromMinutes(5))));
 }
Beispiel #11
0
 public ProfileRepository()
 {
     _bucket = ClusterHelper.GetBucket("hello-couchbase");
 }
Beispiel #12
0
 public BeerSample()
     : this(ClusterHelper.GetBucket("beer-sample"))
 {
 }
 public ApplicationDbContext()
     : base(ClusterHelper.GetBucket("beer-sample"))
 {
 }
Beispiel #14
0
 public TravelBucketRepository(string bucketName)
 {
     _bucketContext = new BucketContext(ClusterHelper.GetBucket(bucketName));
 }
Beispiel #15
0
 public TemperatureController(IOptions <CouchbaseOptions> couchbaseOptions, TemperatureHub temperatureHub)
 {
     _temperatureHub = temperatureHub;
     _bucket         = ClusterHelper.GetBucket(couchbaseOptions.Value.CouchbaseBucket);
 }
Beispiel #16
0
 public IOperationResult <dynamic> Upsert(string id, object model, string bucket)
 {
     return(ClusterHelper
            .GetBucket(bucket)
            .Upsert <dynamic>(id, model));
 }
 public NavigationController()
 {
     _bucket = ClusterHelper.GetBucket(ConfigurationDefaults.COUCHBASE_COLLECTIONNAME);
 }
Beispiel #18
0
 public IOperationResult <dynamic> Get(string id, string bucket)
 {
     return(ClusterHelper
            .GetBucket(bucket)
            .Get <dynamic>(id));
 }
Beispiel #19
0
 public HomeController()
 {
     _bucket = ClusterHelper.GetBucket("mybucket");
 }
Beispiel #20
0
 public bool Exists(string id, string bucket)
 {
     return(ClusterHelper
            .GetBucket(bucket)
            .Exists(id));
 }
 public TestController()
 {
     _bucket = ClusterHelper.GetBucket("default");
 }
 public UserController(IUserService userService)
 {
     _bucket      = ClusterHelper.GetBucket("lawyermanagementdb");
     _userService = userService;
 }
Beispiel #23
0
        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");
            //}
        }
Beispiel #24
0
        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();
            }
        }
Beispiel #25
0
 public CouchbaseService()
 {
     this._bucket = ClusterHelper.GetBucket("music");
 }
Beispiel #26
0
 public CrudController()
 {
     bucket = ClusterHelper.GetBucket("Test");
 }
Beispiel #27
0
 public GiftsController()
 {
     _buckate  = ClusterHelper.GetBucket("travel-sample");
     _buckate2 = ClusterHelper.GetBucket("test");
 }
 public ApplicationDbContext()
     : base(ClusterHelper.GetBucket("default"))
 {
 }
Beispiel #29
0
        public ProjectController()
        {
            var bucket = ClusterHelper.GetBucket(ConfigurationManager.AppSettings["CouchbaseBucket"]);

            _dataAccess = new ProjectDataAccess(bucket);
        }
Beispiel #30
0
        public void SetUp()
        {
            ClusterHelper.Initialize(TestConfigurations.DefaultConfig());

            EnsurePrimaryIndexExists(ClusterHelper.GetBucket("beer-sample"));
        }