Exemple #1
0
        public static DisplayedValue DisplayAs(
            this KernelInvocationContext context,
            string value,
            string mimeType)
        {
            if (string.IsNullOrWhiteSpace(mimeType))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(mimeType));
            }

            var displayId = Guid.NewGuid().ToString();

            var formattedValue = new FormattedValue(
                mimeType,
                value);

            context.Publish(
                new DisplayedValueProduced(
                    value,
                    context?.Command,
                    new[] { formattedValue },
                    displayId));

            var displayedValue = new DisplayedValue(displayId, mimeType, context);

            return(displayedValue);
        }
Exemple #2
0
        public static DisplayedValue Display(
            this KernelInvocationContext context,
            object value,
            string mimeType = null)
        {
            var displayId = Guid.NewGuid().ToString();

            mimeType ??= Formatter.PreferredMimeTypeFor(value.GetType());

            var formattedValue = new FormattedValue(
                mimeType,
                value.ToDisplayString(mimeType));

            context.Publish(
                new DisplayedValueProduced(
                    value,
                    context?.Command,
                    new[] { formattedValue },
                    displayId));

            var displayedValue = new DisplayedValue(displayId, mimeType, context);


            return(displayedValue);
        }
Exemple #3
0
        public static DisplayedValue DisplayAs(
            this KernelInvocationContext context,
            string value,
            string mimeType, params string[] additionalMimeTypes)
        {
            if (string.IsNullOrWhiteSpace(mimeType))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(mimeType));
            }

            var displayId = Guid.NewGuid().ToString();

            var mimeTypes = new HashSet <string>(additionalMimeTypes ?? Array.Empty <string>())
            {
                mimeType
            };

            var formattedValues = mimeTypes.Select(mime => new FormattedValue(
                                                       mime,
                                                       value));

            context.Publish(
                new DisplayedValueProduced(
                    value,
                    context?.Command,
                    formattedValues.ToArray(),
                    displayId));

            var displayedValue = new DisplayedValue(displayId, mimeType, context);

            return(displayedValue);
        }
Exemple #4
0
        public static Task <DisplayedValue> DisplayAsync(
            this KernelInvocationContext context,
            object value,
            string mimeType = null)
        {
            DisplayedValue result = Display(context, value, mimeType);

            return(Task.FromResult(result));
        }
Exemple #5
0
        public static DisplayedValue Display(
            this KernelInvocationContext context,
            object value,
            string mimeType = null)
        {
            var displayId = Guid.NewGuid().ToString();

            var formattedValues = FormattedValue.FromObject(value, mimeType);

            context.Publish(
                new DisplayedValueProduced(
                    value,
                    context?.Command,
                    formattedValues,
                    displayId));

            var displayedValue = new DisplayedValue(displayId, mimeType ?? formattedValues.FirstOrDefault()?.MimeType, context);

            return(displayedValue);
        }
Exemple #6
0
        public static DisplayedValue Display(
            this KernelInvocationContext context,
            object value,
            params string[] mimeTypes)
        {
            var displayId = Guid.NewGuid().ToString();

            var formattedValues = FormattedValue.FromObject(value, mimeTypes);

            context.Publish(
                new DisplayedValueProduced(
                    value,
                    context?.Command,
                    formattedValues,
                    displayId));

            var displayedValue = new DisplayedValue(displayId, formattedValues.Select(fv => fv.MimeType).ToArray(), context);

            return(displayedValue);
        }
        private static Command i()
        {
            var iDirective = new Command("#i")
            {
                new Argument <string>("source")
            };

            iDirective.Handler = CommandHandler.Create <string, KernelInvocationContext>((source, context) =>
            {
                if (context.HandlingKernel is ISupportNuget kernel)
                {
                    kernel.AddRestoreSource(source.Replace("nuget:", ""));
                    IHtmlContent content = div(
                        strong("Restore sources"),
                        ul(kernel.RestoreSources.Select(s => li(span(s)))));

                    var displayed = new DisplayedValue("displayedValueRestoreSources" + context.GetHashCode().ToString(), HtmlFormatter.MimeType, context);
                    displayed.Update(content);
                }
            });
            return(iDirective);
        }