public NodeVariable GetVector3Result() { if (resultV3Variable == null) { resultV3Variable = new NodeVariable <Vector3>(); } VectorComponent targetComponent = GetInputValue(targetComponentInput); Vector3 originVector3 = GetInputValue(originV3Input); float targetValue = GetInputValue(valueInput); switch (targetComponent) { case VectorComponent.X: originVector3.x = targetValue; break; case VectorComponent.Y: originVector3.y = targetValue; break; case VectorComponent.Z: originVector3.z = targetValue; break; } resultV3Variable.value = originVector3; return(resultV3Variable); }
public DemoApplication() { LoadCertificateAndPrivateKey(); uaAppDesc = new ApplicationDescription( "url:qs:DemoApplication", "http://quantensystems.com/", new LocalizedText("en-US", "QuantenSystems demo server"), ApplicationType.Server, null, null, null); ItemsRoot = new NodeObject(new NodeId(2, 0), new QualifiedName("Items"), new LocalizedText("Items"), new LocalizedText("Items"), 0, 0, 0); // Objects organizes Items AddressSpaceTable[new NodeId(UAConst.ObjectsFolder)].References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), new NodeId(2, 0), false)); ItemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), new NodeId(UAConst.ObjectsFolder), true)); AddressSpaceTable.TryAdd(ItemsRoot.Id, ItemsRoot); TrendNodes = new NodeVariable[1000]; var nodeTypeFloat = new NodeId(0, 10); for (int i = 0; i < TrendNodes.Length; i++) { var id = string.Format("Trend {0}", (1 + i).ToString("D6")); TrendNodes[i] = new NodeVariable(new NodeId(2, (uint)(1 + i)), new QualifiedName(id), new LocalizedText(id), new LocalizedText(id), 0, 0, AccessLevel.CurrentRead | AccessLevel.HistoryRead, AccessLevel.CurrentRead | AccessLevel.HistoryRead, 0, true, nodeTypeFloat); ItemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), TrendNodes[i].Id, false)); TrendNodes[i].References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), ItemsRoot.Id, true)); AddressSpaceTable.TryAdd(TrendNodes[i].Id, TrendNodes[i]); } }
/// <summary> /// 仅<see cref="SetVariableNode"/>使用 /// </summary> /// <param name="inputVariable"></param> /// <returns></returns> protected NodeVariable GetInputValueRaw(NodeInputVariable <NodeVariable> inputVariable) { if (inputVariable == null) { return(null); } if (inputVariable.targetNodeId < 0 || inputVariable.targetPortId < 0) { Debug.LogError("GetInputValueRaw 出错,该端口必须连接到另外一个output端口"); } NodeBase targetNode = null; //NodeSequence为null 说明是公共节点 if (nodeSequence == null) { targetNode = graphBehaviour.GetCommonNode(inputVariable.targetNodeId); } else { targetNode = nodeSequence.GetNodeAlongThisAndParentSequeces(inputVariable.targetNodeId); } if (targetNode == null) { return(null); } NodeVariable nodeVariable = targetNode.GetOutputPortValue(inputVariable.targetPortId); return(nodeVariable); }
public NodeVariable GetJoyStickInput() { if (joyStickInputVariable == null) { joyStickInputVariable = new NodeVariable <Vector2>(); } joyStickInputVariable.value = joyStickInput; return(joyStickInputVariable); }
private static void TestSerialization() { var mbuf = new MemoryBuffer(1 << 25); const int numPasses = 1 << 20; double va = 2.31; int vb = 2321; var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < numPasses; i++) { mbuf.VariantEncode(va); mbuf.VariantEncode(vb); } sw.Stop(); //Console.WriteLine(((numPasses * 2) / (sw.Elapsed.TotalSeconds * 1024.0 * 1024.0)).ToString("N2")); Console.WriteLine("{0} KB/{1} KB in {2}", (mbuf.Position / 1024.0).ToString("N2"), (mbuf.Capacity / 1024.0).ToString("N2"), sw.Elapsed.ToString()); mbuf.Rewind(); sw.Restart(); for (int i = 0; i < numPasses; i++) { object vra = null; mbuf.VariantDecode(out vra); mbuf.VariantDecode(out vra); } sw.Stop(); Console.WriteLine("{0} KB/{1} KB in {2}", (mbuf.Position / 1024.0).ToString("N2"), (mbuf.Capacity / 1024.0).ToString("N2"), sw.Elapsed.ToString()); var nodeDict = new Dictionary <NodeId, Node>(); sw.Restart(); for (int i = 0; i < (1 << 18); i++) { var node = new NodeVariable(new NodeId(2, (uint)(i + 100)), new QualifiedName(0, string.Format("V|{0}", i)), new LocalizedText(i.ToString()), new LocalizedText(i.ToString()), 0, 0, AccessLevel.CurrentRead, AccessLevel.CurrentRead, 0, false, NodeId.Zero); //bool put = nodeDict.TryAdd(node.Id, node); //Debug.Assert(put); nodeDict.Add(node.Id, node); } sw.Stop(); Console.WriteLine("Created node objects in {0}, {1 }M/sec", sw.Elapsed.ToString(), ((nodeDict.Count / 1000000.0) / sw.Elapsed.TotalSeconds).ToString("N2")); }
public void SetGraphVariable(int variableId, NodeVariable value) { if (variableDictionary.ContainsKey(variableId)) { variableDictionary[variableId] = value; } else { variableDictionary.Add(variableId, value); } }
public void AddDatapoint(NodeId nodeId, float value) { var node = new NodeVariable(nodeId, new QualifiedName(nodeId.StringIdentifier), new LocalizedText(nodeId.StringIdentifier), new LocalizedText(nodeId.StringIdentifier), 0, 0, AccessLevel.CurrentRead, AccessLevel.CurrentRead, 0, false, new NodeId(0, 10)); _itemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), node.Id, false)); node.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), _itemsRoot.Id, true)); AddressSpaceTable.TryAdd(node.Id, node); _nodes.Add(nodeId, value); }
public NodeVariable GetInverseDirection() { Vector3 originDirection = GetInputValue(directionInput); if (inverseDirectionVariable == null) { inverseDirectionVariable = new NodeVariable <Vector3>(); } inverseDirectionVariable.value = -originDirection; return(inverseDirectionVariable); }
public override void OnEnter() { base.OnEnter(); int variableId = GetInputValue(setVariableWrapperInput).variableId; NodeVariable saveValue = GetInputValueRaw(valueVariableInput); graphBehaviour.SetGraphVariable(variableId, saveValue); EventTiming(0); Finish(); }
public NodeVariable GetRandomFloat() { if (returnFloatVariable == null) { returnFloatVariable = new NodeVariable <float>(); } float min = GetInputValue(minInputVariable); float max = GetInputValue(maxInputVariable); returnFloatVariable.value = Random.Range(min, max); return(returnFloatVariable); }
public NodeVariable GetScalarVector2() { float scalar = GetInputValue(scalarInput); if (scalarVector2Variable == null) { scalarVector2Variable = new NodeVariable <Vector2>(); } Vector2 v2 = GetInputValue(v2Input); scalarVector2Variable.value = v2 * scalar; return(scalarVector2Variable); }
public void EvalThroughFunction() { var nodeMockReturns = _fixture.Create <double>(); var varNameMock = _fixture.Create <string>(); var ctxMock = new Mock <IContext>(); ctxMock.Setup(_ => _.ResolveVariable(varNameMock)).Returns(nodeMockReturns).Verifiable(); var sut = new NodeVariable(varNameMock); var result = sut.Eval(ctxMock.Object); Assert.IsType <double>(result); Assert.Equal(nodeMockReturns, result); ctxMock.Verify(); }
public NodeVariable GetScalarVector3() { float scalar = GetInputValue(scalarInput); if (scalarVector3Variable == null) { scalarVector3Variable = new NodeVariable <Vector3>(); } Vector3 v3 = GetInputValue(v3Input); scalarVector3Variable.value = v3 * scalar; return(scalarVector3Variable); }
public void Node_AssignTest() { foreach (var value in VariableValueTest.ValidParseValues) { var expectedValue = VariableValue.Parse(value); var context = new TestContext(); var lhs = new NodeVariable("test"); var rhs = new NodeValue(expectedValue); Evaluate_ValidTest(expectedValue, new NodeAssign(lhs, rhs), context); Assert.AreEqual(expectedValue, lhs.Evaluate(context)); } }
public DemoApplication() { //LoadCertificateAndPrivatekeyFromFile(); LoadCertficateAndPrivateKeyFromCertStore("1.3.6.1.5.5.7.3.1", "CN=OLPDO-CA, DC=olplastik, DC=de"); if (this.appCertificate == null) //Valid certificate could not be found... { throw (new OperationCanceledException("Unable to load valid certificate from certificates store. Aborting.")); //Raise exception which will cause the program to abort } else { this.printCertInfo(); } uaAppDesc = new ApplicationDescription( "url:qs:DemoApplication", "http://quantensystems.com/", new LocalizedText("en-US", "QuantenSystems demo server"), ApplicationType.Server, null, null, null); ItemsRoot = new NodeObject(new NodeId(2, 0), new QualifiedName("Items"), new LocalizedText("Items"), new LocalizedText("Items"), 0, 0, 0); // Objects organizes Items AddressSpaceTable[new NodeId(UAConst.ObjectsFolder)].References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), new NodeId(2, 0), false)); ItemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), new NodeId(UAConst.ObjectsFolder), true)); AddressSpaceTable.TryAdd(ItemsRoot.Id, ItemsRoot); TrendNodes = new NodeVariable[1000]; var nodeTypeFloat = new NodeId(0, 10); for (int i = 0; i < TrendNodes.Length; i++) { var id = string.Format("Trend {0}", (1 + i).ToString("D6")); TrendNodes[i] = new NodeVariable(new NodeId(2, (uint)(1 + i)), new QualifiedName(id), new LocalizedText(id), new LocalizedText(id), 0, 0, AccessLevel.CurrentRead | AccessLevel.HistoryRead, AccessLevel.CurrentRead | AccessLevel.HistoryRead, 0, true, nodeTypeFloat); ItemsRoot.References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), TrendNodes[i].Id, false)); TrendNodes[i].References.Add(new ReferenceNode(new NodeId(UAConst.Organizes), ItemsRoot.Id, true)); AddressSpaceTable.TryAdd(TrendNodes[i].Id, TrendNodes[i]); } }
protected T GetInputValue <T>(NodeInputVariable <T> inputVariable) { if (inputVariable == null) { return(default(T)); } if (inputVariable.targetNodeId < 0 && inputVariable.targetPortId < 0) { return(inputVariable.value); } NodeBase targetNode = null; //NodeSequence为null 说明是公共节点 if (nodeSequence == null) { targetNode = graphBehaviour.GetCommonNode(inputVariable.targetNodeId); } else { targetNode = nodeSequence.GetNodeAlongThisAndParentSequeces(inputVariable.targetNodeId); } if (targetNode == null) { return(default(T)); } NodeVariable nodeVariable = targetNode.GetOutputPortValue(inputVariable.targetPortId); NodeVariable <T> resultVariable = nodeVariable as NodeVariable <T>; if (resultVariable == null) { Debug.LogErrorFormat("获取节点 {0} 的输出端口 {1} 的值发生错误,类型不匹配", inputVariable.targetNodeId, inputVariable.targetPortId); return(default(T)); } return(resultVariable.value); }
private bool TryParseAssign(out Node result) { if (Tokens.CurrentToken == TokenType.Symbol) { string name = Tokens.CurrentSymbol; Tokens.ReadNext(); if (Tokens.CurrentToken == TokenType.Assign) { Node lhs = new NodeVariable(name); Tokens.ReadNext(); Node rhs = ParseOr(); result = new NodeAssign(lhs, rhs); return(true); } } Tokens.Reset(); result = default; return(false); }
private INode ParseLeaf() { //_tokenizer.Next(); if (_tokenizer.Token == Token.Number) { return(new NodeNumber(_tokenizer.Number)); } else if (_tokenizer.Token == Token.OpenParens) { var node = ParseAddAndSubstract(); if (_tokenizer.Token != Token.CloseParens) { throw new InvalidDataException($"Missing close parenthesis"); } return(node); } else if (_tokenizer.Token == Token.Identifier) { var node = new NodeVariable(_tokenizer.Identifier, Context); return(node); } throw new InvalidDataException($"Unexpect token: {_tokenizer.Token}"); }
public NodeVariable GetCompareResult() { if (resultVariable == null) { resultVariable = new NodeVariable <bool>(); } int a = GetInputValue(aInput); int b = GetInputValue(bInput); CompareType compareType = GetInputValue(compareTypeInput); switch (compareType) { case CompareType.Less: resultVariable.value = a < b; break; case CompareType.LessEqual: resultVariable.value = a <= b; break; case CompareType.Equal: resultVariable.value = a == b; break; case CompareType.GreaterEqual: resultVariable.value = a >= b; break; case CompareType.Greater: resultVariable.value = a > b; break; } return(resultVariable); }
public NodeVariable GetResult() { if (resultVectorVariab == null) { resultVectorVariab = new NodeVariable <Vector3>(); } calculateType = GetInputValue(typeInput); Vector3 a = GetInputValue(aVectorInput); Vector3 b = GetInputValue(bVectorInput); switch (calculateType) { case CalculateType.Add: resultVectorVariab.value = a + b; break; case CalculateType.Minus: resultVectorVariab.value = a - b; break; } return(resultVectorVariab); }
public void NodeVariableEvaluateWithVariableDictionaryIsNullThrows() { var node = new NodeVariable("a"); node.Evaluate(null); }
private INode ParseLeaf() { if (tokenizer.currentToken == Token.Number) { var node = new NodeNumber(tokenizer.number); tokenizer.NextToken(); return(node); } if (tokenizer.currentToken == Token.OpenParens) { tokenizer.NextToken(); var node = ParseAddSubtract(); if (tokenizer.currentToken != Token.CloseParens) { throw new SyntaxException("Falta cerrar paréntesis"); } tokenizer.NextToken(); return(node); } if (tokenizer.currentToken == Token.Identifier) { var name = tokenizer.identifier; tokenizer.NextToken(); if (tokenizer.currentToken != Token.OpenParens) { NodeVariable node = new NodeVariable(name); if (!node.isReserved()) { variables.Add(name); } return(node); } else { tokenizer.NextToken(); var arguments = new List <INode>(); while (true) { arguments.Add(ParseAddSubtract()); if (tokenizer.currentToken == Token.Comma) { tokenizer.NextToken(); continue; } break; } if (tokenizer.currentToken != Token.CloseParens) { throw new SyntaxException("Falta cerrar paréntesis"); } tokenizer.NextToken(); return(new NodeFunctionCall(name, arguments.ToArray())); } } throw new SyntaxException(GetUnexpectedTokenMessage(tokenizer.currentToken)); }
/// <summary> /// 反序列化图的变量,并返回结果 /// </summary> /// <param name="graphInfo"></param> /// <returns></returns> public static Dictionary <int, NodeVariable> DeserializeGraphVariableInfo(GraphInfo graphInfo) { Dictionary <int, NodeVariable> resultDictionary = new Dictionary <int, NodeVariable>(); int graphVariableCount = graphInfo.GraphVariableInfosLength; for (int i = 0; i < graphVariableCount; i++) { GraphVariableInfo graphVariableInfo = graphInfo.GraphVariableInfos(i).Value; int id = graphVariableInfo.Id; string typeName = graphVariableInfo.TypeName; string valueString = graphVariableInfo.ValueString; if (resultDictionary.ContainsKey(id)) { continue; } Type variableType = Type.GetType(typeName); if (variableType == null) { variableType = Type.GetType(typeName + ",UnityEngine"); if (variableType == null) { variableType = Type.GetType(typeName + ",Assembly-CSharp"); } } Type baseType = typeof(NodeVariable <>); Type genericType = baseType.MakeGenericType(variableType); NodeVariable instanceVariable = Activator.CreateInstance(genericType) as NodeVariable; //支持以下类型初始化值 if (variableType == typeof(int)) { NodeVariable <int> variable = instanceVariable as NodeVariable <int>; int intValue; if (int.TryParse(valueString, out intValue)) { variable.value = intValue; } } else if (variableType == typeof(float)) { NodeVariable <float> variable = instanceVariable as NodeVariable <float>; float floatValue; if (float.TryParse(valueString, out floatValue)) { variable.value = floatValue; } } else if (variableType == typeof(bool)) { NodeVariable <bool> variable = instanceVariable as NodeVariable <bool>; bool boolValue; if (bool.TryParse(valueString, out boolValue)) { variable.value = boolValue; } } else if (variableType == typeof(string)) { NodeVariable <string> variable = instanceVariable as NodeVariable <string>; variable.value = valueString; } //其他类型初始时均为null或默认值 resultDictionary.Add(id, instanceVariable); } return(resultDictionary); }