コード例 #1
0
        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);
        }
コード例 #2
0
 public JsonProperty Visit(JsonField field)
 {
     return(CreateProperty(field, jsonProperty =>
     {
         jsonProperty.Type = JsonObjectType.Object;
     }));
 }
コード例 #3
0
        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()
            });
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 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();
         }
     }
 }
コード例 #6
0
 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) => { });
 }
コード例 #7
0
        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));
        }
コード例 #8
0
ファイル: JsonFieldTests.cs プロジェクト: ifle/squidex
        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);
        }
コード例 #9
0
        private static string GenerateFieldDeserializer(JsonField field)
        {
            return($@"
if ({GenerateFieldNameCondition(field)})
{{
	jsonReader.Read();
	{field.Name} = {DeserializationGenerator.Generate("jsonReader", field.Type)};
}}");
        }
コード例 #10
0
        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);
        }
コード例 #11
0
    public void Add(JsonField jsonfield)
    {
        LinkedListNode <JsonField> jsonelement = jsonlinking.Last;

        if (jsonelement != null)
        {
            jsonelement.Value.SpecialChar = ",";
        }
        jsonlinking.AddLast(jsonfield);
    }
コード例 #12
0
ファイル: JsonFieldTests.cs プロジェクト: ifle/squidex
        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." });
        }
コード例 #13
0
        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); });
        }
コード例 #14
0
 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) => { });
 }
コード例 #15
0
        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); });
        }
コード例 #16
0
    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;
            }
        }
    }
コード例 #17
0
 partial void Value_SetCondition(ref JsonField instance, ref Object setValue);
コード例 #18
0
 partial void ToString_PreCondition(JsonField instance);
コード例 #19
0
 partial void ToString_PostValidate(JsonField instance, String _retVal);
コード例 #20
0
 partial void ReferenceName_SetCondition(ref JsonField instance, ref String setValue);
コード例 #21
0
 partial void JsonValue_SetCondition(ref JsonField instance, ref JToken setValue);
コード例 #22
0
 static partial void InstanceFactory(ref JsonField instance, [CallerMemberName] string callerName = "");
コード例 #23
0
 partial void FieldDefinition_SetCondition(ref JsonField instance, ref JsonFieldDefinition setValue);
コード例 #24
0
 partial void GetType_PostValidate(JsonField instance, Type _retVal);
コード例 #25
0
 partial void GetHashCode_PreCondition(JsonField instance);
コード例 #26
0
 partial void GetHashCode_PostValidate(JsonField instance, Int32 _retVal);
コード例 #27
0
 partial void FromToken_PreCondition(JsonField instance, ref JToken token);
コード例 #28
0
 partial void GetType_PreCondition(JsonField instance);
コード例 #29
0
 partial void FromToken_PostValidate(JsonField instance, JToken token, JsonField _retVal);
コード例 #30
0
 partial void Equals_PreCondition(JsonField instance, ref Object obj);