Beispiel #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JToken t     = JObject.ReadFrom(reader);
            string type  = ((FunctionType)t["Type"].Value <int>()).ToString();
            string value = t["Val"].Value <string>();

            return(ValueUtilities.CreateValue(type, value));
        }
Beispiel #2
0
        public void ReadAndSetInputValues(OperatorPart opPart, JToken jsonOpPart)
        {
            opPart.Name = jsonOpPart["Name"].Value <string>();
            if (opPart.ID != Guid.Parse(jsonOpPart["ID"].Value <string>()))
            {
                throw new System.Exception("Wrong op part id in file");
            }

            string type  = jsonOpPart["Type"].Value <string>();
            string value = jsonOpPart["Value"].Value <string>();

            opPart.Func = Utilities.CreateValueFunction(ValueUtilities.CreateValue(type, value));
        }
Beispiel #3
0
        private MetaInput BuildMetaInput(MetaManager metaManager, JToken jsonInput)
        {
            var metaInstanceID = Guid.Parse(jsonInput["MetaInstanceID"].Value <string>());
            var name           = jsonInput["Name"].Value <string>();
            var metaIDOfOpPart = Guid.Parse(jsonInput["MetaID"].Value <string>());
            var opPart         = metaManager.GetMetaOperatorPart(metaIDOfOpPart);

            // read default value - can be multi line value
            var defaultValueString = string.Empty;
            var defaultValueEntry  = jsonInput["DefaultValue"]["Value"];

            if (defaultValueEntry is JValue)
            {
                defaultValueString = defaultValueEntry.Value <string>();
            }
            else
            {
                var lines = new List <String>();
                foreach (var valueLine in defaultValueEntry)
                {
                    lines.Add(valueLine.Value <string>());
                }
                defaultValueString = string.Join("\n", lines);
            }
            var defaultValue = ValueUtilities.CreateValue(jsonInput["DefaultValue"]["Type"].Value <string>(), defaultValueString);

            var isMultiInput = jsonInput["IsMultiInput"].Value <bool>();
            var relevance    = (MetaInput.RelevanceType)Enum.Parse(typeof(MetaInput.RelevanceType), jsonInput["Relevance"].Value <string>());
            var description  = jsonInput["Description"].Value <string>();

            var min       = jsonInput["Min"].Value <float>();
            var max       = jsonInput["Max"].Value <float>();
            var scale     = jsonInput["Scale"].Value <float>();
            var scaleType = (MetaInput.Scaling)Enum.Parse(typeof(MetaInput.Scaling), jsonInput["ScaleType"].Value <string>());

            var enumEntries = (from enumEntry in jsonInput["EnumValues"]
                               let metaOpPart = BuildEnumEntry(enumEntry)
                                                select metaOpPart).ToList();

            return(new MetaInput(metaInstanceID, name, opPart, defaultValue, isMultiInput)
            {
                Relevance = relevance,
                Description = description,
                Min = min,
                Max = max,
                Scale = scale,
                ScaleType = scaleType,
                EnumValues = enumEntries
            });
        }
Beispiel #4
0
 public OperatorPart CreateInstance()
 {
     return(OpPart.CreateFunc(ID, Utilities.CreateValueFunction(ValueUtilities.CreateValue(OpPart.Type.ToString(), String.Empty)), false, Name));
 }
Beispiel #5
0
        private MetaOperator.InstanceProperties BuildOperatorInstanceProperties(MetaManager metaManager, MetaOperator metaOp, JToken jsonOp)
        {
            var opProperties = new MetaOperator.InstanceProperties();

            opProperties.Name     = jsonOp["Name"].Value <string>();
            opProperties.Position = new Point(jsonOp["PosX"].Value <double>(), jsonOp["PosY"].Value <double>());
            opProperties.Width    = jsonOp["Width"].Value <double>();
            opProperties.Visible  = jsonOp["Visible"].Value <bool>();
            if (jsonOp["Disabled"] != null)
            {
                opProperties.Disabled = jsonOp["Disabled"].Value <bool>();
            }

            var foundMetaInputsList = new List <MetaInput>();

            foreach (var jsonInput in jsonOp["Inputs"])
            {
                var id        = Guid.Parse(jsonInput["ID"].Value <string>());
                var metaInput = (from input in metaOp.Inputs
                                 where input.ID == id
                                 select input).SingleOrDefault();
                if (metaInput == null)
                {
                    Logger.Debug("Skipped obsolete parameter value {0} in meta operator {1}, because it no longer exists.", id.ToString(), metaOp.Name);
                    continue;
                }

                var valueToken = jsonInput["Type"];
                if (valueToken != null)
                {
                    var type  = valueToken.Value <string>();
                    var lines = new List <String>();
                    foreach (var valueLine in jsonInput["Value"])
                    {
                        lines.Add(valueLine.Value <string>());
                    }
                    var value = string.Join("\n", lines);
                    opProperties.InputValues[id] = Utilities.CreateValueFunction(ValueUtilities.CreateValue(type, value));
                }
                else
                {
                    opProperties.InputValues[id] = metaInput.DefaultFunc;
                }

                foundMetaInputsList.Add(metaInput);
            }

            // extract inputs for which no values have been set, e.g. because the input was added later after creating the parent op
            // for these inputs the default func is set
            var inputsWithoutStoredInstanceValues = foundMetaInputsList.Except(metaOp.Inputs);

            foreach (var input in inputsWithoutStoredInstanceValues)
            {
                opProperties.InputValues[input.ID] = input.DefaultFunc;
                Logger.Debug("Added default value for new parameter {0} in Operator {1}", input.Name, input.ID.ToString());
            }

            foreach (var jsonState in jsonOp["States"])
            {
                var opPartId        = Guid.Parse(jsonState.Value <string>("ID"));
                var metaOpPart      = metaOp.OperatorParts.First(opPartEntry => opPartEntry.Item1 == opPartId).Item2;
                var stateType       = metaOpPart.StateType;
                var serializedState = jsonState.Value <JObject>("State");

                var serializer = new JsonSerializer();
                using (var reader = new StringReader(serializedState.ToString()))
                {
                    var state = serializer.Deserialize(reader, stateType) as IOperatorPartState;
                    if (state != null)
                    {
                        opProperties.OperatorPartStates.Add(opPartId, state);
                    }
                }
            }

            return(opProperties);
        }