internal virtual void ToJson(JsonWriter jw) { Dictionary<string, object> dictionary = new Dictionary<string, object>(); AddToJsonDictionary(ref dictionary); jw.StartObject(); bool wroteFirst = false; #region serialize dictionary foreach (KeyValuePair<string, object> item in dictionary) { if (wroteFirst) jw.Writer.Write(","); else wroteFirst = true; if (item.Key == "defaultValue") { if (item.Value is ESRI.ArcGIS.Client.Tasks.GPLinearUnit) { ESRI.ArcGIS.Client.Tasks.GPLinearUnit linearUnit = item.Value as ESRI.ArcGIS.Client.Tasks.GPLinearUnit; jw.StartProperty("defaultValue"); jw.StartObject(); jw.WriteProperty("distance", linearUnit.Distance); jw.Writer.Write(","); jw.WriteProperty("units", linearUnit.Unit); jw.EndObject(); } else if (item.Value is ESRI.ArcGIS.Client.Tasks.GPRasterData) { ESRI.ArcGIS.Client.Tasks.GPRasterData raster = item.Value as ESRI.ArcGIS.Client.Tasks.GPRasterData; jw.StartProperty("defaultValue"); jw.StartObject(); jw.WriteProperty("url", raster.Url); jw.Writer.Write(","); jw.WriteProperty("format", raster.Format); jw.EndObject(); } else jw.WriteProperty(item.Key, item.Value, false); } else jw.WriteProperty(item.Key, item.Value, false); } #endregion #region Choice List if (ChoiceList != null && ChoiceList.Count > 0) { jw.Writer.Write(","); jw.StartProperty("choiceList"); jw.StartArray(); wroteFirst = false; foreach (Choice item in ChoiceList) { if (item != null) { if (!wroteFirst) wroteFirst = true; else jw.Writer.Write(","); item.ToJson(jw); } } jw.EndArray(); } #endregion jw.EndObject(); }
public string ToJson() { StringBuilder sb = new StringBuilder(); JsonWriter jw = new JsonWriter(new StringWriter(sb)); jw.StartObject(); jw.WriteProperty("taskEndPoint", TaskEndPoint.ToString()); jw.Writer.Write(","); if (!string.IsNullOrEmpty(Title)) { jw.WriteProperty("title", Title.ToString()); jw.Writer.Write(","); } if (!string.IsNullOrEmpty(TaskName)) { jw.WriteProperty("taskName", TaskName.ToString()); jw.Writer.Write(","); } if (HelpUrl != null) { jw.WriteProperty("helpUrl", HelpUrl.ToString()); jw.Writer.Write(","); } jw.WriteProperty("useProxy", UseProxy.ToString()); jw.Writer.Write(","); jw.StartProperty("inputParameters"); jw.StartArray(); bool wroteFirst = false; foreach (ParameterSupport.ParameterConfig config in InputParameters) { if (config == null) continue; if (wroteFirst) jw.Writer.Write(","); else wroteFirst = true; config.ToJson(jw); } jw.EndArray(); jw.Writer.Write(","); jw.StartProperty("outputParameters"); jw.StartArray(); wroteFirst = false; foreach (ParameterSupport.ParameterConfig config in OutputParameters) { if (config == null) continue; if (wroteFirst) jw.Writer.Write(","); else wroteFirst = true; config.ToJson(jw); } jw.EndArray(); if (LayerOrder != null) { jw.Writer.Write(","); jw.StartProperty("layerOrder"); jw.StartArray(); wroteFirst = false; foreach (string layer in LayerOrder) { if (string.IsNullOrEmpty(layer)) continue; if (wroteFirst) jw.Writer.Write(","); else wroteFirst = true; jw.Writer.Write(string.Format("\"{0}\"", layer)); } jw.EndArray(); } jw.EndObject(); return sb.ToString(); }