Exemplo n.º 1
0
        string ExecuteReader(IDbCommand command, IQuery query,
                             string preferred_json_collection)
        {
            IDataReader     reader          = command.ExecuteReader();
            IJsonCollection json_collection =
                json_collection_factory_
                .CreateJsonCollection(preferred_json_collection, reader);

            return(Serialize(json_collection, json_collection.Count));
        }
Exemplo n.º 2
0
        string ExecuteNonQuery(IDbCommand command, IQuery query,
                               string preferred_json_collection)
        {
            int             no_of_affected_records = command.ExecuteNonQuery();
            IJsonCollection json_collection        =
                json_collection_factory_
                .CreateJsonCollection(preferred_json_collection);

            return(Serialize(json_collection, no_of_affected_records));
        }
Exemplo n.º 3
0
        public static T Convert <T>(IJsonCollection obj)
        {
            /* TODO: can this be done more efficiently? */
            var serializer = new DataContractJsonSerializer(typeof(T));
            var textData   = obj.ToString();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(textData))) {
                return((T)serializer.ReadObject(stream));
            }
        }
Exemplo n.º 4
0
        string Serialize(IJsonCollection json_collection, int no_of_affected_rows)
        {
            JsonStringBuilder builder = new JsonStringBuilder()
                                        .WriteBeginObject()
                                        .WriteMember(Strings.kResponseAffectedRowsMemberName,
                                                     no_of_affected_rows)
                                        .WriteMemberName(Strings.kResponseDataMemberName)
                                        .WriteUnquotedString(json_collection.AsJson())
                                        .WriteEndObject();

            return(builder.ToString());
        }
Exemplo n.º 5
0
        public void ShouldCreateTableCollection()
        {
            var reader  = Mock.Create <IDataReader>();
            var factory = new JsonCollectionFactory();

            IJsonCollection table =
                factory.CreateJsonCollection(JsonCollectionFactory.kJsonTableCollection);

            Assert.That(table, Is.InstanceOf <JsonTable>());

            table = factory
                    .CreateJsonCollection(JsonCollectionFactory.kJsonTableCollection, reader);
            Assert.That(table, Is.InstanceOf <JsonTable>());
        }
Exemplo n.º 6
0
 private string generateJson(IJsonCollection jsonData)
 {
     return("json=" + HttpUtility.UrlEncode(Json.Serialize(jsonData)));
 }
Exemplo n.º 7
0
 public static string Serialize(IJsonCollection obj)
 {
     serializer.SetInput(obj);
     return(serializer.Serialize());
 }
 string Serialize(IJsonCollection json_collection, int no_of_affected_rows) {
   JsonStringBuilder builder = new JsonStringBuilder()
     .WriteBeginObject()
     .WriteMember(Strings.kResponseAffectedRowsMemberName,
       no_of_affected_rows)
     .WriteMemberName(Strings.kResponseDataMemberName)
     .WriteUnquotedString(json_collection.AsJson())
     .WriteEndObject();
   return builder.ToString();
 }