Exemplo n.º 1
0
        private void InitializeRegisteredRootComponents(WebAssemblyJSRuntimeInvoker jsRuntimeInvoker)
        {
            var componentsCount = jsRuntimeInvoker.InvokeUnmarshalled <object, object, object, int>(RegisteredComponentsInterop.GetRegisteredComponentsCount, null, null, null);

            if (componentsCount == 0)
            {
                return;
            }

            var registeredComponents = new WebAssemblyComponentMarker[componentsCount];

            for (var i = 0; i < componentsCount; i++)
            {
                var id       = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, int>(RegisteredComponentsInterop.GetId, i, null, null);
                var assembly = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetAssembly, id, null, null);
                var typeName = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetTypeName, id, null, null);
                var serializedParameterDefinitions = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetParameterDefinitions, id, null, null);
                var serializedParameterValues      = jsRuntimeInvoker.InvokeUnmarshalled <int, object, object, string>(RegisteredComponentsInterop.GetParameterValues, id, null, null);
                registeredComponents[i] = new WebAssemblyComponentMarker(WebAssemblyComponentMarker.ClientMarkerType, assembly, typeName, serializedParameterDefinitions, serializedParameterValues, id.ToString());
            }

            var componentDeserializer = WebAssemblyComponentParameterDeserializer.Instance;

            foreach (var registeredComponent in registeredComponents)
            {
                _rootComponentCache = new RootComponentTypeCache();
                var componentType = _rootComponentCache.GetRootComponent(registeredComponent.Assembly, registeredComponent.TypeName);
                var definitions   = componentDeserializer.GetParameterDefinitions(registeredComponent.ParameterDefinitions);
                var values        = componentDeserializer.GetParameterValues(registeredComponent.ParameterValues);
                var parameters    = componentDeserializer.DeserializeParameters(definitions, values);

                RootComponents.Add(componentType, registeredComponent.PrerenderId, parameters);
            }
        }
Exemplo n.º 2
0
    void Awake()
    {
        Instance = this;

        AssetLoader = new BundleAssetLoader();

        ClientHash = AssetLoader.CalculateDomainHash();


        MainAssetCache = new AssetCache();
    }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a <see cref="WebAssemblyHost"/> instance based on the configuration of this builder.
        /// </summary>
        /// <returns>A <see cref="WebAssemblyHost"/> object.</returns>
        public WebAssemblyHost Build()
        {
            // Intentionally overwrite configuration with the one we're creating.
            Services.AddSingleton <IConfiguration>(Configuration);

            // A Blazor application always runs in a scope. Since we want to make it possible for the user
            // to configure services inside *that scope* inside their startup code, we create *both* the
            // service provider and the scope here.
            var services = _createServiceProvider();
            var scope    = services.GetRequiredService <IServiceScopeFactory>().CreateScope();

            return(new WebAssemblyHost(services, scope, Configuration, RootComponents.ToArray(), _persistedState));
        }
Exemplo n.º 4
0
    private void InitializeRegisteredRootComponents(IJSUnmarshalledRuntime jsRuntime)
    {
        var componentsCount = jsRuntime.InvokeUnmarshalled <int>(RegisteredComponentsInterop.GetRegisteredComponentsCount);

        if (componentsCount == 0)
        {
            return;
        }

        var registeredComponents = new WebAssemblyComponentMarker[componentsCount];

        for (var i = 0; i < componentsCount; i++)
        {
            var id       = jsRuntime.InvokeUnmarshalled <int, int>(RegisteredComponentsInterop.GetId, i);
            var assembly = jsRuntime.InvokeUnmarshalled <int, string>(RegisteredComponentsInterop.GetAssembly, id);
            var typeName = jsRuntime.InvokeUnmarshalled <int, string>(RegisteredComponentsInterop.GetTypeName, id);
            var serializedParameterDefinitions = jsRuntime.InvokeUnmarshalled <int, object?, object?, string>(RegisteredComponentsInterop.GetParameterDefinitions, id, null, null);
            var serializedParameterValues      = jsRuntime.InvokeUnmarshalled <int, object?, object?, string>(RegisteredComponentsInterop.GetParameterValues, id, null, null);
            registeredComponents[i] = new WebAssemblyComponentMarker(WebAssemblyComponentMarker.ClientMarkerType, assembly, typeName, serializedParameterDefinitions, serializedParameterValues, id.ToString(CultureInfo.InvariantCulture));
        }

        var componentDeserializer = WebAssemblyComponentParameterDeserializer.Instance;

        foreach (var registeredComponent in registeredComponents)
        {
            _rootComponentCache = new RootComponentTypeCache();
            var componentType = _rootComponentCache.GetRootComponent(registeredComponent.Assembly !, registeredComponent.TypeName !);
            if (componentType is null)
            {
                throw new InvalidOperationException(
                          $"Root component type '{registeredComponent.TypeName}' could not be found in the assembly '{registeredComponent.Assembly}'. " +
                          $"This is likely a result of trimming (tree shaking).");
            }

            var definitions = componentDeserializer.GetParameterDefinitions(registeredComponent.ParameterDefinitions !);
            var values      = componentDeserializer.GetParameterValues(registeredComponent.ParameterValues !);
            var parameters  = componentDeserializer.DeserializeParameters(definitions, values);

            RootComponents.Add(componentType, registeredComponent.PrerenderId !, parameters);
        }
    }