public ArrayElementValueIterator(IArrayValue arrayValue)
 {
     this._arrayValue = arrayValue;
     this._array      = (IArrayInstance)arrayValue.Symbol;
     this._type       = (IArrayType)arrayValue.DataType;
     this._indexIter  = new ArrayIndexIterator(this._type);
 }
Exemplo 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);
        }
Exemplo n.º 3
0
        public object ReadArrayElement(IArrayInstance symbol, int[] indices, out DateTime utcReadTime)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (indices == null)
            {
                throw new ArgumentNullException("indices");
            }
            if (indices.Length == 0)
            {
                throw new ArgumentOutOfRangeException("indices");
            }
            int    num    = 0;
            object result = null;
            string str    = string.Join <int>(",", indices);

            num = this.tryReadValue(symbol, indices, out result, out utcReadTime);
            if (num == 0)
            {
                return(true);
            }
            Exception ex = new SymbolException($"Could not read ArrayInstance '{symbol.InstancePath}[{str}]'! Error: {num}", symbol);

            Module.Trace.TraceError(ex);
            throw ex;
        }
Exemplo n.º 4
0
        private bool TryGetSubSymbol(IArrayInstance root, int[] indices, out T found)
        {
            IArrayType dataType = (IArrayType)root.DataType;
            ISymbol    symbol   = null;
            T          local    = default(T);

            if (!root.TryGetElement(indices, out symbol))
            {
                found = default(T);
                return(false);
            }
            local = (T)symbol;
            found = local;
            return(true);
        }
Exemplo n.º 5
0
        private bool TryGetSubSymbol(T root, string[] relativePath, int index, out T found)
        {
            string        instanceName = null;
            IList <int[]> list;

            SymbolParser.ArrayIndexType type;
            string          indicesStr = null;
            IList <ISymbol> list2;

            if (!SymbolParser.TryParseArrayElement(relativePath[index], out instanceName, out indicesStr, out list, out type))
            {
                if (root.Category == DataTypeCategory.Struct)
                {
                    return(this.TryGetSubSymbol((IStructInstance)root, relativePath, index, out found));
                }
                found = default(T);
                return(false);
            }
            ((IStructInstance)root).MemberInstances.TryGetInstanceByName(instanceName, out list2);
            IArrayInstance instance2 = (IArrayInstance)list2[0];
            T    local = default(T);
            bool flag  = true;
            int  num   = 0;

            while (true)
            {
                if (num < list.Count)
                {
                    flag &= this.TryGetSubSymbol(instance2, list[num], out local);
                    if (flag)
                    {
                        instance2 = local as IArrayInstance;
                        num++;
                        continue;
                    }
                }
                if (flag)
                {
                    found = local;
                }
                else
                {
                    found = default(T);
                }
                return(flag);
            }
        }
Exemplo n.º 6
0
        private void WriteArrayElement(IArrayInstance arrInstance, int[] indices, object value, out DateTime utcWriteTime)
        {
            if (arrInstance == null)
            {
                throw new ArgumentNullException("arrInstance");
            }
            if (indices == null)
            {
                throw new ArgumentNullException("indices");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            IArrayType dataType    = (IArrayType)arrInstance.DataType;
            IDataType  elementType = dataType.ElementType;

            ArrayType.CheckIndices(indices, dataType, false);
            int     elementPosition = ArrayType.GetElementPosition(indices, dataType);
            ISymbol symbol          = arrInstance.SubSymbols[elementPosition];

            this.WriteValue(symbol, value, out utcWriteTime);
        }
Exemplo n.º 7
0
        public bool TryGetElement(IList <int[]> jaggedIndices, out ISymbol symbol)
        {
            if (jaggedIndices == null)
            {
                throw new ArgumentNullException("jaggedIndices");
            }
            if (((IArrayType)base.DataType).JaggedLevel < jaggedIndices.Count)
            {
                throw new ArgumentOutOfRangeException("jaggedIndices");
            }
            bool           flag     = true;
            IArrayInstance instance = this;
            ISymbol        symbol2  = null;

            symbol = null;
            int num = 0;

            while (true)
            {
                if (num < jaggedIndices.Count)
                {
                    flag &= instance.TryGetElement(jaggedIndices[num], out symbol2);
                    if (flag)
                    {
                        instance = symbol2 as IArrayInstance;
                        num++;
                        continue;
                    }
                }
                if (flag)
                {
                    symbol = symbol2;
                }
                return(flag);
            }
        }
Exemplo n.º 8
0
 public void Apply(IArrayInstance instance)
 {
     instance.Access.Field();
 }
Exemplo n.º 9
0
        internal static bool TryGetSubItem(IInstanceCollection <T> coll, string[] pathSplit, int splitIndex, out T symbol)
        {
            SymbolParser.ArrayIndexType type;
            T local = default(T);

            symbol = default(T);
            string        nameWithIndices = pathSplit[splitIndex];
            string        instanceName    = null;
            IList <int[]> jaggedIndices   = null;
            string        indicesStr      = null;
            bool          flag            = SymbolParser.TryParseArrayElement(nameWithIndices, out instanceName, out indicesStr, out jaggedIndices, out type);

            if (flag)
            {
                nameWithIndices = instanceName;
            }
            bool flag2 = nameWithIndices[nameWithIndices.Length - 1] == '^';

            if (flag2)
            {
                nameWithIndices = nameWithIndices.Substring(0, nameWithIndices.Length - 1);
            }
            IList <T> list2 = null;

            if (coll.TryGetInstanceByName(nameWithIndices, out list2))
            {
                local = list2[0];
                if (flag)
                {
                    ISymbol                  symbol2  = null;
                    IArrayInstance           instance = local as IArrayInstance;
                    IReferenceInstanceAccess access   = local as IReferenceInstanceAccess;
                    if (instance != null)
                    {
                        instance.TryGetElement(jaggedIndices, out symbol2);
                    }
                    else if (access != null)
                    {
                        access.TryGetElement(jaggedIndices, out symbol2);
                    }
                    local = (T)symbol2;
                }
                if ((local == null) || (splitIndex >= (pathSplit.Length - 1)))
                {
                    symbol = !((splitIndex == (pathSplit.Length - 1)) & flag2) ? local : ((ISymbolInternal)local).SubSymbolsInternal[0];
                }
                else
                {
                    ISymbol symbol3 = local as ISymbol;
                    if (symbol3.IsContainerType)
                    {
                        ISymbolCollection subSymbolsInternal = ((ISymbolInternal)symbol3).SubSymbolsInternal;
                        if (flag2)
                        {
                            subSymbolsInternal = ((ISymbolInternal)subSymbolsInternal[0]).SubSymbolsInternal;
                        }
                        if ((subSymbolsInternal != null) && (subSymbolsInternal.Count > 0))
                        {
                            T local2 = default(T);
                            splitIndex++;
                            if (InstanceCollection <T> .TryGetSubItem((IInstanceCollection <T>)subSymbolsInternal, pathSplit, splitIndex, out local2))
                            {
                                symbol = local2;
                            }
                            else
                            {
                                symbol = default(T);
                            }
                        }
                    }
                }
            }
            return(((T)symbol) != null);
        }
Exemplo n.º 10
0
 internal DynamicArrayInstance(IArrayInstance symbol) : base((IValueSymbol)symbol)
 {
 }
        public static void AddSymbolRecursive(List <ISymbol> symbols, ISymbol symbol, bool debug = false)
        {
            try
            {
                if (symbol.DataType == null && symbol.Category != DataTypeCategory.Struct)
                {
                    return;
                }
                if (symbol.DataType != null && symbol.DataType.Name.StartsWith("TC2_MC2."))
                {
                    return;
                }
                if (symbol.TypeName != null && symbol.TypeName == "TC2_MC2.MC_Power")
                {
                    Console.WriteLine();
                }
                foreach (ITypeAttribute attribute in symbol.Attributes)
                {
                    if (debug)
                    {
                        Debug.WriteLine($"{attribute.Name} : {attribute.Value}");
                    }
                }

                if (debug)
                {
                    Debug.WriteLine(
                        $"{symbol.InstancePath} : {symbol.TypeName} (IG: 0x{((IAdsSymbol)symbol).IndexGroup:x} IO: 0x{((IAdsSymbol)symbol).IndexOffset:x} size: {symbol.Size})");
                }

                switch (symbol.Category)
                {
                case DataTypeCategory.Array:
                    IArrayInstance arrInstance = (IArrayInstance)symbol;
                    //IArrayType arrType = (IArrayType)symbol.DataType;

                    if (arrInstance.Elements != null)
                    {
                        // int count = 0;
                        foreach (ISymbol arrayElement in arrInstance.Elements)
                        {
                            AddSymbolRecursive(symbols, arrayElement);

                            //count++;
                            //if (count > 20) // Write only the first 20 to limit output
                            //    break;
                        }
                    }
                    else
                    {
                        Debug.WriteLine($"Array elements of {arrInstance.TypeName} are null");
                    }

                    break;

                case DataTypeCategory.Struct:
                    IStructInstance structInstance = (IStructInstance)symbol;
                    //IStructType structType = (IStructType)symbol.DataType;
                    try
                    {
                        foreach (ISymbol member in structInstance.MemberInstances)
                        {
                            AddSymbolRecursive(symbols, member);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }

                    break;

                case DataTypeCategory.Reference:
                    // "REFERENCE TO ..." cannot be read, so filter it out. Comes from InOut variables in function blocks
                    // pass
                    if (symbol.IsPointer || symbol.DataType.Name.StartsWith("POINTER"))
                    {
                        break;
                    }
                    break;

                default:
                    symbols.Add(symbol);
                    break;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                throw;
            }
        }