Exemplo n.º 1
0
        internal static void Serialize(ObjectProperty prop, Dictionary<string, object> fieldDict)
        {
            if (prop == null)
                return;

            if (fieldDict == null)
                fieldDict = new Dictionary<string, object>();

            fieldDict.AddObject(_TYPE, prop.PropertyType.ToString(), _PROPERTY_TYPE_DEFAULT.ToString());
            fieldDict.AddObject(_INCLUDE_IN_ALL, prop.IncludeInAll, _INCLUDE_IN_ALL_DEFAULT);
            fieldDict.AddObject(_IS_ENABLED, prop.IsEnabled, _IS_ENABLED_DEFAULT);
            fieldDict.AddObject(_DYNAMIC, prop.Dynamic.RealValue, _DYNAMIC_DEFAULT.RealValue);

            if (prop.CopyTo != null && prop.CopyTo.Any(x => !string.IsNullOrWhiteSpace(x)))
            {
                int count = prop.CopyTo.Count(x => !string.IsNullOrWhiteSpace(x));

                if (count > 1)
                    fieldDict.AddObject(_COPY_TO, prop.CopyTo.Where(x => !string.IsNullOrWhiteSpace(x)));
                else
                    fieldDict.AddObject(_COPY_TO, prop.CopyTo.First(x => !string.IsNullOrWhiteSpace(x)));
            }

            if(prop.Properties != null && prop.Properties.Any(x => x != null))
                fieldDict.AddObject(_PROPERTIES, new DocumentPropertyCollection(prop.Properties));
        }
Exemplo n.º 2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (!(value is TypeMapping))
                throw new SerializeTypeException<TypeMapping>();

            TypeMapping prop = value as TypeMapping;

            Dictionary<string, object> fieldDict = new Dictionary<string, object>();
            DocumentMapping.Serialize(prop.Fields, fieldDict);
            PropertyAnalyzer.Serialize(prop.Analyzer, fieldDict);
            fieldDict.AddObject(TypeMapping.DETECT_DATES, prop.DetectDates, TypeMapping._DETECT_DATES_DEFAULT);
            fieldDict.AddObject(TypeMapping.DETECT_NUMBERS, prop.DetectNumbers, TypeMapping._DETECT_NUMBERS_DEFAULT);
            if (prop.DynamicDateFormats != null && prop.DynamicDateFormats.Any(x => x != null))
                fieldDict.Add(TypeMapping.DYNAMIC_DATE_FORMATS, prop.DynamicDateFormats.Where(x => x != null));
            if (prop.DynamicTemplates != null && prop.DynamicTemplates.Any(x => x != null))
                fieldDict.Add(TypeMapping.DYNAMIC_TEMPLATES, prop.DynamicTemplates.Where(x => x != null));
            
            ObjectProperty objProp = new ObjectProperty(prop.Name)
            {
                //CopyTo = prop.CopyTo,
                Dynamic = prop.Dynamic,
                IncludeInAll = prop.IncludeInAll,
                IsEnabled = prop.IsEnabled,
                Properties = prop.Properties
            };
            ObjectProperty.Serialize(objProp, fieldDict);

            if (prop.MetaData != null && prop.MetaData.Any())
                fieldDict.Add(TypeMapping.META, prop.MetaData);

            Dictionary<string, object> propDict = new Dictionary<string,object>();
            propDict.Add(prop.Name, fieldDict);

            serializer.Serialize(writer, propDict);
        }
Exemplo n.º 3
0
 internal DefaultMapping(ObjectProperty prop)
 {
     this.CopyTo = prop.CopyTo;
     this.Dynamic = prop.Dynamic;
     this.IncludeInAll = prop.IncludeInAll;
     this.IsEnabled = prop.IsEnabled;
 }
Exemplo n.º 4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> propDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(propDict.First().Value.ToString());

            ObjectProperty objProp = new ObjectProperty(propDict.First().Key);
            ObjectProperty.Deserialize(objProp, fieldDict);

            TypeMapping prop = new TypeMapping(objProp);
            prop.Fields = DocumentMapping.Deserialize(fieldDict);
            prop.Analyzer = PropertyAnalyzer.Deserialize(fieldDict);
            prop.DetectDates = fieldDict.GetBool(TypeMapping.DETECT_DATES, TypeMapping._DETECT_DATES_DEFAULT);
            prop.DetectNumbers = fieldDict.GetBool(TypeMapping.DETECT_NUMBERS, TypeMapping._DETECT_NUMBERS_DEFAULT);
            if (fieldDict.ContainsKey(TypeMapping.DYNAMIC_DATE_FORMATS))
            {
                prop.DynamicDateFormats = JsonConvert.DeserializeObject<IEnumerable<DateFormat>>(fieldDict.GetString(TypeMapping.DYNAMIC_DATE_FORMATS));
            }
            if (fieldDict.ContainsKey(TypeMapping.DYNAMIC_TEMPLATES))
            {
                prop.DynamicTemplates = JsonConvert.DeserializeObject<IEnumerable<DynamicTemplate>>(fieldDict.GetString(TypeMapping.DYNAMIC_TEMPLATES));
            }
            if (fieldDict.ContainsKey(TypeMapping.META))
            {
                prop.MetaData = JsonConvert.DeserializeObject<Dictionary<string, object>>(fieldDict.GetString(TypeMapping.META));
            }
            return prop;
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Dictionary<string, object> propDict = serializer.Deserialize<Dictionary<string, object>>(reader);
            Dictionary<string, object> fieldDict = JsonConvert.DeserializeObject<Dictionary<string, object>>(propDict.First().Value.ToString());

            ObjectProperty prop = new ObjectProperty(propDict.First().Key);
            ObjectProperty.Deserialize(prop, fieldDict);

            return prop;
        }
        public void PASS_Serialize()
        {
            ObjectProperty prop = new ObjectProperty("subobj")
            {
                Properties = new List<IDocumentProperty>() 
                { 
                    new StringProperty("title")
                }
            };

            string json = JsonConvert.SerializeObject(prop);
            Assert.IsNotNull(json);

            string expectedJson = "{\"subobj\":{\"properties\":{\"title\":{\"type\":\"string\"}}}}";
            Assert.AreEqual(expectedJson, json);
        }
        public void PASS_Create()
        {
            ObjectProperty prop = new ObjectProperty("subobj")
            {
                Properties = new List<IDocumentProperty>() 
                { 
                    new StringProperty("title")
                }
            };

            Assert.IsNotNull(prop);
            Assert.AreEqual("subobj", prop.Name);
            Assert.AreEqual((int)1, prop.Properties.Count());
            Assert.IsTrue(prop.Properties.First() is StringProperty);
            Assert.AreEqual("title", prop.Properties.First().Name);
        }
Exemplo n.º 8
0
        internal static void Deserialize(ObjectProperty prop, Dictionary<string, object> fieldDict)
        {
            if (fieldDict == null || !fieldDict.Any())
                return;

            if (fieldDict.ContainsKey(_COPY_TO))
            {
                try
                {
                    prop.CopyTo = JsonConvert.DeserializeObject<IEnumerable<string>>(fieldDict.GetString(_COPY_TO));
                }
                catch
                {
                    prop.CopyTo = new List<string>() { fieldDict.GetString(_COPY_TO) };
                }
            }

            prop.Dynamic = DynamicSettingEnum.Find(fieldDict.GetString(_DYNAMIC, _DYNAMIC_DEFAULT.ToString()));
            prop.IncludeInAll = fieldDict.GetBool(_INCLUDE_IN_ALL, _INCLUDE_IN_ALL_DEFAULT);
            prop.IsEnabled = fieldDict.GetBool(_IS_ENABLED, _IS_ENABLED_DEFAULT);

            if (fieldDict.ContainsKey(_PROPERTIES))
            {
                prop.Properties = JsonConvert.DeserializeObject<DocumentPropertyCollection>(fieldDict.GetString(_PROPERTIES));
            }
        }
Exemplo n.º 9
0
 internal TypeMapping(ObjectProperty prop)
 {
     this.Name = prop.Name;
     this.Dynamic = prop.Dynamic;
     this.IncludeInAll = prop.IncludeInAll;
     this.IsEnabled = prop.IsEnabled;
     this.Properties = prop.Properties;
 }