Esempio n. 1
0
        public int GetSubSymbolCount(TcAdsSymbolInfo parent)
        {
            int num2;

            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }
            int count = 0;

            try
            {
                ITcAdsDataType type           = parent.ResolveType(DataTypeResolveStrategy.AliasReference);
                string         referencedType = null;
                if (!parent.TryGetReference(out referencedType))
                {
                    if (!parent.TryGetPointerRef(out referencedType))
                    {
                        if (((type != null) && (type.SubItems != null)) && (type.SubItems.Count > 0))
                        {
                            count = type.SubItems.Count;
                        }
                        else if (((type != null) && (type.Dimensions != null)) && (type.Dimensions.Count > 0))
                        {
                            ReadOnlyDimensionCollection dimensions = type.Dimensions;
                            if (dimensions != null)
                            {
                                count = 1;
                                int num3 = type.Dimensions.Count - 1;
                                while (true)
                                {
                                    if (num3 < 0)
                                    {
                                        if (parent.IsOversamplingArray)
                                        {
                                            count++;
                                        }
                                        break;
                                    }
                                    count *= dimensions[num3].ElementCount;
                                    num3--;
                                }
                            }
                            else
                            {
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        this.SetPlatformPointerSize(parent.Size);
                        ITcAdsDataType typeByName = this.GetTypeByName(referencedType);
                        if (typeByName != null)
                        {
                            count = ((parent.typeEntryFlags & AdsDataTypeFlags.AnySizeArray) != AdsDataTypeFlags.AnySizeArray) ? ((typeByName.Size > 0) ? 1 : 0) : 1;
                        }
                        else
                        {
                            object[] args = new object[] { referencedType };
                            Module.Trace.TraceWarning("Cannot get referenced type '{0}'!", args);
                        }
                    }
                }
                else
                {
                    this.SetPlatformPointerSize(parent.Size);
                    ITcAdsDataType typeByName = this.GetTypeByName(referencedType);
                    count = (typeByName == null) ? 0 : typeByName.SubItems.Count;
                }
                return(count);
            }
            catch (Exception exception)
            {
                Module.Trace.TraceError($"SymbolParent: {parent.ToString()}", exception);
                throw;
            }
            return(num2);
        }
Esempio n. 2
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);
        }