Example #1
0
        /// <summary>
        /// Fetches the column name based on the resource property.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        /// <param name="searchTokens"><see cref="SearchTokens" /> instance to fetch
        /// tokens with.</param>
        /// <param name="resourceTypeFullName">Resource type full name.</param>
        /// <returns>Column name exclosed within box brackets.</returns>
        public static string GetColumnName(string propertyName,
                                           SearchTokens searchTokens, string resourceTypeFullName)
        {
            ScalarProperty scalarProperty =
                searchTokens.FetchPropertyToken(propertyName, resourceTypeFullName);

            if (scalarProperty != null)
            {
                return(Utility.EscapeColumnName(scalarProperty.ColumnName));
            }
            else
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              Resources.SEARCH_INVALID_SORT_PROPERTY, propertyName));
            }
        }
Example #2
0
        /// <summary>
        /// Extracts the data type and properties of the token.
        /// </summary>
        /// <param name="searchTokens">The search tokens.</param>
        /// <returns>List of <see cref="ScalarProperty"/>.</returns>
        private IEnumerable <ScalarProperty> ExtractTokenInformation(SearchTokens searchTokens)
        {
            IEnumerable <ScalarProperty> properties;

            switch (TokenType)
            {
            case ExpressionTokenType.SpecialToken:
            {
                SpecialToken token = searchTokens.FetchSpecialToken(ExpressionToken, ResourceTypeFullName);
                if (token == null)
                {
                    throw new SearchException(string.Format(CultureInfo.CurrentCulture,
                                                            Resources.SEARCH_INVALID_SPECIAL_TOKEN, ExpressionToken));
                }
                properties = token.Properties;
            }
            break;

            case ExpressionTokenType.PropertyToken:
            {
                ScalarProperty token = searchTokens.FetchPropertyToken(ExpressionToken, ResourceTypeFullName);
                if (token == null)
                {
                    throw new SearchException(string.Format(CultureInfo.CurrentCulture,
                                                            Resources.SEARCH_INVALID_PROPERTY_TOKEN, ExpressionToken));
                }
                properties = new ScalarProperty[] { token };
            }
            break;

            case ExpressionTokenType.ImplicitPropertiesToken:
            default:
            {
                IEnumerable <ScalarProperty> tokens =
                    searchTokens.FetchImplicitProperties(ResourceTypeFullName);
                properties = tokens;
            }
            break;
            }
            return(properties);
        }
Example #3
0
        /// <summary>
        /// Gets the matching percentage clause.
        /// </summary>
        /// <param name="searchCriteria">The search criteria.</param>
        /// <param name="resourceTypeFullName">Full name of the resource type.</param>
        /// <returns>The matching percentage clause.</returns>
        private string GetMatchingPercentageClause(
            IEnumerable <PropertyValuePair> searchCriteria,
            string resourceTypeFullName)
        {
            StringBuilder numerator       = new StringBuilder();
            StringBuilder denominator     = new StringBuilder();
            int           numeratorLength = 0;

            foreach (PropertyValuePair pair in searchCriteria)
            {
                ScalarProperty scalarProperty =
                    searchTokens.FetchPropertyToken(pair.PropertyName, resourceTypeFullName);
                string columnName = Utility.EscapeColumnName(scalarProperty.ColumnName);

                if (scalarProperty.DataType == DataTypes.String)
                {
                    numeratorLength += pair.PropertyValue.Length;
                }
                else // if not string type then add the actual length to both numerator and denominator.
                {
                    numerator.AppendFormat(
                        CultureInfo.InvariantCulture, SearchConstants.TSQL_CAST_LEN,
                        SearchConstants.TSQL_SUB + columnName);
                    numerator.Append(SearchConstants.TSQL_PLUS);
                }
                denominator.AppendFormat(
                    CultureInfo.InvariantCulture, SearchConstants.TSQL_CAST_LEN,
                    SearchConstants.TSQL_SUB + columnName);
                denominator.Append(SearchConstants.TSQL_PLUS);
            }
            numerator.Append(numeratorLength.ToString());
            denominator.Remove(denominator.Length - 1, SearchConstants.TSQL_PLUS.Length);

            return
                (String.Format(CultureInfo.InvariantCulture,
                               SearchConstants.TSQL_PERCENTAGE_MATCH_FORMULA, numerator.ToString(),
                               denominator.ToString()));
        }