Пример #1
0
        public string[] Top20(string input)
        {
            if (input == null)
            {
                return(Mappings.Select(x => x.Item1).ToArray());
            }
            Type reqType = Type.GetType(Mappings.First(x => x.Item1 == input).Item3);
            Type boxType = Type.GetType(Mappings.First(x => x.Item1 == input).Item2);

            Type boxedType = typeof(BoxQuery <>).MakeGenericType(boxType);

            var        boxQuery   = Context.Resolve(boxedType);
            MethodInfo takeMethod = typeof(Queryable).GetMethod("Take").MakeGenericMethod(boxType);

            var result = ((IEnumerable <object>)takeMethod.Invoke
                              (null, new object[] { boxQuery, 20 })).ToList();

            var presenter = new DumperBoxPresentation();

            var box = BoxExtensions.CreateFor(boxType);

            result.ToList().ForEach(x => box.Add(x));

            Writer.WriteLine(presenter.AsString(box));

            return(null);
        }
Пример #2
0
        /// <inheritdoc/>
        protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth)
        {
            var border      = BoxExtensions.GetSafeBorder(Border, (context.LegacyConsole || !context.Unicode) && UseSafeBorder);
            var borderStyle = BorderStyle ?? Style.Plain;

            var child      = new Padder(_child, Padding);
            var childWidth = maxWidth - EdgeWidth;

            if (!Expand)
            {
                var measurement = ((IRenderable)child).Measure(context, maxWidth - EdgeWidth);
                childWidth = measurement.Max;
            }

            var panelWidth = childWidth + EdgeWidth;

            panelWidth = Math.Min(panelWidth, maxWidth);

            var result = new List <Segment>();

            // Panel top
            AddTopBorder(result, context, border, borderStyle, panelWidth);

            // Split the child segments into lines.
            var childSegments = ((IRenderable)child).Render(context, childWidth);

            foreach (var line in Segment.SplitLines(context, childSegments, childWidth))
            {
                if (line.Count == 1 && line[0].IsWhiteSpace)
                {
                    // NOTE: This check might impact other things.
                    // Hopefully not, but there is a chance.
                    continue;
                }

                result.Add(new Segment(border.GetPart(BoxBorderPart.Left), borderStyle));

                var content = new List <Segment>();
                content.AddRange(line);

                // Do we need to pad the panel?
                var length = line.Sum(segment => segment.CellCount(context));
                if (length < childWidth)
                {
                    var diff = childWidth - length;
                    content.Add(new Segment(new string(' ', diff)));
                }

                result.AddRange(content);

                result.Add(new Segment(border.GetPart(BoxBorderPart.Right), borderStyle));
                result.Add(Segment.LineBreak);
            }

            // Panel bottom
            AddBottomBorder(result, border, borderStyle, panelWidth);

            return(result);
        }
Пример #3
0
                public void Should_Return_Safe_Border()
                {
                    // Given, When
                    var border = BoxExtensions.GetSafeBorder(BoxBorder.Double, safe: true);

                    // Then
                    border.ShouldBeSameAs(BoxBorder.Double);
                }
        public virtual void SetValue(object val)
        {
            objectCache  = null;
            StringValue  = null;
            NumericValue = null;
            Contract     = null;

            if (val is string)
            {
                StringValue = val.ToString();
                return;
            }

            if (val is ValueType)
            {
                var valType = val as ValueType;
                if (IsNumericType(valType) || val is Enum)
                {
                    NumericValue = Convert.ToDecimal(val);
                    return;
                }
                if (val is bool)
                {
                    NumericValue = ((bool)val) == true ? 1 : 0;
                    return;
                }
                //structs
                if (val is DateTime)
                {
                    NumericValue = ((DateTime)val).Ticks;
                    return;
                }
                //fall to contract
            }
            //contract
            if (val != null)
            {
                var box = BoxExtensions.CreateFor(val.GetType());
                box.Add(val);

                IBoxPresentation serializer = new BinaryBoxPresentation();
                Contract     = serializer.AsBytes(box);
                ContractType = val.GetType().AssemblyQualifiedName;
            }
            else
            {
                ContractType = null;
                Contract     = null;
            }
        }
Пример #5
0
        public void HQL(string query)
        {
            var action = Context.Resolve <HQLQueryAction>();

            action.Query = query;
            var result    = action.ActionCommand();
            var presenter = new DumperBoxPresentation();
            var box       = BoxExtensions.CreateFor(typeof(object));

            foreach (var o in result)
            {
                box.Add(o);
            }
            Writer.WriteLine(presenter.AsString(box));
        }
Пример #6
0
        /// <inheritdoc/>
        protected override IEnumerable <Segment> Render(RenderContext context, int maxWidth)
        {
            var edgeWidth = EdgeWidth;

            var border      = BoxExtensions.GetSafeBorder(Border, (context.LegacyConsole || !context.Unicode) && UseSafeBorder);
            var borderStyle = BorderStyle ?? Style.Plain;

            var showBorder = true;

            if (border is NoBoxBorder)
            {
                showBorder = false;
                edgeWidth  = 0;
            }

            var child      = new Padder(_child, Padding);
            var childWidth = maxWidth - edgeWidth;

            if (!Expand)
            {
                var measurement = ((IRenderable)child).Measure(context, maxWidth - edgeWidth);
                childWidth = measurement.Max;
            }

            var panelWidth = childWidth + edgeWidth;

            panelWidth = Math.Min(panelWidth, maxWidth);

            var result = new List <Segment>();

            if (showBorder)
            {
                // Panel top
                AddTopBorder(result, context, border, borderStyle, panelWidth);
            }

            // Split the child segments into lines.
            var childSegments = ((IRenderable)child).Render(context, childWidth);

            foreach (var(_, _, last, line) in Segment.SplitLines(context, childSegments, childWidth).Enumerate())
            {
                if (line.Count == 1 && line[0].IsWhiteSpace)
                {
                    // NOTE: This check might impact other things.
                    // Hopefully not, but there is a chance.
                    continue;
                }

                if (showBorder)
                {
                    result.Add(new Segment(border.GetPart(BoxBorderPart.Left), borderStyle));
                }

                var content = new List <Segment>();
                content.AddRange(line);

                // Do we need to pad the panel?
                var length = line.Sum(segment => segment.CellCount(context));
                if (length < childWidth)
                {
                    var diff = childWidth - length;
                    content.Add(Segment.Padding(diff));
                }

                result.AddRange(content);

                if (showBorder)
                {
                    result.Add(new Segment(border.GetPart(BoxBorderPart.Right), borderStyle));
                }

                // Don't emit a line break if this is the last
                // line, we're not showing the border, and we're
                // not rendering this inline.
                var emitLinebreak = !(last && !showBorder && !Inline);
                if (!emitLinebreak)
                {
                    continue;
                }

                result.Add(Segment.LineBreak);
            }

            // Panel bottom
            if (showBorder)
            {
                result.Add(new Segment(border.GetPart(BoxBorderPart.BottomLeft), borderStyle));
                result.Add(new Segment(border.GetPart(BoxBorderPart.Bottom).Repeat(panelWidth - EdgeWidth), borderStyle));
                result.Add(new Segment(border.GetPart(BoxBorderPart.BottomRight), borderStyle));
            }

            // TODO: Need a better name for this?
            // If we're rendering this as part of an inline parent renderable,
            // such as columns, we should not emit the last line break.
            if (!Inline)
            {
                result.Add(Segment.LineBreak);
            }

            return(result);
        }