public static ISubmodelElement CreateSubmodelElement(this PropertyInfo property, object target) { if (DataType.IsSimpleType(property.PropertyType)) { DataType dataType = DataType.GetDataTypeFromSystemType(property.PropertyType); Property smProp = new Property(dataType) { IdShort = property.Name, Value = property.GetValue(target) }; return(smProp); } else { SubmodelElementCollection smCollection = new SubmodelElementCollection() { IdShort = property.Name }; object value = property.GetValue(target); Type valueType = value.GetType(); foreach (var subProperty in valueType.GetProperties(BindingFlags.Public | BindingFlags.Instance)) { ISubmodelElement smElement = CreateSubmodelElement(subProperty, value); smCollection.Value.Add(smElement); } return(smCollection); } }
public SubmodelElementCollectionAttribute(string idShort) { SubmodelElementCollection = new SubmodelElementCollection() { IdShort = idShort }; }
void createSMECItems(Item smeRootItem, SubmodelElementCollection smec, int i) { List <Item> smChilds = new List <Item>(); foreach (var sme in smec.value) { var smeItem = new Item(); smeItem.envIndex = i; smeItem.Text = sme.submodelElement.idShort; smeItem.Tag = sme.submodelElement; smChilds.Add(smeItem); if (sme.submodelElement is SubmodelElementCollection) { var smecNext = sme.submodelElement as SubmodelElementCollection; createSMECItems(smeItem, smecNext, i); } if (sme.submodelElement is Operation) { var o = sme.submodelElement as Operation; createOperationItems(smeItem, o, i); } if (sme.submodelElement is Entity) { var e = sme.submodelElement as Entity; createEntityItems(smeItem, e, i); } } smeRootItem.Childs = smChilds; foreach (var c in smChilds) { c.parent = smeRootItem; } }
public SubmodelElementCollectionAttribute(string idShort, string semanticId, KeyElements semanticKeyElement, KeyType semanticKeyType, bool semanticIdLocal) { SubmodelElementCollection = new SubmodelElementCollection() { IdShort = idShort, SemanticId = new Reference(new Key(semanticKeyElement, semanticKeyType, semanticId, semanticIdLocal)) }; }
private static SubmodelElementCollection setCollection(UANode node) { //Collection // -> SubmodelElement (multiple) SubmodelElementCollection coll = new SubmodelElementCollection(); foreach (Reference _ref in node.References) { if (_ref.ReferenceType == "HasComponent") { coll.value.Add(createSubmodelElement(findNode(_ref.Value))); } } return(coll); }
public static ISubmodelElementCollection CreateSubmodelElementCollection <T>(this IEnumerable <T> enumerable, string idShort) { SubmodelElementCollection smCollection = new SubmodelElementCollection() { IdShort = idShort }; Type type = typeof(T); foreach (var item in enumerable) { foreach (var property in type.GetProperties()) { ISubmodelElement smElement = CreateSubmodelElement(property, item); smCollection.Value.Add(smElement); } } return(smCollection); }
public static ISubmodelElement ToSubmodelElement(this SubmodelElementType_V1_0 envSubmodelElement, List <IConceptDescription> conceptDescriptions) { if (envSubmodelElement == null) { logger.Warn("EnvironmentSubmodelElement is null"); return(null); } ModelType modelType = envSubmodelElement.ModelType; if (modelType == null) { logger.Warn("ModelType of Element " + envSubmodelElement.IdShort + " is null"); return(null); } SubmodelElement submodelElement = null; if (modelType == ModelType.Property && envSubmodelElement is Property_V1_0 castedProperty) { Property property; if (DataObjectType.TryParse(castedProperty.ValueType, out DataObjectType dataObjectType)) { property = new Property(new DataType(dataObjectType)); } else { logger.Warn("Unable to parse ValueType of Property " + castedProperty.IdShort + " - ValueType: " + castedProperty.ValueType); property = new Property(); } property.Value = castedProperty.Value; property.ValueId = castedProperty.ValueId?.ToReference_V1_0(); submodelElement = property; } else if (modelType == ModelType.File && envSubmodelElement is File_V1_0 castedFile) { File file = new File { MimeType = castedFile.MimeType, Value = castedFile.Value }; submodelElement = file; } else if (modelType == ModelType.Blob && envSubmodelElement is Blob_V1_0 castedBlob) { Blob blob = new Blob { MimeType = castedBlob.MimeType, Value = Convert.FromBase64String(castedBlob.Value) }; submodelElement = blob; } else if (modelType == ModelType.RelationshipElement && envSubmodelElement is RelationshipElement_V1_0 castedRelationshipElement) { RelationshipElement relationshipElement = new RelationshipElement { First = castedRelationshipElement.First?.ToReference_V1_0 <IReferable>(), Second = castedRelationshipElement.Second?.ToReference_V1_0 <IReferable>() }; submodelElement = relationshipElement; } else if (modelType == ModelType.ReferenceElement && envSubmodelElement is ReferenceElement_V1_0 castedReferenceElement) { ReferenceElement referenceElement = new ReferenceElement { Value = castedReferenceElement.Value?.ToReference_V1_0() }; submodelElement = referenceElement; } else if (modelType == ModelType.Event && envSubmodelElement is Event_V1_0 castedEvent) { Event eventable = new Event(); submodelElement = eventable; } else if (modelType == ModelType.Operation && envSubmodelElement is Operation_V1_0 castedOperation) { Operation operation = new Operation { InputVariables = new OperationVariableSet(), OutputVariables = new OperationVariableSet() }; var operationInElements = castedOperation.In?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationInElements?.Count > 0) { foreach (var element in operationInElements) { operation.InputVariables.Add(element); } } var operationOutElements = castedOperation.Out?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationOutElements?.Count > 0) { foreach (var element in operationOutElements) { operation.OutputVariables.Add(element); } } submodelElement = operation; } else if (modelType == ModelType.SubmodelElementCollection && envSubmodelElement is SubmodelElementCollection_V1_0 castedSubmodelElementCollection) { SubmodelElementCollection submodelElementCollection = new SubmodelElementCollection(); if (castedSubmodelElementCollection.Value?.Count > 0) { submodelElementCollection.Value = new ElementContainer <ISubmodelElement>(); List <ISubmodelElement> smElements = castedSubmodelElementCollection.Value?.ConvertAll(c => c.submodelElement?.ToSubmodelElement(conceptDescriptions)); foreach (var smElement in smElements) { submodelElementCollection.Value.Add(smElement); } } submodelElement = submodelElementCollection; } if (submodelElement == null) { logger.Warn("SubmodelElement " + envSubmodelElement.IdShort + " is still null"); return(null); } submodelElement.Category = envSubmodelElement.Category; submodelElement.Description = envSubmodelElement.Description; submodelElement.IdShort = envSubmodelElement.IdShort; submodelElement.Kind = envSubmodelElement.Kind; submodelElement.SemanticId = envSubmodelElement.SemanticId?.ToReference_V1_0(); submodelElement.Constraints = null; string semanticId = envSubmodelElement.SemanticId?.Keys?.FirstOrDefault()?.Value; if (!string.IsNullOrEmpty(semanticId)) { submodelElement.ConceptDescription = conceptDescriptions.Find(f => f.Identification.Id == semanticId); submodelElement.EmbeddedDataSpecifications = submodelElement.ConceptDescription?.EmbeddedDataSpecifications; } return(submodelElement); }
public static ISubmodelElement ToSubmodelElement(this SubmodelElementType_V2_0 envSubmodelElement, List <IConceptDescription> conceptDescriptions) { if (envSubmodelElement == null) { return(null); } ModelType modelType = envSubmodelElement.ModelType; if (modelType == null) { return(null); } SubmodelElement submodelElement = null; if (modelType == ModelType.Property && envSubmodelElement is Property_V2_0 castedProperty) { DataObjectType dataObjectType; if (string.IsNullOrEmpty(castedProperty.ValueType)) { dataObjectType = DataObjectType.None; } else if (!DataObjectType.TryParse(castedProperty.ValueType, out dataObjectType)) { return(null); } Property property = new Property(new DataType(dataObjectType)) { Value = castedProperty.Value, ValueId = castedProperty.ValueId?.ToReference_V2_0() }; submodelElement = property; } else if (modelType == ModelType.MultiLanguageProperty && envSubmodelElement is MultiLanguageProperty_V2_0 castedMultiLanguageProperty) { MultiLanguageProperty multiLanguageProperty = new MultiLanguageProperty { Value = castedMultiLanguageProperty.Value, ValueId = castedMultiLanguageProperty.ValueId?.ToReference_V2_0() }; submodelElement = multiLanguageProperty; } else if (modelType == ModelType.Range && envSubmodelElement is Range_V2_0 castedRange) { if (!DataObjectType.TryParse(castedRange.ValueType, out DataObjectType dataObjectType)) { return(null); } Range range = new Range() { Min = new ElementValue(castedRange.Min, new DataType(dataObjectType)), Max = new ElementValue(castedRange.Max, new DataType(dataObjectType)), ValueType = new DataType(dataObjectType) }; submodelElement = range; } else if (modelType == ModelType.File && envSubmodelElement is File_V2_0 castedFile) { File file = new File { MimeType = castedFile.MimeType, Value = castedFile.Value }; submodelElement = file; } else if (modelType == ModelType.Blob && envSubmodelElement is Blob_V2_0 castedBlob) { Blob blob = new Blob { MimeType = castedBlob.MimeType, Value = Convert.FromBase64String(castedBlob.Value) }; submodelElement = blob; } else if (modelType == ModelType.RelationshipElement && envSubmodelElement is RelationshipElement_V2_0 castedRelationshipElement) { RelationshipElement relationshipElement = new RelationshipElement { First = castedRelationshipElement.First?.ToReference_V2_0 <IReferable>(), Second = castedRelationshipElement.Second?.ToReference_V2_0 <IReferable>() }; submodelElement = relationshipElement; } else if (modelType == ModelType.AnnotatedRelationshipElement && envSubmodelElement is AnnotatedRelationshipElement_V2_0 castedAnnotatedRelationshipElement) { AnnotatedRelationshipElement annotatedRelationshipElement = new AnnotatedRelationshipElement() { First = castedAnnotatedRelationshipElement.First?.ToReference_V2_0 <IReferable>(), Second = castedAnnotatedRelationshipElement.Second?.ToReference_V2_0 <IReferable>(), Annotation = castedAnnotatedRelationshipElement.Annotation?.ToReference_V2_0 <ISubmodelElement>() }; submodelElement = annotatedRelationshipElement; } else if (modelType == ModelType.ReferenceElement && envSubmodelElement is ReferenceElement_V2_0 castedReferenceElement) { ReferenceElement referenceElement = new ReferenceElement { Value = castedReferenceElement.Value?.ToReference_V2_0() }; submodelElement = referenceElement; } else if (modelType == ModelType.Event && envSubmodelElement is Event_V2_0 castedEvent) { Event eventable = new Event(); submodelElement = eventable; } else if (modelType == ModelType.BasicEvent && envSubmodelElement is BasicEvent_V2_0 castedBasicEvent) { BasicEvent basicEvent = new BasicEvent() { Observed = castedBasicEvent.Observed.ToReference_V2_0 <IReferable>() }; submodelElement = basicEvent; } else if (modelType == ModelType.Entity && envSubmodelElement is Entity_V2_0 castedEntity) { Entity entity = new Entity() { EntityType = (EntityType)Enum.Parse(typeof(EntityType), castedEntity.EntityType.ToString()), Asset = castedEntity.AssetReference.ToReference_V2_0 <IAsset>() }; var statements = castedEntity.Statements?.ConvertAll(c => c.submodelElement.ToSubmodelElement(conceptDescriptions)); if (statements?.Count > 0) { foreach (var element in statements) { entity.Statements.Add(element); } } submodelElement = entity; } else if (modelType == ModelType.Operation && envSubmodelElement is Operation_V2_0 castedOperation) { Operation operation = new Operation { InputVariables = new OperationVariableSet(), OutputVariables = new OperationVariableSet(), InOutputVariables = new OperationVariableSet() }; var operationInElements = castedOperation.InputVariables?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationInElements?.Count > 0) { foreach (var element in operationInElements) { operation.InputVariables.Add(element); } } var operationOutElements = castedOperation.OutputVariables?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationOutElements?.Count > 0) { foreach (var element in operationOutElements) { operation.OutputVariables.Add(element); } } var operationInOutElements = castedOperation.InOutputVariables?.ConvertAll(c => c.Value?.submodelElement?.ToSubmodelElement(conceptDescriptions)); if (operationInOutElements?.Count > 0) { foreach (var element in operationInOutElements) { operation.InOutputVariables.Add(element); } } submodelElement = operation; } else if (modelType == ModelType.SubmodelElementCollection && envSubmodelElement is SubmodelElementCollection_V2_0 castedSubmodelElementCollection) { SubmodelElementCollection submodelElementCollection = new SubmodelElementCollection(); if (castedSubmodelElementCollection.Value?.Count > 0) { submodelElementCollection.Value = new ElementContainer <ISubmodelElement>(); List <ISubmodelElement> smElements = castedSubmodelElementCollection.Value?.ConvertAll(c => c.submodelElement?.ToSubmodelElement(conceptDescriptions)); foreach (var smElement in smElements) { submodelElementCollection.Value.Add(smElement); } } submodelElement = submodelElementCollection; } if (submodelElement == null) { return(null); } submodelElement.Category = envSubmodelElement.Category; submodelElement.Description = envSubmodelElement.Description; submodelElement.IdShort = envSubmodelElement.IdShort; submodelElement.Kind = envSubmodelElement.Kind; submodelElement.SemanticId = envSubmodelElement.SemanticId?.ToReference_V2_0(); submodelElement.Parent = string.IsNullOrEmpty(envSubmodelElement.Parent) ? null : new Reference( new Key(KeyElements.AssetAdministrationShell, KeyType.IRI, envSubmodelElement.Parent, true)); submodelElement.Constraints = null; string semanticId = envSubmodelElement.SemanticId?.Keys?.FirstOrDefault()?.Value; if (!string.IsNullOrEmpty(semanticId)) { submodelElement.ConceptDescription = conceptDescriptions.Find(f => f.Identification.Id == semanticId); submodelElement.EmbeddedDataSpecifications = submodelElement.ConceptDescription?.EmbeddedDataSpecifications; } return(submodelElement); }