Exemple #1
0
        public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
        {
            writer.WriteStartObject();
            writer.WritePropertyName("x");
            writer.WriteValue(this.X);
            writer.WritePropertyName("y");
            writer.WriteValue(this.Y);
            writer.WritePropertyName("z");
            writer.WriteValue(this.Z);
            if (this.Margin != 0)
            {
                writer.WritePropertyName("margin");
                writer.WriteValue(this.Margin);
            }
            writer.WritePropertyName("pointlist");
            writer.WriteStartArray();

            foreach (float[] points in this.PointList)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("x");
                writer.WriteValue(points[0]);
                writer.WritePropertyName("y");
                writer.WriteValue(points[1]);
                writer.WritePropertyName("z");
                writer.WriteValue(points[2]);
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Exemple #2
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();
        }
Exemple #3
0
 public static void Serialize(Newtonsoft.Json.JsonWriter Writer, Timing TimingCollectionObj)
 {
     Writer.WritePropertyName("Timing");
     Writer.WriteStartArray();
     foreach (TimingType timing in TimingCollectionObj)
     {
         if (timing.Name == TimingCollectionObj.Name)
         {
             continue;
         }
         Writer.WriteStartObject();
         Writer.WritePropertyName("Name");
         Writer.WriteValue(timing.Name);
         Writer.WritePropertyName("ExecutionTime");
         Writer.WriteValue(timing.ExecutionTime);
         Writer.WriteEndObject();
     }
     Writer.WriteEndArray();
     if (TimingCollectionObj.Child != null)
     {
         var timing2 = TimingCollectionObj.Child.Where(tt => tt.Name == TimingCollectionObj.Child.Name).First();
         Writer.WritePropertyName("TimingGroup");
         Writer.WriteStartObject();
         Writer.WritePropertyName("Name");
         Writer.WriteValue(TimingCollectionObj.Child.Name);
         Writer.WritePropertyName("ExecutionTime");
         Writer.WriteValue(timing2.ExecutionTime);
         Timing.Serialize(Writer, TimingCollectionObj.Child);
         Writer.WriteEndObject();
     }
 }
 private void WriteArray(Newtonsoft.Json.JsonWriter writer, BsonArray array, Newtonsoft.Json.JsonSerializer serializer)
 {
     writer.WriteStartArray();
     foreach (var item in array)
     {
         serializer.Serialize(writer, item, typeof(BsonValue));
     }
     writer.WriteEndArray();
 }
 protected override void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WritePropertyName("gravity");
     writer.WriteValue(Gravity);
     writer.WritePropertyName("friction");
     writer.WriteValue(Friction);
     writer.WritePropertyName("targetedTags");
     writer.WriteStartArray();             // Array of components
     TargetedTags.ForEach(t => writer.WriteValue(t));
     writer.WriteEndArray();
 }
Exemple #6
0
        public void Serialization(object obj, Newtonsoft.Json.JsonWriter writer)
        {
            if (obj == null)
            {
                return;
            }
            var objType = obj.GetType();

            if (objType == typeof(string))
            {
                writer.WriteValue(obj as string);
            }
            else if (objType.IsArray || typeof(System.Collections.ICollection).IsAssignableFrom(objType))
            {
                writer.WriteStartArray();
                var list = obj as System.Collections.IList;
                foreach (var element in list)
                {
                    Serialization(element, writer);
                }
                writer.WriteEndArray();
            }
            else if (objType.IsEnum)
            {
                var e = Enum.Parse(objType, obj.ToString());
                writer.WriteValue((int)e);
            }
            else if (objType == typeof(bool))
            {
                var b = (bool)obj;
                int v = b ? 1 : 0;
                writer.WriteValue(v);
            }
            else if (objType.IsClass)
            {
                var properties = objType.GetProperties();
                writer.WriteStartObject();
                foreach (var p in properties)
                {
                    var type  = p.PropertyType;
                    var value = p.GetValue(obj, null);
                    if (value != null)
                    {
                        writer.WritePropertyName(p.Name);
                        Serialization(value, writer);
                    }
                }
                writer.WriteEndObject();
            }
            else
            {
                writer.WriteValue(obj);
            }
        }
Exemple #7
0
 public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("levels");
     writer.WriteStartArray();
     foreach (ThrusterLevel l in this.Levels)
     {
         l.WriteToJson(writer);
     }
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
 public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("type");
     writer.WriteValue(this.Type.ToString());
     writer.WritePropertyName("gears");
     writer.WriteStartArray();
     foreach (EngineGear g in this.Gears)
     {
         g.WriteToJson(writer);
     }
     writer.WriteEndArray();
     writer.WriteEndObject();
 }
 protected override void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     base.WriteToJson(writer);
     writer.WritePropertyName("speed");
     writer.WriteValue(_baseSpeed);
     writer.WritePropertyName("stamina");
     writer.WriteValue(_baseMaxStamina);
     writer.WritePropertyName("expReward");
     writer.WriteValue(_expReward);
     writer.WritePropertyName("targetedTags");
     writer.WriteStartArray();             // Array of components
     TargetedTags.ForEach(t => writer.WriteValue(t));
     writer.WriteEndArray();
 }
 public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("audio");
     writer.WriteStartArray();
     foreach (string audioEvent in this.AudioEvents)
     {
         writer.WriteStartObject();
         writer.WritePropertyName("event");
         writer.WriteValue(audioEvent);
         writer.WriteEndObject();
     }
     writer.WriteEndArray();
     writer.WritePropertyName("guiLayout");
     writer.WriteValue(this.GuiLayout);
     writer.WriteEndObject();
 }
Exemple #11
0
 public void WriteToJson(Newtonsoft.Json.JsonWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("bones");
     writer.WriteStartArray();
     foreach (Bone b in this.Bones)
     {
         b.WriteToJson(writer);
     }
     writer.WriteEndArray();
     writer.WritePropertyName("ragdollPose");
     writer.WriteValue(this.RagdollPose);
     writer.WritePropertyName("enterAudio");
     writer.WriteValue(this.EnterAudio);
     writer.WritePropertyName("exitAudio");
     writer.WriteValue(this.ExitAudio);
     writer.WriteEndObject();
 }
    public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer)
    {
        var _olist = value as System.Collections.Generic.List <GadgetUnion>;

        if (_olist != null)
        {
            writer.WriteStartArray();
            foreach (var _o in _olist)
            {
                this.WriteJson(writer, _o, serializer);
            }
            writer.WriteEndArray();
        }
        else
        {
            this.WriteJson(writer, value as GadgetUnion, serializer);
        }
    }
        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object dataTable,
                                       Newtonsoft.Json.JsonSerializer serializer)
        {
            System.Data.DataTable table     = dataTable as System.Data.DataTable;
            DataRowConverter      converter = new DataRowConverter();

            writer.WriteStartObject();

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

            foreach (System.Data.DataRow row in table.Rows)
            {
                converter.WriteJson(writer, row, serializer);
            }

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

            converter = null;
        }
Exemple #14
0
        public static void WriteJson(this Newtonsoft.Json.JsonWriter writer, Neo.IO.Json.JObject json)
        {
            switch (json)
            {
            case null:
                writer.WriteNull();
                break;

            case Neo.IO.Json.JBoolean boolean:
                writer.WriteValue(boolean.Value);
                break;

            case Neo.IO.Json.JNumber number:
                writer.WriteValue(number.Value);
                break;

            case Neo.IO.Json.JString @string:
                writer.WriteValue(@string.Value);
                break;

            case Neo.IO.Json.JArray @array:
                writer.WriteStartArray();
                foreach (var value in @array)
                {
                    WriteJson(writer, value);
                }
                writer.WriteEndArray();
                break;

            case Neo.IO.Json.JObject @object:
                writer.WriteStartObject();
                foreach (var(key, value) in @object.Properties)
                {
                    writer.WritePropertyName(key);
                    WriteJson(writer, value);
                }
                writer.WriteEndObject();
                break;
            }
        }
        public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object dataset,
                                       Newtonsoft.Json.JsonSerializer serializer)
        {
            System.Data.DataSet dataSet = dataset as System.Data.DataSet;

            DataTableConverter converter = new DataTableConverter();

            writer.WriteStartObject();

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

            foreach (System.Data.DataTable table in dataSet.Tables)
            {
                converter.WriteJson(writer, table, serializer);
            }

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

            converter = null;
        }
Exemple #16
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 catalogue = (Catalog)value;

            if (catalogue.Uuid != Guid.Empty)
            {
                writer.WriteStartObject();

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

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

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

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

                writer.WriteEndObject();
            }
        }
 public void WriteStartArray()
 {
     _jsonWriter.WriteStartArray();
 }
        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();
        }
Exemple #19
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 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();
            }
        }