private List<QueryToken> QueryTokenBuilderOrders_SubTokensEvent(QueryToken token)
        {
            var cr = (UserChartEntity)DataContext;
            if (cr == null || QueryDescription == null)
                return new List<QueryToken>();

            return token.SubTokens(QueryDescription, SubTokensOptions.CanElement | (cr.GroupResults ? SubTokensOptions.CanAggregate : 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.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());
        }
Example #3
0
        private List <QueryToken> QueryTokenBuilderOrders_SubTokensEvent(QueryToken token)
        {
            var cr = (UserChartEntity)DataContext;

            if (cr == null || QueryDescription == null)
            {
                return(new List <QueryToken>());
            }

            return(token.SubTokens(QueryDescription, SubTokensOptions.CanElement | (cr.GroupResults ? SubTokensOptions.CanAggregate : 0)));
        }
Example #4
0
        List <QueryToken> qtbFilters_SubTokensEvent(QueryToken token)
        {
            var cr = (ChartRequest)DataContext;

            if (cr == null || chartRenderer.Description == null)
            {
                return(new List <QueryToken>());
            }

            return(token.SubTokens(chartRenderer.Description, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | (cr.GroupResults ? SubTokensOptions.CanAggregate : 0)));
        }
Example #5
0
        List <QueryToken> tokenBuilder_SubTokensEvent(QueryToken arg)
        {
            string canColumn = QueryUtils.CanColumn(arg);

            btCreateColumn.IsEnabled = string.IsNullOrEmpty(canColumn);
            btCreateColumn.ToolTip   = canColumn;


            string canFilter = QueryUtils.CanFilter(arg);

            btCreateFilter.IsEnabled = string.IsNullOrEmpty(canFilter);
            btCreateFilter.ToolTip   = canFilter;

            return(arg.SubTokens(Description, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement));
        }
Example #6
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();
        }
Example #7
0
        static bool TryParseRemember(Replacements replacements, string tokenString, QueryDescription qd, SubTokensOptions options, out QueryToken result)
        {
            string[] parts = tokenString.Split('.');

            result = null;
            for (int i = 0; i < parts.Length; i++)
            {
                string part = parts[i];

                QueryToken newResult = QueryUtils.SubToken(result, qd, options, part);

                if (newResult != null)
                {
                    result = newResult;
                }
                else
                {
                    if (i == 0)
                    {
                        var        entity       = QueryUtils.SubToken(result, qd, options, "Entity");
                        QueryToken newSubResult = QueryUtils.SubToken(entity, qd, options, part);

                        if (newSubResult != null)
                        {
                            result = newSubResult;
                            continue;
                        }
                    }


                    if (Replacements.AutoReplacement != null)
                    {
                        Replacements.Selection?sel = Replacements.AutoReplacement(new Replacements.AutoReplacementContext {
                            ReplacementKey = "QueryToken", OldValue = part, NewValues = result.SubTokens(qd, options).Select(a => a.Key).ToList()
                        });

                        if (sel != null && sel.Value.NewValue != null)
                        {
                            newResult = QueryUtils.SubToken(result, qd, options, sel.Value.NewValue);

                            if (newResult != null)
                            {
                                result = newResult;
                                continue;
                            }
                        }
                    }

                    string key = result == null?QueryKey(qd.QueryName) : TypeKey(result.Type);

                    Dictionary <string, string> dic = replacements.TryGetC(key);

                    if (dic == null)
                    {
                        return(false);
                    }

                    string remainging = parts.Skip(i).ToString(".");

                    string old = dic.Keys.OrderByDescending(a => a.Length).FirstOrDefault(s => remainging.StartsWith(s));

                    if (old == null)
                    {
                        return(false);
                    }

                    var subParts = dic[old].Let(s => s.HasText() ? s.Split('.') : new string[0]);

                    for (int j = 0; j < subParts.Length; j++)
                    {
                        string subPart = subParts[j];

                        QueryToken subNewResult = QueryUtils.SubToken(result, qd, options, subPart);

                        if (subNewResult == null)
                        {
                            return(false);
                        }

                        result = subNewResult;
                    }

                    i += (old == "" ? 0 : old.Split('.').Length) - 1;
                }
            }

            return(true);
        }
Example #8
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);
            }
        }
        List<QueryToken> qtbFilters_SubTokensEvent(QueryToken token)
        {
            var cr = (ChartRequest)DataContext;
            if (cr == null || chartRenderer.Description == null)
                return new List<QueryToken>();

            return token.SubTokens(chartRenderer.Description, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement | (cr.GroupResults ? SubTokensOptions.CanAggregate : 0));
        }
        List<QueryToken> tokenBuilder_SubTokensEvent(QueryToken arg)
        {
            string canColumn = QueryUtils.CanColumn(arg);
            btCreateColumn.IsEnabled = string.IsNullOrEmpty(canColumn);
            btCreateColumn.ToolTip = canColumn;
         

            string canFilter = QueryUtils.CanFilter(arg);
            btCreateFilter.IsEnabled = string.IsNullOrEmpty(canFilter);
            btCreateFilter.ToolTip = canFilter;

            return arg.SubTokens(Description, SubTokensOptions.CanAnyAll | SubTokensOptions.CanElement);
        }
Example #11
0
 private List <QueryToken> QueryTokenBuilder_SubTokensEvent(QueryToken token)
 {
     return(token.SubTokens(QueryDescription, SubTokensOptions.CanElement));
 }
        static bool TryParseRemember(Replacements replacements, string tokenString, QueryDescription qd, SubTokensOptions options, out QueryToken result)
        {
            string[] parts = tokenString.Split('.');

            result = null;
            for (int i = 0; i < parts.Length; i++)
            {
                string part = parts[i];

                QueryToken newResult = QueryUtils.SubToken(result, qd, options, part);

                if (newResult != null)
                {
                    result = newResult;
                }
                else
                {
                    if (i == 0)
                    {
                        var entity = QueryUtils.SubToken(result, qd, options, "Entity");
                        QueryToken newSubResult = QueryUtils.SubToken(entity, qd, options, part);

                        if (newSubResult != null)
                        {
                            result = newSubResult;
                            continue;
                        }
                    }


                    if (Replacements.AutoReplacement != null)
                    {
                        Replacements.Selection? sel = Replacements.AutoReplacement(part, result.SubTokens(qd, options).Select(a => a.Key).ToList());

                        if (sel != null && sel.Value.NewValue != null)
                        {
                            newResult = QueryUtils.SubToken(result, qd, options, sel.Value.NewValue);

                            if (newResult != null)
                            {
                                result = newResult;
                                continue;
                            }
                        }
                    }

                    string key = result == null ? QueryKey(qd.QueryName) : TypeKey(result.Type);

                    Dictionary<string, string> dic = replacements.TryGetC(key);

                    if (dic == null)
                        return false;

                    string remainging = parts.Skip(i).ToString(".");

                    string old = dic.Keys.OrderByDescending(a => a.Length).FirstOrDefault(s => remainging.StartsWith(s));

                    if (old == null)
                        return false;

                    var subParts = dic[old].Let(s => s.HasText() ? s.Split('.') : new string[0]);

                    for (int j = 0; j < subParts.Length; j++)
                    {
                        string subPart = subParts[j];

                        QueryToken subNewResult = QueryUtils.SubToken(result, qd, options, subPart);

                        if (subNewResult == null)
                            return false;

                        result = subNewResult;
                    }

                    i += (old == "" ? 0 : old.Split('.').Length) - 1;
                }
            }

            return true;
        }
        static UserAssetTokenAction? SelectInteractive(ref QueryToken token, QueryDescription qd, SubTokensOptions options, 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.WriteLineColor(ConsoleColor.Cyan, "  " + token.Try(a => a.FullKey()));

                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;
                        }
                    }

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

                    Console.WriteLine("Error");
                }
            }
            finally
            {
                Clean(top, Console.CursorTop);
            }
        }
Example #14
0
 private List<QueryToken> QueryTokenBuilder_SubTokensEvent(QueryToken token)
 {
     return token.SubTokens(QueryDescription, SubTokensOptions.CanElement);
 }