Exemplo n.º 1
0
        public void GivenValidNestedStructure_WhenValidateRecursively_ThenCorrectValidationResults()
        {
            RecursiveValidator      validator = new RecursiveValidator(null);
            List <ValidationResult> results   = validator.ValidateObjectRecursively(NestedArray.Valid());

            Assert.Empty(results);
        }
Exemplo n.º 2
0
        public void GivenInvalidChild_WhenValidateRecursively_ThenCorrectValidationResults()
        {
            RecursiveValidator      validator = new RecursiveValidator(null);
            List <ValidationResult> results   = validator.ValidateObjectRecursively(NestedArray.WithInvalidChild());

            Assert.Equal(3, results.Count);
            ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "Child[0].RequiredString");
            ValidationResultUtility.AssertValidationResultEquals(results[1], "The RequiredLong field is required.", "Child[0].RequiredLong");
            ValidationResultUtility.AssertValidationResultEquals(results[2], "The RequiredUnsignedLong field is required.", "Child[0].RequiredUnsignedLong");
        }
Exemplo n.º 3
0
        public SERIParameter ParseSERIArray(Stream fileData, Stream names, byte[] pointers, int valuesOffset, string name)
        {
            using (var br = new BinaryReaderX(fileData, true))
            {
                var arrayDataType = br.ReadString(1);
                br.BaseStream.Position += 1;
                var     arrayLength = br.ReadInt16();
                short[] pointersA   = br.ReadMultiple <short>(arrayLength).ToArray();

                switch (arrayDataType)
                {
                case "s":      //Of String
                    string[] StringArray = new string[arrayLength];

                    for (int i = 0; i < pointersA.Length; i++)
                    {
                        using (var namesB = new BinaryReaderX(names, true))
                        {
                            namesB.BaseStream.Position = pointersA[i];
                            string ItemName = namesB.ReadCStringA();
                            StringArray[i] = ItemName;
                        }
                    }

                    return(new StringArray(name, StringArray));

                case "i":     //Of Integer
                    switch (name)
                    {
                    case "texi":
                    case "model":
                    case "cloth":
                    case "list":
                        string[] NameArray = new string[arrayLength];

                        for (int i = 0; i < pointersA.Length; i++)
                        {
                            using (var namesB = new BinaryReaderX(names, true))
                                using (var pointersB = new BinaryReaderX(new MemoryStream(pointers)))
                                {
                                    br.BaseStream.Position        = valuesOffset + pointersA[i];
                                    pointersB.BaseStream.Position = (br.ReadInt32() - 1) * 4;
                                    namesB.BaseStream.Position    = pointersB.ReadInt32();
                                    string ItemName = namesB.ReadCStringA();
                                    NameArray[i] = ItemName;
                                }
                        }

                        return(new StringArray(name, NameArray));

                    default:
                        int[] IntArray = new int[arrayLength];

                        for (int i = 0; i < pointersA.Length; i++)
                        {
                            br.BaseStream.Position = valuesOffset + pointersA[i];
                            IntArray[i]            = br.ReadInt32();
                        }

                        return(new IntegerArray(name, IntArray));
                    }

                case "b":     //Of Boolean
                    bool[] BooleanArray = new bool[arrayLength];

                    for (int i = 0; i < pointersA.Length; i++)
                    {
                        br.BaseStream.Position = valuesOffset + pointersA[i];
                        BooleanArray[i]        = br.ReadByte() == 1;
                    }

                    return(new BooleanArray(name, BooleanArray));

                case "f":     //Of Float
                    float[] FloatArray = new float[arrayLength];

                    for (int i = 0; i < pointersA.Length; i++)
                    {
                        br.BaseStream.Position = valuesOffset + pointersA[i];
                        FloatArray[i]          = br.ReadSingle();
                    }

                    return(new FloatArray(name, FloatArray));

                case "h":     //Of Array
                    SERIParameter[] NestedArray = new SERIParameter[arrayLength];

                    for (int i = 0; i < pointersA.Length; i++)
                    {
                        br.BaseStream.Position = valuesOffset + pointersA[i];
                        ushort          Count            = br.ReadUInt16();
                        long            TypesTableOffset = valuesOffset + pointersA[i] + 2 + Count * 4;
                        SERIParameter[] Arrays           = new SERIParameter[Count];
                        for (int Index = 0; Index < Count; Index++)
                        {
                            using (var namesB = new BinaryReaderX(names, true))
                            {
                                br.BaseStream.Position = valuesOffset + pointersA[i] + 2 + Index * 4;
                                ushort NameOffset  = br.ReadUInt16();
                                ushort ValueOffset = br.ReadUInt16();

                                namesB.BaseStream.Position = NameOffset;
                                string ArrayName = namesB.ReadCStringA();

                                br.BaseStream.Seek(TypesTableOffset + Index, SeekOrigin.Begin);
                                string ValueType = br.ReadString(1);

                                Arrays[Index] = ParseSERIParameter(
                                    br.BaseStream,
                                    names,
                                    pointers,
                                    ValueType,
                                    name,
                                    ValueOffset,
                                    valuesOffset);
                            }
                        }

                        NestedArray[i] = new NestedArray(null, Arrays);
                    }

                    return(new NestedArray(name, NestedArray));

                default:
                    throw new Exception($"Type {arrayDataType} is unknown!");
                }
            }
        }