Exemplo n.º 1
0
        static QueryToken Append(this QueryToken baseToken, QueryToken suffix)
        {
            var        steps = suffix.Follow(a => a.Parent).Reverse();
            QueryToken token = baseToken;

            foreach (var step in steps)
            {
                QueryToken?newToken = null;
                if (step.Key == "Entity" && step is ColumnToken)
                {
                    if (token.Type.CleanType() == step.Type.CleanType())
                    {
                        continue;
                    }
                    else
                    {
                        newToken = token.SubTokenInternal("[" + TypeLogic.GetCleanName(baseToken.Type.CleanType()) + "]", SubTokensOptions.CanElement) !;
                    }
                }

                newToken = token.SubTokenInternal(step.Key, SubTokensOptions.CanElement);
                token    = newToken ?? throw new InvalidOperationException($"Token '{step}' not found in '{token.FullKey()}'");
            }

            return(token);
        }
Exemplo n.º 2
0
 private void UpdateTokenList(QueryToken queryToken)
 {
     if (queryToken == null)
         tokens = new List<QueryToken>();
     else
         tokens = queryToken.Follow(a => a.Parent).Reverse().ToList();
     UpdateCombo();
 }
Exemplo n.º 3
0
 private void UpdateTokenList(QueryToken queryToken)
 {
     if (queryToken == null)
     {
         tokens = new List <QueryToken>();
     }
     else
     {
         tokens = queryToken.Follow(a => a.Parent).Reverse().ToList();
     }
     UpdateCombo();
 }
Exemplo n.º 4
0
        static void Remember(Replacements replacements, string tokenString, QueryToken token)
        {
            List <QueryToken> tokenList = token.Follow(a => a.Parent).Reverse().ToList();

            string[] oldParts = tokenString.Split('.');
            string[] newParts = token.FullKey().Split('.');

            List <string> oldPartsList = oldParts.ToList();
            List <string> newPartsList = newParts.ToList();

            Func <string, string> rep = str =>
            {
                if (Replacements.AutoReplacement == null)
                {
                    return(null);
                }

                Replacements.Selection?sel = Replacements.AutoReplacement(new Replacements.AutoReplacementContext {
                    ReplacementKey = "QueryToken", OldValue = str, NewValues = null
                });

                if (sel == null || sel.Value.NewValue == null)
                {
                    return(null);
                }

                return(sel.Value.NewValue);
            };

            int pos = -1;

            while (oldPartsList.Count > 0 && newPartsList.Count > 0 &&
                   (oldPartsList[0] == newPartsList[0] ||
                    rep(oldPartsList[0]) == newPartsList[0]))
            {
                oldPartsList.RemoveAt(0);
                newPartsList.RemoveAt(0);
                pos++;
            }

            while (oldPartsList.Count > 0 && newPartsList.Count > 0 &&
                   (oldPartsList[oldPartsList.Count - 1] == newPartsList[newPartsList.Count - 1] ||
                    rep(oldPartsList[oldPartsList.Count - 1]) == newPartsList[newPartsList.Count - 1]))
            {
                oldPartsList.RemoveAt(oldPartsList.Count - 1);
                newPartsList.RemoveAt(newPartsList.Count - 1);
            }

            string key = pos == -1 ? QueryKey(tokenList[0].QueryName) : TypeKey(tokenList[pos].Type);

            replacements.GetOrCreate(key)[oldPartsList.ToString(".")] = newPartsList.ToString(".");
        }
        public static MvcHtmlString QueryTokenBuilderOptions(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            var tokenPath = queryToken.Follow(qt => qt.Parent).Reverse().NotNull().ToList();

            HtmlStringBuilder sb = new HtmlStringBuilder();

            for (int i = 0; i < tokenPath.Count; i++)
            {
                sb.AddLine(helper.QueryTokenCombo(i == 0 ? null : tokenPath[i - 1], tokenPath[i], i, context, settings));
            }

            sb.AddLine(helper.QueryTokenCombo(queryToken, null, tokenPath.Count, context, settings));

            return(sb.ToHtml());
        }
Exemplo n.º 6
0
        public static MvcHtmlString QueryTokenBuilderOptions(this HtmlHelper helper, QueryToken queryToken, Context context, QueryTokenBuilderSettings settings)
        {
            var tokenPath = queryToken.Follow(qt => qt.Parent).Reverse().NotNull().ToList();

            HtmlStringBuilder sb = new HtmlStringBuilder();

            for (int i = 0; i < tokenPath.Count; i++)
            {
                sb.AddLine(helper.QueryTokenCombo(i == 0 ? null : tokenPath[i - 1], tokenPath[i], i, context, settings));
            }

            sb.AddLine(helper.QueryTokenCombo(queryToken, null, tokenPath.Count, context, settings));

            return sb.ToHtml();
        }
Exemplo n.º 7
0
        QueryToken DeterminEntityToken(QueryToken token, Action <bool, string> addError)
        {
            var entityToken = token.Follow(a => a.Parent).FirstOrDefault(a => a.Type.IsLite() || a.Type.IsIEntity());

            if (entityToken == null)
            {
                entityToken = QueryUtils.Parse("Entity", DynamicQueryManager.Current.QueryDescription(token.QueryName), 0);
            }

            if (!entityToken.Type.CleanType().IsAssignableFrom(Route.RootType))
            {
                addError(false, "The entity of {0} ({1}) is not compatible with the property route {2}".FormatWith(token.FullKey(), entityToken.FullKey(), Route.RootType.NiceName()));
            }

            return(entityToken);
        }
        static void Remember(Replacements replacements, string tokenString, QueryToken token)
        {
            List<QueryToken> tokenList = token.Follow(a => a.Parent).Reverse().ToList();

            string[] oldParts = tokenString.Split('.');
            string[] newParts = token.FullKey().Split('.');

            List<string> oldPartsList = oldParts.ToList();
            List<string> newPartsList = newParts.ToList();

            Func<string, string> rep = str =>
            {
                if (Replacements.AutoReplacement == null)
                    return null;

                Replacements.Selection? sel = Replacements.AutoReplacement(str, null);

                if (sel == null || sel.Value.NewValue == null)
                    return null;

                return sel.Value.NewValue;
            };

            int pos = -1;
            while (oldPartsList.Count > 0 && newPartsList.Count > 0 &&
                (oldPartsList[0] == newPartsList[0] ||
                 rep(oldPartsList[0]) == newPartsList[0]))
            {
                oldPartsList.RemoveAt(0);
                newPartsList.RemoveAt(0);
                pos++;
            }

            while (oldPartsList.Count > 0 && newPartsList.Count > 0 &&
                (oldPartsList[oldPartsList.Count - 1] == newPartsList[newPartsList.Count - 1] ||
                 rep(oldPartsList[oldPartsList.Count - 1]) == newPartsList[newPartsList.Count - 1]))
            {
                oldPartsList.RemoveAt(oldPartsList.Count - 1);
                newPartsList.RemoveAt(newPartsList.Count - 1);
            }

            string key = pos == -1 ? QueryKey(tokenList[0].QueryName) : TypeKey(tokenList[pos].Type);

            replacements.GetOrCreate(key)[oldPartsList.ToString(".")] = newPartsList.ToString(".");
        }
Exemplo n.º 9
0
        public override string ToString()
        {
            string token = QueryToken.Follow(q => q.Parent).Reverse().Select(a => a.ToString().ToOmniboxPascal()).ToString(".");

            if (Syntax == null || Syntax.Completion == FilterSyntaxCompletion.Token || CanFilter.HasText())
            {
                return(token);
            }

            string oper = FilterValueConverter.ToStringOperation(Operation !.Value);

            if ((Syntax.Completion == FilterSyntaxCompletion.Operation && Value == null) ||
                (Value as string == DynamicQueryOmniboxResultGenerator.UnknownValue))
            {
                return(token + oper);
            }

            return(token + oper + DynamicQueryOmniboxResultGenerator.ToStringValue(Value));
        }
Exemplo n.º 10
0
        private static QueryToken Append(this QueryToken baseToken, QueryToken suffix)
        {
            var steps = suffix.Follow(a => a.Parent).Reverse();
            var token = baseToken;

            foreach (var step in steps)
            {
                if (step.Key == "Entity" && step is ColumnToken)
                {
                    if (token.Type.CleanType() == step.Type.CleanType())
                    {
                        continue;
                    }
                    else
                    {
                        token = token.SubTokenInternal("[" + TypeLogic.GetCleanName(baseToken.Type.CleanType()) + "]", SubTokensOptions.CanElement);
                    }
                }

                token = token.SubTokenInternal(step.Key, SubTokensOptions.CanElement);
            }

            return(token);
        }
Exemplo n.º 11
0
        private void SetTokens(QueryToken token)
        {
            itemsControl.ItemsSource = token.Follow(a => a.Parent).Reverse().ToArray();

            AutomationProperties.SetName(this, token.FullKey());
        }
        private void SetTokens(QueryToken token)
        {
            itemsControl.ItemsSource = token.Follow(a => a.Parent).Reverse().ToArray();

            AutomationProperties.SetName(this, token.FullKey());
        }