当前位置: 首页>>代码示例>>C#>>正文


C# RiakObject类代码示例

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


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


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