Пример #1
0
 protected override void PreSaving(PreSavingContext ctx)
 {
     if (token != null)
     {
         TokenString = token.FullKey();
     }
 }
        static MvcHtmlString QueryTokenCombo(this HtmlHelper helper, QueryToken previous, QueryToken selected, int index, Context context, QueryTokenBuilderSettings settings)
        {
            if (previous != null && AllowSubTokens != null && !AllowSubTokens(previous))
            {
                return(MvcHtmlString.Create(""));
            }

            var queryTokens = previous.SubTokens(settings.QueryDescription, settings.Options);

            if (queryTokens.IsEmpty())
            {
                return(new HtmlTag("input")
                       .Attr("type", "hidden")
                       .IdName(context.Compose("ddlTokensEnd_" + index))
                       .Attr("disabled", "disabled")
                       .Attr("data-parenttoken", previous == null ? "" : previous.FullKey()));
            }

            var options = new HtmlStringBuilder();

            options.AddLine(new HtmlTag("option").Attr("value", "").SetInnerText("-").ToHtml());
            foreach (var qt in queryTokens)
            {
                var option = new HtmlTag("option")
                             .Attr("value", previous == null ? qt.FullKey() : qt.Key)
                             .SetInnerText((previous == null && qt.Parent != null ? " - " : "") + qt.ToString());

                if (selected != null && qt.Key == selected.Key)
                {
                    option.Attr("selected", "selected");
                }

                option.Attr("title", qt.NiceTypeName);
                option.Attr("style", "color:" + qt.TypeColor);

                if (settings.Decorators != null)
                {
                    settings.Decorators(qt, option);
                }

                options.AddLine(option.ToHtml());
            }

            HtmlTag dropdown = new HtmlTag("select")
                               .Class("form-control")
                               .IdName(context.Compose("ddlTokens_" + index))
                               .InnerHtml(options.ToHtml())
                               .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            if (selected != null)
            {
                dropdown.Attr("title", selected.NiceTypeName);
                dropdown.Attr("style", "color:" + selected.TypeColor);
            }

            return(dropdown.ToHtml());
        }
Пример #3
0
        public QueryTokenTS(QueryToken qt, bool recursive)
        {
            this.toString        = qt.ToString();
            this.niceName        = qt.NiceName();
            this.key             = qt.Key;
            this.fullKey         = qt.FullKey();
            this.type            = new TypeReferenceTS(qt.Type, qt.GetImplementations());
            this.filterType      = QueryUtils.TryGetFilterType(qt.Type);
            this.format          = qt.Format;
            this.unit            = qt.Unit;
            this.typeColor       = qt.TypeColor;
            this.niceTypeName    = qt.NiceTypeName;
            this.queryTokenType  = GetQueryTokenType(qt);
            this.isGroupable     = qt.IsGroupable;
            this.hasOrderAdapter = QueryUtils.OrderAdapters.ContainsKey(qt.Type);

            this.preferEquals = qt.Type == typeof(string) &&
                                qt.GetPropertyRoute() is PropertyRoute pr &&
                                typeof(Entity).IsAssignableFrom(pr.RootType) &&
                                Schema.Current.HasSomeIndex(pr);

            this.propertyRoute = qt.GetPropertyRoute()?.ToString();
            if (recursive && qt.Parent != null)
            {
                this.parent = new QueryTokenTS(qt.Parent, recursive);
            }
        }
Пример #4
0
        internal string ToString(ScopedDictionary <string, ValueProviderBase> variables)
        {
            if (QueryToken == null)
            {
                return(String);
            }

            return(SimplifyToken(variables, QueryToken.FullKey()));
        }
Пример #5
0
        public override string ToString()
        {
            if (token != null)
            {
                return(token.FullKey());
            }

            return(TokenString);
        }
Пример #6
0
        static string ToGraphField(QueryToken token, bool simplify = false)
        {
            var field = token.FullKey().Split(".").ToString(a => a.FirstLower(), "/");

            if (simplify)
            {
                return(field.TryBefore("/") ?? field);
            }

            return(field);
        }
Пример #7
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(".");
        }
Пример #8
0
        static MvcHtmlString QueryTokenCombo(this HtmlHelper helper, QueryToken previous, QueryToken selected, int index, Context context, QueryTokenBuilderSettings settings)
        {
            if (previous != null && AllowSubTokens != null && !AllowSubTokens(previous))
                return MvcHtmlString.Create("");

            var queryTokens = previous.SubTokens(settings.QueryDescription, settings.CanAggregate);

            if (queryTokens.IsEmpty())
                return new HtmlTag("input")
                .Attr("type", "hidden")
                .IdName(context.Compose("ddlTokensEnd_" + index))
                .Attr("disabled", "disabled")
                .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            var options = new HtmlStringBuilder();
            options.AddLine(new HtmlTag("option").Attr("value", "").SetInnerText("-").ToHtml());
            foreach (var qt in queryTokens)
            {
                var option = new HtmlTag("option")
                    .Attr("value", previous == null ? qt.FullKey() : qt.Key)
                    .SetInnerText((previous == null && qt.Parent != null ? " - " : "") + qt.ToString());

                if (selected != null && qt.Key == selected.Key)
                    option.Attr("selected", "selected");

                option.Attr("title", qt.NiceTypeName);
                option.Attr("style", "color:" + qt.TypeColor);

                if (settings.Decorators != null)
                    settings.Decorators(qt, option); 

                options.AddLine(option.ToHtml());
            }

            HtmlTag dropdown = new HtmlTag("select")
                .Class("form-control")
                .IdName(context.Compose("ddlTokens_" + index))
                .InnerHtml(options.ToHtml()) 
                .Attr("data-parenttoken", previous == null ? "" : previous.FullKey());

            if (selected != null)
            {
                dropdown.Attr("title", selected.NiceTypeName);
                dropdown.Attr("style", "color:" + selected.TypeColor);
            }

            return dropdown.ToHtml();
        }
        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(".");
        }
Пример #10
0
 public QueryTokenTS(QueryToken qt, bool recursive)
 {
     this.toString       = qt.ToString();
     this.niceName       = qt.NiceName();
     this.key            = qt.Key;
     this.fullKey        = qt.FullKey();
     this.type           = new TypeReferenceTS(qt.Type, qt.GetImplementations());
     this.filterType     = QueryUtils.TryGetFilterType(qt.Type);
     this.format         = qt.Format;
     this.unit           = qt.Unit;
     this.typeColor      = qt.TypeColor;
     this.niceTypeName   = qt.NiceTypeName;
     this.queryTokenType = GetQueryTokenType(qt);
     this.isGroupable    = qt.IsGroupable;
     this.propertyRoute  = qt.GetPropertyRoute()?.ToString();
     if (recursive && qt.Parent != null)
     {
         this.parent = new QueryTokenTS(qt.Parent, recursive);
     }
 }
        private void SetTokens(QueryToken token)
        {
            itemsControl.ItemsSource = token.Follow(a => a.Parent).Reverse().ToArray();

            AutomationProperties.SetName(this, token.FullKey());
        }
Пример #12
0
 static FilterOption GetTokenFilters(QueryToken queryToken, object p)
 {
     return(new FilterOption(queryToken.FullKey(), p));
 }
Пример #13
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);
        }
Пример #14
0
        private void SetTokens(QueryToken token)
        {
            itemsControl.ItemsSource = token.Follow(a => a.Parent).Reverse().ToArray();

            AutomationProperties.SetName(this, token.FullKey());
        }
Пример #15
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);
        }
Пример #16
0
 static FilterOption GetTokenFilters(QueryToken queryToken, object p)
 {
     return new FilterOption(queryToken.FullKey(), p);
 }
Пример #17
0
        static UserAssetTokenAction?SelectInteractive(ref QueryToken token, QueryDescription qd, SubTokensOptions options, string remainingText, bool allowRemoveToken, bool allowReGenerate)
        {
            var top = Console.CursorTop;

            try
            {
                if (Console.Out == null)
                {
                    throw new InvalidOperationException("Impossible to synchronize without interactive Console");
                }

                var subTokens = token.SubTokens(qd, options).OrderBy(a => a.Parent != null).ThenBy(a => a.Key).ToList();

                int startingIndex = 0;

                SafeConsole.WriteColor(ConsoleColor.Cyan, "  " + token?.FullKey());
                if (remainingText.HasText())
                {
                    Console.Write(" " + remainingText);
                }
                Console.WriteLine();

                bool isRoot = token == null;

retry:
                int maxElements = Console.LargestWindowHeight - 11;

                subTokens.Skip(startingIndex).Take(maxElements)
                .Select((s, i) => "- {1,2}: {2} ".FormatWith(i + " ", i + startingIndex, ((isRoot && s.Parent != null) ? "-" : "") + s.Key)).ToConsole();
                Console.WriteLine();

                int remaining = subTokens.Count - startingIndex - maxElements;
                if (remaining > 0)
                {
                    SafeConsole.WriteLineColor(ConsoleColor.White, "- +: Show more values ({0} remaining)", remaining);
                }

                if (token != null)
                {
                    SafeConsole.WriteLineColor(ConsoleColor.White, "- b: Back");
                    SafeConsole.WriteLineColor(ConsoleColor.Green, "- c: Confirm");
                }

                SafeConsole.WriteLineColor(ConsoleColor.Yellow, "- s: Skip entity");

                if (allowRemoveToken)
                {
                    SafeConsole.WriteLineColor(ConsoleColor.DarkRed, "- r: Remove token");
                }

                if (allowReGenerate)
                {
                    SafeConsole.WriteLineColor(ConsoleColor.Magenta, "- g: Generate from default template");
                }


                SafeConsole.WriteLineColor(ConsoleColor.Red, "- d: Delete entity");

                while (true)
                {
                    string answer = Console.ReadLine();

                    if (answer == null)
                    {
                        throw new InvalidOperationException("Impossible to synchronize interactively without Console");
                    }

                    answer = answer.ToLower();

                    if (answer == "+" && remaining > 0)
                    {
                        startingIndex += maxElements;
                        goto retry;
                    }

                    if (answer == "s")
                    {
                        return(UserAssetTokenAction.SkipEntity);
                    }

                    if (answer == "r" && allowRemoveToken)
                    {
                        return(UserAssetTokenAction.RemoveToken);
                    }

                    if (answer == "d")
                    {
                        return(UserAssetTokenAction.DeleteEntity);
                    }

                    if (answer == "g")
                    {
                        return(UserAssetTokenAction.ReGenerateEntity);
                    }

                    if (token != null)
                    {
                        if (answer == "c")
                        {
                            return(UserAssetTokenAction.Confirm);
                        }

                        if (answer == "b")
                        {
                            token = token.Parent;
                            return(null);
                        }
                    }

                    if (int.TryParse(answer, out int option))
                    {
                        token = subTokens[option];
                        return(null);
                    }

                    Console.WriteLine("Error");
                }
            }
            finally
            {
                Clean(top, Console.CursorTop);
            }
        }
Пример #18
0
 public QueryTokenTS(QueryToken qt, bool recursive)
 {
     this.toString = qt.ToString();
     this.niceName = qt.NiceName();
     this.key = qt.Key;
     this.fullKey = qt.FullKey();
     this.type = new TypeReferenceTS(qt.Type, qt.GetImplementations());
     this.filterType = QueryUtils.TryGetFilterType(qt.Type);
     this.format = qt.Format;
     this.unit = qt.Unit;
     this.typeColor = qt.TypeColor;
     this.niceTypeName = qt.NiceTypeName;
     this.queryTokenType = GetQueryTokenType(qt);
     this.isGroupable = qt.IsGroupable;
     this.propertyRoute = qt.GetPropertyRoute()?.ToString();
     if (recursive && qt.Parent != null)
         this.parent = new QueryTokenTS(qt.Parent, recursive);
 }
Пример #19
0
 protected override void PreSaving(ref bool graphModified)
 {
     TokenString = token?.FullKey();
 }