示例#1
0
        /// <summary>
        /// Gets override string value from element parameter.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="paramName">
        /// The parameter name.
        /// </param>
        /// <param name="originalValue">
        /// The original value.
        /// </param>
        /// <returns>
        /// The string contains the string value.
        /// </returns>
        public static string GetOverrideStringValue(Element element, string paramName, string originalValue)
        {
            //string strValue;
            string paramValue;

            if (element != null)
            {
                if (ParameterUtil.GetStringValueFromElement(element, paramName, out paramValue) != null && !string.IsNullOrEmpty(paramValue))
                {
                    string propertyValue  = null;
                    string paramValuetrim = paramValue.Trim();
                    // This is kind of hack to quickly check whether we need to parse the parameter or not by checking that the value is enclosed by "{ }" or "u{ }" for unique value
                    if (((paramValuetrim.Length > 1 && paramValuetrim[0] == '{') || (paramValuetrim.Length > 2 && paramValuetrim[1] == '{')) && (paramValuetrim[paramValuetrim.Length - 1] == '}'))
                    {
                        ParamExprResolver pResv = new ParamExprResolver(element, paramName, paramValuetrim);
                        propertyValue = pResv.GetStringValue();
                        if (string.IsNullOrEmpty(propertyValue))
                        {
                            propertyValue = paramValue; // return the original paramValue
                        }
                    }
                    else
                    {
                        propertyValue = paramValue; // return the original paramValue
                    }
                    //return paramValue;
                    return(propertyValue);
                }
            }

            return(originalValue);
        }
示例#2
0
        /// <summary>
        /// Gets override string value from element parameter.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <param name="paramName">
        /// The parameter name.
        /// </param>
        /// <param name="originalValue">
        /// The original value.
        /// </param>
        /// <returns>
        /// The string contains the string value.
        /// </returns>
        public static string GetOverrideStringValue(Element element, string paramName, string originalValue)
        {
            //string strValue;
            string paramValue;

            if (element != null)
            {
                if (ParameterUtil.GetStringValueFromElement(element, paramName, out paramValue) != null && !string.IsNullOrEmpty(paramValue))
                {
                    string propertyValue = null;
                    object strValue      = null;
                    ParamExprResolver.CheckForParameterExpr(paramValue, element, paramName, ParamExprResolver.ExpectedValueEnum.STRINGVALUE, out strValue);
                    if (strValue != null && strValue is string)
                    {
                        propertyValue = strValue as string;
                    }
                    else
                    {
                        propertyValue = paramValue; // return the original paramValue
                    }
                    return(propertyValue);
                }
            }

            return(originalValue);
        }
示例#3
0
        /// <summary>
        /// Check for a special parameter value containing the Paramater expression
        /// </summary>
        /// <param name="paramValue">the Parameter value</param>
        /// <param name="element">the Element</param>
        /// <param name="paramName">the Parameter Name</param>
        /// <returns>the resolved Parameter Expression value or null if not resolved</returns>
        public static ParamExprResolver CheckForParameterExpr(string paramValue, Element element, string paramName, ExpectedValueEnum expectedDataType, out object propertyValue)
        {
            propertyValue = null;
            string paramValuetrim = paramValue.Trim();

            if (IsParameterExpr(paramValue))
            {
                ParamExprResolver pResv = new ParamExprResolver(element, paramName, paramValuetrim);
                switch (expectedDataType)
                {
                case ExpectedValueEnum.STRINGVALUE:
                    propertyValue = pResv.GetStringValue();
                    break;

                case ExpectedValueEnum.DOUBLEVALUE:
                    propertyValue = pResv.GetDoubleValue();
                    break;

                case ExpectedValueEnum.INTVALUE:
                    propertyValue = pResv.GetIntValue();
                    break;

                default:
                    break;
                }
                return(pResv);
            }

            return(null);
        }
示例#4
0
        /// <summary>
        /// Gets double value from parameter of an element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="group">Optional property group to limit search to.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="propertyValue">The output property value.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when propertyName is null or empty.</exception>
        /// <returns>The parameter, or null if not found.</returns>
        public static Parameter GetDoubleValueFromElement(Element element, BuiltInParameterGroup?group, string propertyName, out double propertyValue)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (String.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentException("It is null or empty.", "propertyName");
            }

            propertyValue = 0.0;

            Parameter parameter = GetParameterFromName(element.Id, group, propertyName);

            if (parameter != null && parameter.HasValue)
            {
                switch (parameter.StorageType)
                {
                case StorageType.Double:
                    propertyValue = parameter.AsDouble();
                    return(parameter);

                case StorageType.Integer:
                    propertyValue = parameter.AsInteger();
                    return(parameter);

                case StorageType.String:
                {
                    string propValue;
                    propValue = parameter.AsString();

                    string propValuetrim = propValue.Trim();
                    // This is kind of hack to quickly check whether we need to parse the parameter or not
                    if (((propValuetrim.Length > 1 && propValuetrim[0] == '{') || (propValuetrim.Length > 2 && propValuetrim[1] == '{')) && (propValuetrim[propValuetrim.Length - 1] == '}'))
                    {
                        ParamExprResolver pResv = new ParamExprResolver(element, propertyName, propValuetrim);
                        double?           propertyDoubleValue = pResv.GetDoubleValue();
                        if (propertyDoubleValue.HasValue)
                        {
                            propertyValue = propertyDoubleValue.Value;
                            return(parameter);
                        }
                    }

                    return(Double.TryParse(propValue, out propertyValue) ? parameter : null);
                }
                }
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Executed upon exiting expr rule
        /// </summary>
        /// <param name="context">the expr context</param>
        public override void ExitExpr([NotNull] ParamExprGrammarParser.ExprContext context)
        {
            base.ExitExpr(context);
            NodeProperty retExpr = new NodeProperty();

            // value
            if (context.GetChild(0) is ParamExprGrammarParser.ValueContext && context.children.Count == 1)
            {
                retExpr = GetNodePropertyValue(context.GetChild(0));
            }
            // | atomic_param
            else if (context.GetChild(0) is ParamExprGrammarParser.Atomic_paramContext && context.children.Count == 1)
            {
                retExpr = GetNodePropertyValue(context.GetChild(0));
            }
            // | unary_operator expr
            else if (context.GetChild(0) is ParamExprGrammarParser.Unary_operatorContext && context.ChildCount == 2)
            {
                retExpr = ParamExprResolver.ResolveExprUnaryOperator(context.GetChild(0).GetText(), GetNodePropertyValue(context.GetChild(1)));
            }
            // | expr ops expr
            else if (context.GetChild(1) is ParamExprGrammarParser.OpsContext && context.ChildCount == 3)
            {
                retExpr = ParamExprResolver.ResolveExprOpsExpr(context.GetChild(0) as ParamExprGrammarParser.ExprContext, GetNodePropertyValue(context.GetChild(0)),
                                                               context.GetChild(1) as ParamExprGrammarParser.OpsContext, GetNodePropertyValue(context.GetChild(2)));
            }
            // | '(' expr ')' (power_op)?
            else if (context.GetChild(0) is ITerminalNode && context.GetChild(2) is ITerminalNode)
            {
                int powerOp = +1;
                if (context.ChildCount == 4)
                {
                    powerOp = ParamExprResolver.GetPowerOp(context.GetChild(3) as ParamExprGrammarParser.Power_opContext);
                }
                retExpr = ParamExprResolver.ResolveExprPowerOp(GetNodePropertyValue(context.GetChild(1) as ParamExprGrammarParser.ExprContext), powerOp);
            }
            else
            {
                // Not valid rule, return nothing? or the original text?
            }

            SetNodePropertyValue(context, retExpr);
        }
示例#6
0
        private static Parameter GetStringValueFromElementBase(Element element, ElementId elementId, string propertyName, bool allowUnset, out string propertyValue)
        {
            if (elementId == ElementId.InvalidElementId)
            {
                throw new ArgumentNullException("element");
            }

            propertyValue = string.Empty;
            if (String.IsNullOrEmpty(propertyName))
            {
                return(null);
            }

            propertyValue = string.Empty;

            Parameter parameter = GetParameterFromName(elementId, null, propertyName);

            if (parameter != null)
            {
                StorageType storageType = parameter.StorageType;
                if (storageType != StorageType.String && storageType != StorageType.ElementId)
                {
                    return(null);
                }

                if (parameter.HasValue)
                {
                    string propValue;
                    propValue = parameter.AsString();

                    if (!string.IsNullOrEmpty(propValue))
                    {
                        string propValuetrim = propValue.Trim();
                        // This is kind of hack to quickly check whether we need to parse the parameter or not
                        if (((propValuetrim.Length > 1 && propValuetrim[0] == '{') || (propValuetrim.Length > 2 && propValuetrim[1] == '{')) && (propValuetrim[propValuetrim.Length - 1] == '}'))
                        {
                            ParamExprResolver pResv = new ParamExprResolver(element, propertyName, propValuetrim);
                            propertyValue = pResv.GetStringValue();
                            if (string.IsNullOrEmpty(propertyValue))
                            {
                                propertyValue = propValue; // return the original propValue (un-trimmed)
                            }
                        }
                        else
                        {
                            propertyValue = propValue; // return the original propValue (un-trimmed)
                        }
                        return(parameter);
                    }
                    else if (parameter.AsElementId() != null)
                    {
                        propertyValue = PropertyUtil.ElementIdParameterAsString(parameter);
                        return(parameter);
                    }
                }

                if (allowUnset)
                {
                    propertyValue = null;
                    return(parameter);
                }
            }

            return(null);
        }
示例#7
0
        /// <summary>
        /// Gets integer value from parameter of an element.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="propertyName">The property name.</param>
        /// <param name="propertyValue">The output property value.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when element is null.</exception>
        /// <exception cref="System.ArgumentException">Thrown when propertyName is null or empty.</exception>
        /// <returns>The parameter, or null if not found.</returns>
        public static Parameter GetIntValueFromElement(Element element, string propertyName, out int propertyValue)
        {
            if (element == null)
            {
                throw new ArgumentNullException("element");
            }

            if (String.IsNullOrEmpty(propertyName))
            {
                throw new ArgumentException("It is null or empty.", "propertyName");
            }

            propertyValue = 0;

            Parameter parameter = GetParameterFromName(element.Id, null, propertyName);

            if (parameter != null && parameter.HasValue)
            {
                switch (parameter.StorageType)
                {
                case StorageType.Double:
                {
                    try
                    {
                        propertyValue = (int)parameter.AsDouble();
                        return(parameter);
                    }
                    catch
                    {
                        return(null);
                    }
                }

                case StorageType.Integer:
                {
                    propertyValue = parameter.AsInteger();
                    return(parameter);
                }

                case StorageType.String:
                {
                    string propValue;
                    propValue = parameter.AsString();

                    string propValuetrim = propValue.Trim();
                    // This is kind of hack to quickly check whether we need to parse the parameter or not
                    if (((propValuetrim.Length > 1 && propValuetrim[0] == '{') || (propValuetrim.Length > 2 && propValuetrim[1] == '{')) && (propValuetrim[propValuetrim.Length - 1] == '}'))
                    {
                        ParamExprResolver pResv = new ParamExprResolver(element, propertyName, propValuetrim);
                        int?propertyIntValue    = pResv.GetIntValue();
                        if (propertyIntValue.HasValue)
                        {
                            propertyValue = propertyIntValue.Value;
                            return(parameter);
                        }
                    }

                    try
                    {
                        propertyValue = Convert.ToInt32(parameter.AsString());
                        return(parameter);
                    }
                    catch
                    {
                        return(null);
                    }
                }
                }
            }
            return(null);
        }