WriteEndArray() public method

Writes the end of an array.
public WriteEndArray ( ) : void
return void
Exemplo n.º 1
2
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var representation = value as Representation;
            if (representation != null)
                representation.RepopulateHyperMedia();

            var list = (IRepresentationList)value;

            writer.WriteStartObject();
            writer.WritePropertyName("_links");
            serializer.Serialize(writer, list.Links);

            writer.WritePropertyName("_embedded");
            writer.WriteStartObject();
            writer.WritePropertyName(list.Rel);
            writer.WriteStartArray();
            foreach (Representation halResource in list)
            {
                serializer.Serialize(writer, halResource);
            }

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

            var listType = list.GetType();
            var propertyInfos = typeof(RepresentationList<>).GetProperties().Select(p => p.Name);
            foreach (var property in listType.GetProperties().Where(p => !propertyInfos.Contains(p.Name)))
            {
                writer.WritePropertyName(property.Name.ToLower());
                serializer.Serialize(writer, property.GetValue(value, null));
            }

            writer.WriteEndObject();
        }
Exemplo n.º 2
0
        public void FormatJson(ref JsonWriter writer)
        {
            writer.WriteStartObject();

            writer.WritePropertyName("type");
            writer.WriteValue("table");

            writer.WritePropertyName("headers");
            writer.WriteStartArray();
            foreach(var header in this.headers.ToArray())
            {
                writer.WriteValue(header);
            }
            writer.WriteEndArray();

            writer.WritePropertyName("rows");
            writer.WriteStartArray();
            foreach (var row in this.rows.ToArray())
            {
                writer.WriteStartArray();

                foreach( var field in row)
                {
                    writer.WriteValue(field);
                }

                writer.WriteEndArray();
            }
            writer.WriteEndArray();

            writer.WriteEndObject();
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var marker = value as Indices;
			if (marker == null)
			{
				writer.WriteNull();
				return;
			}
			marker.Match(
				all =>
				{
					writer.WriteStartArray();
					writer.WriteValue("_all");
					writer.WriteEndArray();
				},
				many =>
				{
					var settings = serializer.GetConnectionSettings();
					writer.WriteStartArray();
					foreach (var m in many.Indices.Cast<IUrlParameter>())
						writer.WriteValue(m.GetString(settings));
					writer.WriteEndArray();
				}
			);
		}
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			BoolQuery term = (BoolQuery)value;
			if (term != null)
			{
				writer.WriteStartObject();
				writer.WritePropertyName("bool");
				writer.WriteStartObject();
				bool pre = false;
				if(term.MustQueries!=null&&term.MustQueries.Count>0)
				{
					writer.WritePropertyName("must");
					writer.WriteStartArray();
					foreach (var VARIABLE in term.MustQueries)
					{
						serializer.Serialize(writer, VARIABLE);
					}
					writer.WriteEndArray();
				}
				if (term.MustNotQueries != null&&term.MustNotQueries.Count>0)
				{
					writer.WritePropertyName("must_not");
					writer.WriteStartArray();
					foreach (var VARIABLE in term.MustNotQueries)
					{
						serializer.Serialize(writer, VARIABLE);
					}
					writer.WriteEndArray();
				}
				if (term.ShouldQueries !=null&& term.ShouldQueries.Count > 0)
				{
					writer.WritePropertyName("should");
					writer.WriteStartArray();
					foreach (var shouldQuery in term.ShouldQueries)
					{
						serializer.Serialize(writer,shouldQuery);
					}
					writer.WriteEndArray();
				}
				if (Math.Abs(term.Boost - 1.0) > 0)
				{
					writer.WritePropertyName("boost");
					writer.WriteValue(term.Boost);
				}
				if (term.DisableCoord)
				{
					writer.WritePropertyName("disable_coord");
					writer.WriteValue(term.DisableCoord);
				}
				if (term.MinimumNumberShouldMatch != 1)
				{
					writer.WritePropertyName("minimum_number_should_match");
					writer.WriteValue(term.MinimumNumberShouldMatch);
				}
				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var rt = (ResultTable)value;
            
            writer.WriteStartObject();

            writer.WritePropertyName("entityColumn");
            writer.WriteValue(rt.EntityColumn?.Name);

            writer.WritePropertyName("columns");
            serializer.Serialize(writer, rt.Columns.Select(c => c.Column.Token.FullKey()).ToList());

            writer.WritePropertyName("pagination");
            serializer.Serialize(writer, new PaginationTS(rt.Pagination));

            writer.WritePropertyName("totalElements");
            writer.WriteValue(rt.TotalElements);


            writer.WritePropertyName("rows");
            writer.WriteStartArray();
            foreach (var row in rt.Rows)
            {
                writer.WriteStartObject();
                if (rt.EntityColumn != null)
                {
                    writer.WritePropertyName("entity");
                    serializer.Serialize(writer, row.Entity);
                }

                writer.WritePropertyName("columns");
                writer.WriteStartArray();
                foreach (var column in rt.Columns)
                {
                    using (JsonSerializerExtensions.SetCurrentPropertyRoute(column.Column.Token.GetPropertyRoute()))
                    {
                        serializer.Serialize(writer, row[column]);
                    }
                }
                writer.WriteEndArray();


                writer.WriteEndObject();

            }
            writer.WriteEndArray();


            writer.WriteEndObject();
        }
Exemplo n.º 6
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var extent = (Extent)value;
     writer.WriteStartArray();
     writer.WriteStartArray();
     writer.WriteValue(extent.X1);
     writer.WriteValue(extent.Y1);
     writer.WriteEndArray();
     writer.WriteStartArray();
     writer.WriteValue(extent.X2);
     writer.WriteValue(extent.Y2);
     writer.WriteEndArray();
     writer.WriteEndArray();
 }
Exemplo n.º 7
0
        public override void WriteJson(
            JsonWriter writer, object value, JsonSerializer serializer)
        {
            var settings = new JsonWriterSettings
            {
                OutputMode = JsonOutputMode.Strict
            };


            var cursor = value as IEnumerable <BsonDocument>;

            if (cursor == null)
            {
                var document = value as BsonDocument;

                if (document != null)
                {
                    writer.WriteRawValue(document.ToJson(settings));
                }
            }
            else
            {
                writer.WriteStartArray();

                foreach (BsonDocument document in cursor)
                {
                    writer.WriteRawValue(document.ToJson(settings));
                }

                writer.WriteEndArray();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <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)
        {
            DataTable table = (DataTable)value;
            DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

            writer.WriteStartArray();

            foreach (DataRow row in table.Rows)
            {
                writer.WriteStartObject();
                foreach (DataColumn column in row.Table.Columns)
                {
                    object columnValue = row[column];

                    if (serializer.NullValueHandling == NullValueHandling.Ignore && (columnValue == null || columnValue == DBNull.Value))
                        continue;

                    writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(column.ColumnName) : column.ColumnName);
                    serializer.Serialize(writer, columnValue);
                }
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var states = (List<StateObject>)value;

            writer.WriteStartArray();

            foreach (var state in states)
            {
                if (state.ControlValue is List<DatabaseClass>)
                {
                    var scripts = (List<DatabaseClass>)state.ControlValue;

                    state.IsList = true;
                    var sList = new List<ScriptContainer>();

                    foreach (DatabaseClass s in scripts)
                    {
                        sList.Add(new ScriptContainer { TypeName = s.GetType().FullName, Value = s });
                    }

                    state.Value = sList;
                }
                else
                {
                    state.Value = state.ControlValue;
                }

                JObject.FromObject(state).WriteTo(writer);
            }

            writer.WriteEndArray();
        }
        public override void WriteJson(JsonWriter __writer, object __value, JsonSerializer __serializer)
        {
            var __对象 = (M接收事件)__value;
            __writer.WriteStartObject();
            __writer.WritePropertyName("对象名称");
            __writer.WriteValue(__对象.对象名称);
            __writer.WritePropertyName("事件名称");
            __writer.WriteValue(__对象.事件名称);
            __writer.WritePropertyName("实参列表");
            __writer.WriteStartArray();
            if (__对象.实参列表 != null)
            {
                foreach (var __kv in __对象.实参列表)
                {
                    __writer.WriteStartObject();
                    __writer.WritePropertyName("名称");
                    __writer.WriteValue(__kv.名称);
                    __writer.WritePropertyName("值");

                    if (__kv.值.TrimStart().StartsWith("{") || __kv.值.TrimStart().StartsWith("["))
                    {
                        __writer.WriteRawValue(__kv.值);
                    }
                    else
                    {
                        __writer.WriteValue(__kv.值);
                    }
                    __writer.WriteEndObject();
                }
            }
            __writer.WriteEndArray();
            __writer.WriteEndObject();
        }
Exemplo n.º 11
0
        private void ProcessObject(JsonWriter writer, object value)
        {
            Dictionary<string, object> valueAsDictionary = value as Dictionary<string, object>;
            object[] valueAsArray = value as object[];
            if (valueAsDictionary != null)
            {
                writer.WriteStartObject();
                foreach (string key in valueAsDictionary.Keys)
                {
                    writer.WritePropertyName(key);
                    ProcessObject(writer, valueAsDictionary[key]);
                }

                writer.WriteEndObject();
            }
            else if (valueAsArray != null)
            {
                writer.WriteStartArray();
                foreach (object item in valueAsArray)
                {
                    ProcessObject(writer, item);
                }

                writer.WriteEndArray();
            }
            else
            {
                writer.WriteValue(value);
            }
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			CustomFiltersScoreQuery term = (CustomFiltersScoreQuery)value;
			if (term != null)
			{
				writer.WriteStartObject();
				writer.WritePropertyName("custom_filters_score");
				writer.WriteStartObject();
				writer.WritePropertyName("query");
				serializer.Serialize(writer,term.Query);
				writer.WritePropertyName("filters");

				writer.WriteStartArray();
				foreach (var filter in term.Filters)
				{
					serializer.Serialize(writer,filter);
				}
				writer.WriteEndArray();

				writer.WritePropertyName("score_mode");
				writer.WriteValue(term.ScoreMode);

				writer.WritePropertyName("script");
				writer.WriteValue(term.Script);

				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
Exemplo n.º 13
0
        public override void WriteJson(JsonWriter writer, object value)
        {
            _lines = ((string)value).Split('\n');

            writer.WriteStartArray();

            // Format the first line to match ruby's way of writing stack trace lines.
            // This is needed because HopToad tries to parse that line to set the
            // "File" row.
            try
            {
                writer.WriteValue(formatFirstLine());

                // Leave some free space from the above custom/hacked line.
                writer.WriteValue(" ");
                writer.WriteValue("--");
                writer.WriteValue("--");
                writer.WriteValue(" ");
            }
            catch
            {
            }

            // Now write the actual Backtrace
            foreach (var line in _lines)
                writer.WriteValue(line);

            writer.WriteEndArray();
        }
Exemplo n.º 14
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var heartActivitiesIntraday = value as HeartActivitiesIntraday;

            //{
            writer.WriteStartObject();

            // "DatasetInterval" : "1"
            writer.WritePropertyName("DatasetInterval");
            writer.WriteValue(heartActivitiesIntraday.DatasetInterval);

            // "DatasetType" : "SecondsHeartrate"
            writer.WritePropertyName("DatasetType");
            writer.WriteValue(heartActivitiesIntraday.DatasetType);

            writer.WritePropertyName("Dataset");
            writer.WriteStartArray();
            foreach (var datasetInverval in heartActivitiesIntraday.Dataset)
            {
                // "Time" : "2008-09-22T14:01:54.9571247Z"
                writer.WritePropertyName("Time");
                writer.WriteValue(datasetInverval.Time.ToString("o"));

                // "Value": 1
                writer.WritePropertyName("Value");
                writer.WriteValue(datasetInverval.Value);

            }
            writer.WriteEndArray();
            
            //}
            writer.WriteEndObject();

        }
Exemplo n.º 15
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var ts = value as Timeseries;

            if(ts == null)
                throw new InvalidOperationException("Cannot serialize type {0}".FormatString(value.GetType()));

            writer.WriteStartArray();
            foreach(var kv in ts) {
                writer.WriteStartArray();
                writer.WriteValue(kv.Key.ToString("yyyy-MM-dd"));
                writer.WriteValue(kv.Value.Count);
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			DisjunctionMaxQuery term = (DisjunctionMaxQuery)value;
			if (term != null)
			{
				if (term.Queries == null || term.Queries.Count < 0)
				{
					throw new ArgumentException();
				}

				writer.WriteStartObject();
				writer.WritePropertyName("dis_max");
				writer.WriteStartObject();
				writer.WritePropertyName("tie_breaker");
				writer.WriteValue(term.TieBreaker);
				writer.WritePropertyName("boost");
				writer.WriteValue(term.Boost);
				writer.WritePropertyName("queries");
				writer.WriteStartArray();
				foreach (var query in term.Queries)
				{
					serializer.Serialize(writer, query);
				}
				writer.WriteEndArray();
				writer.WriteEndObject();
				writer.WriteEndObject();
			}
		}
Exemplo n.º 17
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var list = (HalResource)value;

            list.Links.Add(new Link
            {
                Rel = "self",
                Href = list.Href
            });

            writer.WriteStartObject();
            writer.WritePropertyName("_links");
            serializer.Serialize(writer, list.Links);

            writer.WritePropertyName("_embedded");
            writer.WriteStartObject();
            writer.WritePropertyName(list.Rel);
            writer.WriteStartArray();
            foreach (HalResource halResource in (IEnumerable)value)
            {
                serializer.Serialize(writer, halResource);
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
            writer.WriteEndObject();
        }
Exemplo n.º 18
0
        public override JsonWriter WriteJson(JsonWriter writer)
        {
            if(Filters.Count > 0)
            {
                writer.WritePropertyName("inputs");
                writer.WriteStartObject();

                writer.WritePropertyName("bucket");
                writer.WriteValue(_bucket);

                writer.WritePropertyName("key_filters");
                writer.WriteStartArray();

                Filters.ForEach(f => writer.WriteRawValue(f.ToJsonString()));

                writer.WriteEndArray();
                writer.WriteEndObject();
            }
            else
            {
                writer.WritePropertyName("inputs");
                writer.WriteValue(_bucket);
            }

            return writer;
        }
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var request = value as IMultiGetRequest;
			writer.WriteStartObject();
			if (!(request?.Documents.HasAny()).GetValueOrDefault(false))
			{
				writer.WriteEndObject();
				return;
			}
			var docs = request.Documents.Select(d =>
			{
				if (request.Index != null) d.Index = null;
				if (request.Type != null) d.Type = null;
				return d;
			}).ToList();

			var flatten = docs.All(p => p.CanBeFlattened);

			writer.WritePropertyName(flatten ? "ids" : "docs");
			writer.WriteStartArray();
			foreach (var id in docs)
			{
				if (flatten)
					serializer.Serialize(writer, id.Id);
				else
					serializer.Serialize(writer, id);
			}
			writer.WriteEndArray();
			writer.WriteEndObject();
		}
        /// <summary>
        /// Writes the Object to JSON
        /// </summary>
        /// <param name="writer">A JSON Writer object</param>
        /// <param name="value">Object to be converted</param>
        /// <param name="serializer">JSON Serializer object instance</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            // We need a custom writer for char arrays, such as are used with SendKeys.
            // JSON.NET does not properly handle converting unicode characters to \uxxxx.
            writer.WriteStartArray();
            char[] arrayObject = value as char[];
            if (arrayObject != null)
            {
                foreach (char currentChar in arrayObject)
                {
                    int codepoint = Convert.ToInt32(currentChar);
                    if ((codepoint >= 32) && (codepoint <= 126))
                    {
                        writer.WriteValue(currentChar);
                    }
                    else
                    {
                        string charRepresentation = "\\u" + Convert.ToString(codepoint, 16).PadLeft(4, '0');
                        writer.WriteRawValue("\"" + charRepresentation + "\"");
                    }
                }
            }

            writer.WriteEndArray();
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                var notifications = (ClientNotifications)value;
                writer.WriteStartArray();

                foreach (var p in notifications)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("id");
                    writer.WriteValue(p.Id.ToString("N"));
                    writer.WritePropertyName("message");
                    writer.WriteValue(p.Message);
                    writer.WritePropertyName("title");
                    writer.WriteValue(p.Title);
                    writer.WritePropertyName("type");
                    writer.WriteValue(p.Type.ToString().ToLower());
                    writer.WriteEndObject();
                }
                writer.WriteEndArray();
            }

        }
Exemplo n.º 22
0
 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     UUIDConverter UUID = new UUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         try
         {
             Hashtable hashtable = queue.Dequeue();
             serializer.Serialize(jsonWriter, hashtable);
         }
         catch(Exception e)
         {
             AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
         }
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
Exemplo n.º 23
0
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     // value should be an entity or a collection of entities.
     var singleEntity = !(value is IEnumerable);
     writer.WriteStartObject();
     writer.WritePropertyName("@odata.context");
     writer.WriteValue(GenerateContextUrlString(value, singleEntity));
     if (!singleEntity)
     {
         writer.WritePropertyName("value");
         writer.WriteStartArray();
     }
     if (singleEntity)
     {
         WriteEntity(writer, value);
     }
     else
     {
         foreach (var o in (IEnumerable)value)
         {
             writer.WriteStartObject();
             WriteEntity(writer, o);
             writer.WriteEndObject();
         }
     }
     if (!singleEntity)
     {
         writer.WriteEndArray();
     }
     writer.WriteEndObject();
 }
 private void WriteJsonCoordinatesEnumerable2(JsonWriter writer, List<List<Coordinate[]>> coordinates, JsonSerializer serializer)
 {
     writer.WriteStartArray();
     foreach (List<Coordinate[]> coordinate in coordinates)
         WriteJsonCoordinatesEnumerable(writer, coordinate, serializer);
     writer.WriteEndArray();
 }
Exemplo n.º 25
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var links = new HashSet<Link>((IList<Link>)value, new LinkEqualityComparer());

            writer.WriteStartObject();

            var lookup = links.ToLookup(l => l.Rel);

            foreach (var rel in lookup)
            {
                writer.WritePropertyName(rel.Key);
                if (rel.Count() > 1)
                    writer.WriteStartArray();
                foreach (var link in rel)
                {
                    writer.WriteStartObject();
                    writer.WritePropertyName("href");
                    writer.WriteValue(ResolveUri(link.Href));

                    if (link.IsTemplated)
                    {
                        writer.WritePropertyName("templated");
                        writer.WriteValue(true);
                    }

                    writer.WriteEndObject();
                }
                if (rel.Count() > 1)
                    writer.WriteEndArray();
            }
            writer.WriteEndObject();
        }
 protected void WriteJsonCoordinatesEnumerable(JsonWriter writer, IEnumerable<Coordinate[]> coordinates, JsonSerializer serializer)
 {
     writer.WriteStartArray();
     foreach (Coordinate[] coordinate in coordinates)
         WriteJsonCoordinates(writer, coordinate, serializer);
     writer.WriteEndArray();
 }
        private void writeErrors(ExecutionErrors errors, JsonWriter writer, JsonSerializer serializer)
        {
            if (errors == null || errors.Count == 0)
            {
                return;
            }

            writer.WritePropertyName("errors");

            writer.WriteStartArray();

            errors.Apply(error =>
            {
                writer.WriteStartObject();

                writer.WritePropertyName("message");
                serializer.Serialize(writer, error.Message);

                if (error.Locations != null)
                {
                    writer.WritePropertyName("locations");
                    serializer.Serialize(writer, error.Locations);
                }

                writer.WriteEndObject();
            });

            writer.WriteEndArray();
        }
Exemplo n.º 28
0
        /// <summary>
        ///     Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.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 coordinateElements = value as List<LineString>;
            if (coordinateElements != null && coordinateElements.Count > 0)
            {
                if (coordinateElements[0].Coordinates[0] != null)
                {
                    writer.WriteStartArray();

                    foreach (var subPolygon in coordinateElements)
                    {
                        LineStringConverter.WriteJson(writer, subPolygon.Coordinates, serializer);
                    }

                    writer.WriteEndArray();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                serializer.Serialize(writer, value);
            }
        }
        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();
        }
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var list = value as IList;

            writer.WriteStartArray();

            if (list == null || list.Count == 0)
            {
                foreach (var item in list)
                {
                    writer.WriteStartObject();
                    if (value != null)
                    {
                        var type = value.GetType();
                        var name = type.Name;
                        var attribute = type.GetCustomAttributes(typeof(JsonWrapPropertyAttribute), true).FirstOrDefault() as JsonWrapPropertyAttribute;
                        if (attribute != null)
                        {
                            name = attribute.WrapName;
                        }

                        writer.WritePropertyName(name);
                        serializer.Serialize(writer, value);

                    }
                    writer.WriteEndObject();
                }
            }
            writer.WriteEndArray();
        }
Exemplo n.º 31
0
        private void WriteIdsArrayJson(Newtonsoft.Json.JsonWriter writer, IEnumerable <object> value, Newtonsoft.Json.JsonSerializer serializer)
        {
            IEnumerator <Object> collectionEnumerator = (value as IEnumerable <object>).GetEnumerator();

            writer.WriteStartArray();
            while (collectionEnumerator.MoveNext())
            {
                var serializable = collectionEnumerator.Current;
                writer.WriteValue(this.GetIdFor(serializable));
            }
            writer.WriteEndArray();
        }
Exemplo n.º 32
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            IList items = (IList)value;

            if (value != null && items.Count > 0)
            {
                if (items.Count == 1 && this.IsSingleItemArray())
                {
                    Control item = (Control)items[0];

                    var pnl = item as AbstractPanel;

                    if (!item.Visible)
                    {
                        writer.WriteNull();
                        return;
                    }

                    writer.WriteRawValue(this.Format(items[0] as Control));
                }
                else
                {
                    bool visible = false;

                    foreach (Observable item in items)
                    {
                        if (item.Visible)
                        {
                            visible = true;
                        }
                    }

                    if (visible)
                    {
                        writer.WriteStartArray();

                        foreach (Observable item in items)
                        {
                            if (item.Visible)
                            {
                                writer.WriteRawValue(this.Format(item));
                            }
                        }

                        writer.WriteEndArray();
                    }
                    else
                    {
                        writer.WriteNull();
                    }
                }
            }
        }
Exemplo n.º 33
0
 public void WriteToManyRelationship(JsonWriter writer, JsonApiToManyRelationshipObject value, JsonSerializer serializer)
 {
     if (value.Data == null || value.Data.Count < 1)
     {
         //an empty array([]) for empty to-many relationships.
         writer.WriteStartArray();
         writer.WriteEndArray();
     }
     else
     {
         //an array of resource identifier objects for non - empty to - many relationships.
         serializer.Serialize(writer, value.Data);
     }
 }
 public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("name");
     writer.WriteValue(this.Name);
     writer.WritePropertyName("prop");
     writer.WriteValue(this.Prop);
     writer.WritePropertyName("rotation");
     writer.WriteStartArray();
     foreach (Rotation r in this.Rotations)
     {
         r.WriteToJson(writer);
     }
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
Exemplo n.º 35
0
        public override void WriteJson(
            Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            var cursor   = (List <BsonDocument>)value;
            var settings = new JsonWriterSettings
            {
                OutputMode = JsonOutputMode.Strict
            };

            writer.WriteStartArray();

            foreach (BsonDocument document in cursor)
            {
                writer.WriteRawValue(document.ToJson(settings));
            }

            writer.WriteEndArray();
        }
 private void WriteConnectedObjects(ChildTableQuery ctq, SQLiteDataReader sdr, Newtonsoft.Json.JsonWriter wr, bool includeThids)
 {
     //string value;
     wr.WritePropertyName(ctq.Connection.FullName);
     wr.WriteStartArray();
     while (sdr.Read())
     {
         wr.WriteStartObject();
         if (_settings.IncludeConnectionInfo)
         {
             wr.WritePropertyName("Connection");
             wr.WriteValue(ctq.Connection.Name);
             wr.WritePropertyName("ToCategory");
             wr.WriteValue(ctq.Connection.ToCategory);
         }
         WriteObjects(sdr, wr, includeThids);
         wr.WriteEndObject();
     }
     wr.WriteEndArray();
 }
Exemplo n.º 37
0
            /// <summary>
            /// Serialise an API event to JSON
            /// </summary>
            /// <returns>JObject of the event</returns>
            public void Serialise(Newtonsoft.Json.JsonWriter writer, Newtonsoft.Json.JsonSerializer serializer)
            {
                writer.WriteStartArray();

                writer.WriteValue(Graph !.ConstructedTime);
                writer.WriteValue(Node !.Index);
                writer.WriteValue(Index);
                writer.WriteValue(Repeats);
                writer.WriteValue(UniqID);

                if (APIDetails.HasValue)
                {
                    serializer.Serialize(writer, APIDetails);
                }
                else
                {
                    writer.WriteNull();
                }
                writer.WriteEndArray();
            }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
        {
            IList items = (IList)value;

            if (value != null && items.Count > 0)
            {
                if (items.Count == 1 && this.IsSingleItemArray())
                {
                    Control item = (Control)items[0];

                    if (!item.Visible)
                    {
                        writer.WriteNull();
                        return;
                    }

                    if (!(item is IProxyContainer))
                    {
                        writer.WriteRawValue(this.Format(items[0] as Control));
                    }
                    else
                    {
                        List <string> ids = ((IProxyContainer)item).GetIDS();

                        if (ids != null && ids.Count > 0)
                        {
                            if (ids.Count == 1)
                            {
                                writer.WriteRawValue(this.Format(ids[0]));
                            }
                            else
                            {
                                writer.WriteStartArray();

                                foreach (string id in ids)
                                {
                                    writer.WriteRawValue(this.Format(id));
                                }

                                writer.WriteEndArray();
                            }
                        }
                    }
                }
                else
                {
                    bool visible = false;

                    foreach (Observable item in items)
                    {
                        if (item.Visible)
                        {
                            visible = true;
                        }
                    }

                    if (visible)
                    {
                        writer.WriteStartArray();

                        foreach (Observable item in items)
                        {
                            if (item.Visible)
                            {
                                if (!(item is IProxyContainer))
                                {
                                    writer.WriteRawValue(this.Format(item));
                                }
                                else
                                {
                                    List <string> ids = ((IProxyContainer)item).GetIDS();

                                    if (ids != null && ids.Count > 0)
                                    {
                                        foreach (string id in ids)
                                        {
                                            writer.WriteRawValue(this.Format(id));
                                        }
                                    }
                                }
                            }
                        }

                        writer.WriteEndArray();
                    }
                    else
                    {
                        writer.WriteNull();
                    }
                }
            }
        }
Exemplo n.º 39
0
        /// <summary>
        /// Writes the json.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The serializer.</param>
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
        {
            DataTable table = value as DataTable;

            writer.WriteStartObject();

            writer.WritePropertyName("TableName");
            writer.WriteValue(table.TableName);

            writer.WritePropertyName("Columns");
            writer.WriteStartArray();

            foreach (DataColumn column in table.Columns)
            {
                writer.WriteStartObject();

                writer.WritePropertyName("AllowDBNull");
                writer.WriteValue(column.AllowDBNull);
                writer.WritePropertyName("AutoIncrement");
                writer.WriteValue(column.AutoIncrement);
                writer.WritePropertyName("AutoIncrementSeed");
                writer.WriteValue(column.AutoIncrementSeed);
                writer.WritePropertyName("AutoIncrementStep");
                writer.WriteValue(column.AutoIncrementStep);
                writer.WritePropertyName("Caption");
                writer.WriteValue(column.Caption);
                writer.WritePropertyName("ColumnName");
                writer.WriteValue(column.ColumnName);
                writer.WritePropertyName("DataType");
                writer.WriteValue(column.DataType.Name);
                writer.WritePropertyName("DateTimeMode");
                writer.WriteValue(column.DateTimeMode.ToString());
                writer.WritePropertyName("DefaultValue");
                writer.WriteValue(column.DefaultValue);
                writer.WritePropertyName("MaxLength");
                writer.WriteValue(column.MaxLength);
                writer.WritePropertyName("Ordinal");
                writer.WriteValue(column.Ordinal);
                writer.WritePropertyName("ReadOnly");
                writer.WriteValue(column.ReadOnly);
                writer.WritePropertyName("Unique");
                writer.WriteValue(column.Unique);

                writer.WriteEndObject();
            }

            writer.WriteEndArray();

            writer.WritePropertyName("Rows");
            writer.WriteStartArray();

            foreach (DataRow row in table.Rows)
            {
                if (row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Detached)
                {
                    writer.WriteStartArray();

                    for (int index = 0; index <= table.Columns.Count - 1; index++)
                    {
                        writer.WriteValue(row[index]);
                    }

                    writer.WriteEndArray();
                }
            }

            writer.WriteEndArray();

            // Write out primary key if the table has one. This will be useful when deserializing the table.
            // We will write it out as an array of column names
            writer.WritePropertyName("PrimaryKey");
            writer.WriteStartArray();
            if (table.PrimaryKey.Length > 0)
            {
                foreach (DataColumn column in table.PrimaryKey)
                {
                    writer.WriteValue(column.ColumnName);
                }
            }
            writer.WriteEndArray();

            writer.WriteEndObject();
        }
Exemplo n.º 40
-1
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var links = new HashSet<Link>((IList<Link>)value, Link.EqualityComparer);
            var lookup = links.ToLookup(l => l.Rel);
            
            if (lookup.Count == 0) 
                return;

            writer.WriteStartObject();

            foreach (var rel in lookup)
            {
                var count = rel.Count();

                writer.WritePropertyName(rel.Key);
                
                if ((count > 1) || (rel.Key == Link.RelForCuries))
                    writer.WriteStartArray();

                foreach (var link in rel)
                    WriteLink(writer, link);

                if ((count > 1) || (rel.Key == Link.RelForCuries))
                    writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }