Esempio n. 1
0
        internal static void CheckIndices(int[] indices, IArrayType arrayType, bool acceptOversampled)
        {
            IOversamplingSupport support = arrayType as IOversamplingSupport;
            bool flag = ((support != null) && support.IsOversampled) & acceptOversampled;

            ArrayIndexConverter.CheckIndices(indices, arrayType.Dimensions.LowerBounds, arrayType.Dimensions.UpperBounds, false, acceptOversampled);
        }
Esempio n. 2
0
        private Array createPrimitiveValueArray(IArrayInstance arraySymbol, byte[] rawData, int offset, DateTime utcReadTime)
        {
            Array           array       = null;
            IArrayType      dataType    = (IArrayType)arraySymbol.DataType;
            IDataType       elementType = dataType.ElementType;
            IResolvableType type3       = elementType as IResolvableType;

            if (type3 != null)
            {
                elementType = type3.ResolveType(DataTypeResolveStrategy.AliasReference);
            }
            int  elementCount = dataType.Dimensions.ElementCount;
            Type managed      = null;

            int[] dimensionLengths = dataType.Dimensions.GetDimensionLengths();
            Array.Reverse(dimensionLengths);
            array = !base.valueConverter.TryGetManagedType(elementType, out managed) ? Array.CreateInstance(typeof(object), dimensionLengths) : Array.CreateInstance(managed, dimensionLengths);
            foreach (int[] numArray2 in new ArrayIndexIterator(dataType, false))
            {
                int[] numArray3 = ArrayIndexConverter.NormalizeIndices(numArray2, dataType);
                Array.Reverse(numArray3);
                int    num2 = ArrayIndexConverter.IndicesToSubIndex(numArray2, dataType);
                object obj2 = this.CreateValue(arraySymbol.SubSymbols[num2], rawData, offset, utcReadTime);
                array.SetValue(obj2, numArray3);
                offset += elementType.ByteSize;
            }
            return(array);
        }
Esempio n. 3
0
        internal static bool AreIndicesValid(int[] indices, IArrayType type, bool acceptOversampled)
        {
            IOversamplingSupport support = type as IOversamplingSupport;
            bool oversampled             = ((support != null) && support.IsOversampled) & acceptOversampled;

            return(ArrayIndexConverter.TryCheckIndices(indices, type.Dimensions.LowerBounds, type.Dimensions.UpperBounds, false, oversampled));
        }
Esempio n. 4
0
        internal Symbol(int[] indices, bool oversampleElement, ISymbol parent)
        {
            this.accessRights = SymbolAccessRights.All;
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            this.factoryServices = ((ISymbolFactoryServicesProvider)parent).FactoryServices;
            this.parent          = parent;
            base.Bind(((IBinderProvider)parent).Binder);
            string    str  = string.Empty;
            ArrayType type = (ArrayType)((DataType)parent.DataType).ResolveType(DataTypeResolveStrategy.AliasReference);

            type.CheckIndices(indices, oversampleElement);
            str = !oversampleElement?ArrayIndexConverter.IndicesToString(indices) : ArrayIndexConverter.OversamplingSubElementToString(type.Dimensions.ElementCount);

            base.instanceName = parent.InstanceName + str;
            this.instancePath = parent.InstancePath + str;
            DataType elementType = (DataType)type.ElementType;

            base.resolvedDataType = elementType;
            base.flags            = this.getSymbolFlags(parent, elementType);
            if (base.resolvedDataType != null)
            {
                base.size       = base.resolvedDataType.Size;
                base.dataTypeId = ((DataType)base.resolvedDataType).DataTypeId;
                base.category   = base.resolvedDataType.Category;
                base.typeName   = base.resolvedDataType.Name;
            }
            else
            {
                base.size       = !base.IsBitType ? type.ElementSize : 1;
                base.dataTypeId = type.ElementTypeId;
                base.category   = DataTypeCategory.Unknown;
                base.typeName   = type.ElementTypeName;
            }
            if (!oversampleElement)
            {
                this.calcAccess(parent, elementType, ArrayType.GetElementOffset(indices, (IArrayType)((DataType)parent.DataType).ResolveType(DataTypeResolveStrategy.AliasReference)), base.flags, elementType.Flags, out this.indexGroup, out this.indexOffset);
            }
            else
            {
                this.indexGroup  = 0xf019;
                this.indexOffset = 0;
            }
            base.SetContextMask(((IContextMaskProvider)parent).ContextMask);
            DataTypeCategory category = base.category;
        }
Esempio n. 5
0
 internal static bool IsOversamplingIndex(int[] indices, IArrayType type) =>
 ArrayIndexConverter.IsOversamplingIndex(indices, type);
Esempio n. 6
0
 internal int[] GetIndicesOfPosition(int position) =>
 ArrayIndexConverter.SubIndexToIndices(position, this);
Esempio n. 7
0
 internal static int GetElementPosition(int[] indices, IArrayType type)
 {
     CheckIndices(indices, type, false);
     return(ArrayIndexConverter.IndicesToSubIndex(indices, type));
 }
Esempio n. 8
0
            internal TcAdsSymbolInfo CreateArrayElement(TcAdsSymbolInfo parentArrayInstance, TcAdsDataType parentArrayType, int subIndex)
            {
                if (parentArrayInstance == null)
                {
                    throw new ArgumentNullException("arrayInstance");
                }
                if (parentArrayType == null)
                {
                    throw new ArgumentNullException("parentArrayType");
                }
                TcAdsSymbolInfo info     = null;
                ITcAdsDataType  baseType = parentArrayType.BaseType;

                if (baseType == null)
                {
                    DataTypeException innerException = new DataTypeException("Base type of Array '{0}' not defined!", parentArrayType);
                    throw new AdsSymbolException("Cannot create array element!", parentArrayInstance, innerException);
                }
                bool isBitType = parentArrayInstance.IsBitType;
                ReadOnlyDimensionCollection dimensions = parentArrayType.Dimensions;
                int elementSize = this.calcElementBaseSize(parentArrayInstance);

                if (subIndex < parentArrayType.Dimensions.ElementCount)
                {
                    info = new TcAdsSymbolInfo(this._parser, parentArrayInstance, subIndex)
                    {
                        size           = (uint)elementSize,
                        typeEntryFlags = this.createElementTypeEntryFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        flags          = this.createElementSymbolFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        dataTypeId     = (baseType == null) ? AdsDatatypeId.ADST_BIGTYPE : baseType.DataTypeId
                    };
                    if (baseType != null)
                    {
                        info.typeName  = baseType.Name;
                        info.arrayInfo = baseType.Dimensions.ToArray();
                    }
                    else
                    {
                        info.typeName  = parentArrayType.BaseTypeName;
                        info.arrayInfo = null;
                    }
                    info.comment = parentArrayInstance.Comment;
                    this.calcArrayElementIndexGroupIndexOffset(subIndex, parentArrayInstance, elementSize, out info.indexGroup, out info.indexOffset);
                    string str = ArrayIndexConverter.SubIndexToIndexString(parentArrayType.Dimensions.LowerBounds, parentArrayType.Dimensions.UpperBounds, subIndex);
                    info.instancePath = parentArrayInstance.instancePath + str;
                    info.shortName    = parentArrayInstance.shortName + str;
                    info.attributes   = parentArrayInstance.attributes;
                }
                if ((subIndex == parentArrayType.Dimensions.ElementCount) && ((parentArrayType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.Oversample)) != AdsDataTypeFlags.None))
                {
                    info = new TcAdsSymbolInfo(this._parser, parentArrayInstance, subIndex)
                    {
                        size           = (uint)elementSize,
                        typeEntryFlags = this.createElementTypeEntryFlags(parentArrayInstance, (TcAdsDataType)baseType),
                        flags          = this.createElementSymbolFlags(parentArrayInstance, (TcAdsDataType)baseType)
                    };
                    if (info.typeEntryFlags.HasFlag(AdsDataTypeFlags.None | AdsDataTypeFlags.Static))
                    {
                        info.indexGroup  = 0xf019;
                        info.indexOffset = 0;
                    }
                    else
                    {
                        info.indexGroup  = parentArrayInstance.indexGroup;
                        info.indexOffset = parentArrayInstance.indexOffset;
                    }
                    if (baseType != null)
                    {
                        info.dataTypeId = baseType.DataTypeId;
                        info.typeName   = baseType.Name;
                    }
                    else
                    {
                        info.dataTypeId = AdsDatatypeId.ADST_BIGTYPE;
                        info.typeName   = parentArrayType.BaseTypeName;
                    }
                    info.comment = parentArrayInstance.Comment;
                    string str2 = ArrayIndexConverter.OversamplingSubElementToString(subIndex);
                    info.instancePath = parentArrayInstance.instancePath + str2;
                    info.shortName    = parentArrayInstance.shortName + str2;
                    if ((parentArrayType.Flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.PropItem))
                    {
                        info.indexGroup  = 0xf017;
                        info.indexOffset = parentArrayType.TypeHashValue;
                    }
                    info.attributes = parentArrayInstance.attributes;
                }
                return(info);
            }
Esempio n. 9
0
        private TcAdsSymbolInfo GetSubSymbol(TcAdsSymbolInfo symbol, string symbolName, int pos)
        {
            TcAdsSymbolInfo parent = null;

            if (symbol.DataType == null)
            {
                symbol.dataType = this.GetTypeByName(symbol.typeName);
            }
            if (symbol.DataType != null)
            {
                ITcAdsDataType type = symbol.ResolveType(DataTypeResolveStrategy.AliasReference);
                if (type.SubItems.Count > 0)
                {
                    string str    = symbolName;
                    char[] anyOf  = new char[] { '.', '[' };
                    int    length = str.IndexOfAny(anyOf, pos + 1);
                    if (length != -1)
                    {
                        str = str.Substring(0, length);
                    }
                    bool flag = str[str.Length - 1] == '^';
                    if (flag)
                    {
                        str = str.Substring(0, str.Length - 1);
                    }
                    for (int i = 0; i < type.SubItems.Count; i++)
                    {
                        parent = this.GetSubSymbol(symbol, i, true);
                        if (parent.instancePath.Equals(str, StringComparison.OrdinalIgnoreCase))
                        {
                            if ((parent != null) & flag)
                            {
                                parent = this.GetSubSymbol(parent, 0, true);
                            }
                            if (length != -1)
                            {
                                parent = this.GetSubSymbol(parent, symbolName, length);
                            }
                            return(parent);
                        }
                    }
                    return(null);
                }
                if (type.Dimensions.Count > 0)
                {
                    SymbolParser.ArrayIndexType type2;
                    IList <int[]> jaggedIndices = null;
                    int           index         = symbolName.IndexOf(']', pos + 1);
                    if (index == -1)
                    {
                        return(null);
                    }
                    int length = symbol.instancePath.Length;
                    if (!SymbolParser.TryParseIndices(symbolName.Substring(length, (index + 1) - length), out jaggedIndices, out type2))
                    {
                        goto TR_0013;
                    }
                    else if (jaggedIndices.Count <= 1)
                    {
                        ReadOnlyDimensionCollection dimensions = type.Dimensions;
                        bool flag3 = type2 == SymbolParser.ArrayIndexType.Oversample;
                        if (ArrayIndexConverter.TryCheckIndices(jaggedIndices, type))
                        {
                            int subIndex = -1;
                            if (ArrayIndexConverter.TryGetSubIndex(jaggedIndices[0], dimensions.LowerBounds, dimensions.UpperBounds, type2 == SymbolParser.ArrayIndexType.Oversample, out subIndex))
                            {
                                parent = this.GetSubSymbol(symbol, subIndex, true);
                                if ((parent != null) && (symbolName.Length > (index + 1)))
                                {
                                    parent = this.GetSubSymbol(parent, symbolName, index + 1);
                                }
                            }
                        }
                    }
                    else
                    {
                        goto TR_0013;
                    }
                }
            }
            return(parent);

TR_0013:
            return(null);
        }