コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static IReadOnlyCollection <FormattedValue> FromObject(object value, string mimeType = null)
        {
            mimeType ??= Formatter.GetPreferredMimeTypeFor(value?.GetType());

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

            return(new[] { formattedValue });
        }
コード例 #4
0
        public void Update(object updatedValue)
        {
            var formatted = new FormattedValue(
                _mimeType,
                updatedValue.ToDisplayString(_mimeType));

            var kernel = KernelInvocationContext.Current.HandlingKernel;

            Task.Run(() =>
                     kernel.SendAsync(new UpdateDisplayedValue(updatedValue, formatted, _displayId)))
            .Wait();
        }
コード例 #5
0
        public void Update(object updatedValue)
        {
            var formatted = new FormattedValue(
                _mimeType,
                updatedValue.ToDisplayString(_mimeType));

            if (KernelInvocationContext.Current?.Command is SubmitCode)
            {
                _context = KernelInvocationContext.Current;
            }

            _context.Publish(new DisplayedValueUpdated(updatedValue, _displayId, _context.Command, new[] { formatted }));
        }
コード例 #6
0
        public static void display(
            object value,
            string mimeType = HtmlFormatter.MimeType)
        {
            var formatted = new FormattedValue(
                mimeType,
                value.ToDisplayString(mimeType));

            var kernel = KernelInvocationContext.Current.Kernel;

            Task.Run(() =>
                     kernel.SendAsync(new DisplayValue(formatted)))
            .Wait();
        }
コード例 #7
0
        public static DisplayedValue display(
            object value,
            string mimeType = HtmlFormatter.MimeType)
        {
            var displayId = Guid.NewGuid().ToString();
            var formatted = new FormattedValue(
                mimeType,
                value.ToDisplayString(mimeType));

            var kernel = KernelInvocationContext.Current.HandlingKernel;

            Task.Run(() =>
                     kernel.SendAsync(new DisplayValue(value, formatted, displayId)))
            .Wait();
            return(new DisplayedValue(displayId, mimeType));
        }
コード例 #8
0
        public static void Javascript(string scriptContent)
        {
            PocketView value =
                script[type : "text/javascript"](
                    HTML(
                        scriptContent));

            var formatted = new FormattedValue(
                HtmlFormatter.MimeType,
                value.ToString());

            var kernel = KernelInvocationContext.Current.HandlingKernel;

            Task.Run(() =>
                     kernel.SendAsync(new DisplayValue(formatted)))
            .Wait();
        }
コード例 #9
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);
        }
コード例 #10
0
        public static async Task <DisplayedValue> DisplayAsync(
            this KernelInvocationContext context,
            object value,
            string mimeType = null)
        {
            var displayId = Kernel.DisplayIdGenerator?.Invoke() ??
                            Guid.NewGuid().ToString();

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

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

            var kernel = context.HandlingKernel ?? context.CurrentKernel;

            await kernel.SendAsync(new DisplayValue(value, formatted, displayId));

            return(new DisplayedValue(displayId, mimeType));
        }
コード例 #11
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);
        }
コード例 #12
0
        public static Task <DisplayedValue> DisplayAsync(
            this KernelInvocationContext context,
            object value,
            string mimeType = null)
        {
            var displayId = Kernel.DisplayIdGenerator?.Invoke() ??
                            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));

            return(Task.FromResult(new DisplayedValue(displayId, mimeType, context)));
        }
コード例 #13
0
 public SignatureInformation(string label, FormattedValue documentation, IReadOnlyList <ParameterInformation> parameters)
 {
     Label         = label ?? throw new ArgumentNullException(nameof(label));
     Documentation = documentation ?? throw new ArgumentNullException(nameof(documentation));
     Parameters    = parameters ?? throw new ArgumentNullException(nameof(parameters));
 }