Beispiel #1
0
        internal static YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XmlAttribute attribute, Action <MessageEventArgs> messageHandler)
        {
            string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly, messageHandler);

            if (0 < value.Length)
            {
                switch (Wix.Enums.ParseYesNoType(value))
                {
                case Wix.YesNoType.no:
                    return(YesNoType.No);

                case Wix.YesNoType.yes:
                    return(YesNoType.Yes);

                case Wix.YesNoType.NotSet:
                    // Previous code never returned 'NotSet'!
                    break;

                default:
                    if (null != messageHandler)
                    {
                        messageHandler(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.OwnerElement.Name, attribute.Name, value));
                    }
                    break;
                }
            }

            return(YesNoType.IllegalValue);
        }
Beispiel #2
0
        public static int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum, Action <MessageEventArgs> messageHandler)
        {
            Debug.Assert(minimum > CompilerConstants.IntegerNotSet && minimum > CompilerConstants.IllegalInteger, "The legal values for this attribute collide with at least one sentinel used during parsing.");

            string value   = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly, messageHandler);
            int    integer = CompilerConstants.IllegalInteger;

            if (0 < value.Length)
            {
                try
                {
                    integer = Convert.ToInt32(value, CultureInfo.InvariantCulture.NumberFormat);

                    if (CompilerConstants.IntegerNotSet == integer || CompilerConstants.IllegalInteger == integer)
                    {
                        messageHandler(WixErrors.IntegralValueSentinelCollision(sourceLineNumbers, integer));
                    }
                    else if (minimum > integer || maximum < integer)
                    {
                        messageHandler(WixErrors.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum));
                        integer = CompilerConstants.IllegalInteger;
                    }
                }
                catch (FormatException)
                {
                    messageHandler(WixErrors.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
                catch (OverflowException)
                {
                    messageHandler(WixErrors.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
            }

            return(integer);
        }
Beispiel #3
0
        internal static string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, Action <MessageEventArgs> messageHandler)
        {
            string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly, messageHandler);

            if (Common.IsIdentifier(value))
            {
                if (72 < value.Length && null != messageHandler)
                {
                    messageHandler(WixWarnings.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }

                return(value);
            }
            else
            {
                if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal) && null != messageHandler)
                {
                    messageHandler(WixErrors.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
                else if (null != messageHandler)
                {
                    messageHandler(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }

                return(String.Empty);
            }
        }
        /// <summary>
        /// Get an integer attribute value and displays an error for an illegal integer value.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
        /// <param name="attribute">The attribute containing the value to get.</param>
        /// <param name="minimum">The minimum legal value.</param>
        /// <param name="maximum">The maximum legal value.</param>
        /// <param name="messageHandler">A delegate that receives error messages.</param>
        /// <returns>The attribute's integer value or a special value if an error occurred during conversion.</returns>
        public static int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum)
        {
            Debug.Assert(minimum > CompilerConstants.IntegerNotSet && minimum > CompilerConstants.IllegalInteger, "The legal values for this attribute collide with at least one sentinel used during parsing.");

            string value   = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly);
            int    integer = CompilerConstants.IllegalInteger;

            if (0 < value.Length)
            {
                if (Int32.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out integer))
                {
                    if (CompilerConstants.IntegerNotSet == integer || CompilerConstants.IllegalInteger == integer)
                    {
                        Messaging.Instance.OnMessage(WixErrors.IntegralValueSentinelCollision(sourceLineNumbers, integer));
                    }
                    else if (minimum > integer || maximum < integer)
                    {
                        Messaging.Instance.OnMessage(WixErrors.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum));
                        integer = CompilerConstants.IllegalInteger;
                    }
                }
                else
                {
                    Messaging.Instance.OnMessage(WixErrors.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
            }

            return(integer);
        }
        /// <summary>
        /// Gets a yes/no value and displays an error for an illegal yes/no value.
        /// </summary>
        /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
        /// <param name="attribute">The attribute containing the value to get.</param>
        /// <param name="messageHandler">A delegate that receives error messages.</param>
        /// <returns>The attribute's YesNoType value.</returns>
        internal static YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XAttribute attribute)
        {
            string    value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly);
            YesNoType yesNo = YesNoType.IllegalValue;

            if ("yes".Equals(value) || "true".Equals(value))
            {
                yesNo = YesNoType.Yes;
            }
            else if ("no".Equals(value) || "false".Equals(value))
            {
                yesNo = YesNoType.No;
            }
            else
            {
                Messaging.Instance.OnMessage(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
            }

            return(yesNo);
        }
Beispiel #6
0
        internal static YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, Action <MessageEventArgs> messageHandler)
        {
            string    value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly, messageHandler);
            YesNoType yesNo = YesNoType.IllegalValue;

            if ("yes".Equals(value, StringComparison.Ordinal) || "true".Equals(value, StringComparison.Ordinal))
            {
                yesNo = YesNoType.Yes;
            }
            else if ("no".Equals(value, StringComparison.Ordinal) || "false".Equals(value, StringComparison.Ordinal))
            {
                yesNo = YesNoType.No;
            }
            else
            {
                if (null != messageHandler)
                {
                    messageHandler(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
            }

            return(yesNo);
        }