Beispiel #1
0
        /// <summary>
        /// 关闭某个密保方式,获得关闭后的值
        /// </summary>
        /// <param name="oldValidateValue"></param>
        /// <param name="toSet"></param>
        /// <returns></returns>
        public static byte ReduceValidationFlag(byte?oldValidateValue, ValidationFlag toSet)
        {
            if (!oldValidateValue.HasValue || oldValidateValue.Value == 0)
            {
                return((byte)0);
            }
            ValidationFlag validate = (ValidationFlag)Enum.Parse(typeof(ValidationFlag), oldValidateValue.Value.ToString());

            return((byte)(validate & (~toSet)));
        }
Beispiel #2
0
        /// <summary>
        /// 判断是否开否某个密保方式
        /// </summary>
        /// <param name="validateValue"></param>
        /// <param name="validationFlag"></param>
        /// <returns></returns>
        public static bool CheckSecurityOpened(byte?validateValue, ValidationFlag validationFlag)
        {
            if (!validateValue.HasValue || validateValue.Value == 0)
            {
                return(false);
            }
            ValidationFlag validate = (ValidationFlag)Enum.Parse(typeof(ValidationFlag), validateValue.Value.ToString());

            return((validate & validationFlag) != 0);
        }
    bool ValidateScene(int validationCount, List <Shape> shapes)
    {
        bool           ok = true;
        ValidationFlag validationFlags = 0;

        foreach (Shape shape in shapes)
        {
            // Find the associated handler.
            MessageHandler handler = FindHandlerFor(shape);
            if (handler != null)
            {
                bool       validated = false;
                GameObject obj       = FindObjectFor(shape, handler);
                if (obj != null)
                {
                    if (!_validationFlags.TryGetValue(shape.GetType(), out validationFlags))
                    {
                        validationFlags = ValidationFlag.Default;
                    }
                    validated = ValidateAgainstObject(shape, obj, validationFlags);
                }
                else if (ValidateWithoutObject(shape, handler))
                {
                    validated = true;
                }
                else
                {
                    Debug.LogError(string.Format("Failed to validate shape {0}", shape.GetType().Name));
                }

                ok = ok && validated;
            }
            else
            {
                ok = false;
                Debug.LogError(string.Format("Failed to find validation handler for shape {0}", shape.GetType().Name));
            }
        }
        // Not implemented.
        return(ok);
    }
    /// <summary>
    /// Validate that the given list of <paramref name="shapes"/> is correctly represented in the Unity scene.
    /// </summary>
    /// <param name="shapes">The list of shapes to validate.</param>
    /// <returns>True on success, false if there are inconsistencies between <paramref name="shapes"/> and the scene.
    /// </returns>
    bool ValidateScene(List <Shape> shapes)
    {
        bool           ok = true;
        ValidationFlag validationFlags = 0;

        foreach (Shape referenceShape in shapes)
        {
            // Find the associated handler.
            MessageHandler handler = FindHandlerFor(referenceShape);
            if (handler != null)
            {
                bool  validated  = false;
                Shape sceneShape = ExtractSceneRepresentation(referenceShape, handler);
                if (sceneShape != null)
                {
                    if (!_validationFlags.TryGetValue(referenceShape.GetType(), out validationFlags))
                    {
                        validationFlags = ValidationFlag.Default;
                    }
                    validated = ValidateShape(sceneShape, referenceShape, validationFlags, handler);
                }
                else if (ValidateWithoutReference(referenceShape, handler))
                {
                    validated = true;
                }
                else
                {
                    Debug.LogError(string.Format("Failed to validate shape {0}", referenceShape.GetType().Name));
                }

                ok = ok && validated;
            }
            else
            {
                ok = false;
                Debug.LogError(string.Format("Failed to find validation handler for shape {0}", referenceShape.GetType().Name));
            }
        }
        // Not implemented.
        return(ok);
    }
    bool ValidateAgainstObject(Shape shape, GameObject obj, ValidationFlag flags)
    {
        // Validate position and rotation. Can't do scale due to varying semantics.
        var  shapeComponent = obj.GetComponentInChildren <Tes.Handlers.ShapeComponent>();
        var  xform          = obj.transform;
        bool ok             = true;

        if (shapeComponent.Category != shape.Category)
        {
            Debug.LogError(string.Format("{0} Category mismatch.", obj.name));
            ok = false;
        }
        if (shapeComponent.ObjectFlags != shape.Flags)
        {
            Debug.LogError(string.Format("{0} Flags mismatch", obj.name));
            ok = false;
        }

        // Convert to Unity position.
        if ((flags & ValidationFlag.Position) != 0)
        {
            Vector3 shapePos = Tes.Maths.Vector3Ext.ToUnity(shape.Position);
            if ((flags & ValidationFlag.PositionConverted) != 0)
            {
                shapePos = Tes.Runtime.FrameTransform.RemoteToUnity(shapePos, ServerCoordinateFrame);
            }

            if (xform.localPosition != shapePos)
            {
                Debug.LogError(string.Format("{0} Position mismatch: {2} != {3}", obj.name, xform.localPosition, shapePos));
                ok = false;
            }
        }
        else if ((flags & ValidationFlag.PositionConverted) != 0)
        {
        }

        if ((flags & ValidationFlag.Rotation) != 0)
        {
            Quaternion shapeRot = Tes.Maths.QuaternionExt.ToUnity(shape.Rotation);
            if ((flags & ValidationFlag.RotationAsNormal) != 0)
            {
                // TODO:
                shapeRot = xform.localRotation;
            }

            if (xform.localRotation != shapeRot)
            {
                Debug.LogError(string.Format("{0} Rotation mismatch: {1} != {2}",
                                             xform.localRotation, Tes.Maths.QuaternionExt.ToUnity(shape.Rotation)));
                ok = false;
            }
        }

        if ((flags & ValidationFlag.Colour) != 0)
        {
            Color32 c1 = shapeComponent.Colour;
            Color32 c2 = Tes.Handlers.ShapeComponent.ConvertColour(shape.Colour);
            if (c1.r != c2.r || c1.g != c2.g || c1.b != c2.b || c1.a != c2.a)
            {
                Debug.LogError(string.Format("{0} Colour mismatch: {1} != {2}", obj.name, c1, c2));
                ok = false;
            }
        }

        if (shape.ID != shapeComponent.ObjectID)
        {
            Debug.LogError(string.Format("{0} Shape ID mismatch: {1} != {2}", obj.name, shape.ID, shapeComponent.ObjectID));
            ok = false;
        }

        // Special validation.
        SpecialObjectValidation specialValidation;

        if (_specialObjectValidation.TryGetValue(shape.GetType(), out specialValidation))
        {
            if (!specialValidation(shape, obj))
            {
                ok = false;
            }
        }

        return(ok);
    }
    bool ValidateShape(Shape shape, Shape referenceShape, ValidationFlag flags, MessageHandler handler)
    {
        bool ok = true;

        // Validate core data.
        if (shape.ID != referenceShape.ID)
        {
            Debug.LogError($"{handler.Name} {shape.ID} does not match reference ID {referenceShape.ID}.");
            ok = false;
        }

        if (shape.Category != referenceShape.Category)
        {
            Debug.LogError($"{handler.Name} {shape.ID} category mismatch. Category {shape.Category} expect {referenceShape.ID}.");
            ok = false;
        }

        if (shape.Flags != shape.Flags)
        {
            Debug.LogError($"{handler.Name} {shape.ID} flags mismatch. Flags {shape.Flags} expect ${referenceShape.Flags}");
            ok = false;
        }

        // Validate position.
        if ((flags & ValidationFlag.Position) != 0)
        {
            if (shape.Position != referenceShape.Position)
            {
                Debug.LogError($"{handler.Name} {shape.ID} position mismatch. Position {shape.Position} expect {referenceShape.Position}");
                ok = false;
            }
        }

        if ((flags & ValidationFlag.Rotation) != 0)
        {
            if (shape.Rotation != referenceShape.Rotation)
            {
                Debug.LogError($"{handler.Name} {shape.ID} rotation mismatch. Rotation {shape.Rotation} expect {referenceShape.Rotation}");
                ok = false;
            }
        }

        if ((flags & ValidationFlag.Scale) != 0)
        {
            if (shape.Scale != referenceShape.Scale)
            {
                Debug.LogError($"{handler.Name} {shape.ID} scale mismatch. Scale {shape.Scale} expect {referenceShape.Scale}");
                ok = false;
            }
        }

        if ((flags & ValidationFlag.Colour) != 0)
        {
            if (shape.Colour != referenceShape.Colour)
            {
                Debug.LogError($"{handler.Name} {shape.ID} colour mismatch. Colour {shape.Colour} expect {referenceShape.Colour}");
                ok = false;
            }
        }

        // Special validation.
        SpecialShapeValidation specialValidation;

        if (_specialShapeValidation.TryGetValue(shape.GetType(), out specialValidation))
        {
            if (!specialValidation(shape, referenceShape, handler))
            {
                ok = false;
            }
        }

        return(ok);
    }