public T FromXml <T>(StructureMetadata metadata, XmlNode node)
        {
            Type type = typeof(T);

            EnsureTypeIsCached(type);

            T returnObject = default(T);

            if (!type.Equals(typeof(string)))
            {
                returnObject = Activator.CreateInstance <T>();
            }

            if (metadata == null)
            {
                return((T)this.FromRemoteValue(type, node.InnerText));
            }

            foreach (var field in metadata.Fields)
            {
                string       fieldName = field.Name;
                XmlNode      valueNode = node.SelectSingleNode(fieldName);
                PropertyInfo property  = null;
                if (typeProperties[type].TryGetValue(fieldName.ToLower(), out property))
                {
                    SetProperty(returnObject, property, valueNode.InnerText);
                }
            }
            return(returnObject);
        }
        private void AssertStructureMetadataField(StructureMetadata metadata, string name, AbapDataType dataType)
        {
            var field = metadata.GetField(name);

            Assert.Equal(name, field.Name);
            Assert.Equal(dataType, field.DataType);
        }
        private ParameterMetadata CreateParameterMetadata(string name, string typeName, bool isSequence)
        {
            AbapDataType      parameterType = AbapDataTypeParser.ParseFromTypeAttribute(typeName, isSequence);
            StructureMetadata metadata      = null;

            if (typeName.StartsWith("s0:"))
            {
                metadata = this.LoadStructureMetadata(typeName.Replace("s0:", ""));
            }

            return(new ParameterMetadata(name, parameterType, metadata));
        }
Beispiel #4
0
        protected override FunctionMetadata LoadFunctionMetadata(string functionName)
        {
            var remoteFunctionMetadata = this.connection.Repository.GetFunctionMetadata(functionName);

            List <ParameterMetadata> inputParameters  = new List <ParameterMetadata>();
            List <ParameterMetadata> outputParameters = new List <ParameterMetadata>();

            for (int i = 0; i < remoteFunctionMetadata.ParameterCount; i++)
            {
                StructureMetadata structureMetadata = null;
                if (remoteFunctionMetadata[i].DataType == RfcDataType.STRUCTURE)
                {
                    string structureName = remoteFunctionMetadata[i].ValueMetadataAsStructureMetadata.Name;
                    structureMetadata = this.GetStructureMetadata(structureName);
                }
                else if (remoteFunctionMetadata[i].DataType == RfcDataType.STRUCTURE)
                {
                    string structureName = remoteFunctionMetadata[i].ValueMetadataAsTableMetadata.LineType.Name;
                    structureMetadata = this.GetStructureMetadata(structureName);
                }

                var parameter = new ParameterMetadata(remoteFunctionMetadata[i].Name, remoteFunctionMetadata[i].GetAbapDataType(), structureMetadata);
                switch (remoteFunctionMetadata[i].Direction)
                {
                case RfcDirection.EXPORT:
                    outputParameters.Add(parameter);
                    break;

                case RfcDirection.IMPORT:
                    inputParameters.Add(parameter);
                    break;

                case RfcDirection.TABLES:
                case RfcDirection.CHANGING:
                    inputParameters.Add(parameter);
                    outputParameters.Add(parameter);
                    break;

                default:
                    break;
                }
            }

            return(new FunctionMetadata(functionName, inputParameters, outputParameters));
        }
        public async Task WriteBinaryResponse(List <DbStructure> structures)
        {
            //Binary mode writes out structures in binary structs

            //HEADER FORMAT:
            //  4   static  Signature, says "DWMS"
            //  4   int32   File type version, should be 3
            //  4   int32   Metadata version
            //  4   int32   Structure count

            //  4   int32   Saved epoch
            //  4   int32   RESERVED
            //  4   int32   RESERVED
            //  4   int32   RESERVED
            //TOTAL: 32 bytes

            //Struct format:
            //  2   short   Metadata Index
            //  1   byte    Rotation (in degrees, 0-360, but scaled so that 256=360)
            //  1   byte    Flags (SEE BELOW)
            //  4   float   Position X
            //  4   float   Position Y
            //  4   int32   ID
            //  4   float   Position Z
            //  4   int32   Tribe ID
            //TOTAL: 24 bytes each

            //FLAGS
            //0: Has inventory
            //1: Is remove
            //2: RESERVED
            //3: RESERVED
            //4: RESERVED
            //5: RESERVED
            //6: RESERVED
            //7: RESERVED

            //Set headers
            e.Response.ContentLength = (24 * structures.Count) + 32;
            e.Response.ContentType   = "application/octet-stream";
            e.Response.StatusCode    = 200;

            //Create and send file header
            byte[] buf = new byte[32];
            buf[0] = 0x44;
            buf[1] = 0x57;
            buf[2] = 0x4D;
            buf[3] = 0x53;
            BinaryTool.WriteInt32(buf, 4, 3); //Version tag
            BinaryTool.WriteInt32(buf, 8, 0);
            BinaryTool.WriteInt32(buf, 12, structures.Count);

            BinaryTool.WriteInt32(buf, 16, 0); //Was epoch, now unused
            BinaryTool.WriteInt32(buf, 20, 0);
            BinaryTool.WriteInt32(buf, 24, 0);
            BinaryTool.WriteInt32(buf, 28, 0);

            await e.Response.Body.WriteAsync(buf, 0, 32);

            //Loop through structures and find where they are
            foreach (var t in structures)
            {
                //Get data
                StructureMetadata metadata = Program.structureMetadata.Where(x => x.names.Contains(t.classname)).FirstOrDefault();
                int index = Program.structureMetadata.IndexOf(metadata);

                //Produce flags
                byte flags = 0;
                if (t.has_inventory)
                {
                    flags |= 0x01 << 0;
                }

                //Write parts
                BinaryTool.WriteInt16(buf, 0, (short)index);
                buf[2] = (byte)(t.location.yaw * 0.70833333333333333333333333333333f); //Scales this to fit the 0-360 degrees into 0-255
                buf[3] = flags;
                BinaryTool.WriteFloat(buf, 4, t.location.x);
                BinaryTool.WriteFloat(buf, 8, t.location.y);
                BinaryTool.WriteInt32(buf, 12, t.structure_id);
                BinaryTool.WriteFloat(buf, 16, t.location.z);
                BinaryTool.WriteInt32(buf, 20, t.tribe_id);

                //Write to stream
                await e.Response.Body.WriteAsync(buf, 0, 24);
            }
        }