public void Save(IPersistable build)
        {
            using (var fileStream = new FileStream(Source, FileMode.Open, FileAccess.ReadWrite))
            {
                if (fileStream.Length > 0) //remove ] if we have content in file
                {
                    fileStream.Seek(-1, SeekOrigin.End);
                }
                using (var sw = new StreamWriter(fileStream)) //add item to array
                {
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        if (sw.BaseStream.Position == 0) //begin array if this is first item
                        {
                            writer.WriteRawValue("[");
                        }
                        else //we are adding item to existing array
                        {
                            writer.WriteRawValue(",");
                        }

                        serializer.Serialize(writer, build.Data());

                        writer.WriteRawValue("]");
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Convert parameter list to json object
        /// </summary>
        public static string parameterFieldMapJson(parameters parms, string ProjectID, string QueryID)
        {
            StringWriter sw = new StringWriter();
            JsonTextWriter json = new JsonTextWriter(sw);

            json.WriteStartObject();
            json.WritePropertyName("results");
            json.WriteStartArray();
            json.WriteStartObject();
            // ProjectID and QueryID
            json.WritePropertyName("ProjectID");
            json.WriteValue(ProjectID);
            json.WritePropertyName("QueryID");
            json.WriteValue(QueryID);

            json.WritePropertyName("parameters");
            json.WriteRawValue(JsonConvert.SerializeObject(parms));

            json.WriteEndObject();
            json.WriteEndArray();
            json.WriteEndObject();

            json.Flush();
            sw.Flush();

            return sw.ToString();
        }
Exemple #3
0
        public void Serialize(JsonWriter writer)
        {
            if (string.IsNullOrWhiteSpace(MimeType) || string.IsNullOrWhiteSpace(Content))
                return;

            var sb = new StringBuilder();
            var sw = new StringWriter(sb);
            using (JsonWriter jw = new JsonTextWriter(sw))
            {
                jw.WritePropertyName(MimeType);

                jw.WriteStartObject();

                if (!string.IsNullOrWhiteSpace(Content))
                {
                    jw.WriteRawValue(Content);
                }

                jw.WriteEndObject();

                if (jw.WriteState == WriteState.Error)
                    sb.Clear();
            }
            writer.WriteRawValue(sb.ToString());
        }
 void do确定_Click(object sender, EventArgs e)
 {
     var __sw = new StringWriter();
     JsonWriter __writer = new JsonTextWriter(__sw);
     __writer.WriteStartArray();
     foreach (DataGridViewRow __行 in this.out值.Rows)
     {
         if (!__行.IsNewRow)
         {
             var __value = __行.Cells[0].Value == null ? "" : __行.Cells[0].Value.ToString();
             if (_元数据 != null)
             {
                 switch (_元数据.类型)
                 {
                     case "string":
                     case "字符串":
                         __writer.WriteValue(__value);
                         break;
                     default:
                         __writer.WriteRawValue(__value);
                         break;
                 }
             }
             else
             {
                 __writer.WriteRawValue(__value);
             }
         }
     }
     __writer.WriteEndArray();
     __writer.Flush();
     _值 = __sw.GetStringBuilder().ToString();
     this.DialogResult = DialogResult.OK;
 }
 /// <summary>
 /// Serializes <see cref="Graphic"/> into JSON string.
 /// </summary>
 /// <param name="graphic">graphic to serialize into JSON.</param>
 /// <returns>string representation of the JSON object.</returns>
 public static string ToJson(this  Graphic graphic)
 {
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (JsonWriter jw = new JsonTextWriter(sw))
         {
             if (graphic.Geometry != null)
             {
                 jw.WriteStartObject();
                 jw.WritePropertyName("geometry");
                 // Gets the JSON string representation of the Geometry.
                 jw.WriteRawValue(graphic.Geometry.ToJson());
                 jw.WriteEndObject();
             }
             if (graphic.Attributes.Count > 0)
             {
                 jw.WriteStartObject();
                 foreach (var item in graphic.Attributes)
                 {
                     jw.WritePropertyName(item.Key);
                     jw.WriteValue(item.Value);
                 }
                 jw.WriteEndObject();
             }
         }
         return sb.ToString();
     }
 }
 public static void AddEntry(String displayName, String name, String id)
 {
     _catalog.configs[name] = "{\"displayName\":\""+displayName+"\",\"folder\":\"" + name + "\", \"id\":\"" + id + "\"}";
     using (StreamWriter sw = new StreamWriter(_configDirectory + "catalog.json"))
     {
         using (JsonTextWriter jw = new JsonTextWriter(sw))
         {
             jw.WriteRawValue(JsonConvert.SerializeObject(_catalog));
         }
     }
 }
        public HttpResponseMessage GetOuterBoundaryMask()
        {
            var stringBuilder = new StringBuilder();
            var jsonTextWriter = new JsonTextWriter(new StringWriter(stringBuilder));
            var outerBoundaryGeoJson = _geoService.GetOuterBoundaryMaskGeoJson();
            jsonTextWriter.WriteRawValue(outerBoundaryGeoJson);

            var response = this.Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(stringBuilder.ToString(), Encoding.UTF8, "application/json");
            return response;
        }
Exemple #8
0
        internal string WriteApi(Uri basePath, string servicePath, Type serviceType, Stack<Type> typeStack)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.WriteStartObject();
                writer.WritePropertyName("apiVersion");
                writer.WriteValue(serviceType.Assembly.GetName().Version.ToString());
                writer.WritePropertyName("swaggerVersion");
                writer.WriteValue(Globals.SWAGGER_VERSION);
                writer.WritePropertyName("basePath");
                writer.WriteValue(string.Format("{0}://{1}", basePath.Scheme, basePath.Authority));
                writer.WritePropertyName("resourcePath");
                writer.WriteValue(string.Format(servicePath));

                writer.WritePropertyName("apis");
                writer.WriteRawValue(WriteApis(_Mapper.FindMethods(servicePath, serviceType, typeStack)));

                writer.WritePropertyName("models");
                writer.WriteRawValue(WriteModels(typeStack));
            }
            return sb.ToString();
        }
        public HttpResponseMessage GetBoroughBoundaries()
        {
            var stringBuilder = new StringBuilder();
            var jsonTextWriter = new JsonTextWriter(new StringWriter(stringBuilder));
            jsonTextWriter.WriteStartObject();
            foreach (var boroughBoundary in _geoService.GetBoroughBoundariesGeoJson())
            {
                jsonTextWriter.WritePropertyName(boroughBoundary.Key);
                jsonTextWriter.WriteRawValue(boroughBoundary.Value);
            }
            jsonTextWriter.WriteEndObject();

            var response = this.Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(stringBuilder.ToString(), Encoding.UTF8, "application/json");
            return response;
        }
 internal override string ToJson()
 {
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (JsonWriter jw = new JsonTextWriter(sw))
         {
             jw.WriteStartObject();
             if (Graphics != null && Graphics.Count > 0)
             {
                 jw.WritePropertyName("featureCollection");
                 jw.WriteRawValue(new FeatureSet(Graphics).ToJson());
             }
             jw.WriteEndObject();
         }
     }
     return sb.ToString();
 }
Exemple #11
0
        public string ToJsonString()
        {
            var sb = new StringBuilder();

            using(var sw = new StringWriter(sb))
            using(JsonWriter jw = new JsonTextWriter(sw))
            {
                jw.WriteStartArray();

                jw.WriteValue(FunctionName);
                jw.WriteStartArray();

                Argument.ForEach(a => jw.WriteRawValue(a.ToString()));

                jw.WriteEndArray();
                jw.WriteEndArray();
            }

            return sb.ToString();
        }
 /// <summary>
 /// Extension method for serializing <see cref="Envelope"/> into JSON object 
 /// as expected in context parameter of <see cref="AggregatePointsParameter"/>
 /// </summary>
 /// <param name="envelope"></param>
 /// <returns></returns>
 public static string ToJson2(this Envelope envelope)
 {
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (JsonWriter jw = new JsonTextWriter(sw))
         {
             jw.WriteStartObject();
             jw.WritePropertyName("outExtent");
             jw.WriteRawValue(envelope.ToJson());
             if (envelope.SpatialReference != null && envelope.SpatialReference.WKID > 0)
             {
                 jw.WritePropertyName("outSR");
                 jw.WriteValue(envelope.SpatialReference.WKID.ToString(CultureInfo.InvariantCulture));
             }
             jw.WriteEndObject();
         }
     }
     return sb.ToString();
 }
Exemple #13
0
        internal string WriteType(Type t, Stack<Type> typeStack)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.WriteStartObject();

                var idValue = Helpers.GetDataContractNamePropertyValue(t) ?? t.FullName;
                writer.WritePropertyName("id");
                writer.WriteValue(idValue);

                writer.WritePropertyName("properties");
                writer.WriteRawValue(WriteProperties(t, typeStack));
            }
            return sb.ToString();
        }
    public void WriteRawValue()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        int i = 0;
        string rawJson = "[1,2]";

        jsonWriter.WriteStartObject();

        while (i < 3)
        {
          jsonWriter.WritePropertyName("d" + i);
          jsonWriter.WriteRawValue(rawJson);

          i++;
        }

        jsonWriter.WriteEndObject();
      }

      Assert.AreEqual(@"{""d0"":[1,2],""d1"":[1,2],""d2"":[1,2]}", sb.ToString());
    }
Exemple #15
0
        /// <summary>
        /// Serializes only the necessary components of the <see cref="PersistentResponse"/> to JSON
        /// using Json.NET's JsonTextWriter to improve performance.
        /// </summary>
        /// <param name="writer">The <see cref="System.IO.TextWriter"/> that receives the JSON serialization.</param>
        void IJsonWritable.WriteJson(TextWriter writer)
        {
            var jsonWriter = new JsonTextWriter(writer);
            jsonWriter.WriteStartObject();

            jsonWriter.WritePropertyName("C");
            jsonWriter.WriteValue(MessageId);

            if (Disconnect)
            {
                jsonWriter.WritePropertyName("D");
                jsonWriter.WriteValue(1);
            }

            if (TimedOut)
            {
                jsonWriter.WritePropertyName("T");
                jsonWriter.WriteValue(1);
            }

            if (GroupsToken != null)
            {
                jsonWriter.WritePropertyName("G");
                jsonWriter.WriteValue(GroupsToken);
            }

            if (LongPollDelay.HasValue)
            {
                jsonWriter.WritePropertyName("L");
                jsonWriter.WriteValue(LongPollDelay.Value);
            }

            jsonWriter.WritePropertyName("M");
            jsonWriter.WriteStartArray();

            Messages.Enumerate(m => !m.IsCommand && !ExcludeFilter(m),
                               m => jsonWriter.WriteRawValue(m.Value));

            jsonWriter.WriteEndArray();
            jsonWriter.WriteEndObject();
        }
Exemple #16
0
        public void Compile(Program program, TextWriter wr)
        {
            Contract.Requires(program != null);

              // program.Name is the source filename without any path.  Remove the extension
              // and use it as the name of the default module.  In C#, this would have been
              // "_module".  See WriteLident() for the renaming process.
              DafnyDefaultModuleName = System.IO.Path.GetFileNameWithoutExtension(program.Name).Replace('.', '_');

              // Kremlin's JSON input is all JSON arrays, not serialized objects in the usual way.
              //  [6, [
              //      ["FStar_Mul", []],
              //      ["FStar_UInt", [
              //          ["DFunction", [
              //              ["TUnit"], "FStar_UInt_lognot_lemma_2", [{
              //                  "name": "n",
              //                  "typ": ["TQualified", [
              //                      ["Prims"], "pos"
              //                  ]],
              //                 "mut": false,
              //                  "mark": 0
              //              }],
              //              ["EUnit"]
              //          ]]
              //      ]], ...

              j = new JsonTextWriter(wr);
              j.Formatting = Formatting.Indented;
              j.Indentation = 1;
              using (WriteArray()) { // Entire contents is an array - type binary_format
            j.WriteRawValue(KremlinAst.Version); // binary_format = version * file list
            using (WriteArray()) { // start of file list

              // bugbug: generate builtins as needed
              //CompileBuiltIns(program.BuiltIns);

              // Compile modules in order by height (program.Modules is sorted this way but in
              // reverse order). Compile SystemModule last, as it has height -1 and is not in
              // the .Modules list.
              List<ModuleDefinition> sortedModules = new List<ModuleDefinition>(program.Modules());
              sortedModules.Reverse();

              int previousHeight = sortedModules[0].Height+1;
              foreach (ModuleDefinition m in sortedModules) {
            Contract.Assert(m.Height < previousHeight); // .Modules is sorted
            CompileModule(m, wr);
            previousHeight = m.Height;
              }
              CompileModule(program.BuiltIns.SystemModule, wr);

            } // End of file list
              } // End of entire contents
              j.Close();
        }
Exemple #17
0
 private string WriteApis(IEnumerable<Models.Method> methods)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     using (JsonWriter writer = new JsonTextWriter(sw))
     {
         writer.WriteStartArray();
         foreach (Models.Method m in methods.OrderBy(s => s.path))
         {
             writer.WriteRawValue(JsonConvert.SerializeObject(m));
         }
         writer.WriteEnd();
     }
     return sb.ToString();
 }
 internal string ToJson()
 {
     StringBuilder sb = new StringBuilder();
     using (StringWriter sw = new StringWriter(sb))
     {
         using (JsonWriter jw = new JsonTextWriter(sw))
         {
             jw.WriteStartObject();
             if (!string.IsNullOrEmpty(GeographyType))
             {
                 jw.WritePropertyName("geographyType");
                 jw.WriteValue(GeographyType);
             }
             if (!string.IsNullOrEmpty(SourceCountry))
             {
                 jw.WritePropertyName("sourceCountry");
                 jw.WriteValue(SourceCountry);
             }
             if (!string.IsNullOrEmpty(GeographyLayer))
             {
                 jw.WritePropertyName("geographyLayer");
                 jw.WriteValue(GeographyLayer);
             }
             if (!string.IsNullOrEmpty(Url))
             {
                 jw.WritePropertyName("url");
                 jw.WriteValue(Url);
             }
             if (!string.IsNullOrEmpty(Name))
             {
                 jw.WritePropertyName("name");
                 jw.WriteValue(Name);
             }
             if (OutFields != null && OutFields.Count > 0)
             {
                 jw.WritePropertyName("outfields");
                 jw.WriteStartArray();
                 foreach (var f in OutFields)
                     jw.WriteValue(f);
                 jw.WriteEndArray();
             }
             if (IntersectingInfo != null)
             {
                 jw.WritePropertyName("intersectionInfo");
                 jw.WriteRawValue(IntersectingInfo.ToJson());
             }
             jw.WriteEndObject();
         }
     }
     return sb.ToString();
 }
        private string CreateRegionJsonString()
        {
            StringBuilder regionJsonBuilder = new StringBuilder();
            using (StringWriter stringWriter = new StringWriter(regionJsonBuilder))
            using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
            {
                jsonTextWriter.WriteStartObject();

                jsonTextWriter.WritePropertyName("HeaderPanelId");
                jsonTextWriter.WriteValue(this.headerPanel.ClientID);

                jsonTextWriter.WritePropertyName("MenuPanelId");
                jsonTextWriter.WriteValue(this.menuPanel.ClientID);

                jsonTextWriter.WritePropertyName("FooterPanelId");
                jsonTextWriter.WriteValue(this.footerPanel.ClientID);

                jsonTextWriter.WritePropertyName("NavigationBarTitle");
                jsonTextWriter.WriteValue(this.configurationSection.NavigationBarTitle);

                jsonTextWriter.WritePropertyName("NavigationItems");
                jsonTextWriter.WriteRawValue(CreateMenuJsonString(this.siteMapItems));

                jsonTextWriter.WriteEndObject();
            }

            return regionJsonBuilder.ToString();
        }
Exemple #20
0
        protected override void WriteTransaction(JsonTextWriter writer, Transaction tx)
        {
            WritePropertyValue(writer, "txid", tx.GetHash().ToString());
            WritePropertyValue(writer, "version", tx.Version);
            WritePropertyValue(writer, "locktime", tx.LockTime);

            writer.WritePropertyName("vin");
            writer.WriteStartArray();
            foreach(var txin in tx.Inputs)
            {
                writer.WriteStartObject();

                if(txin.PrevOut.Hash == new uint256(0))
                {
                    WritePropertyValue(writer, "coinbase", Encoders.Hex.EncodeData(txin.ScriptSig.ToRawScript()));
                }
                else
                {
                    WritePropertyValue(writer, "txid", txin.PrevOut.Hash.ToString());
                    WritePropertyValue(writer, "vout", txin.PrevOut.N);
                    writer.WritePropertyName("scriptSig");
                    writer.WriteStartObject();

                    WritePropertyValue(writer, "asm", txin.ScriptSig.ToString());
                    WritePropertyValue(writer, "hex", Encoders.Hex.EncodeData(txin.ScriptSig.ToRawScript()));

                    writer.WriteEndObject();
                }
                WritePropertyValue(writer, "sequence", txin.Sequence);
                writer.WriteEndObject();
            }
            writer.WriteEndArray();

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

            int i = 0;
            foreach(var txout in tx.Outputs)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("value");
                writer.WriteRawValue(ValueFromAmount(txout.Value));
                WritePropertyValue(writer, "n", i);

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

                WritePropertyValue(writer, "asm", txout.ScriptPubKey.ToString());
                WritePropertyValue(writer, "hex", Encoders.Hex.EncodeData(txout.ScriptPubKey.ToRawScript()));

                var destinations = txout.ScriptPubKey.GetDestinations().ToArray();

                if(destinations.Length == 1)
                {
                    WritePropertyValue(writer, "reqSigs", 1);
                    WritePropertyValue(writer, "type", GetScriptType(txout.ScriptPubKey.FindTemplate()));
                    writer.WritePropertyName("addresses");
                    writer.WriteStartArray();
                    writer.WriteValue(new BitcoinAddress(destinations[0], Network).ToString());
                    writer.WriteEndArray();
                }
                else
                {
                    var multi = new PayToMultiSigTemplate().ExtractScriptPubKeyParameters(txout.ScriptPubKey);
                    WritePropertyValue(writer, "reqSigs", multi.SignatureCount);
                    WritePropertyValue(writer, "type", GetScriptType(txout.ScriptPubKey.FindTemplate()));
                    writer.WriteStartArray();
                    foreach(var key in multi.PubKeys)
                    {
                        writer.WriteValue(new BitcoinAddress(key.ID, Network).ToString());
                    }
                    writer.WriteEndArray();
                }

                writer.WriteEndObject(); //endscript
                writer.WriteEndObject(); //in out
                i++;
            }
            writer.WriteEndArray();
        }
        /// <summary>
        /// Serializes only the necessary components of the <see cref="SignalR.PersistentResponse"/> to JSON
        /// using Json.NET's JsonTextWriter to improve performance.
        /// </summary>
        /// <param name="writer">The <see cref="System.IO.TextWriter"/> that receives the JSON serialization.</param>
        void IJsonWritable.WriteJson(TextWriter writer)
        {
            var jsonWriter = new JsonTextWriter(writer);
            jsonWriter.WriteStartObject();

            jsonWriter.WritePropertyName("MessageId");
            jsonWriter.WriteValue(MessageId);

            jsonWriter.WritePropertyName("Disconnect");
            jsonWriter.WriteValue(Disconnect);

            jsonWriter.WritePropertyName("TimedOut");
            jsonWriter.WriteValue(TimedOut);

            if (TransportData != null)
            {
                jsonWriter.WritePropertyName("TransportData");
                jsonWriter.WriteStartObject();

                object value;
                if (TransportData.TryGetValue("Groups", out value))
                {
                    jsonWriter.WritePropertyName("Groups");
                    jsonWriter.WriteStartArray();
                    foreach (var group in (IEnumerable<string>)value)
                    {
                        jsonWriter.WriteValue(group);
                    }
                    jsonWriter.WriteEndArray();
                }

                jsonWriter.WriteEndObject();
            }

            jsonWriter.WritePropertyName("Messages");
            jsonWriter.WriteStartArray();

            for (int i = 0; i < Messages.Count; i++)
            {
                ArraySegment<Message> segment = Messages[i];
                for (int j = segment.Offset; j < segment.Offset + segment.Count; j++)
                {
                    Message message = segment.Array[j];
                    if (!message.IsCommand)
                    {
                        jsonWriter.WriteRawValue(message.Value);
                    }
                }
            }

            jsonWriter.WriteEndArray();
            jsonWriter.WriteEndObject();
        }
Exemple #22
0
        internal string WriteModels(Stack<Type> typeStack)
        {
            StringBuilder sb = new StringBuilder();

            sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            using (JsonWriter writer = new JsonTextWriter(sw))
            {
                writer.Formatting = Formatting.None;
                writer.WriteStartObject();
                while (typeStack.Count > 0)
                {
                    Type t = typeStack.Pop();
                    if (t.GetCustomAttribute<HiddenAttribute>() != null) { continue; }
                    if (t.GetCustomAttributes<TagAttribute>().Select(tn => tn.TagName).Any(HiddenTags.Contains)) { continue; }

                    var propName = Helpers.GetDataContractNamePropertyValue(t) ?? t.FullName;
                    writer.WritePropertyName(propName);
                    writer.WriteRawValue(WriteType(t, typeStack));
                }
                writer.WriteEnd();
            }

            return sb.ToString();
        }
        /// <summary>
        /// Serializes only the necessary components of the <see cref="PersistentResponse"/> to JSON
        /// using Json.NET's JsonTextWriter to improve performance.
        /// </summary>
        /// <param name="writer">The <see cref="System.IO.TextWriter"/> that receives the JSON serialization.</param>
        void IJsonWritable.WriteJson(TextWriter writer)
        {
            var jsonWriter = new JsonTextWriter(writer);
            jsonWriter.WriteStartObject();

            jsonWriter.WritePropertyName("MessageId");
            jsonWriter.WriteValue(MessageId);

            jsonWriter.WritePropertyName("Disconnect");
            jsonWriter.WriteValue(Disconnect);

            jsonWriter.WritePropertyName("TimedOut");
            jsonWriter.WriteValue(TimedOut);

            if (TransportData != null)
            {
                jsonWriter.WritePropertyName("TransportData");
                jsonWriter.WriteStartObject();

                object value;
                if (TransportData.TryGetValue("Groups", out value))
                {
                    jsonWriter.WritePropertyName("Groups");
                    jsonWriter.WriteStartArray();
                    foreach (var group in (IEnumerable<string>)value)
                    {
                        jsonWriter.WriteValue(group);
                    }
                    jsonWriter.WriteEndArray();
                }

                jsonWriter.WriteEndObject();
            }

            jsonWriter.WritePropertyName("Messages");
            jsonWriter.WriteStartArray();

            Messages.Enumerate(m => !m.IsCommand && !ExcludeFilter(m),
                               m => jsonWriter.WriteRawValue(m.Value));

            jsonWriter.WriteEndArray();
            jsonWriter.WriteEndObject();
        }
 void do确定_Click(object sender, EventArgs e)
 {
     var __sw = new StringWriter();
     var __writer = new JsonTextWriter(__sw);
     __writer.WriteStartArray();
     for (int i = 0; i < this.out值.Rows.Count; i++)
     {
         if (this.out值.Rows[i].IsNewRow)
         {
             continue;
         }
         __writer.WriteStartObject();
         for (int j = 0; j < this.out值.Columns.Count; j++)
         {
             var __名称 = this.out值.Columns[j].Name;
             var __元数据 = _元数据列表[j].元数据;
             var __value = this.out值[j, i].Value == null ? "" : this.out值[j, i].Value.ToString();
             __writer.WritePropertyName(__名称);
             if (__元数据.结构 == E数据结构.点)
             {
                 switch (__元数据.类型)
                 {
                     case "string":
                     case "字符串":
                         __writer.WriteValue(__value);
                         break;
                     default:
                         __writer.WriteRawValue(__value);
                         break;
                 }
             }
             else
             {
                 __writer.WriteRawValue(__value);
             }
         }
         __writer.WriteEndObject();
     }
     __writer.WriteEndArray();
     __writer.Flush();
     _值 = __sw.GetStringBuilder().ToString();
     this.DialogResult = DialogResult.OK;
 }
Exemple #25
0
            public static string getJsonString(projectResults ProjectResults)
            {
                StringWriter sw = new StringWriter();
                JsonTextWriter json = new JsonTextWriter(sw);

                json.WriteStartObject();
                json.WritePropertyName("results");
                json.WriteStartArray();

                //TODO context projResults needs to update for multiple query operation
                foreach (results rslts in ProjectResults.results)
                {
                    json.WriteStartObject();
                    // ProjectID and QueryID
                    json.WritePropertyName("ProjectID");

                    // get projectid, for subjhow
                    json.WriteValue((rslts.schema.Count > 0 ) ? rslts.schema[0].project : ProjectResults.results[0].schema[0].project);
                    json.WritePropertyName("QueryID");
                    json.WriteValue((rslts.schema.Count > 0 ) ? rslts.schema[0].name : String.Format("{0}.subquery",  ProjectResults.results[0].schema[0].name));

                    if (rslts.schema.Count > 0)
                    {
                        // parameters
                        json.WritePropertyName("parameters");
                        getParameterJsonStringArray(json, rslts.schema[0].parameters);

                        // paging
                        json.WritePropertyName("paging");

                        string pagingstring = JsonConvert.SerializeObject(rslts.schema[0].paging);
                        json.WriteRawValue(pagingstring);
                    }

                    // fields
                    json.WritePropertyName("fields");
                    getFieldJsonStringArray(json, (rslts.schema.Count > 0) ? rslts.schema[0].fields : ProjectResults.results[0].schema[0].fields);

                    // results
                    json.WritePropertyName("result");
                    getRowJsonStringArray(json, rslts.result, (rslts.schema.Count > 0) ? rslts.schema[0].fields : ProjectResults.results[0].schema[0].fields);
                    json.WriteEndObject();

                }
                json.WriteEndArray();
                json.WriteEndObject();

                json.Flush();
                sw.Flush();

                return sw.ToString();
            }
        private void WriteMessages(TextWriter writer, JsonTextWriter jsonWriter)
        {
            if (Messages == null)
            {
                return;
            }

            // If the writer is a binary writer then write to the underlying writer directly
            var binaryWriter = writer as IBinaryWriter;

            bool first = true;

            for (int i = 0; i < Messages.Count; i++)
            {
                ArraySegment<Message> segment = Messages[i];
                for (int j = segment.Offset; j < segment.Offset + segment.Count; j++)
                {
                    Message message = segment.Array[j];

                    if (!message.IsCommand && !_exclude(message))
                    {
                        if (binaryWriter != null)
                        {
                            if (!first)
                            {
                                // We need to write the array separator manually
                                writer.Write(',');
                            }

                            // If we can write binary then just write it
                            binaryWriter.Write(message.Value);

                            first = false;
                        }
                        else
                        {
                            // Write the raw JSON value
                            jsonWriter.WriteRawValue(message.GetString());
                        }
                    }
                }
            }
        }
Exemple #27
0
            public static void getRowJsonStringArray(JsonTextWriter json, result Result, List<field> fields)
            {
                json.WriteStartObject();
                json.WritePropertyName("row");

                json.WriteStartArray();

                foreach (row schemaRow in Result.row)
                {

                    json.WriteStartObject();

                    foreach (XmlAttribute att in schemaRow.AnyAttr)
                    {
                        json.WritePropertyName(att.Name);
                        var parm = fields.Find(p => p.name.Equals(att.Name));

                        // write value as is
                        if (parm == null)
                        {
                            json.WriteValue(att.Value.Trim());
                            continue;
                        }

                        // evaluate value for field type
                        switch(parm.type)
                        {
                            case fieldType.json:
                                json.WriteRawValue(att.Value);
                                break;
                            case fieldType.date:
                                var dt = new DateTime(1970, 1, 1);
                                DateTime.TryParse(att.Value, out dt);
                                if (dt.ToString("d").Equals("1/1/1970"))
                                    json.WriteValue(att.Value);
                                else
                                    json.WriteValue(dt.ToString("d"));
                                break;
                            case fieldType.datetime:
                                var dttime = new DateTime(1970, 1, 1);
                                DateTime.TryParse(att.Value, out dttime);
                                if (dttime.ToString("d").Equals("1/1/1970"))
                                    json.WriteValue(att.Value);
                                else
                                    json.WriteValue(dttime.ToString("r"));
                                break;
                            default:
                                json.WriteValue(att.Value.Trim());
                                break;
                        }

                    }

                    json.WriteEndObject();
                }

                json.WriteEndArray();
                json.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();

                writer.WriteEndObject();
            }

            _query = sb.ToString();
        }
Exemple #29
0
		protected override void WriteTransaction(JsonTextWriter writer, Transaction tx)
		{
			WritePropertyValue(writer, "txid", tx.GetHash().ToString());
			WritePropertyValue(writer, "version", tx.Version);
			WritePropertyValue(writer, "locktime", tx.LockTime.Value);

			writer.WritePropertyName("vin");
			writer.WriteStartArray();
			foreach(var txin in tx.Inputs)
			{
				writer.WriteStartObject();

				if(txin.PrevOut.Hash == uint256.Zero)
				{
					WritePropertyValue(writer, "coinbase", Encoders.Hex.EncodeData(txin.ScriptSig.ToBytes()));
				}
				else
				{
					WritePropertyValue(writer, "txid", txin.PrevOut.Hash.ToString());
					WritePropertyValue(writer, "vout", txin.PrevOut.N);
					writer.WritePropertyName("scriptSig");
					writer.WriteStartObject();

					WritePropertyValue(writer, "asm", txin.ScriptSig.ToString());
					WritePropertyValue(writer, "hex", Encoders.Hex.EncodeData(txin.ScriptSig.ToBytes()));

					writer.WriteEndObject();
				}
				WritePropertyValue(writer, "sequence", (uint)txin.Sequence);
				writer.WriteEndObject();
			}
			writer.WriteEndArray();

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

			int i = 0;
			foreach(var txout in tx.Outputs)
			{
				writer.WriteStartObject();
				writer.WritePropertyName("value");
				writer.WriteRawValue(ValueFromAmount(txout.Value));
				WritePropertyValue(writer, "n", i);

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

				WritePropertyValue(writer, "asm", txout.ScriptPubKey.ToString());
				WritePropertyValue(writer, "hex", Encoders.Hex.EncodeData(txout.ScriptPubKey.ToBytes()));

				var destinations = new List<TxDestination>() { txout.ScriptPubKey.GetDestination() };
				if(destinations[0] == null)
				{
					destinations = txout.ScriptPubKey.GetDestinationPublicKeys()
														.Select(p => p.Hash)
														.ToList<TxDestination>();
				}
				if(destinations.Count == 1)
				{
					WritePropertyValue(writer, "reqSigs", 1);
					WritePropertyValue(writer, "type", GetScriptType(txout.ScriptPubKey.FindTemplate()));
					writer.WritePropertyName("addresses");
					writer.WriteStartArray();
					writer.WriteValue(destinations[0].GetAddress(Network).ToString());
					writer.WriteEndArray();
				}
				else
				{
					var multi = PayToMultiSigTemplate.Instance.ExtractScriptPubKeyParameters(txout.ScriptPubKey);
					WritePropertyValue(writer, "reqSigs", multi.SignatureCount);
					WritePropertyValue(writer, "type", GetScriptType(txout.ScriptPubKey.FindTemplate()));
					writer.WriteStartArray();
					foreach(var key in multi.PubKeys)
					{
						writer.WriteValue(key.Hash.GetAddress(Network).ToString());
					}
					writer.WriteEndArray();
				}

				writer.WriteEndObject(); //endscript
				writer.WriteEndObject(); //in out
				i++;
			}
			writer.WriteEndArray();
		}
#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();
        }