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