Exemplo n.º 1
0
        public ProductNoSqlRepositoryFixture()
        {
            // Fixture setup
            var fixture = new Fixture()
                          .Customize(new AutoMoqCustomization());

            mockProduct  = fixture.Freeze <Product>();
            mockProducts = fixture.Freeze <IEnumerable <Product> >();
            string mockProductString = JsonConvert.SerializeObject(mockProduct);
            IDictionary <string, object> mockFindResultSet = new Dictionary <string, object>();

            foreach (var product in MockProducts.MockBooks)
            {
                mockFindResultSet.Add("product::" + product.Uid,
                                      JsonConvert.SerializeObject(product));
            }

            IFactory <IProduct> productFactory = new ProductFactory();
            ICouchbaseClient    db             = MakeMockCbClient(mockProductString, mockFindResultSet);
            ILocale             locale         = fixture.Freeze <DefaultLocale>();
            IRestClient         restClient     = MakeMockRestClient();

            productRepo = new ProductNoSqlRepository(productFactory, db, locale, restClient,
                                                     "http://localhost:9200/unittests/_search");
        }
        public static T GetJson <T>(this ICouchbaseClient client, string key) where T : class
        {
            var json = client.Get <string>(key);

            json = DocHelper.InsertId(json, key);
            return(json == null ? null : JsonConvert.DeserializeObject <T>(json));
        }
 internal CouchbaseView(ICouchbaseClient client, IHttpClientLocator clientLocator,
                        string designDocument, string indexName, int retryCount, bool shouldLookupDocById = false,
                        string pagedViewIdProperty = null, string pagedViewKeyProperty = null)
     : base(client, clientLocator, designDocument, indexName, retryCount)
 {
     _shouldLookupDocById = shouldLookupDocById;
 }
Exemplo n.º 4
0
 public UserRepository(ICouchbaseClient db, IFactory <IUser> userFactory, ILocale locale, string searchUrl)
 {
     this.db         = db;
     this.dataType   = ((IHelpCategorizeNoSqlData)userFactory.GetInstance())._type;
     this.keyPattern = String.Concat(this.dataType, "::{0}");
     this.locale     = locale;
     this.searchUrl  = searchUrl;
 }
Exemplo n.º 5
0
 internal CouchbaseViewHandler(ICouchbaseClient client, IHttpClientLocator clientLocator, string designDocument, string indexName, string viewPath = "_view")
 {
     this.Client         = client;
     this.ClientLocator  = clientLocator;
     this.DesignDocument = designDocument;
     this.IndexName      = indexName;
     this.ViewPath       = viewPath;
 }
Exemplo n.º 6
0
        public static ICouchbaseClient CreateCouchbaseClient()
        {
            if (_client == null)
            {
                _client = new CouchbaseClient();
            }

            return(_client);
        }
        public static ICouchbaseClient CreateCouchbaseClient()
        {
            if (_client == null)
            {
                _client = new CouchbaseClient("couchbase");
            }

            return _client;
        }
Exemplo n.º 8
0
 public void SetUp()
 {
     Client = CouchbaseClientFactory.CreateCouchbaseClient();
     if (_numberOfTimesCalled < 1)
     {
         CreateDocsFromFile("Data\\CityDocs.json", "city_", "state", "name");
         CreateViewFromFile("Data\\CityViews.json", "cities");
         Interlocked.Increment(ref _numberOfTimesCalled);
     }
 }
        public static ICouchbaseClient CreateCouchbaseClient()
        {
            if (Client == null)
            {
                log4net.Config.XmlConfigurator.Configure();
                Client = new CouchbaseClient("couchbase");
            }

            return(Client);
        }
 public void SetUp()
 {
     Client = CouchbaseClientFactory.CreateCouchbaseClient();
         if (_numberOfTimesCalled < 1)
         {
             CreateDocsFromFile("Data\\CityDocs.json", "city_", "state", "name");
             CreateViewFromFile("Data\\CityViews.json", "cities");
             Interlocked.Increment(ref _numberOfTimesCalled);
         }
 }
Exemplo n.º 11
0
 public ProductNoSqlRepository(IFactory <IProduct> productFactory, ICouchbaseClient db, ILocale locale, IRestClient restClient, string searchUrl)
 {
     this.productFactory = productFactory;
     this.db             = db;
     this.locale         = locale;
     this.dataType       = ((IHelpCategorizeNoSqlData)productFactory.GetInstance())._type;
     this.keyPattern     = String.Concat(this.dataType, "::{0}");
     this.restClient     = restClient;
     this.searchUrl      = searchUrl;
 }
        public static ICouchbaseClient CreateCouchbaseClient()
        {
            if (Client == null)
            {
                log4net.Config.XmlConfigurator.Configure();
                Client = new CouchbaseClient("couchbase");
            }

            return Client;
        }
Exemplo n.º 13
0
 public DataStore(
     ICouchbaseFactory couchbaseFactory,
     ICompassEnvironment compassEnvironment,
     ICouchbaseClient couchbaseClient
     )
 {
     _couchbaseFactory   = couchbaseFactory;
     _compassEnvironment = compassEnvironment;
     _couchbaseClient    = couchbaseClient;
 }
Exemplo n.º 14
0
        /// <summary>
        /// Yeni bir CouchbaseDistributedCache instance ı oluşturur. Bu objenin oluşturulabilmesi için config dosyasında
        /// DistributedCache ayarları yapılmış olamlı. Bu ayarın içeriğinin
        /// { "ServerAddress": "http://sunucu.com", BucketName: "default", "SecondaryServerAdress": "http://sunucu2.com|bucket2" }
        /// gibi JSON formatında olması gerekli. ServerAddress ve BucketName alanları zorunludur. SecondaryServerAdress, varsa
        /// mirrorlama için kullanılacak ikincil bir sunucu (bu sunucuya sadece veri silme işlemleri mirror lanır) adresi
        /// "sunucu | bucket adı" formatında girilebilir.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Lutfen uygulama icin AppSettings -> DistributedCache ->
        /// ServerAddress ayarini yapiniz!</exception>
        public CouchbaseDistributedCache()
        {
            var setting = (ConfigurationManager.AppSettings["DistributedCache"] ?? "").Trim();

            if (setting.Length == 0)
            {
                setting = "{}";
            }

            this.configuration = JsonConvert.DeserializeObject <Configuration>(setting, JsonSettings.Tolerant);

            if (String.IsNullOrWhiteSpace(this.configuration.ServerAddress))
            {
                throw new InvalidOperationException(
                          "Lutfen uygulama icin AppSettings -> DistributedCache -> ServerAddress ayarini yapiniz!");
            }

            if (String.IsNullOrWhiteSpace(this.configuration.BucketName))
            {
                throw new InvalidOperationException(
                          "Lutfen uygulama icin AppSettings -> DistributedCache -> BucketName ayarini yapiniz!");
            }

            var config = new CouchbaseClientConfiguration
            {
                Bucket         = this.configuration.BucketName,
                BucketPassword = this.configuration.BucketPass
            };

            config.Urls.Add(new Uri(this.configuration.ServerAddress));

            this.cacheClient = new CouchbaseClient(config);

            foreach (var secondaryServerAddress in
                     (this.configuration.SecondaryServerAddress ?? "").Trim()
                     .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                if (!String.IsNullOrWhiteSpace(secondaryServerAddress))
                {
                    var secondaryConfig = new CouchbaseClientConfiguration();
                    secondaryConfig.Bucket         = config.Bucket;
                    secondaryConfig.BucketPassword = config.BucketPassword;
                    var secondaryServer = (secondaryServerAddress ?? "").Trim();
                    var pipeIndex       = secondaryServer.IndexOf('|');
                    if (pipeIndex > 0)
                    {
                        secondaryConfig.Bucket = secondaryServer.Substring(pipeIndex + 1);
                        secondaryServer        = secondaryServer.Substring(0, pipeIndex);
                    }
                    secondaryConfig.Urls.Add(new Uri(secondaryServer));
                    this.secondaryClients = this.secondaryClients ?? new List <ICouchbaseClient>();
                    this.secondaryClients.Add(new CouchbaseClient(secondaryConfig));
                }
            }
        }
        public void SetUp()
        {
            _Client = CouchbaseClientFactory.CreateCouchbaseClient();

            //TODO: uncomment this line when next NuGet (1.2.7) is pushed
            //log4net.Config.XmlConfigurator.Configure();

            var cluster = new CouchbaseCluster("couchbase");

            var stream = File.Open(@"Data\\ThingViews.json", FileMode.Open);
            cluster.CreateDesignDocument("default", "things", stream);
        }
Exemplo n.º 16
0
        public void SetUp()
        {
            _Client = CouchbaseClientFactory.CreateCouchbaseClient();

            //TODO: uncomment this line when next NuGet (1.2.7) is pushed
            //log4net.Config.XmlConfigurator.Configure();

            var cluster = new CouchbaseCluster("couchbase");

            var stream = File.Open(@"Data\\ThingViews.json", FileMode.Open);

            cluster.CreateDesignDocument("default", "things", stream);
        }
Exemplo n.º 17
0
        public static IStoreOperationResult Store(ICouchbaseClient client, StoreMode mode = StoreMode.Set, string key = null, string value = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = GetUniqueKey("store");
            }

            if (value == null)
            {
                value = GetRandomString();
            }
            return(client.ExecuteStore(mode, key, value));
        }
Exemplo n.º 18
0
        public static IStoreOperationResult Store(ICouchbaseClient client, StoreMode mode = StoreMode.Set, string key = null, string value = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                key = GetUniqueKey("store");
            }

            if (value == null)
            {
                value = GetRandomString();
            }
            return client.ExecuteStore(mode, key, value);
        }
        public void SetUp()
        {
            Client = CouchbaseClientFactory.CreateCouchbaseClient();

            if (_numberOfTimesCalled < 1)
            {
                var cluster = CouchbaseClusterFactory.CreateCouchbaseCluster();
                using (var stream = File.Open(@"Data\\ThingViews.json", FileMode.Open))
                {
                    cluster.CreateDesignDocument("default", "things", stream);
                }
                Interlocked.Increment(ref _numberOfTimesCalled);
            }
        }
        public void SetUp()
        {
            Client = CouchbaseClientFactory.CreateCouchbaseClient();

            if (_numberOfTimesCalled < 1)
            {
                var cluster = CouchbaseClusterFactory.CreateCouchbaseCluster();
                using (var stream = File.Open(@"Data\\ThingViews.json", FileMode.Open))
                {
                    cluster.CreateDesignDocument("default", "things", stream);
                }
                Interlocked.Increment(ref _numberOfTimesCalled);
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Unmanaged kaynakları boşaltır (Couchbase bağlantılarını).
        /// </summary>
        public void Dispose()
        {
            if (cacheClient != null)
            {
                cacheClient.Dispose();
                cacheClient = null;
            }

            if (secondaryClient != null)
            {
                secondaryClient.Dispose();
                secondaryClient = null;
            }
        }
Exemplo n.º 22
0
        internal CouchbaseViewHandler(ICouchbaseClient client, IHttpClientLocator clientLocator, string designDocument, string indexName, int retryCount, string viewPath = "_view")
        {
            this.Client         = client;
            this.ClientLocator  = clientLocator;
            this.DesignDocument = designDocument;
            this.IndexName      = indexName;
            this.ViewPath       = viewPath;

            if (retryCount < 0 || retryCount > 10)
            {
                const string msg = "Must be greater than 0 and less than or equal to 10.";
                throw new ArgumentOutOfRangeException("retryCount", msg);
            }
            RetryCount = retryCount;
        }
        public static IGetOperationResult <T> ExecuteGetJson <T>(this ICouchbaseClient client, string key) where T : class
        {
            var result = client.ExecuteGet <string>(key);
            var retVal = new GetOperationResult <T>();

            result.Combine(retVal);
            retVal.Cas = result.Cas;

            if (!result.Success)
            {
                return(retVal);
            }
            retVal.Value = DeserializeObject <T>(key, result.Value);
            return(retVal);
        }
Exemplo n.º 24
0
        public UserRepositoryFixture()
        {
            // Fixture setup
            var fixture = new Fixture()
                          .Customize(new AutoMoqCustomization());

            mockUser  = fixture.Freeze <User>();
            mockUsers = fixture.Freeze <IEnumerable <User> >();
            string mockProductString = JsonConvert.SerializeObject(mockUser);

            ICouchbaseClient db          = MakeMockCbClient(mockProductString);
            IFactory <IUser> userFactory = new UserFactory();
            ILocale          locale      = fixture.Freeze <DefaultLocale>();

            //ICouchbaseClient db, IFactory<IUser> userFactory, ILocale locale
            userRepo = new UserRepository(db, userFactory, locale, "http://localhost:9200/unittests/_search");
        }
Exemplo n.º 25
0
        /// <summary>
        /// Unmanaged kaynakları boşaltır (Couchbase bağlantılarını).
        /// </summary>
        public void Dispose()
        {
            if (cacheClient != null)
            {
                cacheClient.Dispose();
                cacheClient = null;
            }

            if (secondaryClients != null)
            {
                foreach (var secondaryClient in secondaryClients)
                {
                    secondaryClient.Dispose();
                }
                secondaryClients = null;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Yeni bir CouchbaseDistributedCache instance ı oluşturur. Bu objenin oluşturulabilmesi için config dosyasında
        /// DistributedCache ayarları yapılmış olamlı. Bu ayarın içeriğinin
        /// { "ServerAddress": "http://sunucu.com", BucketName: "default", "SecondaryServerAdress": "http://sunucu2.com|bucket2" }
        /// gibi JSON formatında olması gerekli. ServerAddress ve BucketName alanları zorunludur. SecondaryServerAdress, varsa
        /// mirrorlama için kullanılacak ikincil bir sunucu (bu sunucuya sadece veri silme işlemleri mirror lanır) adresi
        /// "sunucu | bucket adı" formatında girilebilir.
        /// </summary>
        /// <exception cref="System.InvalidOperationException">Lutfen uygulama icin AppSettings -> DistributedCache ->
        /// ServerAddress ayarini yapiniz!</exception>
        public CouchbaseDistributedCache()
        {
            this.configuration = JsonConvert.DeserializeObject <Configuration>(
                ConfigurationManager.AppSettings["DistributedCache"].TrimToNull() ?? "{}", JsonSettings.Tolerant);

            if (this.configuration.ServerAddress.IsTrimmedEmpty())
            {
                throw new InvalidOperationException(
                          "Lutfen uygulama icin AppSettings -> DistributedCache -> ServerAddress ayarini yapiniz!");
            }

            if (this.configuration.BucketName.IsTrimmedEmpty())
            {
                throw new InvalidOperationException(
                          "Lutfen uygulama icin AppSettings -> DistributedCache -> BucketName ayarini yapiniz!");
            }

            var config = new CouchbaseClientConfiguration
            {
                Bucket         = this.configuration.BucketName,
                BucketPassword = this.configuration.BucketPass
            };

            config.Urls.Add(new Uri(this.configuration.ServerAddress));

            this.cacheClient = new CouchbaseClient(config);

            // ikinci mirror sunucusu sadece konfigürasyonda belirtilmişse kullanılır
            if (!this.configuration.SecondaryServerAddress.IsTrimmedEmpty())
            {
                var secondaryConfig = new CouchbaseClientConfiguration();
                secondaryConfig.Bucket         = config.Bucket;
                secondaryConfig.BucketPassword = config.BucketPassword;
                var secondaryServer = this.configuration.SecondaryServerAddress;
                var pipeIndex       = secondaryServer.IndexOf('|');
                if (pipeIndex > 0)
                {
                    secondaryConfig.Bucket = secondaryServer.Substring(pipeIndex + 1);
                    secondaryServer        = secondaryServer.Substring(0, pipeIndex);
                }
                secondaryConfig.Urls.Add(new Uri(secondaryServer));
                this.secondaryClient = new CouchbaseClient(secondaryConfig);
            }
        }
        public static IGetOperationResult <T> ExecuteGetJson <T>(this ICouchbaseClient client, string key) where T : class
        {
            var result = client.ExecuteGet <string>(key);
            var retVal = new GetOperationResult <T>();

            result.Combine(retVal);
            retVal.Cas = result.Cas;

            if (!result.Success)
            {
                return(retVal);
            }

            var json = DocHelper.InsertId(result.Value, key);
            var obj  = JsonConvert.DeserializeObject <T>(json);

            retVal.Value = obj;
            return(retVal);
        }
        public static T TransformRow(JsonReader reader, ICouchbaseClient client, bool shouldLookupById)
        {
            if (shouldLookupById)
            {
                var key  = Json.ParseValue(reader, "id") as string;
                var json = client.Get <string>(key);
                if (string.IsNullOrEmpty(json))
                {
                    return(default(T));
                }

                var jsonWithId = DocHelper.InsertId(json, key);                //_id is omitted from the Json return by Get
                return(JsonConvert.DeserializeObject <T>(jsonWithId));
            }
            else
            {
                var jObject = Json.ParseValue(reader, "value");
                return(JsonConvert.DeserializeObject <T>(jObject));
            }
        }
Exemplo n.º 29
0
        public static Tuple <bool, int, string> StoreDictionary(
            this ICouchbaseClient client,
            StoreMode storeMode,
            string key,
            Dictionary <string, object> dictionary)
        {
            var json   = JsonConvert.SerializeObject(dictionary);
            var result = client.ExecuteStore(storeMode, key, json);

            if (!result.Success)
            {
                if (result.Exception != null)
                {
                    throw result.Exception;
                }

                return(Tuple.Create(false, result.StatusCode.HasValue ? result.StatusCode.Value : -1, result.Message));
            }

            return(Tuple.Create(true, 0, string.Empty));
        }
        public static bool CasJson(this ICouchbaseClient client, StoreMode mode, string key, object value, ulong cas, DateTime expiresAt)
        {
            var json = SerializeObject(value);

            return(client.ExecuteCas(mode, key, json, expiresAt, cas).Success);
        }
        public static IStoreOperationResult ExecuteCasJson(this ICouchbaseClient client, StoreMode mode, string key, object value, DateTime expiresAt, ulong cas)
        {
            var json = SerializeObject(value);

            return(client.ExecuteCas(mode, key, json, expiresAt, cas));
        }
        public static IStoreOperationResult ExecuteStoreJson(this ICouchbaseClient client, StoreMode mode, string key, object value, PersistTo persistTo, ReplicateTo replicateTo = ReplicateTo.Zero)
        {
            var json = SerializeObject(value);

            return(client.ExecuteStore(mode, key, json, persistTo, replicateTo));
        }
        public static bool StoreJson(this ICouchbaseClient client, StoreMode mode, string key, object value)
        {
            var json = SerializeObject(value);

            return(client.ExecuteStore(mode, key, json).Success);
        }
        public static IStoreOperationResult ExecuteStoreJson(this ICouchbaseClient client, StoreMode mode, string key, object value)
        {
            var json = SerializeObject(value);

            return(client.ExecuteStore(mode, key, json));
        }
        public static T GetJson <T>(this ICouchbaseClient client, string key) where T : class
        {
            var json = client.Get <string>(key);

            return(json == null || json == Null ? null : DeserializeObject <T>(key, json));
        }
 internal CouchbaseSpatialView(ICouchbaseClient client, IHttpClientLocator clientLocator, string designDocument, string indexName, int retryCount, bool shouldLookUpDocById = false)
     : base(client, clientLocator, designDocument, indexName, retryCount)
 {
     _shouldLookupDocById = shouldLookUpDocById;
 }
        public void SetUp()
        {
            _Client = CouchbaseClientFactory.CreateCouchbaseClient();

            log4net.Config.XmlConfigurator.Configure();
        }