Exemplo n.º 1
0
        public void SaveMyDto(Dto dto)
        {
            CellSet cellSet = new CellSet();
            CellSet.Row cellSetRow = new CellSet.Row { key = Encoding.UTF8.GetBytes(_sampleRowKey) };
            cellSet.rows.Add(cellSetRow);

            Cell value1 = new Cell { column = Encoding.UTF8.GetBytes("CF1:field1"), data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto.Field1)) };
            Cell value2 = new Cell { column = Encoding.UTF8.GetBytes("CF1:field2"), data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto.Field2)) };
            Cell value3 = new Cell { column = Encoding.UTF8.GetBytes("CF1:field3"), data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto.Field3)) };
            Cell value4 = new Cell { column = Encoding.UTF8.GetBytes("CF1:field4"), data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto.Field4)) };
            Cell value5 = new Cell { column = Encoding.UTF8.GetBytes("CF1:field5"), data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto.Field5)) };
            //     Cell value6 = new Cell { column = Encoding.UTF8.GetBytes("CF1:NestedData"), data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dto.NestedData))};

            byte[] nestedDataBlob;

            using (var memoryStream = new MemoryStream())
            {
                using (var writer = new BsonWriter(memoryStream))
                {
                    _serializer.Serialize(writer, dto.NestedData);
                    nestedDataBlob = memoryStream.ToArray();
                }
            }

            Cell value6 = new Cell { column = Encoding.UTF8.GetBytes("CF1:NestedData"), data = nestedDataBlob };
            cellSetRow.values.AddRange(new List<Cell>() { value1, value2, value3, value4, value5, value6 });
            _client.StoreCells(_sampleTableName, cellSet);
        }
Exemplo n.º 2
0
        private Dto BuildUpDto()
        {
            var myDto = new Dto();
            myDto.Field1 = JsonConvert.DeserializeObject<string>(Encoding.UTF8.GetString(_columnNameMapping["CF1:field1"]));
            myDto.Field2 = JsonConvert.DeserializeObject<string>(Encoding.UTF8.GetString(_columnNameMapping["CF1:field2"]));
            myDto.Field3 = JsonConvert.DeserializeObject<string>(Encoding.UTF8.GetString(_columnNameMapping["CF1:field3"]));
            myDto.Field4 = JsonConvert.DeserializeObject<string>(Encoding.UTF8.GetString(_columnNameMapping["CF1:field4"]));
            myDto.Field5 = JsonConvert.DeserializeObject<string>(Encoding.UTF8.GetString(_columnNameMapping["CF1:field5"]));
            //myDto.NestedData=JsonConvert.DeserializeObject<NestedDto>(Encoding.UTF8.GetString(_columnNameMapping["CF1:NestedData"]));

            var ms = new MemoryStream(_columnNameMapping["CF1:NestedData"]);
            using (var reader = new BsonReader(ms))
            {
                myDto.NestedData = _serializer.Deserialize<NestedDto>(reader);

            }

            return myDto;
       
        }