Exemplo n.º 1
0
        public bool TrySetAutoRotateOptions(XElement element, IAutoRotateRoot ancestor, IAutoRotateRoot target)
        {
            if (ancestor != null)
            {
                target.AutoRotate     = ancestor.AutoRotate;
                target.AutoRotateFlip = ancestor.AutoRotateFlip;
            }

            var autorotate = element.Attribute("autorotate");

            if (autorotate == null)
            {
                return(true);
            }

            var options = autorotate.Value.Split(',');

            if (options.Length == 0)
            {
                logger.LogError(autorotate, "Autorotate options cannot be empty");
                return(false);
            }

            if (!Enum.TryParse <AutoRotateType>(options[0], true, out var autoRotateType))
            {
                logger.LogError(autorotate, $"Unknown autorotation type '{options[0]}'");
                return(false);
            }

            var flipState = FlipState.None;

            foreach (var option in options.Skip(1))
            {
                if (string.Equals(option, "FlipPrimary", StringComparison.OrdinalIgnoreCase))
                {
                    flipState |= FlipState.Primary;
                }
                else if (string.Equals(option, "FlipSecondary", StringComparison.OrdinalIgnoreCase))
                {
                    flipState |= FlipState.Secondary;
                }
                else
                {
                    logger.LogError(autorotate, $"Unknown option '{option}'");
                    return(false);
                }
            }

            target.AutoRotate     = autoRotateType;
            target.AutoRotateFlip = flipState;
            return(true);
        }
Exemplo n.º 2
0
 public bool TrySetAutoRotateOptions(XElement element, IAutoRotateRoot target)
 {
     return(TrySetAutoRotateOptions(element, null, target));
 }