• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# RiakObject类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中RiakObject的典型用法代码示例。如果您正苦于以下问题:C# RiakObject类的具体用法?C# RiakObject怎么用?C# RiakObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RiakObject类属于命名空间,在下文中一共展示了RiakObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Save

        public async Task Save(String endpoint, long position)
        {
            var id = new RiakObjectId($"{Settings.Bucket}.system", endpoint);

            var options = new RiakGetOptions { };
            options.SetRw(Quorum.WellKnown.All);
            var exists = await _riak.Async.Get(id, options);
            if (exists.IsSuccess)
            {
                var checkpoint = exists.Value.GetObject<Checkpoint>();
                checkpoint.Position = position;

                exists.Value.SetObject(checkpoint);

                var putOpt = new RiakPutOptions { IfNotModified = true, IfNoneMatch = false };
                putOpt.SetW(Quorum.WellKnown.All);
                await _riak.Async.Put(exists.Value, putOpt);
            }
            else
            {
                var checkpoint = new Checkpoint
                {
                    Id = endpoint,
                    Position = position,
                };
                var putOpt = new RiakPutOptions { IfNotModified = false, IfNoneMatch = true };
                putOpt.SetW(Quorum.WellKnown.All);
                var o = new RiakObject(id, checkpoint);
                await _riak.Async.Put(o, putOpt);

            }
        }
开发者ID:volak,项目名称:DDD.Enterprise.Example,代码行数:32,代码来源:RiakCheckpoints.cs


示例2: CustomSerializerWillSerializeJson

        public void CustomSerializerWillSerializeJson()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email = "[email protected]",
                Name = new Name
                {
                    FirstName = "OJ",
                    Surname = "Reeves"
                },
                PhoneNumbers = new List<PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };

            var sots = new SerializeObjectToString<Person>(JsonConvert.SerializeObject);

            var obj = new RiakObject("bucket", "key");
            obj.SetObject(testPerson, RiakConstants.ContentTypes.ApplicationJson, sots);
            obj.Value.ShouldNotBeNull();
            obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);

            var json = obj.Value.FromRiakString();
            json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"\\/Date(281664000000)\\/\",\"Email\":\"[email protected]\"}");

            var deserialisedPerson = obj.GetObject<Person>();
            deserialisedPerson.ShouldEqual(testPerson);
        }
开发者ID:tiagomargalho,项目名称:CorrugatedIron,代码行数:34,代码来源:RiakObjectConversionTests.cs


示例3: RangeQuery

        public void RangeQuery()
        {
            var Cluster = RiakCluster.FromConfig("riakConfig");
            var Client = Cluster.CreateClient();

            var bucket = "rsds";

            Client.Batch(batch =>
            {
                for (var i = 1; i < 11; i++)
                {
                    var d = DateTime.Now.AddDays(0 - i);
                    var doc = new RiakObject(bucket, i.ToString(), new { value = i, created_date = d });

                    var position = 100 + i;

                    doc.BinIndex("position").Set(position.ToString());
                    
                    batch.Put(doc);
                }
            });

            var query = new RiakMapReduceQuery()
                    .Inputs(RiakIndex.Range("bucket", "position", 100, 200))
                    .MapJs(m => m.Name("Riak.mapValuesJson").Keep(true));

            var result = Client.MapReduce(query);
            //var items = result.Value.PhaseResults.SelectMany(x => x.GetObjects<dynamic>);
        }
开发者ID:shuk,项目名称:CorrugatedIron.Samples,代码行数:29,代码来源:SecondaryIndices.cs


示例4: InvalidFieldNamesAndTypes

 public void InvalidFieldNamesAndTypes()
 {
     id = new RiakObjectId("indexes", "mykey", "test value");
     var obj = new RiakObject("indexes", "mykey", "test value");
     var intIdx = obj.IntIndex("test-int-idx");
     Assert.Throws<FormatException>(() => intIdx.Add("invalid-value"));
 }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:7,代码来源:SecondaryIndexes.cs


示例5: ObjectsAreConvertedProperly

        public void ObjectsAreConvertedProperly()
        {
            var testPerson = new Person
            {
                DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
                Email = "[email protected]",
                Name = new Name
                {
                    FirstName = "OJ",
                    Surname = "Reeves"
                },
                PhoneNumbers = new List<PhoneNumber>
                {
                    new PhoneNumber
                    {
                        Number = "12345678",
                        NumberType = PhoneNumberType.Home
                    }
                }
            };
            var obj = new RiakObject("bucket", "key");
            obj.SetObject(testPerson);
            obj.Value.ShouldNotBeNull();
            obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);

            var json = obj.Value.FromRiakString();
            json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"1978-12-05T00:00:00Z\",\"Email\":\"[email protected]\"}");

            var deserialisedPerson = obj.GetObject<Person>();
            deserialisedPerson.ShouldEqual(testPerson);
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:31,代码来源:RiakObjectConversionTests.cs


示例6: AsyncDeleteIsSuccessful

        public void AsyncDeleteIsSuccessful()
        {
            var riakObject = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var riakObjectId = riakObject.ToRiakObjectId();

            var putResult = Client.Put(riakObject);
            putResult.IsSuccess.ShouldBeTrue();

            RiakResult theResult = null;
            var resetEvent = new AutoResetEvent(false);

            Client.Async.Delete(riakObjectId, result =>
                                            {
                                                theResult = result;
                                                resetEvent.Set();
                                            });
            resetEvent.WaitOne();

            theResult.IsSuccess.ShouldBeTrue();

            var getResult = Client.Get(riakObjectId);
            getResult.IsSuccess.ShouldBeFalse();
            getResult.ResultCode.ShouldEqual(ResultCode.NotFound);
            getResult.Value.ShouldBeNull();
        }
开发者ID:tiagomargalho,项目名称:CorrugatedIron,代码行数:25,代码来源:RiakClientTests.cs


示例7: AsyncDeleteMultipleIsSuccessful

        public void AsyncDeleteMultipleIsSuccessful()
        {
            var one = new RiakObject(TestBucket, "one", TestJson, RiakConstants.ContentTypes.ApplicationJson);
            var two = new RiakObject(TestBucket, "two", TestJson, RiakConstants.ContentTypes.ApplicationJson);

            Client.Put(one);
            Client.Put(two);

            var oneObjectId = one.ToRiakObjectId();
            var twoObjectId = two.ToRiakObjectId();

            var list = new List<RiakObjectId> { oneObjectId, twoObjectId };

            var results = Client.Async.Delete(list).Result;

            foreach (var riakResult in results)
            {
                riakResult.IsSuccess.ShouldBeTrue(riakResult.ErrorMessage);
            }

            var oneResult = Client.Get(oneObjectId);
            oneResult.IsSuccess.ShouldBeFalse();
            oneResult.ResultCode.ShouldEqual(ResultCode.NotFound);
            oneResult.Value.ShouldBeNull();

            var twoResult = Client.Get(twoObjectId);
            twoResult.IsSuccess.ShouldBeFalse();
            twoResult.ResultCode.ShouldEqual(ResultCode.NotFound);
            twoResult.Value.ShouldBeNull();
        }
开发者ID:TWith2Sugars,项目名称:CorrugatedIron,代码行数:30,代码来源:RiakClientTests.cs


示例8: AllKeysReturnsListOfKeys

        public void AllKeysReturnsListOfKeys()
        {
            var bucket = Bucket + "_" + Guid.NewGuid().ToString();
            var originalKeys = new List<string>();

            for (var i = 0; i < 10; i++)
            {
                var o = new RiakObject(bucket, Guid.NewGuid().ToString(), "{ value: \"this is an object\" }");
                originalKeys.Add(o.Key);

                Client.Put(o);
            }

            var mr = new RiakMapReduceQuery()
                .Inputs(RiakIndex.AllKeys(bucket));

            var result = Client.MapReduce(mr);
            var keys = result.Value.PhaseResults.SelectMany(x => x.GetObjectIds()).ToList();

            result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
            keys.Count.ShouldEqual(10);

            foreach (var key in keys)
            {
                key.Bucket.ShouldNotBeNullOrEmpty();
                key.Key.ShouldNotBeNullOrEmpty();
                originalKeys.Contains(key.Key).ShouldBeTrue();
            }
        }
开发者ID:TWith2Sugars,项目名称:CorrugatedIron,代码行数:29,代码来源:RiakIndexTests.cs


示例9: CreatingBucketInSpecificBucketType

 public void CreatingBucketInSpecificBucketType()
 {
     id = new RiakObjectId("no_siblings", "sensitive_user_data", "user19735");
     var obj = new RiakObject(id, "{\"name\":\"Bob\"}");
     var rslt = client.Put(obj);
     CheckResult(rslt);
 }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:7,代码来源:BucketTypes.cs


示例10: CreateLinkedObjects

        protected void CreateLinkedObjects(string bucketName)
        {
            var oj = new RiakObject(bucketName, OJ, new Person() { Name = "oj" });
            var jeremiah = new RiakObject(bucketName, Jeremiah, new Person() { Name = "jeremiah" });
            var brent = new RiakObject(bucketName, Brent, new Person() { Name = "brent" });
            var rob = new RiakObject(bucketName, Rob, new Person() { Name = "rob" });

            oj.ContentType = RiakConstants.ContentTypes.ApplicationJson;
            jeremiah.ContentType = RiakConstants.ContentTypes.ApplicationJson;
            brent.ContentType = RiakConstants.ContentTypes.ApplicationJson;
            rob.ContentType = RiakConstants.ContentTypes.ApplicationJson;

#pragma warning disable 618
            oj.LinkTo(jeremiah, "friends");
            oj.LinkTo(jeremiah, "coworkers");

            jeremiah.LinkTo(oj, "friends");
            jeremiah.LinkTo(oj, "coworkers");
            jeremiah.LinkTo(oj, "ozzies");
            jeremiah.LinkTo(brent, "friends");
            jeremiah.LinkTo(brent, "coworkers");
            jeremiah.LinkTo(rob, "ozzies");

            brent.LinkTo(jeremiah, "coworkers");
            brent.LinkTo(jeremiah, "friends");
#pragma warning restore 618
            Client.Put(new[] { oj, jeremiah, brent, rob });
        }
开发者ID:basho,项目名称:riak-dotnet-client,代码行数:28,代码来源:RiakObjectTests.cs


示例11: StoreData

        private static void StoreData()
        {
            Console.WriteLine("[ChaosMonkeyApp] store thread starting");
            IRiakClient client = cluster.CreateClient();
            try
            {
                while (true)
                {
                    var id = new RiakObjectId("chaos-monkey", key.ToString());
                    var obj = new RiakObject(id, Guid.NewGuid().ToString());
                    obj.ContentEncoding = RiakConstants.CharSets.Utf8;
                    obj.ContentType = RiakConstants.ContentTypes.TextPlain;

                    var rslt = client.Put(obj);
                    if (rslt.IsSuccess)
                    {
                        Console.WriteLine("[ChaosMonkeyApp] stored key: {0}", key);
                    }
                    else
                    {
                        Console.WriteLine("[ChaosMonkeyApp] error storing key {0}, {1}", key, rslt.ErrorMessage);
                    }

                    ++key;
                    Thread.Sleep(storeDataInterval);
                    ct.ThrowIfCancellationRequested();
                }
            }
            finally
            {
                Console.WriteLine("[ChaosMonkeyApp] store thread stopping");
            }
        }
开发者ID:basho,项目名称:riak-dotnet-client,代码行数:33,代码来源:Program.cs


示例12: TestKVOperations

        public void TestKVOperations()
        {
            const string key = "bucket_type_test_key";
            var id = new RiakObjectId(TestBucketType, TestBucket, key);
            var obj = new RiakObject(id, Value);

            // put
            var putResult = Client.Put(obj, new RiakPutOptions().SetReturnBody(true).SetDw(3));
            putResult.IsSuccess.ShouldBeTrue();
            putResult.Value.BucketType.ShouldEqual(TestBucketType);

            // get
            var getResult = Client.Get(id);
            getResult.IsSuccess.ShouldBeTrue();
            getResult.Value.BucketType.ShouldEqual(TestBucketType);

            // delete
            var deleteResult = Client.Delete(id, new RiakDeleteOptions().SetDw(3));
            deleteResult.IsSuccess.ShouldBeTrue();

            // multiget
            var ids = new List<RiakObjectId>();
            for (int i = 0; i < 3; i++)
            {
                obj = new RiakObject(new RiakObjectId(TestBucketType, TestBucket, key + i), Value);
                Client.Put(obj, new RiakPutOptions().SetReturnBody(true).SetDw(3));
                ids.Add(obj.ToRiakObjectId());
            }

            var multiGetResult = Client.Get(ids).ToList();
            multiGetResult.All(r => r.IsSuccess).ShouldBeTrue();
            multiGetResult.All(r => r.Value.BucketType == TestBucketType).ShouldBeTrue();
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:33,代码来源:BucketTypeTests.cs


示例13: SettingLegacySearchOnRiakBucketMakesBucketSearchable

        public void SettingLegacySearchOnRiakBucketMakesBucketSearchable()
        {
            var bucket = Guid.NewGuid().ToString();
            var key = Guid.NewGuid().ToString();
            var props = Client.GetBucketProperties(bucket).Value;
            props.SetLegacySearch(true);

            var setResult = Client.SetBucketProperties(bucket, props);
            setResult.IsSuccess.ShouldBeTrue(setResult.ErrorMessage);

            var obj = new RiakObject(bucket, key, new { name = "OJ", age = 34 });
            var putResult = Client.Put(obj);
            putResult.IsSuccess.ShouldBeTrue(putResult.ErrorMessage);

            var q = new RiakFluentSearch(bucket, "name")
                .Search("OJ")
                .And("age", "34")
                .Build();

            var search = new RiakSearchRequest
            {
                Query = q
            };

            var searchResult = Client.Search(search);
            searchResult.IsSuccess.ShouldBeTrue(searchResult.ErrorMessage);
            searchResult.Value.NumFound.ShouldEqual(1u);
            searchResult.Value.Documents[0].Fields.Count.ShouldEqual(3);
            searchResult.Value.Documents[0].Fields.First(x => x.Key == "id").Value.ShouldEqual(key);
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:30,代码来源:BucketPropertyTests.cs


示例14: ToRiakObjectIdProducesAValidRiakObjectId

        public void ToRiakObjectIdProducesAValidRiakObjectId()
        {
            var riakObject = new RiakObject(Bucket, Key, "value");
            var riakObjectId = riakObject.ToRiakObjectId();

            riakObjectId.Bucket.ShouldEqual(Bucket);
            riakObjectId.Key.ShouldEqual(Key);
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:8,代码来源:RiakObjectTests.cs


示例15: CreatingBucketInSpecificBucketTypeExampleTwo

 public void CreatingBucketInSpecificBucketTypeExampleTwo()
 {
     id = new RiakObjectId("no_siblings", "old_memes", "all_your_base");
     var obj = new RiakObject(id, "all your base are belong to us",
         RiakConstants.ContentTypes.TextPlain);
     var rslt = client.Put(obj);
     CheckResult(rslt);
 }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:8,代码来源:BucketTypes.cs


示例16: PutCoach

        private RiakObjectId PutCoach(string team, string coach)
        {
            var id = new RiakObjectId("siblings", "coaches", team);
            var obj = new RiakObject(id, coach,
                RiakConstants.ContentTypes.TextPlain);
            var rslt = client.Put(obj);
            CheckResult(rslt);

            return id;
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:10,代码来源:Updates.cs


示例17: WritingLargeObjectIsSuccessful

 public void WritingLargeObjectIsSuccessful()
 {
     var text = Enumerable.Range(0, 2000000)
                          .Aggregate(new StringBuilder(),
                                     (sb, i) => sb.Append(i.ToString()))
                          .ToString();
     var riakObject = new RiakObject(TestBucket, "large", text, RiakConstants.ContentTypes.TextPlain);
     var result = Client.Put(riakObject);
     result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
 }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:10,代码来源:RiakClientTests.cs


示例18: Putting_A_Value_To_A_Write_Once_Bucket_Works

        public void Putting_A_Value_To_A_Write_Once_Bucket_Works()
        {
            string key = Guid.NewGuid().ToString();
            string value = "test value";

            var id = new RiakObjectId(BucketType, Bucket, key);
            var obj = new RiakObject(id, value, RiakConstants.ContentTypes.TextPlain);

            RiakResult<RiakObject> rslt = client.Put(obj);
            Assert.True(rslt.IsSuccess, rslt.ErrorMessage);
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:11,代码来源:GitHub_277.cs


示例19: RiakSessionItem

        public RiakSessionItem(RiakObject riakObject)
        {
            SessionStoreItems = riakObject.Value.FromRiakString();
            Created = DateTime.Parse(riakObject.UserMetaData["X-Riak-Meta-Created"]);
            Expires = DateTime.Parse(riakObject.UserMetaData["X-Riak-Meta-Expires"]);
            LockDate = DateTime.Parse(riakObject.UserMetaData["X-Riak-Meta-LockDate"]);
            LockId = int.Parse(riakObject.UserMetaData["X-Riak-Meta-LockId"]);
            Locked = bool.Parse(riakObject.UserMetaData["X-Riak-Meta-Locked"]);
            Flags = int.Parse(riakObject.UserMetaData["X-Riak-Meta-Flags"]);

            _timeout = (Expires - Created).Minutes;
        }
开发者ID:peschkaj,项目名称:CorrugatedIron.Samples,代码行数:12,代码来源:RiakSessionItem.cs


示例20: LotsOfConcurrentMapRedRequestsShouldWork

        public void LotsOfConcurrentMapRedRequestsShouldWork()
        {
            var keys = new List<string>();

            for (var i = 1; i < 11; i++)
            {
                var key = "key" + i;
                var doc = new RiakObject(MapReduceBucket, key, new { value = i });
                keys.Add(key);

                var result = Client.Put(doc, new RiakPutOptions { ReturnBody = true });
                result.ShouldNotBeNull();
            }

            var input = new RiakBucketKeyInput();
            keys.ForEach(k => input.Add(MapReduceBucket, k));

            var query = new RiakMapReduceQuery()
                .Inputs(input)
                .MapJs(m => m.Source(@"function(o){return[1];}"))
                .ReduceJs(r => r.Name(@"Riak.reduceSum").Keep(true));
            query.Compile();

            var results = new List<RiakMapReduceResult>[ThreadCount];
            var watch = Stopwatch.StartNew();
            Parallel.For(0, ThreadCount, i =>
                {
                    results[i] = DoMapRed(query);
                });
            watch.Stop();
            var executionTime = watch.Elapsed;

            var failures = 0;
            foreach (var r in results.SelectMany(l => l))
            {
                if (r != null)
                {
                    var resultValue = JsonConvert.DeserializeObject<int[]>(r.PhaseResults.ElementAt(1).Values.First().FromRiakString())[0];
                    resultValue.ShouldEqual(10);
                    //r.Value.PhaseResults.ElementAt(1).GetObject<int[]>()[0].ShouldEqual(10);
                }
                else
                {
                    // the only acceptable result is that it ran out of retries when
                    // talking to the cluster (trying to get a connection)
                    //r.ResultCode.ShouldEqual(ResultCode.NoRetries);
                    ++failures;
                }
            }

            Console.WriteLine("Total of {0} out of {1} failed to execute due to connection contention. Execution time = {2} milliseconds, for an average of {3} milliseconds", failures, ThreadCount * ActionCount, executionTime.TotalMilliseconds, (executionTime.TotalMilliseconds/(ThreadCount * ActionCount)));
        }
开发者ID:taliesins,项目名称:CorrugatedIron,代码行数:52,代码来源:LoadTests.cs



注:本文中的RiakObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Ribbon类代码示例发布时间:2022-05-24
下一篇:
C# RhinoDoc类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap