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


C# RiakObject.SetObject方法代码示例

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


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

示例1: 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

示例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: JsonConversionTimerTest

        public void JsonConversionTimerTest()
        {
            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");

            var sw = new Stopwatch();
            sw.Start();
            const int iterations = 1000000;

            for (var i = 0; i < iterations; ++i)
            {
                obj.SetObject(testPerson);
            }
            sw.Stop();
            Console.WriteLine("Serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));

            sw.Reset();
            sw.Start();

            for (var i = 0; i < iterations; ++i)
            {
                var result = obj.GetObject<Person>();
            }
            sw.Stop();
            Console.WriteLine("De" +
                "serialisation took a total of {0} - {1} per iteration", sw.Elapsed, new TimeSpan(sw.ElapsedTicks / iterations));
        }
开发者ID:remotex,项目名称:CorrugatedIron,代码行数:44,代码来源:RiakObjectConversionTests.cs

示例4: SavedObjectsShouldBeIdentical

        public void SavedObjectsShouldBeIdentical()
        {
            // create a proto-contract class (https://code.google.com/p/protobuf-net/wiki/GettingStarted)
            //var testPerson = new ProtoBufPerson()
            //{
            //    Id = 42,
            //    Name = "alex",
            //    Address = new Address()
            //    {
            //        Line1 = "16 dusty road",
            //        Line2 = "santa fe, nm 87508"
            //    }
            //};
            const string bucketName = "test";
            var ojPerson = new Person() { Name = "oj", CurrentlyDrinking = "tea" };

            var oj = new RiakObject(bucketName, OJ) { ContentType = RiakConstants.ContentTypes.ProtocolBuffers };
            oj.SetObject(ojPerson);

            // Don't capture result to avoid compiler warning
            Client.Put(oj);

            var getResult = Client.Get(bucketName, OJ);
            var newPerson = getResult.Value.GetObject<Person>();

            ojPerson.Name.ShouldEqual(newPerson.Name);


            var testPerson = new ProtoBufPerson()
            {
                Id = 42,
                Name = "alex",
                Address = new Address()
                {
                    Line1 = "16 dusty road",
                    Line2 = "santa fe, nm 87508"
                }
            };

            var ro = new RiakObject(bucketName, testPerson.Id.ToString());
            ro.ContentType = RiakConstants.ContentTypes.ProtocolBuffers;
            ro.SetObject(testPerson);

            // Don't capture result to avoid compiler warning
            Client.Put(ro);

            var getResult2 = Client.Get(bucketName, testPerson.Id.ToString());
            var testPerson2 = getResult2.Value.GetObject<ProtoBufPerson>();

            testPerson.Id.ShouldEqual(testPerson2.Id);
            testPerson.Name.ShouldEqual(testPerson2.Name);
            testPerson.Address.Line1.ShouldEqual(testPerson2.Address.Line1);
            testPerson.Address.Line2.ShouldEqual(testPerson2.Address.Line2);
        }
开发者ID:basho,项目名称:riak-dotnet-client,代码行数:54,代码来源:RiakObjectTests.cs

示例5: LastModifiedShouldChangeAfterAPutRequest

        public void LastModifiedShouldChangeAfterAPutRequest()
        {
            var o = new RiakObject(TestBucket, "1234", new { value = 1234 });
            o = Client.Put(o).Value;

            var lm2 = o.LastModified;
            var lmu2 = o.LastModifiedUsec;

            Thread.Sleep(500);
            o.SetObject(new { value = 12345 });
            o = Client.Put(o).Value;

            var lm3 = o.LastModified;
            var lmu3 = o.LastModifiedUsec;

            lm2.ShouldNotEqual(lm3);
            lmu2.ShouldNotEqual(lmu3);

            Thread.Sleep(500);
            o.SetObject(new { value = 76543 });
            o = Client.Put(o, new RiakPutOptions { ReturnBody = false }).Value;

            var lm4 = o.LastModified;
            var lmu4 = o.LastModifiedUsec;

            lm2.ShouldNotEqual(lm4);
            lmu2.ShouldNotEqual(lmu4);
        }
开发者ID:corkupine,项目名称:CorrugatedIron,代码行数:28,代码来源:GeneralIntegrationTests.cs

示例6: CausalContext

        public void CausalContext()
        {
            id = new RiakObjectId("sports", "nba", "champion");
            var obj = new RiakObject(id, "Washington Generals",
                RiakConstants.ContentTypes.TextPlain);
            CheckResult(client.Put(obj));

            var rslt = client.Get(id);
            CheckResult(rslt);

            obj = rslt.Value;
            obj.SetObject("Harlem Globetrotters", RiakConstants.ContentTypes.TextPlain);
            rslt = client.Put(obj);
            CheckResult(rslt);

            Assert.IsTrue(EnumerableUtil.IsNullOrEmpty(rslt.Value.Siblings));
            Assert.AreEqual("Harlem Globetrotters", Encoding.UTF8.GetString(rslt.Value.Value));
        }
开发者ID:josephjeganathan,项目名称:riak-dotnet-client,代码行数:18,代码来源:Basics.cs


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