public override string ToJson()
        {
            if (!base.IsIncluded && base.IsOptional)
            {
                return("");
            }

            StringBuilder sb = new StringBuilder();

            foreach (UIElement uc in Controls)
            {
                if (!(uc is DMControl))
                {
                    continue;
                }

                DMControl dmControl   = (DMControl)uc;
                string    controlJson = dmControl.ToJson();

                if (!String.IsNullOrEmpty(controlJson))
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(",\n");
                    }
                    sb.Append(controlJson);
                }
            }

            StringBuilder asb = new StringBuilder();

            if (PropertyName.Length > 0)
            {
                asb.Append("\"" + PropertyName + "\" : ");
                asb.Append("{\n");
                asb.Append(sb.ToString());
                asb.Append("}\n");
            }
            else
            {
                asb.Append(sb.ToString());
            }

            return(asb.ToString());
        }
Пример #2
0
        public void FromJsonObject(JToken json)
        {
            if (json is JObject)
            {
                JObject jObject = (JObject)json;

                foreach (UIElement uc in PropertiesCollection)
                {
                    if (!(uc is DMControl))
                    {
                        continue;
                    }

                    DMControl dmControl = (DMControl)uc;
                    JProperty property  = jObject.Property(dmControl.PropertyName);
                    dmControl.PropertyValue = (property != null) ? (string)property.Value : DMJSonConstants.NotFoundString;
                }
            }
            else if (json is JValue)
            {
                JValue jValue = (JValue)json;
                string value  = (string)jValue.Value;
                if (value == DMJSonConstants.NoReportString)
                {
                    foreach (UIElement uc in PropertiesCollection)
                    {
                        if (!(uc is DMControl))
                        {
                            continue;
                        }

                        DMControl dmControl = (DMControl)uc;
                        dmControl.PropertyValue = DMJSonConstants.NAString;
                    }
                }
            }
        }
Пример #3
0
        public virtual string ToJsonString()
        {
            bool useShortForm = true;

            StringBuilder json = new StringBuilder();

            json.Append("\"" + SectionName + "\" : ");

            if (ApplyProperties)
            {
                StringBuilder propertiesString = new StringBuilder();
                foreach (UIElement uc in PropertiesCollection)
                {
                    if (!(uc is DMControl))
                    {
                        continue;
                    }

                    DMControl dmControl   = (DMControl)uc;
                    string    controlJson = dmControl.ToJson();

                    if (!String.IsNullOrEmpty(controlJson))
                    {
                        if (propertiesString.Length > 0)
                        {
                            propertiesString.Append(",\n");
                        }
                        propertiesString.Append(controlJson);
                    }
                }

                if (propertiesString.Length > 0)
                {
                    json.Append("{\n");
                    json.Append("    \"" + DMJSonConstants.ApplyPropertiesString + "\" : ");
                    json.Append("{\n" + propertiesString.ToString() + "\n},");
                    json.Append("    \"" + DMJSonConstants.ReportPropertiesString + "\" : ");
                    if (ReportProperties)
                    {
                        json.Append("\"" + DMJSonConstants.YesString + "\"\n");
                    }
                    else
                    {
                        json.Append("\"" + DMJSonConstants.NoString + "\"\n");
                    }
                    json.Append("}");
                    useShortForm = false;
                }
            }

            if (useShortForm)
            {
                // This means applyProperties is either "no" or empty.
                if (ReportProperties)
                {
                    json.Append("\"" + DMJSonConstants.NoApplyYesReportString + "\"");
                }
                else
                {
                    json.Append("\"" + DMJSonConstants.NoApplyNoReportString + "\"");
                }
            }

            return(json.ToString());
        }