Ejemplo n.º 1
0
        public void TestMethod4()
        {
            var source = @"
 [
  [""Jack Smith"",""22.33.44.55:6666""],
  [""John Doe"",""22.33.44.11:6666""]
  ]			
			
			"            ;

            var a = new List <Info>();

            JSONDocument.ParseMatrix(source,
                                     delegate
            {
                var n = new Info();

                a.Add(n);

                return(new JSONDocument.ParseArguments[]
                {
                    (JSONDocument.StringAction)(Name => n.Name = Name),
                    (JSONDocument.StringAction)(Target => n.Target = Target)
                });
            }
                                     );

            foreach (var k in a)
            {
                Console.WriteLine(new { k.Name, k.Target });
            }

            // talk about dynamic contexts... :)
            Console.WriteLine(
                JSONDocument.ToString(
                    delegate
            {
                var i = -1;

                return(delegate
                {
                    i++;

                    if (i < a.Count)
                    {
                        var c = a[i];

                        return new[] { c.Name, c.Target };
                    }

                    return null;
                });
            }
                    )
                );
        }
Ejemplo n.º 2
0
            public static string ToString(Info2[] a)
            {
                return(JSONDocument.ToString(
                           delegate
                {
                    var i = -1;

                    return delegate
                    {
                        i++;

                        if (i < a.Length)
                        {
                            var c = a[i];

                            return new[] { c.Name, c.Target };
                        }

                        return null;
                    };
                }
                           ));
            }
Ejemplo n.º 3
0
        public void Print(System.IO.TextWriter output)
        {
            output.Write("QueryCriteria:{");
            output.Write("Projections=[");
            for (int i = 0; i < _projections.Count; i++)
            {
                _projections[i].Print(output);
                if (i != _projections.Count - 1)
                {
                    output.Write(",");
                }
            }
            output.Write("]");
            output.Write(",Aggregations=[");
            if (_aggregations != null)
            {
                for (int i = 0; i < _aggregations.Count; i++)
                {
                    _aggregations[i].Print(output);
                    if (i != _aggregations.Count - 1)
                    {
                        output.Write(",");
                    }
                }
            }
            else
            {
                output.Write("null");
            }
            output.Write("]");

            output.Write(",GroupByField=");
            if (_groupByField != null)
            {
                _groupByField.Print(output);
            }
            else
            {
                output.Write("null");
            }
            output.Write(",OrderByField=");
            if (_orderByField != null)
            {
                _orderByField.Print(output);
            }
            else
            {
                output.Write("null");
            }

            output.Write(",DistinctField=");
            if (_distinctField != null)
            {
                _distinctField.Print(output);
            }
            else
            {
                output.Write("null");
            }

            output.Write(",Store=");
            if (_store != null)
            {
                _store.Print(output);
            }
            else
            {
                output.Write("null");
            }
            output.Write(",SubstituteStore=");
            if (_substituteStore != null)
            {
                _substituteStore.Print(output);
            }
            else
            {
                output.Write("null");
            }

            output.Write(",Update=");
            if (_documentUpdate != null)
            {
                _documentUpdate.Print(output);
            }
            else
            {
                output.Write("null");
            }
            output.Write(",NewDocuemnt=");
            output.Write(newDocument != null ? newDocument.ToString() : "null");
            output.Write(",UpdateOption=" + _updateOption);
            output.Write(",SortResult=" + sortResult);
            output.Write(",QueryID=" + queryId);
            output.Write("}");
        }
Ejemplo n.º 4
0
        public void GetNextChunk(string requestUri, string readerId, int lastChunkId)
        {
            //Create Web Request
            WebRequest request = WebRequest.Create(requestUri);

            //Set Request Method to POST. POST is used for GetChunk also.
            request.Method = "POST";

            //Information Required to GetNextChunk.
            var jsonDocument = new JSONDocument {
                { "ReaderId", readerId }, { "LastChunkId", lastChunkId }
            };
            string postData = jsonDocument.ToString();

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            //Content-Type must be set to application/getchunk.
            request.ContentType   = "application/getchunk";
            request.ContentLength = byteArray.Length;

            //Get Request stream and write data.. Data written in the stream is a body of Request.
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response;

            try
            {
                //Send request and get HTTP response.
                response = request.GetResponse();
            }
            catch (WebException exception)
            {
                PrintErrorResponse(exception);
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }

            dataStream = response.GetResponseStream();
            if (dataStream != null)
            {
                var    reader             = new StreamReader(dataStream);
                string responseFromServer = reader.ReadToEnd();
                var    responseDocument   = JSONDocument.Parse(responseFromServer);

                if (responseDocument != null)
                {
                    string temp      = responseDocument.GetString("value");              //Query Result Data in JSON Array
                    var    customers = JsonConvert.DeserializeObject <Customer[]>(temp); //Deserialize JSON Array to Customer Array.
                    _numberOfRecords += customers.Length;
                    //Perform Operations
                }

                reader.Close();
            }
            if (dataStream != null)
            {
                dataStream.Close();
            }

            //Retrieve Query Result Set Information From Response Header.
            //This information is required to GetNextChunk.
            readerId = response.Headers.Get("ReaderId");
            string isLastChunk = response.Headers.Get("IsLastChunk");
            string chunkId     = response.Headers.Get("ChunkId");

            response.Close();

            if (isLastChunk.Equals("False", StringComparison.OrdinalIgnoreCase)) //Check if this is a last chunk of data.
            {
                //If IsLastChunk is false then GetNextChunk of Data.
                //Else Complete Data is retrieved.
                GetNextChunk(requestUri, readerId, Convert.ToInt32(chunkId));
            }
        }