Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 protected override void UpdateDisplay(RenderBatch batch)
 {
     RegisteredFunction.InvokeUnmarshalled <int, RenderBatch, object>(
         "renderBatch",
         _browserRendererId,
         batch);
 }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public void NavigateTo(string uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            RegisteredFunction.InvokeUnmarshalled <object>($"{_functionPrefix}.navigateTo", uri);
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
 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);
     }
 }
Exemplo n.º 8
0
 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);
     }
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
 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");
     }
 }
Exemplo n.º 13
0
        /// <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);
        }
Exemplo n.º 14
0
        /// <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);
            }
        }
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
0
 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));
 }