コード例 #1
0
ファイル: NumericExpressionNode.cs プロジェクト: 3F/IeXod
 internal override bool CanNumericEvaluate(ConditionEvaluationState state)
 {
     // It is not always possible to numerically evaluate even a numerical expression -
     // for example, it may overflow a double. So check here.
     return(ConversionUtilities.ValidDecimalOrHexNumber(value));
 }
コード例 #2
0
ファイル: NumericExpressionNode.cs プロジェクト: 3F/IeXod
 internal override string GetExpandedValue(ConditionEvaluationState state)
 {
     return(value);
 }
コード例 #3
0
ファイル: NumericExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Evaluate as numeric
 /// </summary>
 internal override double NumericEvaluate(ConditionEvaluationState state)
 {
     return(ConversionUtilities.ConvertDecimalOrHexToDouble(value));
 }
コード例 #4
0
ファイル: NumericExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Whether it can be evaluated as a boolean: never allowed for numerics
 /// </summary>
 internal override bool CanBoolEvaluate(ConditionEvaluationState state)
 {
     // Numeric expressions are never allowed to be treated as booleans.
     return(false);
 }
コード例 #5
0
ファイル: OperatorExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Value before any item and property expressions are expanded
 /// </summary>
 /// <returns></returns>
 internal override string GetUnexpandedValue(ConditionEvaluationState state)
 {
     return(null);
 }
コード例 #6
0
ファイル: NumericExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Evaluate as boolean
 /// </summary>
 internal override bool BoolEvaluate(ConditionEvaluationState state)
 {
     // Should be unreachable: all calls check CanBoolEvaluate() first
     ErrorUtilities.VerifyThrow(false, "Can't evaluate a numeric expression as boolean.");
     return(false);
 }
コード例 #7
0
ファイル: OperatorExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Whether boolean evaluation is allowed: always allowed for operators
 /// </summary>
 internal override bool CanBoolEvaluate(ConditionEvaluationState state)
 {
     return(true);
 }
コード例 #8
0
 internal abstract bool BoolEvaluate(ConditionEvaluationState state);
コード例 #9
0
        /// <summary>
        /// Evaluate node as boolean
        /// </summary>
        internal override bool BoolEvaluate(ConditionEvaluationState state)
        {
            if (String.Compare(functionName, "exists", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Check we only have one argument
                VerifyArgumentCount(1, state);

                // Expand properties and items, and verify the result is an appropriate scalar
                string expandedValue = ExpandArgumentForScalarParameter("exists", (GenericExpressionNode)arguments[0], state);

                if (Project.PerThreadProjectDirectory != null && !String.IsNullOrEmpty(expandedValue))
                {
                    try
                    {
                        expandedValue = Path.GetFullPath(Path.Combine(Project.PerThreadProjectDirectory, expandedValue));
                    }
                    catch (Exception e) // Catching Exception, but rethrowing unless it's an IO related exception.
                    {
                        if (ExceptionHandling.NotExpectedException(e))
                        {
                            throw;
                        }

                        // Ignore invalid characters or path related exceptions

                        // We will ignore the PathTooLong exception caused by GetFullPath becasue in single proc this code
                        // is not executed and the condition is just evaluated to false as File.Exists and Directory.Exists does not throw in this situation.
                        // To be consistant with that we will return a false in this case also.
                        // DevDiv Bugs: 46035

                        return(false);
                    }
                }

                // Both Exists functions return false if the value is null or empty
                return(File.Exists(expandedValue) || Directory.Exists(expandedValue));
            }
            else if (String.Compare(functionName, "HasTrailingSlash", StringComparison.OrdinalIgnoreCase) == 0)
            {
                // Check we only have one argument
                VerifyArgumentCount(1, state);

                // Expand properties and items, and verify the result is an appropriate scalar
                string expandedValue = ExpandArgumentForScalarParameter("HasTrailingSlash", (GenericExpressionNode)arguments[0], state);

                // Is the last character a backslash?
                if (expandedValue.Length != 0)
                {
                    char lastCharacter = expandedValue[expandedValue.Length - 1];
                    // Either back or forward slashes satisfy the function: this is useful for URL's
                    return(lastCharacter == Path.DirectorySeparatorChar || lastCharacter == Path.AltDirectorySeparatorChar);
                }
                else
                {
                    return(false);
                }
            }
            // We haven't implemented any other "functions"
            else
            {
                ProjectErrorUtilities.VerifyThrowInvalidProject(
                    false,
                    state.conditionAttribute,
                    "UndefinedFunctionCall",
                    state.parsedCondition,
                    this.functionName);

                return(false);
            }
        }
コード例 #10
0
ファイル: OperatorExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Numeric evaluation is never allowed for operators
 /// </summary>
 internal override double NumericEvaluate(ConditionEvaluationState state)
 {
     // Should be unreachable: all calls check CanNumericEvaluate() first
     ErrorUtilities.VerifyThrow(false, "Cannot numeric evaluate an operator");
     return(0.0D);
 }
コード例 #11
0
        /// <summary>
        /// Expands properties and items in the argument, and verifies that the result is consistent
        /// with a scalar parameter type.
        /// </summary>
        /// <param name="function">Function name for errors</param>
        /// <param name="argumentNode">Argument to be expanded</param>
        /// <returns>Scalar result</returns>
        /// <owner>danmose</owner>
        private string ExpandArgumentForScalarParameter(string function, GenericExpressionNode argumentNode, ConditionEvaluationState state)
        {
            string argument = argumentNode.GetUnexpandedValue(state);

            List <TaskItem> items = state.expanderToUse.ExpandAllIntoTaskItems(argument, state.conditionAttribute);

            string expandedValue = String.Empty;

            if (items.Count == 0)
            {
                // Empty argument, that's fine.
            }
            else if (items.Count == 1)
            {
                expandedValue = items[0].ItemSpec;
            }
            else // too many items for the function
            {
                // We only allow a single item to be passed into a scalar parameter.
                ProjectErrorUtilities.VerifyThrowInvalidProject(false,
                                                                state.conditionAttribute,
                                                                "CannotPassMultipleItemsIntoScalarFunction", function, argument,
                                                                state.expanderToUse.ExpandAllIntoString(argument, state.conditionAttribute));
            }

            return(expandedValue);
        }
コード例 #12
0
 /// <summary>
 /// Value before any item and property expressions are expanded
 /// </summary>
 /// <returns></returns>
 internal abstract string GetUnexpandedValue(ConditionEvaluationState state);
コード例 #13
0
 internal abstract double NumericEvaluate(ConditionEvaluationState state);
コード例 #14
0
ファイル: NotExpressionNode.cs プロジェクト: 3F/IeXod
 internal override bool CanBoolEvaluate(ConditionEvaluationState state)
 {
     return(LeftChild.CanBoolEvaluate(state));
 }
コード例 #15
0
ファイル: OperatorExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Whether the node can be evaluated as a numeric: by default,
 /// this is not allowed
 /// </summary>
 internal override bool CanNumericEvaluate(ConditionEvaluationState state)
 {
     return(false);
 }
コード例 #16
0
ファイル: NotExpressionNode.cs プロジェクト: 3F/IeXod
 /// <summary>
 /// Returns expanded value with '!' prepended. Useful for error messages.
 /// </summary>
 internal override string GetExpandedValue(ConditionEvaluationState state)
 {
     return("!" + LeftChild.GetExpandedValue(state));
 }
コード例 #17
0
 internal abstract bool CanNumericEvaluate(ConditionEvaluationState state);