示例#1
0
 public static void ToJson(Newtonsoft.Json.JsonWriter jsonWriter, Stock stock)
 {
     jsonWriter.WriteStartObject();
     Madingley.Serialization.Common.Writer.PropertyInt(jsonWriter, "_FunctionalGroupIndex", stock._FunctionalGroupIndex);
     Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_IndividualBodyMass", stock._IndividualBodyMass);
     Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_TotalBiomass", stock._TotalBiomass);
     jsonWriter.WriteEndObject();
 }
        public override void WriteValue(object Value, Newtonsoft.Json.JsonWriter Writer, MudObject Owner)
        {
            var contents = Value as Dictionary<String, Object>;
            if (contents == null) throw new InvalidOperationException();

            Writer.WriteStartObject();

            foreach (var pair in contents)
            {
                Writer.WritePropertyName(pair.Key);
                PersistAttribute._WriteValue(pair.Value, Writer, Owner);
            }

            Writer.WriteEndObject();
        }
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        public override void WriteJson( Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer )
        {
            var catEntry = value as CatalogEntry;
            if( catEntry != null )
            {
                writer.WriteStartObject();
                writer.WritePropertyName( "key" );
                writer.WriteValue( catEntry.Key );

                if( catEntry.Attributes.Length > 0 )
                {
                    writer.WritePropertyName( "attributes" );
                    serializer.Serialize( writer, catEntry.Attributes );
                }
                writer.WriteEndObject();
            }
        }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value)
        {
            CommentCollection c = value as CommentCollection;
            if (c != null)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("Page");
                writer.WriteValue(c.PageNumber);
                writer.WritePropertyName("PageCount");
                writer.WriteValue(c.Pages);
                writer.WritePropertyName("PostLink");
                writer.WriteValue(c.PostLink);

                writer.WritePropertyName("Comments");
                base.WriteJson(writer, value);
                writer.WriteEndObject();
            }
        }
示例#5
0
        public override void WriteValue(object Value, Newtonsoft.Json.JsonWriter Writer, MudObject Owner)
        {
            var contents = Value as Dictionary<RelativeLocations, List<MudObject>>;
            if (contents == null) throw new InvalidOperationException();

            Writer.WriteStartObject();

            foreach (var relloc in contents)
            {
                Writer.WritePropertyName(RelativeLocationToString(relloc.Key));
                Writer.WriteStartArray();

                foreach (var mudObject in relloc.Value.Where(o => o.IsNamedObject && o.IsInstance))
                    Writer.WriteValue(mudObject.GetFullName());

                Writer.WriteEndArray();
            }

            Writer.WriteEndObject();
        }
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        public override void WriteJson( Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer )
        {
            var attribute = value as DataService.Attribute;
            if( attribute != null )
            {
                writer.WritePropertyName( attribute.Key.ToString( System.Globalization.CultureInfo.InvariantCulture ) );
                writer.WriteValue( attribute.Value );
            }
            else
            {
                writer.WriteStartObject();

                var attributes = (DataService.Attribute[])value;
                if( attributes != null && attributes.Length > 0 )
                {
                    foreach( var att in attributes )
                    {
                        writer.WritePropertyName( att.Key.ToString( System.Globalization.CultureInfo.InvariantCulture ) );
                        writer.WriteValue( att.Value );
                    }
                }
                writer.WriteEndObject();
            }
        }
示例#7
0
            public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
            {
                NodeState NodeStateFlags = (NodeState)value;
                //Newtonsoft.Json.JsonConvert.SerializeObject

                writer.WriteStartObject();

                //foreach (NodeState CurrentFlag in Enum.GetValues(NodeStateFlags.GetType()))
                foreach (NodeState CurrentFlag in Enum.GetValues(typeof(NodeState)))
                {

                    if ((NodeStateFlags & CurrentFlag) != 0) // if (name.HasFlag(val))
                    {
                        writer.WritePropertyName(CurrentFlag.ToString());
                        serializer.Serialize(writer, "true");
                    } // End if( (NodeStateFlags & CurrentFlag) != 0)

                } // Next CurrentFlag

                writer.WriteEndObject();
            }
示例#8
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();
        }
示例#9
0
        public void Write(Newtonsoft.Json.JsonWriter writer, object value)
        {
            var grid = (TileData[, ,])value;

            int w = grid.GetLength(2);
            int h = grid.GetLength(1);
            int d = grid.GetLength(0);

            writer.WriteStartObject();

            writer.WritePropertyName("Width");
            writer.WriteValue(w);
            writer.WritePropertyName("Height");
            writer.WriteValue(h);
            writer.WritePropertyName("Depth");
            writer.WriteValue(d);

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

            var queue = new BlockingCollection<Tuple<int, byte[]>>();

            var writerTask = Task.Factory.StartNew(() =>
            {
                foreach (var tuple in queue.GetConsumingEnumerable())
                {
                    writer.WriteValue(tuple.Item1);
                    writer.WriteValue(tuple.Item2);
                }
            });

            Parallel.For(0, d, z =>
            {
                using (var memStream = new MemoryStream())
                {
                    using (var compressStream = new DeflateStream(memStream, CompressionMode.Compress, true))
                    using (var bufferedStream = new BufferedStream(compressStream))
                    using (var streamWriter = new BinaryWriter(bufferedStream))
                    {
                        var srcArr = grid;

                        for (int y = 0; y < h; ++y)
                            for (int x = 0; x < w; ++x)
                                streamWriter.Write(srcArr[z, y, x].Raw);
                    }

                    queue.Add(new Tuple<int, byte[]>(z, memStream.ToArray()));
                }
            });

            queue.CompleteAdding();

            writerTask.Wait();

            writer.WriteEndArray();
            writer.WriteEndObject();
        }
示例#10
0
文件: Message.cs 项目: torgebo/avro
        /// <summary>
        /// Writes the messages section of a protocol definition
        /// </summary>
        /// <param name="writer">writer</param>
        /// <param name="names">list of names written</param>
        /// <param name="encspace">enclosing namespace</param>
        internal void writeJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names, string encspace)
        {
            writer.WriteStartObject();
            JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Doc);

            if (null != this.Request)
                this.Request.WriteJsonFields(writer, names, null);

            if (null != this.Response)
            {
                writer.WritePropertyName("response");
                Response.WriteJson(writer, names, encspace);
            }

            if (null != this.Error)
            {
                writer.WritePropertyName("errors");
                this.Error.WriteJson(writer, names, encspace);
            }

            if (null != Oneway)
            {
                writer.WritePropertyName("one-way");
                writer.WriteValue(Oneway);
            }

            writer.WriteEndObject();
        }
示例#11
0
        private void SerializeNode(Newtonsoft.Json.JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
        {
            switch (node.NodeType)
            {
                case XmlNodeType.Document:
                case XmlNodeType.DocumentFragment:
                    SerializeGroupedNodes(writer, node, manager, writePropertyName);
                    break;
                case XmlNodeType.Element:
                    if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName) && node.ChildNodes.Count > 0)
                    {
                        SerializeGroupedNodes(writer, node, manager, false);
                    }
                    else
                    {
                        manager.PushScope();
                        
                        foreach (IXmlNode attribute in node.Attributes)
                        {
                            if (attribute.NamespaceUri == "http://www.w3.org/2000/xmlns/")
                            {
                                string namespacePrefix = (attribute.LocalName != "xmlns")
                                                         ? attribute.LocalName
                                                         : string.Empty;
                                string namespaceUri = attribute.Value;
                                
                                manager.AddNamespace(namespacePrefix, namespaceUri);
                            }
                        }
                        
                        if (writePropertyName)
                            writer.WritePropertyName(GetPropertyName(node, manager));
                        
                        if (!ValueAttributes(node.Attributes).Any() && node.ChildNodes.Count == 1 &&
                            node.ChildNodes[0].NodeType == XmlNodeType.Text)
                        {
                            // write elements with a single text child as a name value pair
                            writer.WriteValue(node.ChildNodes[0].Value);
                        }
                        else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
                        {
                            IXmlElement element = (IXmlElement)node;
                            
                            // empty element
                            if (element.IsEmpty)
                                writer.WriteNull();
                            else
                                writer.WriteValue(string.Empty);
                        }
                        else
                        {
                            writer.WriteStartObject();
                            
                            for (int i = 0; i < node.Attributes.Count; i++)
                            {
                                SerializeNode(writer, node.Attributes[i], manager, true);
                            }
                            
                            SerializeGroupedNodes(writer, node, manager, true);

                            writer.WriteEndObject();
                        }
                        
                        manager.PopScope();
                    }
                    
                    break;
                case XmlNodeType.Comment:
                    if (writePropertyName)
                        writer.WriteComment(node.Value);
                    break;
                case XmlNodeType.Attribute:
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    if (node.NamespaceUri == "http://www.w3.org/2000/xmlns/" && node.Value == JsonNamespaceUri)
                        return;

                    if (node.NamespaceUri == JsonNamespaceUri)
                    {
                        if (node.LocalName == "Array")
                            return;
                    }
                    
                    if (writePropertyName)
                        writer.WritePropertyName(GetPropertyName(node, manager));
                    writer.WriteValue(node.Value);
                    break;
                case XmlNodeType.XmlDeclaration:
                    IXmlDeclaration declaration = (IXmlDeclaration)node;
                    writer.WritePropertyName(GetPropertyName(node, manager));
                    writer.WriteStartObject();
                    
                    if (!string.IsNullOrEmpty(declaration.Version))
                    {
                        writer.WritePropertyName("@version");
                        writer.WriteValue(declaration.Version);
                    }
                    if (!string.IsNullOrEmpty(declaration.Encoding))
                    {
                        writer.WritePropertyName("@encoding");
                        writer.WriteValue(declaration.Encoding);
                    }
                    if (!string.IsNullOrEmpty(declaration.Standalone))
                    {
                        writer.WritePropertyName("@standalone");
                        writer.WriteValue(declaration.Standalone);
                    }
                    
                    writer.WriteEndObject();
                    break;
                case XmlNodeType.DocumentType:
                    IXmlDocumentType documentType = (IXmlDocumentType)node;
                    writer.WritePropertyName(GetPropertyName(node, manager));
                    writer.WriteStartObject();
                    
                    if (!string.IsNullOrEmpty(documentType.Name))
                    {
                        writer.WritePropertyName("@name");
                        writer.WriteValue(documentType.Name);
                    }
                    if (!string.IsNullOrEmpty(documentType.Public))
                    {
                        writer.WritePropertyName("@public");
                        writer.WriteValue(documentType.Public);
                    }
                    if (!string.IsNullOrEmpty(documentType.System))
                    {
                        writer.WritePropertyName("@system");
                        writer.WriteValue(documentType.System);
                    }
                    if (!string.IsNullOrEmpty(documentType.InternalSubset))
                    {
                        writer.WritePropertyName("@internalSubset");
                        writer.WriteValue(documentType.InternalSubset);
                    }
                    
                    writer.WriteEndObject();
                    break;
                default:
                    throw new Newtonsoft.Json.JsonSerializationException("Unexpected XmlNodeType when serializing nodes: " + node.NodeType);
            }
        }
示例#12
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <param name="value">The value.</param>
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, System.Serialisation.Json.JsonSerializer serializer)
        {
            IXmlNode node = WrapXml(value);

            XmlNamespaceManager manager = new XmlNamespaceManager(new NameTable());
            PushParentNamespaces(node, manager);
            
            if (!OmitRootObject)
                writer.WriteStartObject();

            SerializeNode(writer, node, manager, !OmitRootObject);
            
            if (!OmitRootObject)
                writer.WriteEndObject();
        }
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        public override void WriteJson( Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer )
        {
            var configuration = value as Configuration;
            if( configuration != null )
            {
                writer.WriteStartObject();

                if(configuration.PartAttributes.Length > 0 )
                {
                    writer.WritePropertyName( "partAttributes" );
                    writer.WriteStartArray();
                    foreach( var att in configuration.PartAttributes )
                    {
                        serializer.Serialize( writer, att );
                    }
                    writer.WriteEndArray();
                }

                if( configuration.CharacteristicAttributes.Length > 0 )
                {
                    writer.WritePropertyName( "characteristicAttributes" );
                    writer.WriteStartArray();
                    foreach( var att in configuration.CharacteristicAttributes )
                    {
                        serializer.Serialize( writer, att );
                    }
                    writer.WriteEndArray();
                }

                if( configuration.MeasurementAttributes.Length > 0 )
                {
                    writer.WritePropertyName( "measurementAttributes" );
                    writer.WriteStartArray();
                    foreach( var att in configuration.MeasurementAttributes )
                    {
                        serializer.Serialize( writer, att );
                    }
                    writer.WriteEndArray();
                }

                if( configuration.ValueAttributes.Length > 0 )
                {
                    writer.WritePropertyName( "valueAttributes" );
                    writer.WriteStartArray();
                    foreach( var att in configuration.ValueAttributes )
                    {
                        serializer.Serialize( writer, att );
                    }
                    writer.WriteEndArray();
                }

                if( configuration.CatalogAttributes.Length > 0 )
                {
                    writer.WritePropertyName( "catalogAttributes" );
                    writer.WriteStartArray();
                    foreach( var att in configuration.CatalogAttributes )
                    {
                        serializer.Serialize( writer, att );
                    }
                    writer.WriteEndArray();
                }

                writer.WriteEndObject();
            }
        }
示例#14
0
        internal virtual void writeJson(Newtonsoft.Json.JsonTextWriter writer)
        {
            writeStartObject(writer);
            WriteProperties(writer);

            foreach (KeyValuePair<string, string> kp in this.Props)
            {
                if (log.IsDebugEnabled) log.DebugFormat("Processing \"{0}\"", kp.Key);
                if (RESERVED_PROPS.ContainsKey(kp.Key))
                {
                    if (log.IsWarnEnabled) log.WarnFormat("Skipping reserved property \"{0}\"", kp.Key);
                    continue;
                }

                writer.WritePropertyName(kp.Key);
                writer.WriteValue(kp.Value);
            }

            writer.WriteEndObject();
        }
        public static void ToJson(Newtonsoft.Json.JsonWriter jsonWriter, string name, FunctionalGroupDefinitions functionalGroupDefinitions)
        {
            jsonWriter.WritePropertyName(name);
            jsonWriter.WriteStartObject();

            Madingley.Serialization.Common.Writer.PropertyKeyValuePairs(jsonWriter, "IndexLookupFromTrait", functionalGroupDefinitions.IndexLookupFromTrait,
                (jw, key, value) =>
                {
                    Madingley.Serialization.Common.Writer.PropertyInlineKeyValuePairs(jw, key, value,
                        (jw2, key2, value2) =>
                        {
                            Madingley.Serialization.Common.Writer.PropertyArray(jw2, key2, value2, Madingley.Serialization.Common.Writer.WriteInt);
                        });
                });

            Madingley.Serialization.Common.Writer.PropertyKeyValuePairs(jsonWriter, "FunctionalGroupProperties", functionalGroupDefinitions.FunctionalGroupProperties,
                (jw, key, value) =>
                {
                    Madingley.Serialization.Common.Writer.PropertyInlineArray(jw, key, value, Madingley.Serialization.Common.Writer.WriteDouble);
                });

            Madingley.Serialization.Common.Writer.PropertyKeyValuePairs(jsonWriter, "TraitLookupFromIndex", functionalGroupDefinitions.IndexLookupFromTrait,
                (jw, key, value) =>
                {
                    Madingley.Serialization.Common.Writer.PropertyInlineKeyValuePairs(jw, key, value,
                        (jw2, key2, value2) =>
                        {
                            Madingley.Serialization.Common.Writer.PropertyArray(jw2, key2, value2, Madingley.Serialization.Common.Writer.WriteInt);
                        });
                });

            Madingley.Serialization.Common.Writer.PropertyInlineArray(jsonWriter, "AllFunctionalGroupsIndex", functionalGroupDefinitions.AllFunctionalGroupsIndex, Madingley.Serialization.Common.Writer.WriteInt);

            jsonWriter.WriteEndObject();
        }
示例#16
0
 public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
 {
     writer.WriteStartObject();
     serialize(value, (JsonWriter)writer);
     writer.WriteEndObject();
 }
示例#17
0
        /// <summary>
        /// Writes Protocol in JSON format
        /// </summary>
        /// <param name="writer">JSON writer</param>
        /// <param name="names">list of named schemas already written</param>
        internal void WriteJson(Newtonsoft.Json.JsonTextWriter writer, SchemaNames names)
        {
            writer.WriteStartObject();

            JsonHelper.writeIfNotNullOrEmpty(writer, "protocol", this.Name);
            JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.Namespace);
            JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Doc);

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

            foreach (Schema type in this.Types)
                type.WriteJson(writer, names, this.Namespace);

            writer.WriteEndArray();

            writer.WritePropertyName("messages");
            writer.WriteStartObject();

            foreach (KeyValuePair<string,Message> message in this.Messages)
            {
                writer.WritePropertyName(message.Key);
                message.Value.writeJson(writer, names, this.Namespace);
            }

            writer.WriteEndObject();
            writer.WriteEndObject();
        }
示例#18
0
        internal void writeJson(Newtonsoft.Json.JsonTextWriter writer)
        {
            writer.WriteStartObject();
            //JsonHelper.writeIfNotNullOrEmpty(writer, "name", this.Name);
            JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Doc);

            if (null != this.Request)
            {
                writer.WritePropertyName("request");
                writer.WriteStartArray();

                foreach (Parameter parameter in this.Request)
                {
                    System.Diagnostics.Debug.Assert(parameter != null);
                    parameter.writeJson(writer);
                }

                writer.WriteEndArray();
            }

            if (null != this.Response)
            {
                writer.WritePropertyName("response");
                this.Response.writeJson(writer);
            }

            if (null != this.Error)
            {
                writer.WritePropertyName("errors");
                this.Error.writeJson(writer);
            }


            writer.WriteEndObject();
        }
示例#19
0
        public static void ToJson(Newtonsoft.Json.JsonWriter jsonWriter, Cohort cohort)
        {
            Action<Newtonsoft.Json.JsonWriter, uint> WriteUInt = (jsonWriter2, value) =>
            {
                Madingley.Serialization.Common.Writer.WriteInt(jsonWriter2, (int)value);
            };

            jsonWriter.WriteStartObject();
            Madingley.Serialization.Common.Writer.PropertyInt(jsonWriter, "_BirthTimeStep", (int)cohort._BirthTimeStep);
            Madingley.Serialization.Common.Writer.PropertyInt(jsonWriter, "_MaturityTimeStep", (int)cohort._MaturityTimeStep);
            Madingley.Serialization.Common.Writer.PropertyInlineArray(jsonWriter, "_CohortID", cohort._CohortID, WriteUInt);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_JuvenileMass", cohort._JuvenileMass);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_AdultMass", cohort._AdultMass);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_IndividualBodyMass", cohort._IndividualBodyMass);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_IndividualReproductivePotentialMass", cohort._IndividualReproductivePotentialMass);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_MaximumAchievedBodyMass", cohort._MaximumAchievedBodyMass);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_CohortAbundance", cohort._CohortAbundance);
            Madingley.Serialization.Common.Writer.PropertyInt(jsonWriter, "_FunctionalGroupIndex", cohort._FunctionalGroupIndex);
            Madingley.Serialization.Common.Writer.PropertyBoolean(jsonWriter, "_Merged", cohort._Merged);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_ProportionTimeActive", cohort._ProportionTimeActive);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_TrophicIndex", cohort._TrophicIndex);
            Madingley.Serialization.Common.Writer.PropertyDouble(jsonWriter, "_LogOptimalPreyBodySizeRatio", cohort._LogOptimalPreyBodySizeRatio);
            jsonWriter.WriteEndObject();
        }
示例#20
0
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        public override void WriteJson( Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer )
        {
            var catalog = (Catalog)value;
            if( catalog.Uuid != Guid.Empty )
            {
                writer.WriteStartObject();

                writer.WritePropertyName( "uuid" );
                writer.WriteValue( catalog.Uuid );

                if( !String.IsNullOrEmpty( catalog.Name ) )
                {
                    writer.WritePropertyName( "name" );
                    writer.WriteValue( catalog.Name );
                }

                if( catalog.ValidAttributes.Length > 0 )
                {
                    writer.WritePropertyName( "validAttributes" );
                    writer.WriteStartArray();
                    foreach( var att in catalog.ValidAttributes )
                    {
                        writer.WriteValue( att );
                    }
                    writer.WriteEndArray();
                }

                if( catalog.CatalogEntries.Length > 0 )
                {
                    writer.WritePropertyName( "catalogEntries" );
                    serializer.Serialize( writer, catalog.CatalogEntries );
                }

                writer.WriteEndObject();
            }
        }
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        public override void WriteJson( Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer )
        {
            var definition = value as AbstractAttributeDefinition;
            if( definition != null )
            {
                writer.WriteStartObject();
                writer.WritePropertyName( "key" );
                writer.WriteValue( definition.Key );
                writer.WritePropertyName( "description" );
                writer.WriteValue( definition.Description );

                var attributeDef = definition as AttributeDefinition;
                if( attributeDef != null )
                {
                    if( attributeDef.Length > 0 )
                    {
                        writer.WritePropertyName( "length" );
                        writer.WriteValue( attributeDef.Length );
                    }
                    writer.WritePropertyName( "type" );
                    serializer.Serialize( writer, attributeDef.Type );
                    writer.WritePropertyName( "definitionType" );
                    writer.WriteValue( "AttributeDefinition" );
                }

                var catalogDef = definition as CatalogAttributeDefinition;
                if( catalogDef != null )
                {
                    writer.WritePropertyName( "catalog" );
                    writer.WriteValue( catalogDef.Catalog );
                    writer.WritePropertyName( "definitionType" );
                    writer.WriteValue( "CatalogAttributeDefinition" );
                }

                writer.WriteEndObject();
            }
        }
示例#22
0
        internal void writeJson(Newtonsoft.Json.JsonTextWriter writer)
        {
            writer.WriteStartObject();

            JsonHelper.writeIfNotNullOrEmpty(writer, "namespace", this.Namespace);
            JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Doc);
            JsonHelper.writeIfNotNullOrEmpty(writer, "protocol", this.Name);

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

            foreach (Schema type in this.Types)
            {
                type.writeJson(writer);
            }

            writer.WriteEndArray();


            writer.WritePropertyName("messages");
            writer.WriteStartObject();

            foreach (Message message in this.Messages)
            {
                writer.WritePropertyName(message.Name);
                message.writeJson(writer);
            }

            writer.WriteEndObject();

            writer.WriteEndObject();
        }
示例#23
0
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
        {
            PointSet pointSet = (PointSet)value;

            writer.WriteStartObject();
            writer.WritePropertyName("Seed");
            writer.WriteValue(pointSet.Seed);

            writer.WritePropertyName("Points");
            writer.WriteStartArray();
            for (int i = 0; i < pointSet.Points.Length; ++i)
            {
                writer.WriteStartArray();
                writer.WriteValue(pointSet.Points[i].X);
                writer.WriteValue(pointSet.Points[i].Z);
                writer.WriteValue(pointSet.Points[i].Y);
                writer.WriteEndArray();
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
        }