/// <summary>
 /// The validate values.
 /// </summary>
 /// <param name="controls">
 /// The controls.
 /// </param>
 /// <param name="data">
 /// The data.
 /// </param>
 /// <param name="errorList">
 /// The errorList.
 /// </param>
 private static void ValidateValues(JArray controls, JObject data, List<ValidationError> errorList)
 {
     foreach (JObject child in controls.OfType<JObject>())
     {
         IDynamicControl control = BaseControl.CreateControl(child);
         IDynamicValueControl valueControl = control as IDynamicValueControl;
         JProperty dataValue = null;
         if (valueControl != null)
         {
             dataValue = data.Children<JProperty>().FirstOrDefault(p => p.Name == child.Value<string>("name"));
             if (dataValue != null)
             {
                 JObject dataObject = dataValue.First as JObject;
                 if (dataObject != null)
                 {
                     JObject roles = child["checkedRoles"] as JObject;
                     if (roles != null)
                     {
                         if (roles.Value<bool>("required") && string.IsNullOrEmpty(dataObject.Value<string>("value")))
                         {
                             errorList.Add(new RequiredDataError(child.Value<string>("name")));
                         }
                     }
                     dataObject.Add(new JProperty("checked", true));
                 }
             }
             else
             {
                 errorList.Add(new MissingDataError(child.Value<string>("name")));
             }
         }
         IDynamicParentControl parentControl = control as IDynamicParentControl;
         if (parentControl != null)
         {
             JArray children = child.Value<JArray>("childs");
             if (children != null)
             {
                 JObject anyChildren = children.OfType<JObject>().FirstOrDefault(c => c.Value<string>("key") == "any");
                 if (anyChildren != null)
                 {
                     ValidateValues(anyChildren.Value<JArray>("controls"), data, errorList);
                 }
                 if (valueControl != null && dataValue != null)
                 {
                     JObject valueChildren = children.OfType<JObject>().FirstOrDefault(c => c.Value<string>("key") == dataValue.First.Value<string>("value"));
                     if (valueChildren != null)
                     {
                         ValidateValues(valueChildren.Value<JArray>("controls"), data, errorList);
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
        private static Lut ConvertToValues(JArray obj) {
            var values = new Lut();
            if (obj == null) return values;

            foreach (var entry in obj.OfType<JArray>()) {
                double x, y;
                if (FlexibleParser.TryParseDouble(Convert.ToString(entry[0], CultureInfo.InvariantCulture), out x) &&
                        FlexibleParser.TryParseDouble(Convert.ToString(entry[1], CultureInfo.InvariantCulture), out y)) {
                    values.Add(new LutPoint(x, y));
                }
            }

            return values;
        }
        public void SetCalculatedData(JArray calculatedData)
        {
            //.Where(p=>!((new int[]{5,3}).Contains((int)p["ParameterType"])))
            OutputParameters = calculatedData.OfType<JObject>().Where(ShowOutputParameter).Select(p => new EffectsOutputParameterViewModel() {Data = p});

            Contours = new GraphicCollection(calculatedData.OfType<JObject>().Where(IsContourParameter).Select(p=>((string)p["Data"]["Value"]).ToGraphic(new SpatialReference(28992), new SpatialReference(28992))));
        }
 public void SetModelData(JArray modelData)
 {
     Models.Clear();
     foreach (
         var model in modelData.OfType<JObject>().Select(model => new ModelSelectionViewModel() {Data = model}))
     {
         Models.Add(model);
     }
 }
        internal IDictionary<string, Column> GetColumnsFromItems(JArray items)
        {
            Contract.Requires(items != null, "item cannot be null");

            IDictionary<string, Column> cols = new Dictionary<string, Column>();

            IEnumerator<IDictionary<string, JToken>> objects = items.OfType<IDictionary<string, JToken>>().GetEnumerator();
            objects.MoveNext();
            ICollection<string> columnsToDetermine = objects.Current.Keys;

            do
            {
                IList<string> nullColumns = new List<string>();
                foreach (var key in columnsToDetermine)
                {
                    JToken token;
                    if(defaultColumns.ContainsKey(key))
                    {
                        cols.Add(key, defaultColumns[key]);
                    }
                    else if (objects.Current.TryGetValue(key, out token))
                    {
                        JValue val = token as JValue;
                        if (val != null)
                        {
                            if (val.Value == null)
                            {
                                nullColumns.Add(key);
                            }
                            else
                            {
                                cols.Add(key, new Column(key, ColumnTypeHelper.GetColumnTypeForClrType(val.Value.GetType()), true));
                            }
                        }
                    }
                }
                columnsToDetermine = nullColumns;
            }
            while (columnsToDetermine.Count > 0 && objects.MoveNext());

            return cols;
        }
        private static void RemoveArrayElements(JArray array, string currentPath, Func<string, bool> shouldSerialize, Dictionary<string, bool> cache)
        {
            array.OfType<JObject>()
                .ToList()
                .ForEach(childObject => RemoveObjectProperties(childObject, currentPath, shouldSerialize, cache));

            RemoveArrayIfEmpty(array);
        }