public void TestFixtureSetUp()
        {
            _cluster = new Cluster("couchbaseClients/couchbase");

            using (var bucket = _cluster.OpenBucket())
            {
                bucket.Upsert(TestKeys.KeyWithInt32Value.Key, TestKeys.KeyWithInt32Value.Value);
                bucket.Upsert(TestKeys.KeyWithStringValue.Key, TestKeys.KeyWithStringValue.Value);

                // ISO-8601 and Microsoft JSON Date format:
                bucket.Upsert(TestKeys.KeyWithIsoDateValue.Key, TestKeys.KeyWithIsoDateValue.Value);
                bucket.Upsert(TestKeys.KeyWithIsoUtcDateValue.Key, TestKeys.KeyWithIsoUtcDateValue.Value);
                bucket.Upsert(TestKeys.KeyWithMsDateValue.Key, TestKeys.KeyWithMsDateValue.Value);

                // De-Serialize const JSON string into a Dictionary<string, dynamic> and write via bucket.Upsert(Couchbase.Document<dynamic>)
                var ADict = JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(TestKeys.KeyWithJsonDocValueStr);
                var couchDoc = new Couchbase.Document<dynamic>()
                {
                    Id = TestKeys.KeyWithJsonDocKey,
                    Content = ADict
                };
                bucket.Upsert(couchDoc);


            }
        }
Exemplo n.º 2
0
        public async Task Update(Person person)
        {
            var personDocument = new Couchbase.Document <Person>
            {
                Content = person,
                Id      = person.Id
            };

            await this.peopleBucket.UpsertAsync <Person>(personDocument);
        }
Exemplo n.º 3
0
        public async Task Create(Person newPerson)
        {
            var doc = new Couchbase.Document <Person>
            {
                Content = newPerson,
                Id      = newPerson.Id
            };

            await peopleBucket.InsertAsync(doc);
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var timerState = new TimerState {
                Counter = 0
            };

            timer = new Timer(
                callback: new TimerCallback(TimerTask),
                state: timerState,
                dueTime: 5000,
                period: 5000);

            while (timerState.Counter > -1)
            {
                if (timerState.Counter > 5)
                {
                    timerState.Counter = 0;
                }
                try
                {
                    List <Merchandise> items = new List <Merchandise>();
                    SqlConnection      sc    = new SqlConnection();
                    Startup            s     = new Startup();
                    sc = s.GetSqlConnection();

                    try
                    {
                        sc.Open();

                        for (int i = 0; i < 3; i++)
                        {
                            using (var _bucket = s.GetCouchbaseConnect().OpenBucket(GetBuckets(i)))
                            {
                                Couchbase.Document <Merchandise> doc = new Couchbase.Document <Merchandise>();
                                SqlCommand cmd = sc.CreateCommand();

                                items = sc.Query <Merchandise>("SELECT * FROM USA").ToList();
                                foreach (Merchandise rowdata in items)
                                {
                                    doc.Id      = rowdata.ItemId.ToString();
                                    doc.Content = rowdata;
                                    if (rowdata.CompanyId == i)
                                    {
                                        var result = _bucket.Upsert(doc);
                                    }
                                }
                            }
                        }
                        sc.Close();
                    }
                    catch (SqlException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }