Example #1
0
        public void Test_Dequeue()
        {
            var key = "CouchbaseQueueTests.Test_Dequeue";

            _bucket.Remove(key);

            var queue = new CouchbaseQueue <Poco>(_bucket, key);

            queue.Enqueue(new Poco {
                Name = "pcoco1"
            });
            queue.Enqueue(new Poco {
                Name = "pcoco2"
            });
            queue.Enqueue(new Poco {
                Name = "pcoco3"
            });

            var item = queue.Dequeue();

            Assert.AreEqual("pcoco1", item.Name);

            var items = _bucket.Get <List <Poco> >(key).Value;

            Assert.AreEqual(2, items.Count);
        }
Example #2
0
 /// <summary>
 /// Removes a session store item from the bucket
 /// </summary>
 /// <param name="bucket">Bucket to remove from</param>
 /// <param name="id">Session ID</param>
 public static void Remove(
     IBucket bucket,
     string id)
 {
     bucket.Remove(_dataPrefix + id);
     bucket.Remove(_headerPrefix + id);
 }
 /// <summary>
 /// Removes a session store item from the bucket
 /// </summary>
 /// <param name="bucket">Bucket to remove from</param>
 /// <param name="id">Session ID</param>
 public static void Remove(
     IBucket bucket,
     string id)
 {
     bucket.Remove(CouchbaseSessionStateProvider.DataPrefix + id);
     bucket.Remove(CouchbaseSessionStateProvider.HeaderPrefix + id);
 }
        public void Test_InsertFromJson()
        {
            var id = "25892e17-80f6-415f-9c65-7395632f0223";

            _bucket.Remove(id);
            var json   = File.ReadAllText("Data\\doc-with-embedded-id.json");
            var result = _bucket.ExtractKeyAndInsert <dynamic>(json, "_id");

            Assert.IsTrue(result.Success);
        }
        public void Test_Get()
        {
            var key   = "thekey";
            var value = "thevalue";

            _bucket.Remove(key);
            _bucket.Insert(key, value);
            var result = _bucket.Get <string>(key);

            Assert.AreEqual(ResponseStatus.Success, result.Status);
        }
Example #6
0
        /// <summary>
        /// Помещает коллекцию объектов в кэш
        /// </summary>
        /// <param name="keys"></param>
        /// <returns></returns>
        public bool BulkDelete(List <string> keys)
        {
            var res        = _bucket.Remove(keys, TimeSpan.FromSeconds(10));
            int failsCount = res.Count(x => x.Value.Success == false);

            if (failsCount > 0)
            {
                var fails = res.Where(x => x.Value.Success == false).ToList();
            }
            return(failsCount == 0);
        }
        public override void RemoveServer(string serverId)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException(nameof(serverId));
            }

            string id = $"{serverId}:{DocumentTypes.Server}".GenerateHash();

            bucket.Remove(id);
        }
Example #8
0
        public void DeleteDocument<TDocument>(string collectionName, string id)
        {
            Initialize();

            var documentId = GetDocumentId(collectionName, id);
            bucket.Remove(documentId);
        }
        /// <summary>
        /// Removes a value from the cache for the specified key.
        /// </summary>
        /// <param name="key">The key being used to identify the item within the cache.</param>
        /// <param name="region">The cache region.</param>
        /// <returns>
        /// <c>true</c> if the key was found and removed from the cache, <c>false</c> otherwise.
        /// </returns>
        protected override bool RemoveInternal(string key, string region)
        {
            var fullKey = GetKey(key, region);
            var result  = _bucket.Remove(fullKey);

            return(result.Success);
        }
Example #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mobileNo"></param>
 /// /// <param name="emiratiId"></param>
 /// <returns></returns>
 public string Sendotp(string mobileNo, string emiratiId)
 {
     try
     {
         string Otp = GenerateOtp();
         string Id  = "otp_" + emiratiId;
         _bucket.Remove(Id);
         // mobileSMS.SendOtpViaMobile(mobileNo, Otp);
         var otpDoc = new Document <Otp>()
         {
             Id      = Id,
             Content = new Otp
             {
                 MobileNo  = mobileNo,
                 MobileOtp = Otp
             }
         };
         var result = _bucket.Insert(otpDoc);
         return("ok");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Example #11
0
 public void RemoveFromQueue()
 {
     lock (syncRoot)
     {
         IOperationResult result = bucket.Remove(Id);
         removedFromQueue = result.Success;
     }
 }
Example #12
0
        public IActionResult DeleteData(UserModel Item)
        {
            bucket.Remove(Item.id);



            return(Content("Successfully Deleted"));
        }
Example #13
0
        protected void Delete(Guid id)
        {
            var result = _bucket.Remove(CreateKey(id));

            if (!result.Success)
            {
                throw result.Exception;
            }
        }
Example #14
0
        static void DeleteDocument(IBucket bucket, Document <Person> document)
        {
            var result = bucket.Remove(document);

            if (result.Success)
            {
                Console.WriteLine("Deleted document '{0}'", document.Id);
            }
        }
        /// <exception cref="KeyAttributeMissingException">The document id could not be found.</exception>
        /// <exception cref="AmbiguousMatchException">More than one of the requested attributes was found. </exception>
        /// <exception cref="TypeLoadException">A custom attribute type cannot be loaded. </exception>
        /// <exception cref="CouchbaseWriteException">An exception wrapping the <see cref="IOperationResult"/> interface. Use this to determine what failed.</exception>
        public void Remove <T>(T document)
        {
            var id     = GetDocumentId(document);
            var result = _bucket.Remove(id);

            if (!result.Success)
            {
                throw new CouchbaseWriteException(result);
            }
        }
Example #16
0
        public void Delete(string id)
        {
            var key    = CreateKey(id);
            var result = _bucket.Remove(key);

            if (!result.Success)
            {
                throw result.Exception;
            }
        }
Example #17
0
        /// <summary>
        /// send otp on mobile  for varified
        /// </summary>
        /// <param name="mobileNo"></param>
        /// <param name="otp"></param>
        /// /// <param name="emiratiId"></param>
        /// <returns>otp</returns>
        ///  public string SendOtpViaMobile(MobNum mobileNo, string otp)
        public string SendOtpViaMobile(string mobileNo, string otp, string email)
        {
            string msg = string.Empty;

            try
            {
                msg = "200";
                string Id = "otp_" + email;
                _bucket.Remove(Id);
                var otpDoc = new Document <Otp>()
                {
                    Id      = Id,
                    Content = new Otp
                    {
                        MobileNo  = mobileNo,
                        MobileOtp = otp
                    }
                };
                var result = _bucket.Insert(otpDoc);
                //commented by arvind for by pass mobile sms
                //SmsMessage = SmsMessage.Replace("otpnum", otp);
                //string mobileNoWithCountryCode = mobileNo;
                //HttpClient client = new HttpClient();
                //client.BaseAddress = new Uri(ConfigurationManager.AppSettings.Get("SmsApiBaseUrl"));
                //client.DefaultRequestHeaders.Accept.Clear();
                //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                //HttpResponseMessage response = client.GetAsync("http-api.php?action=sendsms&user="******"&password="******"&from=" + SmsFrom + "&to=" + mobileNoWithCountryCode + "&text=" + SmsMessage + "&maxsplit=" + SmsMaxsplit + "").Result;
                //if (response.IsSuccessStatusCode)
                //{
                //    msg = "200";
                //    string Id = "otp_" + email;
                //    _bucket.Remove(Id);
                //    var otpDoc = new Document<Otp>()
                //    {
                //        Id = Id,
                //        Content = new Otp
                //        {
                //            MobileNo = mobileNo,
                //            MobileOtp = otp
                //        }
                //    };
                //    var result = _bucket.Insert(otpDoc);
                //}
                //else
                //{
                //    msg = "400";
                //}
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            return(msg);
        }
Example #18
0
 public void Remove(string key)
 {
     try
     {
         var upsert = _ibucket.Remove(key);
     }
     catch (Exception ex)
     {
         throw (ex);
     }
 }
        public static async Task <bool> DeleteDocument(string id)
        {
            _bucket = ClusterHelper.GetBucket("beer-sample");
            var result = _bucket.Remove(id);

            if (result.Success)
            {
                return(true);
            }
            return(false);
        }
        public void Dispose()
        {
            if (!string.IsNullOrEmpty(resourceId))
            {
                bucket.Remove(resourceId);
                resourceId = string.Empty;
                logger.Trace($"Lock released for {resource}");
            }

            bucket?.Dispose();
        }
Example #21
0
        /// <summary>
        /// Removes an <see cref="IContact" /> from the relevant <see cref="IBucket" />.
        /// </summary>
        /// <param name="contact"></param>
        public void Remove(IContact contact)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }

            IBucket bucket = GetBucketForKey(contact.NodeId);

            bucket.Remove(contact);
        }
        public void SetUp()
        {
            _cluster = new Cluster(new ClientConfiguration
            {
                Servers = new List <Uri>
                {
                    new Uri("http://10.142.180.102:8091/")
                }
            });

            _cluster.Authenticate("Administrator", "password");
            _bucket = _cluster.OpenBucket();

            if (_bucket.Exists("a"))
            {
                var a = _bucket.Remove("a");
                Assert.IsTrue(a.Success);
            }

            if (_bucket.Exists("b"))
            {
                var b = _bucket.Remove("b");
                Assert.IsTrue(b.Success);
            }

            if (_bucket.Exists("c"))
            {
                var c = _bucket.Remove("c");
                Assert.IsTrue(c.Success);
            }

            if (!_bucket.Exists("counter"))
            {
                var counter = _bucket.Increment("counter");
                Assert.IsTrue(counter.Success);
            }

            var insertC = _bucket.Insert("c", new { });

            Assert.AreEqual(ResponseStatus.Success, insertC.Status);
        }
Example #23
0
        public void Test_Add()
        {
            const string key = "CouchbaseDictionaryTests.Test_Add";

            _bucket.Remove(key);

            var dictionary = new CouchbaseDictionary <string, Poco>(_bucket, key);

            dictionary.Add("somekey1", new Poco {
                Name = "poco1"
            });
            dictionary.Add("somekey2", new Poco {
                Name = "poco2"
            });

            Assert.AreEqual(2, dictionary.Count);
        }
        private void ClearBucket()
        {
            var keys = GetAllKeys();

            using (IBucket bucket = GetBucket())
            {
                foreach (var key in keys)
                {
                    bucket.Remove(key);
                }
            }
        }
Example #25
0
 public IHttpActionResult Delete(string id)
 {
     try
     {
         var userDocument = _bucket.Remove("Customer_" + id);
         return(Content(HttpStatusCode.OK, "success"));
     }
     catch (Exception ex)
     {
         return(Content(HttpStatusCode.Forbidden, ex.Message));
     }
 }
Example #26
0
        public void When_Document_Has_Expiry_It_Is_Evicted_After_It_Expires_Insert()
        {
            var document = new Document <dynamic>
            {
                Id      = "When_Document_Has_Expiry_It_Is_Evicted_After_It_Expires_Insert",
                Expiry  = 1000,
                Content = new { name = "I expire in 2000 milliseconds." }
            };

            _bucket.Remove(document);
            var upsert = _bucket.Insert(document);

            Assert.IsTrue(upsert.Success);

            var get = _bucket.GetDocument <dynamic>(document.Id);

            Assert.AreEqual(ResponseStatus.Success, get.Status);

            Thread.Sleep(2000);
            get = _bucket.GetDocument <dynamic>(document.Id);
            Assert.AreEqual(ResponseStatus.KeyNotFound, get.Status);
        }
Example #27
0
        public void RetrieveAndUpdate()
        {
            var key  = "SampleApp-" + DateTime.Now.Ticks;
            var data = new Data
            {
                Number = 42,
                Text   = "Life, the Universe, and Everything",
                Date   = DateTime.UtcNow
            };

            // Get non-existent document.
            // Note that it's enough to check the Status property,
            // We're only checking all three to show they exist.
            var notFound = _bucket.Get <dynamic>(key);

            if (!notFound.Success &&
                notFound.Status == ResponseStatus.KeyNotFound)
            {
                Console.WriteLine("Document doesn't exist!");
            }

            // Prepare a JSON document value
            _bucket.Upsert(key, data);

            // Get a JSON document string value
            var docResult = _bucket.Get <Data>(key);

            Console.WriteLine("Found: " + docResult.Value);

            // Change the data
            data.Number++;
            data.Text = "What's 7 * 6 + 1?";
            data.Date = DateTime.UtcNow;

            // Try to insert under the same key should fail
            var insertResult = _bucket.Insert(key, data);

            if (!insertResult.Success)
            {
                Console.WriteLine("Inserting under an existing key fails as expected.");
            }

            // Replace existing document
            // Note this only works if the key already exists
            var replaceResult = _bucket.Replace(key, data);

            // Check that the data was updated
            var res = _bucket.Remove(key);

            Console.WriteLine("Got: " + res.Status);
        }
Example #28
0
        public virtual Task <bool> Delete(string item)
        {
            var result = true;

            try
            {
                _bucket.Remove(item);
            }
            catch (Exception ex)
            {
                result = false;
                _logger.Error(ex.InnerException.Message);
            }
            return(Task.FromResult <bool>(result));
        }
Example #29
0
        public override void RemoveFromSet(string key, string value)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (string.IsNullOrEmpty(value))
            {
                throw new ArgumentNullException(nameof(value));
            }

            QueueCommand(() =>
            {
                BucketContext context = new BucketContext(bucket);
                IList <string> ids    = context.Query <Set>()
                                        .Where(s => s.DocumentType == DocumentTypes.Set && s.Key == key)
                                        .AsEnumerable()
                                        .Where(s => s.Value == value)
                                        .Select(s => s.Id)
                                        .ToList();

                bucket.Remove(ids, TimeSpan.FromSeconds(30));
            });
        }
Example #30
0
 /// <summary>
 /// 移除(键不存在,也是删除成功)
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Remove(string key)
 {
     try
     {
         if (!_bucket.Exists(key))
         {
             return(true);
         }
         var result = _bucket.Remove(key);
         return(result.Success);
     }
     catch (Exception ex)
     {
         throw new Exception($"CouchBase Remove Operate Error, Message:{ex.Message}", ex);
     }
 }
 /// <summary>
 /// Removes a session store item from the bucket
 /// </summary>
 /// <param name="bucket">Bucket to remove from</param>
 /// <param name="id">Session ID</param>
 public static void Remove(
     IBucket bucket,
     string id)
 {
     bucket.Remove(CouchbaseSessionStateProvider.DataPrefix + id);
     bucket.Remove(CouchbaseSessionStateProvider.HeaderPrefix + id);
 }
 /// <summary>
 /// Removes a session store item from the bucket
 /// </summary>
 /// <param name="bucket">Bucket to remove from</param>
 /// <param name="id">Session ID</param>
 public static void Remove(
     IBucket bucket,
     string id)
 {
     bucket.Remove(_dataPrefix + id);
     bucket.Remove(_headerPrefix + id);
 }