Esempio n. 1
0
        /// <summary>
        ///     Converts current not to JSON according to the avro specification.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="seenSchemas">The seen schemas.</param>
        internal override void ToJsonSafe(JsonTextWriter writer, HashSet<NamedSchema> seenSchemas)
        {
            if (seenSchemas.Contains(this))
            {
                writer.WriteValue(this.FullName);
                return;
            }

            seenSchemas.Add(this);
            writer.WriteStartObject();
            writer.WriteProperty("type", "fixed");
            writer.WriteProperty("name", this.FullName);
            writer.WriteOptionalProperty("aliases", this.Aliases);
            writer.WriteProperty("size", this.Size);
            writer.WriteEndObject();
        }
        /// <summary>
        /// Serialize this phase to JSON.
        /// </summary>
        /// <returns>The phase as a JSON string.</returns>
        public string ToJsonString()
        {
            /*
             * NB: JsonTextWriter is guaranteed to close the StringWriter
             * https://github.com/JamesNK/Newtonsoft.Json/blob/master/Src/Newtonsoft.Json/JsonTextWriter.cs#L150-L160
             */
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.WriteStartObject();
                writer.WritePropertyName(PhaseType);

                // phase start
                writer.WriteStartObject();

                WriteJson(writer);
                writer.WriteProperty("keep", keep);
                writer.WriteEndObject();

                // phase end
                writer.WriteEndObject();
            }

            return sb.ToString();
        }
Esempio n. 3
0
 /// <summary>
 ///     Converts current not to JSON according to the avro specification.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="seenSchemas">The seen schemas.</param>
 internal override void ToJsonSafe(JsonTextWriter writer, HashSet<NamedSchema> seenSchemas)
 {
     writer.WriteStartObject();
     writer.WriteProperty("type", "array");
     writer.WritePropertyName("items");
     this.itemSchema.ToJson(writer, seenSchemas);
     writer.WriteEndObject();
 }
Esempio n. 4
0
        public string ToJsonString()
        {
            var sb = new StringBuilder();

            using(var sw = new StringWriter(sb))
            using(JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.WriteStartObject();
                writer.WritePropertyName(PhaseType);

                // phase start
                writer.WriteStartObject();
                WriteJson(writer);
                writer.WriteProperty("keep", _keep);
                writer.WriteEndObject();
                // phase end

                writer.WriteEndObject();
            }

            return sb.ToString();
        }
Esempio n. 5
0
        // Returns JavaScript representation of Ext.Direct API
        public string ToJavaScript(bool toJson)
        {
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            using (JsonWriter jsonWriter = new JsonTextWriter(sw)) {
            #if DEBUG
                jsonWriter.Formatting = Formatting.Indented;
            #endif
                jsonWriter.WriteStartObject();
                jsonWriter.WriteProperty("url", this.Url);
                jsonWriter.WriteProperty("type", RemotingProvider);
                if (!String.IsNullOrEmpty(this.Namespace)) {
                    jsonWriter.WriteProperty("namespace", this.Namespace);
                }
                // for integration with the Ext Designer
                if (toJson) {
                    jsonWriter.WriteProperty("descriptor", this.Name);
                }
                if (this.Buffer.HasValue) {
                    jsonWriter.WriteProperty("enableBuffer", this.Buffer);
                }
                jsonWriter.WritePropertyName("actions");
                jsonWriter.WriteStartObject();
                foreach (var action in _actions.Values) {
                    action.WriteJson(jsonWriter);
                }
                jsonWriter.WriteEndObject();
                jsonWriter.WriteEndObject();
            }

            if (toJson) return sb.ToString();

            return String.Format("{0}={1};", this.Name, sb);
        }
Esempio n. 6
0
        /// <summary>
        ///     Converts current not to json according to the avro specification.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="seenSchemas">The seen schemas.</param>
        internal override void ToJsonSafe(JsonTextWriter writer, HashSet<NamedSchema> seenSchemas)
        {
            if (seenSchemas.Contains(this))
            {
                writer.WriteValue(this.FullName);
                return;
            }

            seenSchemas.Add(this);
            writer.WriteStartObject();
            writer.WriteProperty("type", "record");
            writer.WriteProperty("name", this.FullName);
            writer.WriteOptionalProperty("doc", this.Doc);
            writer.WriteOptionalProperty("aliases", this.Aliases);
            writer.WritePropertyName("fields");
            writer.WriteStartArray();
            this.fields.ForEach(_ => _.ToJson(writer, seenSchemas));
            writer.WriteEndArray();
            writer.WriteEndObject();
        }
Esempio n. 7
0
        public string ToString(bool json)
        {
            var config = ProviderConfiguration.GetConfiguration();
            var sb = new StringBuilder();
            var sw = new StringWriter(sb);

            using (var writer = new JsonTextWriter(sw)) {
            #if DEBUG
                writer.Formatting = Formatting.Indented;
            #else
                writer.Formatting = config.Debug ? Formatting.Indented : Formatting.None;
            #endif
                writer.WriteStartObject();
                writer.WriteProperty("type", "remoting");
                writer.WriteProperty("url", Url);
                if (json) {
                    writer.WriteProperty("descriptor", Name ?? config.Name);
                }
                if (!String.IsNullOrEmpty(config.Namespace)) {
                    writer.WriteProperty("namespace", config.Namespace);
                }
                if (config.Buffer.HasValue) {
                    writer.WriteProperty("enableBuffer", config.Buffer.Value);
                }
                if (config.MaxRetries.HasValue) {
                    writer.WriteProperty("maxRetries", config.MaxRetries.Value);
                }
                if (config.Timeout.HasValue) {
                    writer.WriteProperty("timeout", config.Timeout.Value);
                }
                writer.WritePropertyName("actions");
                writer.WriteStartObject();
                foreach (DirectAction action in _actions.Values) {
                    action.WriteJson(writer);
                }
                writer.WriteEndObject();
                writer.WriteEndObject();
            }

            string name = Name ?? config.Name;
            if (name.Contains('.')) {
                name = String.Format("Ext.ns(\"{0}\");\n{1}", name.Substring(0, name.LastIndexOf('.')), name);
            }

            return json ? sb.ToString() : String.Format("{0}={1};", name, sb);
        }
Esempio n. 8
0
        /// <summary>
        ///     Converts current not to JSON according to the avro specification.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="seenSchemas">The seen schemas.</param>
        internal override void ToJsonSafe(JsonTextWriter writer, HashSet<NamedSchema> seenSchemas)
        {
            if (seenSchemas.Contains(this))
            {
                writer.WriteValue(this.FullName);
                return;
            }

            seenSchemas.Add(this);
            writer.WriteStartObject();
            writer.WriteProperty("type", "enum");
            writer.WriteProperty("name", this.FullName);
            writer.WriteOptionalProperty("doc", this.Doc);
            writer.WritePropertyName("symbols");
            writer.WriteStartArray();
            this.symbols.ForEach(writer.WriteValue);
            writer.WriteEndArray();
            writer.WriteEndObject();
        }
        public void Compile()
        {
            System.Diagnostics.Debug.Assert(_inputs != null);
            if(!string.IsNullOrWhiteSpace(_query))
            {
                return;
            }

            var sb = new StringBuilder();

            using(var sw = new StringWriter(sb))
            using(JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.WriteStartObject();

                if(_inputs != null)
                {
                    _inputs.WriteJson(writer);
                }

                writer.WritePropertyName("query");

                writer.WriteStartArray();
                _phases.ForEach(p => writer.WriteRawValue(p.ToJsonString()));
                writer.WriteEndArray();

                if (Timeout.HasValue)
                {
                    writer.WriteProperty<int>("timeout", Timeout.Value);
                }

                writer.WriteEndObject();
            }

            _query = sb.ToString();
        }
Esempio n. 10
0
 /// <summary>
 ///     Converts current not to JSON according to the avro specification.
 /// </summary>
 /// <param name="writer">The writer.</param>
 /// <param name="seenSchemas">The seen schemas.</param>
 internal override void ToJsonSafe(JsonTextWriter writer, HashSet<NamedSchema> seenSchemas)
 {
     writer.WriteStartObject();
     writer.WriteProperty("name", this.FullName);
     writer.WriteOptionalProperty("doc", this.Doc);
     writer.WriteOptionalProperty("aliases", this.Aliases);
     writer.WritePropertyName("type");
     this.TypeSchema.ToJson(writer, seenSchemas);
     writer.WriteEndObject();
 }
#pragma warning restore 618

        /// <summary>
        /// Compile the mapreduce query.
        /// </summary>
        public void Compile()
        {
            Debug.Assert(inputs != null, "Compile inputs must not be null");

            if (!string.IsNullOrWhiteSpace(query))
            {
                return;
            }

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    writer.WriteStartObject();

                    if (inputs != null)
                    {
                        inputs.WriteJson(writer);
                    }

                    writer.WritePropertyName("query");

                    writer.WriteStartArray();
                    phases.ForEach(p => writer.WriteRawValue(p.ToJsonString()));
                    writer.WriteEndArray();

                    if (timeout.HasValue)
                    {
                        writer.WriteProperty<int>("timeout", timeout.Value);
                    }

                    writer.WriteEndObject();
                }
            }

            query = sb.ToString();
        }