public WrappedMethod(MethodInfo methodInfo) { this.methodName = methodInfo.Name; this.returnType = DataTypeHelper.GetWrappedDataTypeFromSystemType(methodInfo.ReturnType); parameters = new List <WrappedParameter>(); foreach (ParameterInfo parameterInfo in methodInfo.GetParameters()) { parameters.Add(new WrappedParameter(parameterInfo)); } if (methodInfo.ReturnType.IsValueType) { returnTypeAttributes |= VariableAttributes.IsValueType; } if (methodInfo.IsStatic) { this.methodAttributes |= MethodAttributes.Static; } if (AttributeHelper.IsObsolete(methodInfo.GetCustomAttributes(false))) { this.methodAttributes |= MethodAttributes.Obsolete; } if (methodInfo.ContainsGenericParameters) { this.methodAttributes |= MethodAttributes.ContainsGenericParameters; } }
public WrappedVariable(FieldInfo fieldInfo, object objectValue) : this(fieldInfo.Name, objectValue, fieldInfo.FieldType, true) { this.variableName = fieldInfo.Name; if (fieldInfo.IsInitOnly) { this.attributes |= VariableAttributes.ReadOnly; } if (fieldInfo.IsStatic) { this.attributes |= VariableAttributes.IsStatic; } if (fieldInfo.IsLiteral) { this.attributes |= VariableAttributes.IsLiteral; } if (fieldInfo.FieldType.IsValueType) { this.attributes |= VariableAttributes.IsValueType; } if (AttributeHelper.IsObsolete(fieldInfo.GetCustomAttributes(false))) { this.attributes |= VariableAttributes.Obsolete; } }
public VariableMetaData(BinaryReader br, DataType dataType, VariableAttributes attributes) { if (dataType == DataType.Enum || dataType == DataType.UnityObjectReference) { typeFullName = br.ReadString(); assemblyName = br.ReadString(); } if (dataType == DataType.Enum) { int enumNameCount = br.ReadInt32(); enumNames = new string[enumNameCount]; enumValues = new int[enumNameCount]; for (int i = 0; i < enumNameCount; i++) { enumNames[i] = br.ReadString(); } for (int i = 0; i < enumNameCount; i++) { enumValues[i] = br.ReadInt32(); } } else if (dataType == DataType.UnityObjectReference) { valueDisplayName = br.ReadString(); } }
public void Write(BinaryWriter bw, DataType dataType, VariableAttributes attributes) { if (dataType == DataType.Enum || dataType == DataType.UnityObjectReference) { bw.Write(typeFullName); bw.Write(assemblyName); } if (dataType == DataType.Enum) { bw.Write(enumNames.Length); for (int i = 0; i < enumNames.Length; i++) { bw.Write(enumNames[i]); } for (int i = 0; i < enumNames.Length; i++) { bw.Write(enumValues[i]); } } else if (dataType == DataType.UnityObjectReference) { bw.Write(valueDisplayName); } }
public VariableMetaData(BinaryReader br, DataType dataType, VariableAttributes attributes) { if (dataType == DataType.UnityObjectReference) { typeFullName = br.ReadString(); assemblyName = br.ReadString(); } if (dataType == DataType.Enum) { enumUnderlyingType = br.ReadString(); int enumNameCount = br.ReadInt32(); enumNames = new string[enumNameCount]; enumValues = new object[enumNameCount]; for (int i = 0; i < enumNameCount; i++) { enumNames[i] = br.ReadString(); } Type enumBackingType = GetTypeFromMetaData(); for (int i = 0; i < enumNameCount; i++) { enumValues[i] = DataTypeHelper.ReadIntegerFromBinary(enumBackingType, br); } } }
public WrappedBaseObject(string variableName, Type type, bool generateMetadata) { this.variableName = variableName; this.dataType = DataTypeHelper.GetWrappedDataTypeFromSystemType(type); bool isArray = type.IsArray; bool isGenericList = TypeUtility.IsGenericList(type); this.attributes = VariableAttributes.None; Type elementType = type; if (isArray || isGenericList) { if (isArray) { this.attributes |= VariableAttributes.IsArray; } else if (isGenericList) { this.attributes |= VariableAttributes.IsList; } elementType = TypeUtility.GetElementType(type); //Debug.Log(elementType); this.dataType = DataTypeHelper.GetWrappedDataTypeFromSystemType(elementType); } if (generateMetadata) { metaData = VariableMetaData.Create(dataType, elementType, attributes); } }
protected WrappedBaseObject(string variableName, DataType dataType, VariableAttributes attributes, VariableMetaData metaData) { this.variableName = variableName; this.dataType = dataType; this.attributes = attributes; this.metaData = metaData; }
public static VariableMetaData Create(DataType dataType, Type elementType, VariableAttributes attributes) { if (dataType == DataType.Enum || dataType == DataType.UnityObjectReference) { VariableMetaData metaData = new VariableMetaData(); if (dataType == DataType.UnityObjectReference) { metaData.typeFullName = elementType.FullName; metaData.assemblyName = elementType.Assembly.FullName; } else if (dataType == DataType.Enum) { Type underlyingType = Enum.GetUnderlyingType(elementType); metaData.enumUnderlyingType = underlyingType.FullName; metaData.enumNames = Enum.GetNames(elementType); metaData.enumValues = new object[metaData.enumNames.Length]; Array enumValuesArray = Enum.GetValues(elementType); for (int i = 0; i < metaData.enumNames.Length; i++) { metaData.enumValues[i] = Convert.ChangeType(enumValuesArray.GetValue(i), underlyingType); } } return(metaData); } else { return(null); } }
/// <summary> /// Funkcja wywoływana przy generowaniu strony /// </summary> public void OnGet() { try { AsixRestClient asixRestClient = new AsixRestClient(); // Odczyt z serwera REST nazw wszystkich atrybutów ServerAttributes serverAttributes = asixRestClient.ReadAttributeNames(); if (!serverAttributes.readSucceeded) { mReadError = serverAttributes.readStatusString; return; } mAttributeNames = serverAttributes.mAttributeNameList; // Odczyt z serwera REST wartości atrybutów atrybutów zmiennej VariableAttributes variableAttributes = asixRestClient.ReadVariableAttributes(mVariableName, mAttributeNames); if (!variableAttributes.readSucceeded) { mReadError = variableAttributes.readStatusString; return; } mVariableAttributes = variableAttributes.mAttributeValueList; } catch (Exception e) { mReadError = e.Message; } }
public void DrawFields(Type componentType, object component, ECSContext ecsContext, string searchTerm, FieldInfo[] fields) { foreach (FieldInfo field in fields) { string fieldName = field.Name; if (!SearchMatches(searchTerm, fieldName)) { // Does not match search term, skip it continue; } Type fieldType = field.FieldType; VariableAttributes variableAttributes = VariableAttributes.None; // See https://stackoverflow.com/a/10261848 if (field.IsLiteral && !field.IsInitOnly) { variableAttributes = VariableAttributes.Constant; // Prevent SetValue as it will result in a FieldAccessException variableAttributes |= VariableAttributes.ReadOnly; } if (field.IsStatic) { variableAttributes |= VariableAttributes.Static; } string tooltip = TypeUtility.GetTooltip(field, variableAttributes); if ((variableAttributes & VariableAttributes.ReadOnly) != 0) { GUI.enabled = false; } DrawVariable(fieldType, fieldName, component != null ? field.GetValue(component) : null, tooltip, variableAttributes, field.GetCustomAttributes(), true, componentType, newValue => { if ((variableAttributes & VariableAttributes.ReadOnly) == 0) { field.SetValue(component, newValue); #if ECS_EXISTS if (ecsContext != null) { ECSAccess.SetComponentData(ecsContext.EntityManager, ecsContext.Entity, ecsContext.ComponentType, component); } #endif } }); if ((variableAttributes & VariableAttributes.ReadOnly) != 0) { GUI.enabled = true; } } }
public WrappedVariable(string variableName, object value, Type type, bool generateMetadata) { this.variableName = variableName; this.dataType = DataTypeHelper.GetWrappedDataTypeFromSystemType(type); this.value = value; bool isArray = type.IsArray; bool isGenericList = TypeUtility.IsGenericList(type); this.attributes = VariableAttributes.None; Type elementType = type; if (isArray || isGenericList) { if (isArray) { this.attributes |= VariableAttributes.IsArray; } else if (isGenericList) { this.attributes |= VariableAttributes.IsList; } elementType = TypeUtility.GetElementType(type); //Debug.Log(elementType); this.dataType = DataTypeHelper.GetWrappedDataTypeFromSystemType(elementType); } // Root data type or element type of collection is unknown if (this.dataType == DataType.Unknown) { if (isArray || isGenericList) { IList list = (IList)value; int count = list.Count; List <string> unknownList = new List <string>(count); for (int i = 0; i < count; i++) { unknownList.Add(type.Name); } this.value = unknownList; } else { // Let's just use the type of the value to help us debug this.value = type.Name; } } if (generateMetadata) { metaData = VariableMetaData.Create(dataType, elementType, value, attributes); } }
VariableAttr FindVariable(VariableAttributes attr) { var val = variableAttrList.FirstOrDefault(a => a.type == attr); if (val == null) { throw new Exception("Attribute " + Enum.GetName(typeof(FixedAttributes), attr) + " not found in " + name); } return(val); }
public void DefineLocalVariable2( string name, VariableAttributes attributes, int sigToken, int addr1, int addr2, int addr3, int startOffset, int endOffset) { m_writer.DefineLocalVariable2(name, (int)attributes, sigToken, 1 /* ILOffset*/, addr1, addr2, addr3, startOffset, endOffset); }
public WrappedBaseObject(BinaryReader br) { this.variableName = br.ReadString(); this.attributes = (VariableAttributes)br.ReadByte(); this.dataType = (DataType)br.ReadByte(); bool hasMetaData = br.ReadBoolean(); if (hasMetaData) { metaData = new VariableMetaData(br, dataType, attributes); } }
public void DefineLocalVariable2( string name, VariableAttributes attributes, SymbolToken sigToken, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset) { m_writer.DefineLocalVariable2(name, (int)attributes, sigToken, (int)addrKind, addr1, addr2, addr3, startOffset, endOffset); }
// Deserialisation constructor public WrappedMethod(BinaryReader br) { this.methodName = br.ReadString(); this.returnType = (DataType)br.ReadByte(); this.returnTypeAttributes = (VariableAttributes)br.ReadByte(); this.methodAttributes = (MethodAttributes)br.ReadByte(); int parameterCount = br.ReadInt32(); parameters.Clear(); for (int i = 0; i < parameterCount; i++) { parameters.Add(new WrappedParameter(br)); } }
public void AddNewNode(NodeId parent) { // Create a Variable node. AddNodesItem node2 = new AddNodesItem( ); node2.ParentNodeId = new NodeId(parent); node2.ReferenceTypeId = ReferenceTypes.HasComponent; node2.RequestedNewNodeId = null; node2.BrowseName = new QualifiedName("DataVariable1"); node2.NodeClass = NodeClass.Variable; node2.NodeAttributes = null; node2.TypeDefinition = VariableTypeIds.BaseDataVariableType; //specify node attributes. VariableAttributes node2Attribtues = new VariableAttributes( ); node2Attribtues.DisplayName = "DataVariable1"; node2Attribtues.Description = "DataVariable1 Description"; node2Attribtues.Value = new Variant(123); node2Attribtues.DataType = (uint)BuiltInType.Int32; node2Attribtues.ValueRank = ValueRanks.Scalar; node2Attribtues.ArrayDimensions = new UInt32Collection( ); node2Attribtues.AccessLevel = AccessLevels.CurrentReadOrWrite; node2Attribtues.UserAccessLevel = AccessLevels.CurrentReadOrWrite; node2Attribtues.MinimumSamplingInterval = 0; node2Attribtues.Historizing = false; node2Attribtues.WriteMask = (uint)AttributeWriteMask.None; node2Attribtues.UserWriteMask = (uint)AttributeWriteMask.None; node2Attribtues.SpecifiedAttributes = (uint)NodeAttributesMask.All; node2.NodeAttributes = new ExtensionObject(node2Attribtues); AddNodesItemCollection nodesToAdd = new AddNodesItemCollection { node2 }; m_session.AddNodes( null, nodesToAdd, out AddNodesResultCollection results, out DiagnosticInfoCollection diagnosticInfos); ClientBase.ValidateResponse(results, nodesToAdd); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToAdd); }
/// <summary> /// Funkcja wywoływana przy generowaniu strony /// </summary> public void OnGet() { try { AsixRestClient asixRestClient = new AsixRestClient(); VariableAttributes variableAttributes = asixRestClient.ReadVariableAttributes(mVariableName, mAttributeNameList); if (variableAttributes.readSucceeded) { mVariableAttributes = variableAttributes.mAttributeValueList; } else { mReadError = variableAttributes.readStatusString; } } catch (Exception e) { mReadError = e.Message; } }
public void Write(BinaryWriter bw, DataType dataType, VariableAttributes attributes) { if (dataType == DataType.UnityObjectReference) { bw.Write(typeFullName); bw.Write(assemblyName); } if (dataType == DataType.Enum) { bw.Write(enumUnderlyingType); bw.Write(enumNames.Length); for (int i = 0; i < enumNames.Length; i++) { bw.Write(enumNames[i]); } for (int i = 0; i < enumNames.Length; i++) { DataTypeHelper.WriteIntegerToBinary(enumValues[i], bw); } } }
public WrappedVariable(BinaryReader br) { this.variableName = br.ReadString(); this.attributes = (VariableAttributes)br.ReadByte(); this.dataType = (DataType)br.ReadByte(); if (this.attributes.HasFlagByte(VariableAttributes.IsArray)) { int count = br.ReadInt32(); object[] array = new object[count]; for (int i = 0; i < count; i++) { array[i] = DataTypeHelper.ReadFromBinary(dataType, br); } this.value = array; } else if (this.attributes.HasFlagByte(VariableAttributes.IsList)) { int count = br.ReadInt32(); List <object> list = new List <object>(count); for (int i = 0; i < count; i++) { list.Add(DataTypeHelper.ReadFromBinary(dataType, br)); } this.value = list; } else { this.value = DataTypeHelper.ReadFromBinary(dataType, br); } bool hasMetaData = br.ReadBoolean(); if (hasMetaData) { metaData = new VariableMetaData(br, dataType, attributes); } }
public void AddNewNode(NodeId parent) { AddNodesItem addNodesItem1 = new AddNodesItem(); addNodesItem1.ParentNodeId = (ExpandedNodeId) new NodeId(parent); addNodesItem1.ReferenceTypeId = (NodeId)47U; addNodesItem1.RequestedNewNodeId = (ExpandedNodeId)null; addNodesItem1.BrowseName = new QualifiedName("DataVariable1"); addNodesItem1.NodeClass = NodeClass.Variable; addNodesItem1.NodeAttributes = (ExtensionObject)null; addNodesItem1.TypeDefinition = (ExpandedNodeId)VariableTypeIds.BaseDataVariableType; VariableAttributes variableAttributes = new VariableAttributes(); variableAttributes.DisplayName = (LocalizedText)"DataVariable1"; variableAttributes.Description = (LocalizedText)"DataVariable1 Description"; variableAttributes.Value = new Opc.Ua.Variant(123); variableAttributes.DataType = (NodeId)6U; variableAttributes.ValueRank = -1; variableAttributes.ArrayDimensions = new UInt32Collection(); variableAttributes.AccessLevel = (byte)3; variableAttributes.UserAccessLevel = (byte)3; variableAttributes.MinimumSamplingInterval = 0.0; variableAttributes.Historizing = false; variableAttributes.WriteMask = 0U; variableAttributes.UserWriteMask = 0U; variableAttributes.SpecifiedAttributes = 4194303U; addNodesItem1.NodeAttributes = new ExtensionObject((object)variableAttributes); AddNodesItemCollection nodesItemCollection = new AddNodesItemCollection(); AddNodesItem addNodesItem2 = addNodesItem1; nodesItemCollection.Add(addNodesItem2); AddNodesItemCollection nodesToAdd = nodesItemCollection; AddNodesResultCollection results; DiagnosticInfoCollection diagnosticInfos; this.m_session.AddNodes((RequestHeader)null, nodesToAdd, out results, out diagnosticInfos); ClientBase.ValidateResponse((IList)results, (IList)nodesToAdd); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, (IList)nodesToAdd); }
public WrappedVariable(PropertyInfo propertyInfo, object objectValue) : this(propertyInfo.Name, objectValue, propertyInfo.PropertyType, true) { MethodInfo getMethod = propertyInfo.GetGetMethod(true); MethodInfo setMethod = propertyInfo.GetSetMethod(true); if (setMethod == null) { this.attributes |= VariableAttributes.ReadOnly; } if (getMethod.IsStatic) { this.attributes |= VariableAttributes.IsStatic; } if (propertyInfo.PropertyType.IsValueType) { this.attributes |= VariableAttributes.IsValueType; } if (AttributeHelper.IsObsolete(propertyInfo.GetCustomAttributes(false))) { this.attributes |= VariableAttributes.Obsolete; } }
public Variable(string name, VariableAttributes attributes, int data2) { Name = name; Attributes = attributes; Data2 = data2; }
public void DefineLocalVariable2( string name, VariableAttributes attributes, SymbolToken sigToken, SymAddressKind addrKind, int addr1, int addr2, int addr3, int startOffset, int endOffset) { m_writer.DefineLocalVariable2 (name, (int)attributes, sigToken, (int)addrKind, addr1, addr2, addr3, startOffset, endOffset); }
public NodeId CreateVariable( NodeId parentId, NodeId referenceTypeId, NodeId nodeId, QualifiedName browseName, VariableAttributes attributes, ExpandedNodeId typeDefinitionId) { return null; }
public void DrawProperties(Type componentType, object component, string searchTerm, PropertyInfo[] properties) { foreach (var property in properties) { if (property.DeclaringType == typeof(Component) || property.DeclaringType == typeof(UnityEngine.Object)) { continue; } if (!SearchMatches(searchTerm, property.Name)) { // Does not match search term, skip it continue; } if (property.GetIndexParameters().Length != 0) { // Indexer, show it in Methods instead as it takes parameters continue; } MethodInfo getMethod = property.GetGetMethod(true); MethodInfo setMethod = property.GetSetMethod(true); object[] attributes = property.GetCustomAttributes(false); VariableAttributes variableAttributes = VariableAttributes.None; if (getMethod != null && getMethod.IsStatic || setMethod != null && setMethod.IsStatic) { variableAttributes |= VariableAttributes.Static; } if (setMethod == null) { variableAttributes |= VariableAttributes.ReadOnly; } if (getMethod == null) { variableAttributes |= VariableAttributes.WriteOnly; } string tooltip = TypeUtility.GetTooltip(property, variableAttributes); if (getMethod == null) { EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent("No get method", SidekickEditorGUI.ErrorIconSmall)); } else if (InspectionExclusions.IsPropertyExcluded(componentType, property)) { EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent("Excluded due to rule", SidekickEditorGUI.ErrorIconSmall, "See InspectionExclusions.cs")); } else if (AttributeHelper.IsObsoleteWithError(attributes)) { // Don't try to get the value of properties that error on access EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent("[Obsolete] error", SidekickEditorGUI.ErrorIconSmall)); } else { object oldValue = null; Exception error = null; try { oldValue = getMethod.Invoke(component, null); } catch (Exception e) { error = e; } if (error != null) { EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent(error.GetType().Name, SidekickEditorGUI.ErrorIconSmall)); } else { DrawVariable(property.PropertyType, property.Name, oldValue, tooltip, variableAttributes, property.GetCustomAttributes(), true, componentType, newValue => { setMethod?.Invoke(component, new[] { newValue }); }); } } } }
public static Type GetSystemTypeFromWrappedDataType(DataType dataType, VariableMetaData metaData, VariableAttributes attributes) { Type elementType = GetSystemTypeFromWrappedDataType(dataType, metaData); if (elementType != null) { if (attributes.HasFlagByte(VariableAttributes.IsArray)) { return(elementType.MakeArrayType()); } else if (attributes.HasFlagByte(VariableAttributes.IsList)) { Type listType = typeof(List <>); return(listType.MakeGenericType(elementType)); } else { return(elementType); } } else { // None matched return(null); } }
public WrappedVariable(string variableName, object value, Type type, bool generateMetadata, VariableAttributes attributes) : this(variableName, value, type, generateMetadata) { this.attributes = attributes; }
public NodeId CreateVariable( NodeId parentId, NodeId referenceTypeId, NodeId nodeId, QualifiedName browseName, VariableAttributes attributes, ExpandedNodeId typeDefinitionId) { try { m_lock.Enter(); // check browse name. if (QualifiedName.IsNull(browseName)) { throw new ServiceResultException(StatusCodes.BadBrowseNameInvalid); } // user default type definition. if (NodeId.IsNull(typeDefinitionId)) { typeDefinitionId = VariableTypes.BaseDataVariableType; } // find type definition. IVariableType variableType = GetManagerHandle(typeDefinitionId) as IVariableType; if (variableType == null) { throw ServiceResultException.Create(StatusCodes.BadTypeDefinitionInvalid, "Type definition '{0}' does not exist or is not an VariableType.", typeDefinitionId); } // check if node id exists. if (!NodeId.IsNull(nodeId)) { if (m_nodes.Exists(nodeId)) { throw ServiceResultException.Create(StatusCodes.BadNodeIdExists, "NodeId '{0}' already exists.", nodeId); } } // create a unique id. else { nodeId = CreateUniqueNodeId(); } // find parent. ILocalNode parent = null; if (!NodeId.IsNull(parentId)) { parent = GetManagerHandle(parentId) as ILocalNode; if (parent == null) { throw ServiceResultException.Create(StatusCodes.BadParentNodeIdInvalid, "Parent node '{0}' does not exist.", parentId); } // validate reference. ValidateReference(parent, referenceTypeId, false, NodeClass.Variable); } // verify instance declarations. ILocalNode instanceDeclaration = FindInstanceDeclaration(parent, browseName); if (instanceDeclaration != null) { if (instanceDeclaration.NodeClass != NodeClass.Variable) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The type model requires that node with a browse name of {0} have a NodeClass of {1}.", browseName, instanceDeclaration.NodeClass); } if (!m_server.TypeTree.IsTypeOf(typeDefinitionId, instanceDeclaration.TypeDefinitionId)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The type model requires that node have a type definition of {0}.", instanceDeclaration.TypeDefinitionId); } } // get the variable. IVariable variable = instanceDeclaration as IVariable; // create node. VariableNode node = new VariableNode(); // set defaults from type definition. node.NodeId = nodeId; node.NodeClass = NodeClass.Variable; node.BrowseName = browseName; node.DisplayName = browseName.Name; node.Description = null; node.WriteMask = 0; node.UserWriteMask = 0; node.Value = (variable == null)?new Variant(Utils.Clone(variableType.Value)):Variant.Null; node.DataType = variableType.DataType; node.ValueRank = variableType.ValueRank; node.ArrayDimensions = new UInt32Collection(variableType.ArrayDimensions); node.AccessLevel = AccessLevels.CurrentReadOrWrite; node.UserAccessLevel = node.AccessLevel; node.MinimumSamplingInterval = MinimumSamplingIntervals.Indeterminate; node.Historizing = false; // set defaults from instance declaration. if (variable != null) { node.DisplayName = variable.DisplayName; node.Description = variable.Description; node.WriteMask = (uint)variable.WriteMask; node.UserWriteMask = (uint)variable.UserWriteMask; node.Value = new Variant(Utils.Clone(variable.Value)); node.DataType = variable.DataType; node.ValueRank = variable.ValueRank; node.ArrayDimensions = new UInt32Collection(variable.ArrayDimensions); node.AccessLevel = variable.AccessLevel; node.UserAccessLevel = variable.UserAccessLevel; node.MinimumSamplingInterval = variable.MinimumSamplingInterval; node.Historizing = variable.Historizing; } // update attributes. UpdateAttributes(node, attributes); // Value if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.Value) != 0) { node.Value = attributes.Value; } // DataType if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.DataType) != 0) { if (!m_server.TypeTree.IsTypeOf(attributes.DataType, variableType.DataType)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The type definition requires a DataType of {0}.", variableType.DataType); } if (variable != null) { if (!m_server.TypeTree.IsTypeOf(attributes.DataType, variable.DataType)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The instance declaration requires a DataType of {0}.", variable.DataType); } } node.DataType = attributes.DataType; } // ValueRank if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.ValueRank) != 0) { if (!ValueRanks.IsValid(attributes.ValueRank, variableType.ValueRank)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The type definition requires a ValueRank of {0}.", variableType.ValueRank); } if (variable != null) { if (!ValueRanks.IsValid(attributes.ValueRank, variable.ValueRank)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The instance declaration requires a ValueRank of {0}.", variable.ValueRank); } } node.ValueRank = attributes.ValueRank; } // ArrayDimensions if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.ArrayDimensions) != 0) { if (!ValueRanks.IsValid(attributes.ArrayDimensions, node.ValueRank, variableType.ArrayDimensions)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The ArrayDimensions do not meet the requirements for the type definition: {0}.", variableType.NodeId); } if (variable != null) { if (!ValueRanks.IsValid(attributes.ArrayDimensions, node.ValueRank, variable.ArrayDimensions)) { throw ServiceResultException.Create( StatusCodes.BadNodeClassInvalid, "The ArrayDimensions do not meet the requirements for the instance declaration: {0}.", variable.ValueRank); } } node.ArrayDimensions = attributes.ArrayDimensions; } // AccessLevel if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.AccessLevel) != 0) { node.AccessLevel = attributes.AccessLevel; } // AccessLevel if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.UserAccessLevel) != 0) { node.UserAccessLevel = attributes.UserAccessLevel; } // MinimumSamplingInterval if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.MinimumSamplingInterval) != 0) { node.MinimumSamplingInterval = attributes.MinimumSamplingInterval; } // Historizing if (attributes != null && (attributes.SpecifiedAttributes & (uint)NodeAttributesMask.Historizing) != 0) { node.Historizing = attributes.Historizing; } // add references with parent. if (parent != null) { AddReference(parent, referenceTypeId, false, node, true); } // add type definition. AddReference(node, ReferenceTypeIds.HasTypeDefinition, false, variableType, false); // add to address space. AddNode(node); // apply modelling rules. NodeFactory factory = new NodeFactory(m_nodes); IList<ILocalNode> nodesToAdd = factory.ApplyModellingRules(node, variableType.NodeId, ref m_lastId, 1); // add the nodes. foreach (Node nodeToAdd in nodesToAdd) { AddNode(nodeToAdd); } // add references with parent. if (parent != null) { AddReference(parent, referenceTypeId, false, node, true); } // find the top level parent that must be used to apply the modelling rules. if (instanceDeclaration != null) { ILocalNode toplevelParent = FindTopLevelModelParent(parent); // add modelling rule. AddReference(node, ReferenceTypeIds.HasModelParent, false, parent, true); // update the hierarchy. nodesToAdd = factory.ApplyModellingRules(toplevelParent, (NodeId)toplevelParent.TypeDefinitionId, ref m_lastId, 1); // add the nodes. foreach (Node nodeToAdd in nodesToAdd) { AddNode(nodeToAdd); } } // return the new node id. return node.NodeId; } finally { m_lock.Exit(); } }
public Variable (string name, VariableAttributes attributes) { m_name = name; m_attributes = attributes; }
public static void DrawVariable(Type fieldType, string fieldName, object fieldValue, string tooltip, VariableAttributes variableAttributes, IEnumerable <Attribute> customAttributes, bool allowExtensions, Type contextType, Action <object> changeCallback) { if ((variableAttributes & VariableAttributes.Static) != 0) { var style = new GUIStyle { normal = { background = SidekickEditorGUI.StaticBackground } }; EditorGUILayout.BeginVertical(style); } GUIStyle expandButtonStyle = new GUIStyle(GUI.skin.button); RectOffset padding = expandButtonStyle.padding; padding.left = 0; padding.right = 1; expandButtonStyle.padding = padding; fieldValue ??= TypeUtility.GetDefaultValue(fieldType); string displayName = SidekickUtility.NicifyIdentifier(fieldName); GUIContent label = new GUIContent(displayName, tooltip); bool isArray = fieldType.IsArray; bool isGenericList = TypeUtility.IsGenericList(fieldType); bool isGenericDictionary = TypeUtility.IsGenericDictionary(fieldType); if (isGenericDictionary) { EditorGUILayout.BeginHorizontal(); string expandedID = fieldType.FullName + fieldName; bool expanded = DrawHeader(expandedID, label, (variableAttributes & VariableAttributes.Static) != 0); int count = 0; if (fieldValue != null) { EditorGUI.BeginDisabledGroup(true); count = (int)fieldType.GetProperty("Count").GetValue(fieldValue); EditorGUILayout.IntField(count, GUILayout.Width(80)); EditorGUI.EndDisabledGroup(); } if (allowExtensions) { DrawExtensions(fieldValue, expandButtonStyle); } EditorGUILayout.EndHorizontal(); if (expanded) { EditorGUI.indentLevel++; if (fieldValue != null) { FieldInfo entriesArrayField = fieldType.GetField("entries", BindingFlags.NonPublic | BindingFlags.Instance); IList entriesArray = (IList)entriesArrayField.GetValue(fieldValue); Type elementType = TypeUtility.GetFirstElementType(entriesArrayField.FieldType); FieldInfo elementKeyFieldInfo = elementType.GetField("key", BindingFlags.Public | BindingFlags.Instance); FieldInfo elementValueFieldInfo = elementType.GetField("value", BindingFlags.Public | BindingFlags.Instance); int oldIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; for (int i = 0; i < count; i++) { object entry = entriesArray[i]; EditorGUILayout.BeginHorizontal(); object key = elementKeyFieldInfo.GetValue(entry); object value = elementValueFieldInfo.GetValue(entry); using (new EditorGUI.DisabledScope(true)) { DrawIndividualVariable(GUIContent.none, key.GetType(), key, null, out _, newValue => { /*list[index] = newValue;*/ }); } DrawIndividualVariable(GUIContent.none, value.GetType(), value, null, out var handled, newValue => { PropertyInfo indexer = fieldType.GetProperties().First(x => x.GetIndexParameters().Length > 0); indexer.SetValue(fieldValue, newValue, new[] { key }); }); EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel = oldIndent; } EditorGUI.indentLevel--; } EditorGUILayout.EndFoldoutHeaderGroup(); } else if (isArray || isGenericList) { Type elementType = TypeUtility.GetFirstElementType(fieldType); EditorGUILayout.BeginHorizontal(); string expandedID = fieldType.FullName + fieldName; bool expanded = DrawHeader(expandedID, label, (variableAttributes & VariableAttributes.Static) != 0); EditorGUI.BeginDisabledGroup((variableAttributes & VariableAttributes.ReadOnly) != 0); IList list = null; int previousSize = 0; if (fieldValue != null) { list = (IList)fieldValue; previousSize = list.Count; } int newSize = Mathf.Max(0, EditorGUILayout.IntField(previousSize, GUILayout.Width(80))); if (newSize != previousSize) { var newValue = CollectionUtility.Resize(list, isArray, fieldType, elementType, newSize); changeCallback(newValue); } if (allowExtensions) { DrawExtensions(fieldValue, expandButtonStyle); } EditorGUILayout.EndHorizontal(); if (expanded) { EditorGUI.indentLevel++; if (list != null) { for (int i = 0; i < list.Count; i++) { EditorGUILayout.BeginHorizontal(); int index = i; DrawIndividualVariable(new GUIContent("Element " + i), elementType, list[i], null, out var handled, newValue => { list[index] = newValue; }); if (allowExtensions) { DrawExtensions(list[i], expandButtonStyle); } EditorGUILayout.EndHorizontal(); } } EditorGUI.indentLevel--; } EditorGUILayout.EndFoldoutHeaderGroup(); } else { EditorGUI.BeginDisabledGroup((variableAttributes & VariableAttributes.ReadOnly) != 0); // Not a collection EditorGUILayout.BeginHorizontal(); DrawIndividualVariable(label, fieldType, fieldValue, customAttributes, out var handled, changeCallback); if (handled && allowExtensions) { DrawExtensions(fieldValue, expandButtonStyle); } EditorGUILayout.EndHorizontal(); if (!handled) { EditorGUI.EndDisabledGroup(); string expandedID = fieldType.FullName + fieldName; EditorGUILayout.BeginHorizontal(); bool expanded = DrawHeader(expandedID, label, (variableAttributes & VariableAttributes.Static) != 0); if (allowExtensions) { DrawExtensions(fieldValue, expandButtonStyle); } EditorGUILayout.EndHorizontal(); EditorGUI.BeginDisabledGroup((variableAttributes & VariableAttributes.ReadOnly) != 0); if (expanded) { EditorGUI.indentLevel++; if (fieldValue != null) { var fields = fieldType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); foreach (var fieldInfo in fields) { GUIContent subLabel = new GUIContent(fieldInfo.Name); DrawIndividualVariable(subLabel, fieldInfo.FieldType, fieldInfo.GetValue(fieldValue), null, out _, newValue => { fieldInfo.SetValue(fieldValue, newValue); }); } } else { GUILayout.Label("Null"); } EditorGUI.indentLevel--; } EditorGUILayout.EndFoldoutHeaderGroup(); } } EditorGUI.EndDisabledGroup(); if ((variableAttributes & VariableAttributes.Static) != 0) { EditorGUILayout.EndVertical(); } }
public Variable(string name, VariableAttributes attributes) { m_name = name; m_attributes = attributes; }
public static VariableMetaData Create(DataType dataType, Type elementType, object value, VariableAttributes attributes) { if (dataType == DataType.Enum || dataType == DataType.UnityObjectReference) { VariableMetaData metaData = new VariableMetaData(); metaData.typeFullName = elementType.FullName; metaData.assemblyName = elementType.Assembly.FullName; if (dataType == DataType.Enum) { metaData.enumNames = Enum.GetNames(elementType); metaData.enumValues = new int[metaData.enumNames.Length]; Array enumValuesArray = Enum.GetValues(elementType); for (int i = 0; i < metaData.enumNames.Length; i++) { metaData.enumValues[i] = (int)enumValuesArray.GetValue(i); } return(metaData); } else if (dataType == DataType.UnityObjectReference) { if ((value as UnityEngine.Object) != null || (value is UnityEngine.Object == false && value != null)) { if (attributes.HasFlagByte(VariableAttributes.IsArray)) { metaData.valueDisplayName = "Array Element"; } else if (attributes.HasFlagByte(VariableAttributes.IsList)) { metaData.valueDisplayName = "List Element"; } else { metaData.valueDisplayName = ((UnityEngine.Object)value).name; } } else { metaData.valueDisplayName = "null"; } return(metaData); } else { return(null); } } else { return(null); } }
public WrappedVariable(WrappedParameter parameter) : this(parameter.VariableName, parameter.DefaultValue, DataTypeHelper.GetSystemTypeFromWrappedDataType(parameter.DataType, parameter.MetaData, parameter.Attributes), parameter.MetaData) { this.attributes = parameter.Attributes; //arguments.Add(new WrappedVariable(parameter.VariableName, parameter.DefaultValue, type, parameter.MetaData)); }