private static void WriteJsonCoordinates(JsonWriter writer, IEnumerable<Coordinate> coordinates, JsonSerializer serializer)
 {
     writer.WriteStartArray();
     foreach (Coordinate coordinate in coordinates)
         WriteJsonCoordinate(writer, coordinate, serializer);
     writer.WriteEndArray();
 }
 private static void WriteJsonCoordinatesEnumerable2(JsonWriter writer, List<List<Coordinate[]>> coordinates, JsonSerializer serializer)
 {
     writer.WriteStartArray();
     foreach (List<Coordinate[]> coordinate in coordinates)
         WriteJsonCoordinatesEnumerable(writer, coordinate, serializer);
     writer.WriteEndArray();
 }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var collection = (NameValueCollection)value;

			writer.WriteStartObject();

			foreach (var key in collection.AllKeys)
			{
				writer.WritePropertyName(key);

				var values = collection.GetValues(key);
				if (values == null)
				{
					writer.WriteNull();
					continue;
				}
				if (values.Length == 1)
				{
					writer.WriteValue(values[0]);
				}
				else
				{
					writer.WriteStartArray();

					foreach (var item in values)
					{
						writer.WriteValue(item);
					}

					writer.WriteEndArray();
				}

			}
			writer.WriteEndObject();
		}
 private void WriteArray(JsonWriter writer, object value) {
     writer.WriteStartArray();
     var array = value as IEnumerable<object>;
     foreach (var o in array) {
         this.WriteValue(writer, o);
     }
     writer.WriteEndArray();
 }
 /// <summary>
 /// Writes the JSON representation of the object.
 /// </summary>
 /// <remarks>This will enumerate the Linq-To-Entities query before serializing it to json array</remarks>
 /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
 /// <param name="value">The value.</param>
 /// <param name="serializer">The calling serializer.</param>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var enumerable = (IEnumerable) value;
     writer.WriteStartArray();
     foreach(var item in enumerable)
         writer.WriteValue(item);
     writer.WriteEndArray();
 }
        private static void WriteJsonCoordinate(JsonWriter writer, Coordinate coordinate, JsonSerializer serializer)
        {
            writer.WriteStartArray();

            writer.WriteValue(coordinate.X);
            writer.WriteValue(coordinate.Y);
            if (!Double.IsNaN(coordinate.Z))
                writer.WriteValue(coordinate.Z);
            
            writer.WriteEndArray();
        }
Beispiel #7
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Envelope envelope = value as Envelope;
            if (envelope == null) return;

            writer.WritePropertyName("bbox");
            writer.WriteStartArray();
            writer.WriteValue(envelope.MinX);
            writer.WriteValue(envelope.MinY);
            writer.WriteValue(envelope.MaxX);
            writer.WriteValue(envelope.MaxY);
            writer.WriteEndArray();
        }
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                writer.WriteStartArray();
                foreach (object item in (IEnumerable) value)
                {
                    writer.WriteStartObject();

                    writer.WritePropertyName("CrlType");
                    writer.WriteValue(item.GetType().AssemblyQualifiedName);

                    writer.WritePropertyName("Value");

                    serializer.Serialize(writer, item);

                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }
Beispiel #9
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var coordinate = value as Coordinate;

            if (coordinate == null)
            {
                writer.WriteNull();
                return;
            }

            writer.WriteStartArray();
            writer.WriteValue(coordinate.Longitude);
            writer.WriteValue(coordinate.Latitude);
            if (coordinate.Is3D || coordinate.IsMeasured)
                writer.WriteValue(((Is3D)coordinate).Elevation);
            if (coordinate.IsMeasured)
                writer.WriteValue(((IsMeasured)coordinate).Measure);
            writer.WriteEndArray();
        }
 private static void WriteItemsFromDb(JsonWriter jsonWriter, string name, Func<int, RavenJArray> getBatchOfItems)
 {
     jsonWriter.WritePropertyName(name);
     jsonWriter.WriteStartArray();
     var totalCount = 0;
     while (true)
     {
         var array = getBatchOfItems(totalCount);
         if (array.Length == 0)
         {
             break;
         }
         totalCount += array.Length;
         foreach (var item in array)
         {
             item.WriteTo(jsonWriter);
         }
     }
     jsonWriter.WriteEndArray();
 }
		/// <summary>
		/// Write a rank of an array in Json format
		/// </summary>
		/// <param name="writer">JsonWriter in use</param>
		/// <param name="serializer">JsonSerializer in use</param>
		/// <param name="array">Array to be written</param>
		/// <param name="currentRank">Current rank "depth"</param>
		/// <param name="assignFromIndexList">List of indexes currently being used to read from the array</param>
		private void WriteRank(JsonWriter writer, JsonSerializer serializer, Array array, int currentRank, int[] assignFromIndexList)
		{
			writer.WriteStartArray();

			var lb = array.GetLowerBound(currentRank);
			var ub = array.GetUpperBound(currentRank);

			// Create a new indices list (one bigger than passed in) and fill with existing values
			var myAssignFromIndex = assignFromIndexList.GetUpperBound(0) + 1;
			var myAssignFromIndexList = new int[myAssignFromIndex + 1];
			Array.Copy(assignFromIndexList, myAssignFromIndexList, assignFromIndexList.Length);

			for (var i = lb; i <= ub; i++)
			{
				// set current index of this current rank
				myAssignFromIndexList[myAssignFromIndex] = i;

				if (currentRank < array.Rank - 1) // There are still more ranks, process them
					WriteRank(writer, serializer, array, currentRank + 1, myAssignFromIndexList);
				else // This is the "bottom" rank, write out values
					serializer.Serialize(writer, array.GetValue(myAssignFromIndexList));
			}

			writer.WriteEndArray();
		}
Beispiel #12
0
 private static void WriteGeometries(JsonWriter writer, IEnumerable<IGeometry> geometries, JsonSerializer serializer)
 {
     writer.WriteStartArray();
     foreach (IGeometry geometry in geometries)
         serializer.Serialize(writer, geometry);
     writer.WriteEndArray();
 }
		public bool TryWriteGeo(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var route = value as Route;
			if (route != null)
			{
				writer.WriteStartObject();

				writer.WritePropertyName("__geo");
				writer.WriteStartObject();
				writer.WritePropertyName("type");
				writer.WriteValue("Route");
				if (route.Metadata.Count > 0)
				{
					writer.WritePropertyName("metadata");
					serializer.Serialize(writer, route.Metadata);
				}
				writer.WriteEndObject();

				writer.WritePropertyName("type");
				writer.WriteValue(Enum.GetName(typeof(ObjectType), ObjectType.LineString));

				writer.WritePropertyName("coordinates");
				WriteJsonCoordinates(writer, _shapeConverter.FromLineString(route.ToLineString()));

				writer.WriteEndObject();
				return true;
			}

			var track = value as Track;
			if (track != null)
			{
				writer.WriteStartObject();

				writer.WritePropertyName("__geo");
				writer.WriteStartObject();
				writer.WritePropertyName("type");
				writer.WriteValue("Track");
				if (track.Metadata.Count > 0)
				{
					writer.WritePropertyName("metadata");
					serializer.Serialize(writer, track.Metadata);
				}
				writer.WritePropertyName("times");
				writer.WriteStartArray();

				foreach (var segment in track.Segments)
				{
					writer.WriteStartArray();
					foreach (var fix in segment.Fixes)
						writer.WriteValue(fix.TimeUtc);
					writer.WriteEndArray();
				}

				writer.WriteEndArray();
				writer.WriteEndObject();

				writer.WritePropertyName("type");
				writer.WriteValue(Enum.GetName(typeof(ObjectType), ObjectType.LineString));

				writer.WritePropertyName("coordinates");
				WriteJsonCoordinates(writer, _shapeConverter.FromLineString(track.ToLineString()));

				writer.WriteEndObject();
				return true;
			}
			return false;
		}
		public bool TryWriteGeometryCollection(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if (!_shapeConverter.CanConvert(ObjectType.GeometryCollection))
				return false;

			ObjectType geomType = _shapeConverter.GetObjectType(value);
			if (geomType != ObjectType.GeometryCollection)
				return false;

			writer.WriteStartObject();
			writer.WritePropertyName("type");
			writer.WriteValue(Enum.GetName(typeof(ObjectType), geomType));

			writer.WritePropertyName("geometries");
			writer.WriteStartArray();
			foreach (var geometry in _shapeConverter.FromGeometryCollection(value))
				serializer.Serialize(writer, geometry);
			writer.WriteEndArray();

			writer.WriteEndObject();
			return true;
		}
		protected static void WriteJsonCoordinatesEnumerable2(JsonWriter writer, CoordinateInfo[][][] coordinates)
		{
			writer.WriteStartArray();
			foreach (var coordinate in coordinates)
				WriteJsonCoordinatesEnumerable(writer, coordinate);
			writer.WriteEndArray();
		}
		private static void WriteJsonCoordinate(JsonWriter writer, CoordinateInfo coordinate)
		{
			writer.WriteStartArray();

			writer.WriteValue(coordinate.X);
			writer.WriteValue(coordinate.Y);

			if (coordinate.Z.HasValue)
				writer.WriteValue(coordinate.Z.Value);

			if (coordinate.Z.HasValue && coordinate.M.HasValue)
				writer.WriteValue(coordinate.M.Value);

			writer.WriteEndArray();
		}