public MetaOperatorPart(Guid id) { ID = id; Version = Guid.NewGuid(); FunctionCreator = () => Utilities.CreateValueFunction(new Float(0)); ScriptAssembly = null; ScriptChanged = false; }
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)); }
public static void SetOperatorPartValue(OperatorPart opPart, double time, float value) { var animationOpPart = GetRegardingAnimationOpPart(opPart); if (animationOpPart != null) { var animationCurve = animationOpPart.Func as ICurve; Utils.AddKeyframeAtTime(animationCurve, time, value); } else { opPart.Func = Utilities.CreateValueFunction(new Float(value)); } }
public OperatorPart CreateOpPart(Guid id) { var opPartFunction = FunctionCreator(); if (opPartFunction == null) { return(CreateFunc(id, Utilities.CreateValueFunction(new Float(0.0f)), false, "")); } else { return new OperatorPart(id, opPartFunction) { IsMultiInput = IsMultiInput, Name = Name, Type = Type } }; }
public CompilerErrorCollection Compile() { var coreAssembly = GetAssemblyFromCurrentDomain("Core"); try { var assemblyToUse = GenerateAssembly(coreAssembly, SourceName, forceInMemoryGeneration: IsOpStoredInCore); var functorType = (from t in assemblyToUse.GetTypes() where t.IsSubclassOf(typeof(OperatorPart.Function)) select t).First(); FunctionCreator = () => assemblyToUse.CreateInstance(functorType.FullName) as OperatorPart.Function; ScriptAssembly = assemblyToUse; Logger.Info("Updating " + Name + " succeeded"); } catch (ScriptCompilerException e) { Logger.Error("Failed to update operator {0}. The operator has been disabled.\n{1}", Name, e.ToString()); FunctionCreator = () => Utilities.CreateValueFunction(new Float(0)); ScriptAssembly = null; return(e.CompilerResults.Errors); } catch (TargetInvocationException e) { Logger.Error("Failed to invoke a component on an instance of the compiled operator {0}. The operator has been disabled.\n{1}", Name, e.ToString()); FunctionCreator = () => Utilities.CreateValueFunction(new Float(0)); ScriptAssembly = null; return(new CompilerErrorCollection()); } ScriptChanged = true; if (ScriptChangedEvent != null) { ScriptChangedEvent(this, EventArgs.Empty); } return(new CompilerErrorCollection()); }
internal void InitScript(string newScript, Guid version) { var coreAssembly = GetAssemblyFromCurrentDomain("Core"); var functorType = (from t in coreAssembly.GetTypes() where t.Namespace == ScriptNamespace where t.IsSubclassOf(typeof(OperatorPart.Function)) select t).FirstOrDefault(); var assemblyToUse = coreAssembly; try { if (functorType != null) { Logger.Info("Implementation of operator {0} is used from core assembly.", functorType.Name); var cachePath = MetaManager.OPERATOR_CACHE_PATH + "/"; var path = cachePath + SourceName + ".cs"; if (File.Exists(path)) { using (var sourceReader = new StreamReader(path)) { _script = sourceReader.ReadToEnd(); } var dllName = cachePath + SourceName + ".dll"; if (File.Exists(dllName)) { File.Delete(dllName); } var pdbName = cachePath + SourceName + ".pdb"; if (File.Exists(pdbName)) { File.Delete(pdbName); } ScriptChanged = true; } } else { _script = newScript; assemblyToUse = GenerateAssembly(coreAssembly, SourceName, forceInMemoryGeneration: false); functorType = (from t in assemblyToUse.GetTypes() where t.IsSubclassOf(typeof(OperatorPart.Function)) select t).First(); } FunctionCreator = () => { try { return(assemblyToUse.CreateInstance(functorType.FullName) as OperatorPart.Function); } catch (Exception ex) { Logger.Error("{0}: Failed to create operator function. replacement created instead. \n\t{1}\n\t{2}", functorType.Name, ex.Message, ex.InnerException); } return(Utilities.CreateValueFunction(new Float(0))); }; ScriptAssembly = assemblyToUse; Logger.Debug("Updating " + Name + " succeeded"); } catch (ScriptCompilerException e) { Logger.Error("Failed to update operator {0}. The operator has been disabled.\n{1}", Name, e.ToString()); FunctionCreator = () => { return(Utilities.CreateValueFunction(new Float(0))); }; ScriptAssembly = null; return; } if (ScriptChangedEvent != null) { ScriptChangedEvent(this, EventArgs.Empty); } }
public void SetValue(IValue value) { Func = Utilities.CreateValueFunction(value); }
public OperatorPart CreateInstance() { return(OpPart.CreateFunc(ID, Utilities.CreateValueFunction(ValueUtilities.CreateValue(OpPart.Type.ToString(), String.Empty)), false, Name)); }
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); }