public static void Replace(this JProperty oldProperty, string newPropertyName, string newPropertyValue)
 {
     if (String.Equals(oldProperty.Name.ToLower(), newPropertyName.ToLower()))
     {
         oldProperty.Value = newPropertyValue;
         return;
     }
     oldProperty.AddAfterSelf(new JProperty(newPropertyName, newPropertyValue));
     oldProperty.Remove();
 }
Ejemplo n.º 2
0
        public void ChangeName(string oldName, string newName)
        {
            JArray ja_views = ElementJson ["Views"] as JArray;

            for (int i = 0; i < ja_views.Count; i++)
            {
                JObject   jo_view         = ja_views [i] as JObject;
                JObject   jo_view_members = jo_view ["Members"] as JObject;
                JProperty jp = jo_view_members.Property(oldName);
                jp.AddAfterSelf(new JProperty(newName, jp.Value));
                jp.Remove();
            }
        }
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        Document doc = (Document)value;
        // Create a JObject from the document, respecting existing JSON attribs
        JObject jo = JObject.FromObject(value);
        // At this point the DocTypeIdentifier is not serialized correctly.
        // Fix it by replacing the property with the correct name and value.
        JProperty prop = jo.Children <JProperty>()
                         .Where(p => p.Name == "DocTypeIdentifier")
                         .First();

        prop.AddAfterSelf(new JProperty(doc.DocTypeIdentifier.ParameterName,
                                        doc.DocTypeIdentifier.Value));
        prop.Remove();
        // Write out the JSON
        jo.WriteTo(writer);
    }
Ejemplo n.º 4
0
        public static JObject GetOrAddProperty(this JObject root, string propertyName, JProperty insertAfter)
        {
            var newProperty = (JObject)root[propertyName];

            if (newProperty == null)
            {
                newProperty = new JObject();
                var property = new JProperty(propertyName, newProperty);
                if (insertAfter != null)
                {
                    insertAfter.AddAfterSelf(property);
                }
                else
                {
                    root.Add(property);
                }
            }

            return(newProperty);
        }
Ejemplo n.º 5
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            IList <PluginDynamic> dynamicProperties = (IList <PluginDynamic>)value;

            // Create a JObject from the document, respecting existing JSON attribs
            JArray jObject = JArray.FromObject(value);

            // Replace the incorrectly serialized PluginDynamic List with all required objects
            JProperty jProperty = jObject.Children <JProperty>()
                                  .Where(p => p.Name == "pluginDynamic")
                                  .First();

            foreach (PluginDynamic dynamicProperty in dynamicProperties)
            {
                jProperty.AddAfterSelf(new JProperty(dynamicProperty.PropertyName, dynamicProperty.PropertyValue));
            }

            jProperty.Remove();

            // Write out the JSON
            jObject.WriteTo(writer);
        }
Ejemplo n.º 6
0
        public static void AddAfterSelf(this JProperty property, CatalogType catalogType, ICatalogClient catalogClient)
        {
            var resultQuery = catalogClient.GetValue(catalogType, property.Value.ToString());

            property.AddAfterSelf(new JProperty($"{property.Name}Descripcion", resultQuery.DESCRIPCION));
        }
Ejemplo n.º 7
0
        public static void AddAfterSelf(this JProperty property, ICatalogClient catalogClient, CatalogType catalogType, string propertyName)
        {
            var resultQuery = catalogClient.GetValue(catalogType, property.Value.ToString());

            property.AddAfterSelf(new JProperty(propertyName, resultQuery.DESCRIPCION));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Changing the property name to a dynamic name of the variables of the class "Last"
        /// if the attribute  is null the property will be removed in the JObject
        /// </summary>
        /// <param name="jo">JObject to write the properties</param>
        /// <param name="elem">Element where the properties should be changed</param>
        private void setPropertiesLast(JObject jo, Last elem)
        {
            JProperty prop = jo.Children <JProperty>()
                             .Where(p => p.Name == "strahlung_")
                             .First();

            if (elem.Strahlung != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Strahlung.Name_id,
                                                elem.Strahlung.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "strahlung2_")
                   .First();
            if (elem.Strahlung2 != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Strahlung2.Name_id,
                                                elem.Strahlung2.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "temp_")
                   .First();
            if (elem.Temperatur != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Temperatur.Name_id,
                                                elem.Temperatur.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "rlt_")
                   .First();
            if (elem.Raumlueftung != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Raumlueftung.Name_id,
                                                elem.Raumlueftung.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "infiltration_")
                   .First();
            if (elem.Infiltration != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Infiltration.Name_id,
                                                elem.Infiltration.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "ilastGer_")
                   .First();
            if (elem.IlastenGeraete != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.IlastenGeraete.Name_id,
                                                elem.IlastenGeraete.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "ilastPer_")
                   .First();
            if (elem.IlastenPersonen != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.IlastenPersonen.Name_id,
                                                elem.IlastenPersonen.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "lueftungsliste_")
                   .First();
            if (elem.Lueftung != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Lueftung.Name_id,
                                                elem.Lueftung.Value));
            }
            prop.Remove();
            prop = jo.Children <JProperty>()
                   .Where(p => p.Name == "wwbVol_")
                   .First();
            if (elem.Warmwasseverbrauch != null)
            {
                prop.AddAfterSelf(new JProperty(prop.Name + elem.Warmwasseverbrauch.Name_id,
                                                elem.Warmwasseverbrauch.Value));
            }
            prop.Remove();
        }