Ejemplo n.º 1
0
 public void RebuildMetaOpManager()
 {
     MetaManager.Dipose();
     MetaOpManager = MetaManager.Instance;
     MetaOpManager.LoadMetaOperators();
     HomeOperator = MetaOpManager.HomeOperator.CreateOperator(Guid.NewGuid());
 }
Ejemplo n.º 2
0
        private MetaOutput BuildMetaOutput(MetaManager metaManager, JToken jsonOutput)
        {
            var metaInstanceID = Guid.Parse(jsonOutput["MetaInstanceID"].Value <string>());
            var name           = jsonOutput["Name"].Value <string>();
            var metaIDOfOpPart = Guid.Parse(jsonOutput["MetaID"].Value <string>());
            var opPart         = metaManager.GetMetaOperatorPart(metaIDOfOpPart);

            return(new MetaOutput(metaInstanceID, name, opPart));
        }
Ejemplo n.º 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
            });
        }
Ejemplo n.º 4
0
        public MetaOperator ReadMetaOperator(MetaManager metaManager)
        {
            var o    = JObject.ReadFrom(Reader);
            var name = o["Name"].Value <string>();
            var id   = Guid.Parse(o["_id"].Value <string>());
            var rev  = o.Value <string>("_rev");

            if (rev == null)
            {
                rev = string.Empty;
            }
            var namesp      = o["Namespace"].Value <string>();
            var description = o["Description"].Value <string>();
            var inputs      = (from i in ((JArray)o["Inputs"])
                               let metaInput = BuildMetaInput(metaManager, i)
                                               select metaInput).ToList();
            var outputs = (from output in ((JArray)o["Outputs"])
                           let metaOutput = BuildMetaOutput(metaManager, output)
                                            select metaOutput).ToList();
            var operators = (from op in ((JArray)o["Operators"])
                             let metaOp = BuildMetaOperator(metaManager, op)
                                          select metaOp).ToDictionary(e => { return(e.Item1); }, e => { return(e.Item2); });
            var connections = (from c in ((JArray)o["Connections"])
                               let metaConnection = BuildMetaConnection(c)
                                                    select metaConnection).ToList();
            var newMetaOp = new MetaOperator(id)
            {
                Revision    = rev,
                Name        = name,
                Inputs      = inputs,
                Outputs     = outputs,
                Operators   = operators,
                Connections = connections,
                Description = description,
                Namespace   = namesp,
            };

            // the loading order matters here, operator parts potentially need the parent op (newMetaOp) in
            // order to determine which supplier assembly need to be loaded
            var opParts = (from opPart in ((JArray)o["OperatorParts"])
                           let metaOpPart = BuildMetaOpPart(metaManager, newMetaOp, opPart)
                                            select metaOpPart).ToList();

            newMetaOp.OperatorParts = opParts;

            newMetaOp.CheckForInconsistencyAndFixThem();
            newMetaOp.Changed = false; // must be set after inconsistencies have been fixed!
            return(newMetaOp);
        }
Ejemplo n.º 5
0
        private Tuple <Guid, MetaOperatorPart> BuildMetaOpPart(MetaManager metaManager, MetaOperator parent, JToken jsonOpPart)
        {
            var metaInstanceID = Guid.Parse(jsonOpPart["MetaInstanceID"].Value <string>());
            var metaIDOfOpPart = Guid.Parse(jsonOpPart["MetaID"].Value <string>());
            var version        = Guid.Parse(jsonOpPart["Version"].Value <string>());

            // build script
            var lines = new List <String>();

            foreach (var scriptLine in jsonOpPart["Script"])
            {
                lines.Add(scriptLine.Value <string>());
            }
            var script = string.Join("\n", lines);

            var additionalAssemblies = new List <string>();

            if (jsonOpPart["AdditionalAssemblies"] != null)
            {
                additionalAssemblies.AddRange(jsonOpPart["AdditionalAssemblies"].Select(assembly => assembly.Value <string>()));
            }

            var isMultiInput = jsonOpPart["IsMultiInput"].Value <bool>();
            var name         = jsonOpPart["Name"].Value <string>();
            var type         = (FunctionType)Enum.Parse(typeof(FunctionType), jsonOpPart["Type"].Value <string>());

            var metaOpPart = new MetaOperatorPart(metaIDOfOpPart)
            {
                IsMultiInput         = isMultiInput,
                Type                 = type,
                Name                 = name,
                AdditionalAssemblies = additionalAssemblies,
                Parent               = parent,
                Version              = version         // set version at last to prevent version updates of property setters above
            };

            foreach (var opEntry in parent.Operators)
            {
                var supplierOpPartDefinition = opEntry.Value.Item1.OperatorParts[0].Item2;
                supplierOpPartDefinition.ScriptChangedEvent += metaOpPart.HandleDependencyOperator_ScriptChange;
            }
            metaOpPart.InitScript(script, version);
            metaManager.AddMetaOperatorPart(metaOpPart);

            return(Tuple.Create(metaInstanceID, metaOpPart));
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private Tuple <Guid, Tuple <MetaOperator, MetaOperator.InstanceProperties> > BuildMetaOperator(MetaManager metaManager, JToken jsonOp)
        {
            var metaInstanceID = Guid.Parse(jsonOp["MetaInstanceID"].Value <string>());
            var metaOpID       = Guid.Parse(jsonOp["MetaID"].Value <string>());
            var metaOp         = metaManager.GetMetaOperator(metaOpID);

            if (metaOp == null)
            {
                return(Tuple.Create(metaInstanceID, (Tuple <MetaOperator, MetaOperator.InstanceProperties>)null));
            }

            var opProperties = BuildOperatorInstanceProperties(metaManager, metaOp, jsonOp["OperatorProperties"]);

            return(Tuple.Create(metaInstanceID, Tuple.Create(metaOp, opProperties)));
        }