예제 #1
0
        private static ABB.Vtrin.Interfaces.IEquipment CreateOrUpdateEquipmentType(
            string equipmentTypeName,
            bool isAbstract = false,
            ABB.Vtrin.Interfaces.IEquipment baseEquipmentType = null)
        {
            var equipmentIntances = RTDBDriver.Classes["Equipment"].Instances;

            // Try to find existing equipment type with the given name
            var equipmentType =
                (ABB.Vtrin.Interfaces.IEquipment)equipmentIntances[equipmentTypeName]?.BeginUpdate();

            // Case: No existing equipment type found
            // > Create a new equipment type
            if (equipmentType == null)
            {
                equipmentType = (ABB.Vtrin.Interfaces.IEquipment)equipmentIntances.Add();
            }

            // Update attributes and commit changes
            equipmentType.Name     = equipmentTypeName;
            equipmentType.Base     = baseEquipmentType;
            equipmentType.Abstract = isAbstract;
            equipmentType.CommitChanges();

            return(equipmentType);
        }
예제 #2
0
        private static ABB.Vtrin.Interfaces.IPropertyDefinition CreateOrUpdateEquipmentProperty(
            string propertyName,
            ABB.Vtrin.cTypeCode propertyType,
            string propertyUnit,
            bool isHistorized,
            ABB.Vtrin.Interfaces.IEquipment equipmentType,
            string propertyDescription = null,
            string referenceTarget     = null)
        {
            ABB.Vtrin.Interfaces.IPropertyDefinition property;
            var equipmentPropertyInstances = RTDBDriver.Classes["EquipmentPropertyInfo"].Instances;

            // Query existing property infos using property name and equipment type
            var properties = equipmentPropertyInstances.GetInstanceSet("Equipment=? AND DisplayName=?", equipmentType, propertyName);

            // Case: No existing property found
            // > Create a new property
            if (properties.Length == 0)
            {
                property = (ABB.Vtrin.Interfaces.IPropertyDefinition)equipmentPropertyInstances.Add();
            }

            // Case: Existing property found
            // > Select that and begin to update
            else
            {
                property = (ABB.Vtrin.Interfaces.IPropertyDefinition)properties[0].BeginUpdate();
            }

            // Update property info
            property.DisplayName     = propertyName;
            property.Type            = (int)propertyType;
            property.Unit            = propertyUnit;
            property.Description     = propertyDescription;
            property.Historized      = isHistorized;
            property.Equipment       = equipmentType;
            property.ReferenceTarget = referenceTarget;

            // Save or update property
            property.CommitChanges();

            return(property);
        }