Example #1
0
 internal DataType(DataTypeCategory cat, AdsDataTypeEntry entry)
 {
     s_idCounter++;
     this.id         = s_idCounter;
     this.comment    = string.Empty;
     this.flags      = AdsDataTypeFlags.DataType;
     this.attributes = new TypeAttributeCollection();
     this.category   = cat;
     this.comment    = entry.comment;
     this.name       = entry.entryName;
     this.flags      = entry.flags;
     this.size       = (int)entry.size;
     this.dataTypeId = entry.baseTypeId;
     if ((this.dataTypeId == AdsDatatypeId.ADST_BIGTYPE) && (this.category == DataTypeCategory.Unknown))
     {
         this.category = DataTypeCategory.Interface;
     }
     else if (this.category == DataTypeCategory.Unknown)
     {
         this.category = DataTypeCategory.Primitive;
     }
     this.typeHashValue = entry.typeHashValue;
     if (entry.HasAttributes)
     {
         this.attributes = new TypeAttributeCollection(entry.attributes);
     }
 }
Example #2
0
 public ReferenceType(AdsDataTypeEntry entry, string referencedTypeName) : base(DataTypeCategory.Reference, entry)
 {
     this.referencedTypeName = string.Empty;
     this.referencedTypeName = referencedTypeName;
     if (base.size == 4)
     {
         base.dotnetType = typeof(uint);
     }
     else if (base.size == 8)
     {
         base.dotnetType = typeof(ulong);
     }
 }
Example #3
0
 internal PointerType(AdsDataTypeEntry entry, string referencedTypeName) : base(DataTypeCategory.Pointer, entry)
 {
     this.referencedTypeName = string.Empty;
     this.referencedTypeName = referencedTypeName;
     if (entry.size == 4)
     {
         base.dotnetType = typeof(uint);
     }
     else
     {
         base.dotnetType = typeof(ulong);
     }
 }
Example #4
0
 internal UnionType(AdsDataTypeEntry entry) : base(DataTypeCategory.Union, entry)
 {
     this._fields = new FieldCollection();
     for (int i = 0; i < entry.subItems; i++)
     {
         AdsFieldEntry subEntry = entry.subEntries[i];
         Member        instance = new Member(this, subEntry);
         if (!this._fields.isUnique(instance))
         {
             ((IInstanceInternal)instance).SetInstanceName(this._fields.createUniquepathName(instance));
         }
         this._fields.Add(instance);
     }
 }
Example #5
0
        internal static ISubRangeType Create(AdsDataTypeEntry entry, IDataTypeResolver resolver)
        {
            ISubRangeType type     = null;
            string        baseType = null;

            if (DataTypeStringParser.TryParseSubRange(entry.entryName, out baseType))
            {
                IDataType type2 = null;
                if (resolver.TryResolveType(baseType, out type2))
                {
                    type = Create(entry.entryName, type2);
                }
            }
            return(type);
        }
Example #6
0
 public StructType(AdsDataTypeEntry entry) : base(DataTypeCategory.Struct, entry)
 {
     this._members      = new MemberCollection();
     this._baseTypeId   = entry.baseTypeId;
     this._baseTypeName = entry.typeName;
     for (int i = 0; i < entry.subItems; i++)
     {
         AdsFieldEntry subEntry = entry.subEntries[i];
         Member        instance = new Member(this, subEntry);
         if (!this._members.isUnique(instance))
         {
             ((IInstanceInternal)instance).SetInstanceName(this._members.createUniquepathName(instance));
         }
         this._members.Add(instance);
     }
 }
Example #7
0
 public EnumType(AdsDataTypeEntry entry) : base(DataTypeCategory.Enum, entry)
 {
     int num1;
     Type type = typeof(T);
     if (((type == typeof(byte)) || ((type == typeof(sbyte)) || ((type == typeof(short)) || ((type == typeof(ushort)) || ((type == typeof(int)) || (type == typeof(uint))))))) || (type == typeof(long)))
     {
         num1 = 1;
     }
     else
     {
         num1 = (int) (type == typeof(ulong));
     }
     if (num1 == 0)
     {
         throw new AdsException($"'{type}' is not a valid base type for an enumeration!");
     }
     base.dotnetType = type;
     this._baseTypeId = entry.baseTypeId;
     this._baseTypeName = entry.typeName;
     this._fields = new EnumValueCollection<T>(entry.enums);
 }
Example #8
0
        private void InitializeServerMemory()
        {
            //Set Upload Info
            memory.SetData(61455, new byte[64]);

            //Set Symbols for read
            memory.SetData(61451, new byte[0]);

            //Set symbols for readwrite
            memory.SetData(61449, new byte[0]);
            //Set symbols for readwrite Handlers
            memory.SetData(61443, new byte[0]);

            //cleanup
            memory.SetData(61446, new byte[1024]);

            //Set Datatype
            memory.SetData(61454, AdsDataTypeEntry.GetBytes());

            //Set Data (access over group + offset stored into handlers)
            memory.SetData(61445, new byte[0]);
        }
Example #9
0
        public ArrayType(AdsDataTypeEntry entry) : base(DataTypeCategory.Array, entry)
        {
            string str2;

            AdsDatatypeArrayInfo[] arrayInfos = entry.arrayInfos;
            AdsDatatypeArrayInfo[] dims       = null;
            AdsDatatypeArrayInfo[] infoArray3 = null;
            string baseType = null;

            if (DataTypeStringParser.TryParseArray(base.name, out dims, out baseType) && DataTypeStringParser.TryParseArray(baseType, out infoArray3, out str2))
            {
                this._dimensions     = new DimensionCollection(dims);
                this.elementTypeName = baseType;
                this.elementTypeId   = entry.baseTypeId;
            }
            else
            {
                this._dimensions     = new DimensionCollection(arrayInfos);
                this.elementTypeName = entry.typeName;
                this.elementTypeId   = entry.baseTypeId;
            }
            this._oversampled = (entry.flags & (AdsDataTypeFlags.None | AdsDataTypeFlags.Oversample)) == (AdsDataTypeFlags.None | AdsDataTypeFlags.Oversample);
        }
Example #10
0
 internal RpcStructType(AdsDataTypeEntry entry) : base(entry)
 {
     this._rpcMethods = new RpcMethodCollection(entry.methods);
 }
Example #11
0
 public AliasType(AdsDataTypeEntry entry) : base(DataTypeCategory.Alias, entry)
 {
     this._baseTypeId   = entry.baseTypeId;
     this._baseTypeName = entry.typeName;
 }
Example #12
0
 internal StringType(AdsDataTypeEntry entry) : base(DataTypeCategory.String, entry)
 {
     base.dotnetType = typeof(string);
 }
Example #13
0
 internal PrimitiveType(AdsDataTypeEntry entry, PrimitiveTypeFlags flags, Type dotnetType) : base(DataTypeCategory.Primitive, entry)
 {
     this._primitiveFlags = flags;
     base.dotnetType      = dotnetType;
 }
Example #14
0
        public static void ParseTypes(AdsStream dataTypeStream, Encoding encoding, IBinder binder, bool buildInTypesInStream, DataTypeCollection <IDataType> buildInTypes)
        {
            AdsBinaryReader reader         = new AdsBinaryReader(dataTypeStream);
            string          referencedType = null;

            while (dataTypeStream.Position < dataTypeStream.Length)
            {
                AdsDataTypeEntry entry = new AdsDataTypeEntry(true, encoding, reader);
                try
                {
                    IDataType type  = null;
                    bool      flag1 = buildInTypes.TryGetType(entry.entryName, out type);
                    DataType  type2 = (DataType)type;
                    if (buildInTypesInStream && flag1)
                    {
                        continue;
                    }
                    DataType type3  = null;
                    int      length = 0;
                    if (DataTypeStringParser.TryParseReference(entry.entryName, out referencedType))
                    {
                        type3 = new ReferenceType(entry, referencedType);
                    }
                    else if (DataTypeStringParser.TryParsePointer(entry.entryName, out referencedType))
                    {
                        type3 = new PointerType(entry, referencedType);
                    }
                    else
                    {
                        bool flag2;
                        if (DataTypeStringParser.TryParseString(entry.entryName, out length, out flag2))
                        {
                            type3 = !flag2 ? ((DataType) new StringType(length)) : ((DataType) new WStringType(length));
                        }
                        else if (entry.methodCount > 0)
                        {
                            type3 = new RpcStructType(entry);
                        }
                        else if (entry.subItems > 0)
                        {
                            bool flag3 = false;
                            bool flag4 = false;
                            if (entry.subItems > 1)
                            {
                                int             num2       = 0;
                                AdsFieldEntry[] subEntries = entry.subEntries;
                                int             index      = 0;
                                while (true)
                                {
                                    if (index >= subEntries.Length)
                                    {
                                        flag3 = entry.BitSize < num2;
                                        break;
                                    }
                                    AdsFieldEntry entry2 = subEntries[index];
                                    if (!entry2.IsStatic && !entry2.IsProperty)
                                    {
                                        int num4 = 0;
                                        num4   = !entry2.IsBitType ? (entry2.Offset * 8) : entry2.Offset;
                                        flag4 |= num4 < num2;
                                        num2  += entry2.BitSize;
                                    }
                                    index++;
                                }
                            }
                            type3 = !flag3 ? ((DataType) new StructType(entry)) : ((DataType) new UnionType(entry));
                        }
                        else if (entry.arrayDim > 0)
                        {
                            type3 = new ArrayType(entry);
                        }
                        else if (entry.enumInfoCount <= 0)
                        {
                            if (DataTypeStringParser.TryParseSubRange(entry.entryName, out referencedType))
                            {
                                type3 = (DataType)SubRangeTypeFactory.Create(entry, binder);
                            }
                            else if (((entry.baseTypeId > AdsDatatypeId.ADST_VOID) && (entry.typeName != null)) && (entry.typeName != string.Empty))
                            {
                                type3 = new AliasType(entry);
                            }
                            else
                            {
                                DataTypeCategory cat = CategoryConverter.FromId(entry.DataTypeId);
                                if (cat != DataTypeCategory.Unknown)
                                {
                                    Type tp = null;
                                    if (PrimitiveTypeConverter.TryGetManagedType(entry.DataTypeId, out tp))
                                    {
                                        if (cat == DataTypeCategory.Primitive)
                                        {
                                            type3 = new PrimitiveType(entry, PrimitiveTypeConverter.GetPrimitiveFlags(entry.DataTypeId), tp);
                                        }
                                        else if (cat == DataTypeCategory.String)
                                        {
                                            type3 = new StringType(entry);
                                        }
                                    }
                                }
                                if (type3 == null)
                                {
                                    type3 = new DataType(cat, entry);
                                }
                            }
                        }
                        else
                        {
                            AdsDatatypeId baseTypeId = entry.baseTypeId;
                            if (baseTypeId == AdsDatatypeId.ADST_INT16)
                            {
                                type3 = new EnumType <short>(entry);
                            }
                            else if (baseTypeId == AdsDatatypeId.ADST_INT32)
                            {
                                type3 = new EnumType <int>(entry);
                            }
                            else
                            {
                                switch (baseTypeId)
                                {
                                case AdsDatatypeId.ADST_INT8:
                                    type3 = new EnumType <sbyte>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT8:
                                    type3 = new EnumType <byte>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT16:
                                    type3 = new EnumType <ushort>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT32:
                                    type3 = new EnumType <uint>(entry);
                                    break;

                                case AdsDatatypeId.ADST_INT64:
                                    type3 = new EnumType <long>(entry);
                                    break;

                                case AdsDatatypeId.ADST_UINT64:
                                    type3 = new EnumType <ulong>(entry);
                                    break;

                                default:
                                    throw new AdsException("Enum base type mismatch!");
                                }
                            }
                        }
                    }
                    binder.RegisterType(type3);
                }
                catch (Exception exception)
                {
                    Module.Trace.TraceWarning($"Cannot parse DataTypeEntry. Skipping dataType '{entry.entryName}'!", exception);
                }
            }
        }