private List <JsonField> AddEmptyFieldsAndArrays(ProtoParsedMessage protoParsedMessage) { var listOfData = new List <JsonField>(); listOfData.AddRange(GetFieldsFromProtoMessage(protoParsedMessage)); foreach (var message in protoParsedMessage.Messages) { var tempJsonModel = new JsonField { Name = message.Name, IsVisible = true, DataType = "array" }; if (message.IsRepeated) { tempJsonModel.Arrays.Add(AddEmptyFieldsAndArrays(message)); } else { tempJsonModel.Fields.AddRange(AddEmptyFieldsAndArrays(message)); } listOfData.Add(tempJsonModel); } // fix the indexes FixIndex(listOfData); return(listOfData); }
public JsonProperty Visit(JsonField field) { return(CreateProperty(field, jsonProperty => { jsonProperty.Type = JsonObjectType.Object; })); }
private JsonLayer Layer(IServiceMap map, int layerId) { var datasetElement = map.MapElements.Where(e => e.ID == layerId).FirstOrDefault(); if (datasetElement == null) { throw new Exception("Unknown layer: " + layerId); } var tocElement = map.TOC.GetTOCElement(datasetElement as ILayer); JsonField[] fields = new JsonField[0]; if (datasetElement.Class is ITableClass) { fields = ((ITableClass)datasetElement.Class).Fields.ToEnumerable().Select(f => { return(new JsonField() { Name = f.name, Alias = f.aliasname, Type = JsonField.ToType(f.type).ToString() }); }).ToArray(); } JsonExtent extent = null; if (datasetElement.Class is IFeatureClass && ((IFeatureClass)datasetElement.Class).Envelope != null) { extent = new JsonExtent() { // DoTo: SpatialReference Xmin = ((IFeatureClass)datasetElement.Class).Envelope.minx, Ymin = ((IFeatureClass)datasetElement.Class).Envelope.miny, Xmax = ((IFeatureClass)datasetElement.Class).Envelope.maxx, Ymax = ((IFeatureClass)datasetElement.Class).Envelope.maxy }; } string type = "Feature Layer"; if (datasetElement.Class is IRasterClass) { type = "Raster Layer"; } return(new JsonLayer() { CurrentVersion = Version, Id = datasetElement.ID, Name = tocElement != null ? tocElement.Name : datasetElement.Title, DefaultVisibility = tocElement != null ? tocElement.LayerVisible : true, MaxScale = tocElement != null && tocElement.Layers.Count() > 0 ? Math.Max(tocElement.Layers[0].MinimumScale > 1 ? tocElement.Layers[0].MinimumScale : 0, 0) : 0, MinScale = tocElement != null && tocElement.Layers.Count() > 0 ? Math.Max(tocElement.Layers[0].MaximumScale > 1 ? tocElement.Layers[0].MaximumScale : 0, 0) : 0, Fields = fields, Extent = extent, Type = type, GeometryType = datasetElement.Class is IFeatureClass?JsonLayer.ToGeometryType(((IFeatureClass)datasetElement.Class).GeometryType).ToString() : EsriGeometryType.esriGeometryNull.ToString() }); }
private static IEnumerable <JsonField> GetFieldsFromProtoMessage(ProtoParsedMessage protoParsedMessage) { EnsureArg.IsNotNull(protoParsedMessage); var list = new List <JsonField>(); foreach (var field in protoParsedMessage.Fields) { var clonedField = field.Copy(); var jsonField = new JsonField() { Name = clonedField.Name, Value = clonedField.IsRepeated ? new List <object>() { clonedField.DefaultValue } : clonedField.Value, Min = clonedField.Min, Max = clonedField.Max, DataType = clonedField.DataType, DefaultValue = clonedField.DefaultValue, IsVisible = false, IsRepeated = clonedField.IsRepeated, IsFieldRepeated = clonedField.IsRepeated }; list.Add(jsonField); } return(list); }
private void ReadJson(JsonField field) { if (field != null) { jsonformat += @""""; jsonformat += field.Name; jsonformat += @""""; if (field.isContainer) { jsonformat += @":{" + Environment.NewLine; int count = field.ChildNodes.Count(); if (count > 0) { foreach (var item in field.ChildNodes) { ReadJson(item); } } jsonformat = (jsonformat.Substring(jsonformat.Length - 1, 1) == ",") ? jsonformat.Substring(0, jsonformat.Length - 1) : jsonformat; jsonformat += @"}" + field.SpecialChar + Environment.NewLine; } else { jsonformat += @":"; jsonformat += field.GetValues(); } } }
public void Value_UnitTest() { ExecuteProperty( () => // Create Test Instance { JsonField instance = GetInstance(); return(instance); }, // Create Set Value instance => { object setValue = default(Object); Value_SetCondition(ref instance, ref setValue); return(setValue); }, // Invoke Setter (instance, setValue) => { instance.Value = setValue; }, // Validate Set Operation (instance, setValue) => { }, // Invoke Getter instance => { return(instance.Value); }, // Validate Get Operation (instance, setValue, getValue) => { }); }
public void Should_get_default_value_from_json_field() { var field = new JsonField(1, "1", Partitioning.Invariant, new JsonFieldProperties()); Assert.Equal(new JObject(), DefaultValueFactory.CreateDefaultValue(field, Now)); }
public async Task Should_not_add_error_if_json_is_valid() { var sut = new JsonField(1, "my-json", Partitioning.Invariant); await sut.ValidateAsync(CreateValue(new JValue(1)), errors); Assert.Empty(errors); }
private static string GenerateFieldDeserializer(JsonField field) { return($@" if ({GenerateFieldNameCondition(field)}) {{ jsonReader.Read(); {field.Name} = {DeserializationGenerator.Generate("jsonReader", field.Type)}; }}"); }
internal static JsonField GetInstance([CallerMemberName] string callerName = "") { JToken json = new JObject(); JsonSource(ref json); JsonField instance = JsonField.FromToken(json); InstanceFactory(ref instance, callerName); return(instance); }
public void Add(JsonField jsonfield) { LinkedListNode <JsonField> jsonelement = jsonlinking.Last; if (jsonelement != null) { jsonelement.Value.SpecialChar = ","; } jsonlinking.AddLast(jsonfield); }
public async Task Should_add_errors_if_json_is_required() { var sut = new JsonField(1, "my-json", Partitioning.Invariant, new JsonFieldProperties { IsRequired = true }); await sut.ValidateAsync(CreateValue(JValue.CreateNull()), errors); errors.ShouldBeEquivalentTo( new[] { "<FIELD> is required." }); }
public void FromToken_UnitTest() { JToken token = default(JToken); JsonField _retVal = default(JsonField); ExecuteMethod( () => { return(GetInstance()); }, instance => { token = default(JToken); //No Constructor FromToken_PreCondition(instance, ref token); }, instance => { return(_retVal = JsonField.FromToken(token)); }, instance => { FromToken_PostValidate(instance, token, _retVal); }); }
public void FieldDefinition_UnitTest() { ExecuteProperty( () => // Create Test Instance { JsonField instance = GetInstance(); return(instance); }, null, null, null, // No Set Accessor // Invoke Getter instance => { return(instance.FieldDefinition); }, // Validate Get Operation (instance, setValue, getValue) => { }); }
public void TryGetField_UnitTest() { String fieldName = default(String); JsonField fieldValue = default(JsonField); Boolean _retVal = default(Boolean); ExecuteMethod( () => { return(GetInstance()); }, instance => { fieldName = default(String); //No Constructor TryGetField_PreCondition(instance, ref fieldName, ref fieldValue); }, instance => { return(_retVal = instance.TryGetField(fieldName, out fieldValue)); }, instance => { TryGetField_PostValidate(instance, fieldName, fieldValue, _retVal); }); }
public static void MapField(Queue <JsonField> linksource) { JsonField primary = null; JsonField relative = null; foreach (var item in linksource) { if (primary == null) { primary = item; } else if (relative == null) { relative = null; } else { JsonConverter.MapField(primary, relative); primary = null; relative = null; } } }
partial void Value_SetCondition(ref JsonField instance, ref Object setValue);
partial void ToString_PreCondition(JsonField instance);
partial void ToString_PostValidate(JsonField instance, String _retVal);
partial void ReferenceName_SetCondition(ref JsonField instance, ref String setValue);
partial void JsonValue_SetCondition(ref JsonField instance, ref JToken setValue);
static partial void InstanceFactory(ref JsonField instance, [CallerMemberName] string callerName = "");
partial void FieldDefinition_SetCondition(ref JsonField instance, ref JsonFieldDefinition setValue);
partial void GetType_PostValidate(JsonField instance, Type _retVal);
partial void GetHashCode_PreCondition(JsonField instance);
partial void GetHashCode_PostValidate(JsonField instance, Int32 _retVal);
partial void FromToken_PreCondition(JsonField instance, ref JToken token);
partial void GetType_PreCondition(JsonField instance);
partial void FromToken_PostValidate(JsonField instance, JToken token, JsonField _retVal);
partial void Equals_PreCondition(JsonField instance, ref Object obj);