Example #1
0
        /// <summary>
        /// Fetches special tokens.
        /// </summary>
        /// <param name="resourceTypeFullName">Full name of resource type.</param>
        /// <param name="context"><see cref="ZentityContext" /> instance to fetch data with.</param>
        /// <returns>Special tokens.</returns>
        private static IEnumerable <SpecialToken> FetchTokens(string resourceTypeFullName, ZentityContext context)
        {
            if (String.IsNullOrEmpty(resourceTypeFullName))
            {
                throw new ArgumentNullException("resourceTypeFullName");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            List <SpecialToken> specialTokens = new List <SpecialToken>();

            XDocument specialTokensDocument =
                Utility.ReadXmlConfigurationFile(Resources.SEARCH_SPECIALTOKENS_FILENAME);

            if (specialTokensDocument == null)
            {
                return(Utility.CreateEmptyEnumerable <SpecialToken>());
            }

            IEnumerable <XElement> xmlTokens =
                specialTokensDocument.Root
                .Elements(XName.Get(SearchConstants.XML_TOKEN, SearchConstants.XMLNS_NAMESPACE));

            ResourceType type =
                ResourceTypeHelper.FetchResourceType(resourceTypeFullName, context);

            if (type == null)
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.CurrentCulture,
                                        Resources.SEARCH_INVALID_RESOURCETYPE, resourceTypeFullName));
            }

            foreach (XElement xmlToken in xmlTokens)
            {
                SpecialToken specialToken = new SpecialToken();
                specialToken.Token    = xmlToken.Attribute(SearchConstants.XML_NAME).Value;
                specialToken.DataType =
                    (DataTypes)Enum.Parse(
                        typeof(DataTypes), xmlToken.Attribute(SearchConstants.XML_DATATYPE).Value);

                specialToken.Properties = FetchProperties(xmlToken, type, context);
                specialTokens.Add(specialToken);
            }

            return(specialTokens);
        }
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>
 /// Indicates whether the specified token is a special token.
 /// </summary>
 /// <param name="token">A token.</param>
 /// <returns>true if the token is a special token; otherwise, false.</returns>
 public static bool IsSpecialToken(string token)
 {
     return(SpecialToken.IsSpecialToken(token));
 }
Example #4
0
 /// <summary>
 /// Fetches data type of the specified token.
 /// </summary>
 /// <param name="token">A token.</param>
 /// <returns>Token data type.</returns>
 public static DataTypes FetchSpecialTokenDataType(string token)
 {
     return(SpecialToken.FetchTokenDataType(token));
 }
Example #5
0
 /// <summary>
 /// Fetches the specified special token.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <param name="resourceTypeFullName">Full name of resource type.</param>
 /// <returns>Special token.</returns>
 public SpecialToken FetchSpecialToken(string token, string resourceTypeFullName)
 {
     return(SpecialToken.FetchToken(token, resourceTypeFullName, context));
 }