Exemplo n.º 1
0
 /// <summary>
 /// Writes JSON property name and value if value is not null
 /// </summary>
 /// <param name="writer">JSON writer</param>
 /// <param name="key">property name</param>
 /// <param name="value">property value</param>
 internal static void writeIfNotNullOrEmpty(JsonTextWriter writer, string key, string value)
 {
     if (string.IsNullOrEmpty(value)) return;
     writer.WritePropertyName(key);
     writer.WriteValue(value);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Writes schema object in JSON format
 /// </summary>
 /// <param name="writer">JSON writer</param>
 /// <param name="names">list of named schemas already written</param>
 /// <param name="encspace">enclosing namespace of the schema</param>
 protected internal virtual void WriteJson(JsonTextWriter writer, SchemaNames names, string encspace)
 {
     writeStartObject(writer);
     WriteJsonFields(writer, names, encspace);
     if (null != this.Props) Props.WriteJson(writer);
     writer.WriteEndObject();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Writes the Field class in JSON format
        /// </summary>
        /// <param name="writer">JSON writer</param>
        /// <param name="names">list of named schemas already written</param>
        /// <param name="encspace">enclosing namespace for the field</param>
        protected internal void writeJson(JsonTextWriter writer, SchemaNames names, string encspace)
        {
            writer.WriteStartObject();
            JsonHelper.writeIfNotNullOrEmpty(writer, "name", this.Name);
            JsonHelper.writeIfNotNullOrEmpty(writer, "doc", this.Documentation);

            if (null != this.DefaultValue)
            {
                writer.WritePropertyName("default");
                this.DefaultValue.WriteTo(writer, null);
            }
            if (null != this.Schema)
            {
                writer.WritePropertyName("type");
                Schema.WriteJson(writer, names, encspace);
            }

            if (null != this.Props)
                this.Props.WriteJson(writer);

            if (null != aliases)
            {
                writer.WritePropertyName("aliases");
                writer.WriteStartArray();
                foreach (string name in aliases)
                    writer.WriteValue(name);
                writer.WriteEndArray();
            }

            writer.WriteEndObject();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Default implementation for writing schema properties in JSON format
 /// </summary>
 /// <param name="writer">JSON writer</param>
 /// <param name="names">list of named schemas already written</param>
 /// <param name="encspace">enclosing namespace of the schema</param>
 protected internal virtual void WriteJsonFields(JsonTextWriter writer, SchemaNames names, string encspace)
 {
 }
Exemplo n.º 5
0
 /// <summary>
 /// Writes opening { and 'type' property 
 /// </summary>
 /// <param name="writer">JSON writer</param>
 private void writeStartObject(JsonTextWriter writer)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("type");
     writer.WriteValue(GetTypeString(this.Tag));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the canonical JSON representation of this schema.
        /// </summary>
        /// <returns>The canonical JSON representation of this schema.</returns>
        public override string ToString()
        {
            System.IO.StringWriter sw = new System.IO.StringWriter();
			Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter writer = new Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter(sw);

            if (this is PrimitiveSchema || this is UnionSchema)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("type");
            }

            WriteJson(writer, new SchemaNames(), null); // stand alone schema, so no enclosing name space

            if (this is PrimitiveSchema || this is UnionSchema)
                writer.WriteEndObject();

            return sw.ToString();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Writes Protocol in JSON format
        /// </summary>
        /// <returns>JSON string</returns>
        public override string ToString()
        {
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
            {
				using (Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter writer = new Arch.CMessaging.Client.Newtonsoft.Json.JsonTextWriter(sw))
                {
                    #if(DEBUG)
					writer.Formatting = Arch.CMessaging.Client.Newtonsoft.Json.Formatting.Indented;
                    #endif

                    WriteJson(writer, new SchemaNames());
                    writer.Flush();
                    return sw.ToString();
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Writes primitive schema in JSON format
 /// </summary>
 /// <param name="w"></param>
 /// <param name="names"></param>
 /// <param name="encspace"></param>
 protected internal override void WriteJson(JsonTextWriter w, SchemaNames names, string encspace)
 {
     w.WriteValue(Name);
 }