public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (!IsEnabled(logLevel)) { return; } if (formatter == null) { throw new ArgumentNullException(nameof(formatter)); } var message = formatter(state, exception); if (!(state is FormattedLogObject)) { var internalFormatter = new FormattedLogObject(logLevel, message, exception); message = internalFormatter.ToString(); } #if !DESKTOP_BUILD RegisteredFunction.InvokeUnmarshalled <object>(LoggerFunctionName, message); #else Console.WriteLine(message); #endif }
/// <inheritdoc /> protected override void UpdateDisplay(RenderBatch batch) { RegisteredFunction.InvokeUnmarshalled <int, RenderBatch, object>( "renderBatch", _browserRendererId, batch); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { switch (logLevel) { case LogLevel.Trace: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Trace", JsonUtil.Serialize(state)); break; case LogLevel.Debug: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Debug", JsonUtil.Serialize(state)); break; case LogLevel.Information: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Info", JsonUtil.Serialize(state)); break; case LogLevel.Warning: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Warn", JsonUtil.Serialize(state)); break; case LogLevel.Critical: case LogLevel.Error: RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Error", JsonUtil.Serialize(state)); if (exception != null) { RegisteredFunction.InvokeUnmarshalled <object>($"{PREFIX}.Error", JsonUtil.Serialize(exception)); } break; default: break; } }
public void RemoveItem(string key) { if (string.IsNullOrWhiteSpace(key)) { throw new ArgumentNullException(nameof(key)); } RegisteredFunction.InvokeUnmarshalled <object>(MethodNames.REMOVE_ITEM_METHOD, StorageTypeNames.LOCAL_STORAGE, key); }
/// <inheritdoc /> public void NavigateTo(string uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } RegisteredFunction.InvokeUnmarshalled <object>($"{_functionPrefix}.navigateTo", uri); }
private T InvokeCanvasMethodUnmarshalled2 <T>(UnmarshalledCanvasMethod method, params object[] args) { object[] realArgs = new object[args.Length + 2]; Array.Copy(args, 0, realArgs, 2, args.Length); realArgs[0] = Id; realArgs[1] = (int)method; // return RegisteredFunction.InvokeUnmarshalled<T>(MethodPrefix + "InvokeUnmarshalled", realArgs); return(RegisteredFunction.InvokeUnmarshalled <T>("G", realArgs)); }
private static void EnsureBaseUriPopulated() { // The <base href> is fixed for the lifetime of the page, so just cache it if (_baseUriString == null) { var baseUri = RegisteredFunction.InvokeUnmarshalled <string>( $"{_functionPrefix}.getBaseURI"); _baseUriString = ToBaseUriPrefix(baseUri); _baseUri = new Uri(_baseUriString); } }
private static void EnsureBaseUriPopulated() { // The <base href> is fixed for the lifetime of the page, so just cache it if (_baseUriStringWithTrailingSlash == null) { var baseUriAbsolute = RegisteredFunction.InvokeUnmarshalled <string>( $"{_functionPrefix}.getBaseURI"); _baseUriStringWithTrailingSlash = ToBaseUri(baseUriAbsolute); _baseUriWithTrailingSlash = new Uri(_baseUriStringWithTrailingSlash); } }
public static Task <TResult> InvokeJavaScriptFunctionAsync <TResult>(string identifier, params object[] args) { var tcs = new TaskCompletionSource <TResult>(); var argsJson = args.Select(JsonUtil.Serialize); var successId = Guid.NewGuid().ToString(); var failureId = Guid.NewGuid().ToString(); var asyncProtocol = JsonUtil.Serialize(new { Success = successId, Failure = failureId, Function = new MethodOptions { Type = new TypeInstance { Assembly = typeof(JavaScriptInvoke).Assembly.FullName, TypeName = typeof(JavaScriptInvoke).FullName }, Method = new MethodInstance { Name = nameof(JavaScriptInvoke.InvokeTaskCallback), ParameterTypes = new[] { new TypeInstance { Assembly = typeof(string).Assembly.FullName, TypeName = typeof(string).FullName }, new TypeInstance { Assembly = typeof(string).Assembly.FullName, TypeName = typeof(string).FullName } } } } }); TrackedReference.Track(successId, new Action <string>(r => { var res = JsonUtil.Deserialize <TResult>(r); tcs.SetResult(res); })); TrackedReference.Track(failureId, (new Action <string>(r => { tcs.SetException(new InvalidOperationException(r)); }))); var resultJson = RegisteredFunction.InvokeUnmarshalled <string>( "invokeWithJsonMarshallingAsync", argsJson.Prepend(asyncProtocol).Prepend(identifier).ToArray()); return(tcs.Task); }
/// <summary> /// Associates the <see cref="IComponent"/> with the <see cref="BrowserRenderer"/>, /// causing it to be displayed in the specified DOM element. /// </summary> /// <param name="componentType">The type of the component.</param> /// <param name="domElementSelector">A CSS selector that uniquely identifies a DOM element.</param> public void AddComponent(Type componentType, string domElementSelector) { var component = InstantiateComponent(componentType); var componentId = AssignComponentId(component); RegisteredFunction.InvokeUnmarshalled <int, string, int, object>( "attachComponentToElement", _browserRendererId, domElementSelector, componentId); RenderNewBatch(componentId); }
/// <summary> /// Associates the <see cref="IComponent"/> with the <see cref="BrowserRenderer"/>, /// causing it to be displayed in the specified DOM element. /// </summary> /// <param name="componentType">The type of the component.</param> /// <param name="domElementSelector">A CSS selector that uniquely identifies a DOM element.</param> public void AddComponent(Type componentType, string domElementSelector) { var component = InstantiateComponent(componentType); var componentId = AssignComponentId(component); RegisteredFunction.InvokeUnmarshalled <int, string, int, object>( "attachRootComponentToElement", _browserRendererId, domElementSelector, componentId); component.SetParameters(ParameterCollection.Empty); }
private static void EnsureNavigationInterceptionEnabled() { // Don't need thread safety because: // (1) there's only one UI thread // (2) doesn't matter if we call enableNavigationInterception more than once anyway if (!_hasEnabledNavigationInterception) { _hasEnabledNavigationInterception = true; RegisteredFunction.InvokeUnmarshalled <object>( $"{_functionPrefix}.enableNavigationInterception"); } }
/// <summary> /// Associates the <see cref="IComponent"/> with the <see cref="BrowserRenderer"/>, /// causing it to be displayed in the specified DOM element. /// </summary> /// <param name="domElementSelector">A CSS selector that uniquely identifies a DOM element.</param> /// <param name="component">The <see cref="IComponent"/>.</param> public void AddComponent(string domElementSelector, IComponent component) { var componentId = AssignComponentId(component); RegisteredFunction.InvokeUnmarshalled <int, string, int, object>( "attachComponentToElement", _browserRendererId, domElementSelector, componentId); _rootComponents.Add(component); RenderNewBatch(componentId); }
/// <inheritdoc /> public string GetAbsoluteUri() { if (_cachedAbsoluteUri == null) { var newUri = RegisteredFunction.InvokeUnmarshalled <string>( $"{_functionPrefix}.getLocationHref"); if (_hasEnabledNavigationInterception) { // Once we turn on navigation interception, we no longer have to query // the browser for its URI each time (because we'd know if it had changed) _cachedAbsoluteUri = newUri; } return(newUri); } else { return(_cachedAbsoluteUri); } }
/// <inheritdoc /> protected override async Task <HttpResponseMessage> SendAsync( HttpRequestMessage request, CancellationToken cancellationToken) { var tcs = new TaskCompletionSource <HttpResponseMessage>(); cancellationToken.Register(() => tcs.TrySetCanceled()); int id; lock (_idLock) { id = _nextRequestId++; _pendingRequests.Add(id, tcs); } var options = new FetchOptions(); if (request.Properties.TryGetValue(FetchArgs, out var fetchArgs)) { options.RequestInitOverrides = fetchArgs; } options.RequestInit = new RequestInit { Credentials = GetDefaultCredentialsString(), Headers = GetHeadersAsStringArray(request), Method = request.Method.Method }; options.RequestUri = request.RequestUri.ToString(); RegisteredFunction.InvokeUnmarshalled <int, byte[], string, object>( $"{typeof(BrowserHttpMessageHandler).FullName}.Send", id, request.Content == null ? null : await request.Content.ReadAsByteArrayAsync(), JsonUtil.Serialize(options)); return(await tcs.Task); }
public void Clear() => RegisteredFunction.InvokeUnmarshalled <object>(MethodNames.CLEAR_METHOD, StorageTypeNames.SESSION_STORAGE);
public static string CoasterData(float[] data) { return(RegisteredFunction.InvokeUnmarshalled <float[], string>( CoasterDataIdentifier, data)); }
public static string CoasterUpdate(int added, int removed) { return(RegisteredFunction.InvokeUnmarshalled <int, int, string>( CoasterUpdateIdentifier, added, removed)); }