コード例 #1
0
        private async Task <int> ReadFileUnmarshalledAsync(
            int fileRef, byte[] buffer, long position, long bufferOffset, int count,
            CancellationToken cancellationToken)
        {
            var taskCompletionSource = new TaskCompletionSource <int>();
            var id = ++_readFileUnmarshalledCallIdSource;

            _readFileUnmarshalledCalls[id] = taskCompletionSource;
            cancellationToken.Register(() => taskCompletionSource.TrySetCanceled());

            // Buffer is not allocated here,
            UnmarshalledRuntime.InvokeUnmarshalled <ReadFileParams, int>(
                $"FileReaderComponent.ReadFileUnmarshalledAsync",
                new ReadFileParams {
                BufferOffset = bufferOffset,
                Count        = count,
                FileRef      = fileRef,
                Position     = position,
                TaskId       = id
            });

            // as the corresponding TypeArray might not survive the heap charge of the following statement
            await taskCompletionSource.Task;

            // It is safely filled up here instead
            var bytesRead = UnmarshalledRuntime.InvokeUnmarshalled <BufferParams, int>(
                $"FileReaderComponent.FillBufferUnmarshalled",
                new BufferParams
            {
                TaskId = id,
                Buffer = buffer
            });

            return(bytesRead);
        }
コード例 #2
0
        private static async Task LoadResourcesAsync(IJSUnmarshalledRuntime jsRuntime)
        {
            var sessionId = jsRuntime.InvokeUnmarshalled <string>("App.getUrlFragmentValue");

            // We use timestamps for session ID and care only about DLLs in caches that contain timestamps
            if (!ulong.TryParse(sessionId, out _))
            {
                return;
            }

            jsRuntime.InvokeUnmarshalled <string, object>("App.CodeExecution.loadResources", sessionId);

            IEnumerable <byte[]> dllsBytes;

            while (true)
            {
                dllsBytes = jsRuntime.InvokeUnmarshalled <IEnumerable <byte[]> >("App.CodeExecution.getLoadedPackageDlls");
                if (dllsBytes != null)
                {
                    break;
                }

                await Task.Delay(50);
            }

            foreach (var dllBytes in dllsBytes)
            {
                AssemblyLoadContext.Default.LoadFromStream(new MemoryStream(dllBytes));
            }
        }
コード例 #3
0
        private void InitializeNavigationManager(IJSUnmarshalledRuntime jsRuntime)
        {
            var baseUri = jsRuntime.InvokeUnmarshalled <string>(BrowserNavigationManagerInterop.GetBaseUri);
            var uri     = jsRuntime.InvokeUnmarshalled <string>(BrowserNavigationManagerInterop.GetLocationHref);

            WebAssemblyNavigationManager.Instance = new WebAssemblyNavigationManager(baseUri, uri);
        }
コード例 #4
0
        private WebAssemblyHostEnvironment InitializeEnvironment(IJSUnmarshalledRuntime jsRuntime)
        {
            var applicationEnvironment = jsRuntime.InvokeUnmarshalled <string>("Blazor._internal.getApplicationEnvironment");
            var hostEnvironment        = new WebAssemblyHostEnvironment(applicationEnvironment, WebAssemblyNavigationManager.Instance.BaseUri);

            Services.AddSingleton <IWebAssemblyHostEnvironment>(hostEnvironment);

            var configFiles = new[]
            {
                "appsettings.json",
                $"appsettings.{applicationEnvironment}.json"
            };

            foreach (var configFile in configFiles)
            {
                var appSettingsJson = jsRuntime.InvokeUnmarshalled <string, byte[]>(
                    "Blazor._internal.getConfig", configFile);

                if (appSettingsJson != null)
                {
                    // Perf: Using this over AddJsonStream. This allows the linker to trim out the "File"-specific APIs and assemblies
                    // for Configuration, of where there are several.
                    Configuration.Add <JsonStreamConfigurationSource>(s => s.Stream = new MemoryStream(appSettingsJson));
                }
            }

            return(hostEnvironment);
        }
コード例 #5
0
ファイル: Interop.cs プロジェクト: n-stefan/diabloblazor
        public GCHandle InitWebAssemblyUnmarshalledBegin(bool isSpawn, byte[] data)
        {
            var gameWasmHandle = GCHandle.Alloc(data, GCHandleType.Pinned);

            _jsUnmarshalledRuntime.InvokeUnmarshalled <bool, IntPtr, int, object>("interop.webassembly.initWebAssemblyUnmarshalledBegin",
                                                                                  isSpawn, gameWasmHandle.AddrOfPinnedObject(), data.Length);
            return(gameWasmHandle);
        }
コード例 #6
0
    private static void InitializeNavigationManager(IJSUnmarshalledRuntime jsRuntime)
    {
#pragma warning disable CS0618 // Type or member is obsolete
        var baseUri = jsRuntime.InvokeUnmarshalled <string>(BrowserNavigationManagerInterop.GetBaseUri);
        var uri     = jsRuntime.InvokeUnmarshalled <string>(BrowserNavigationManagerInterop.GetLocationHref);
#pragma warning restore CS0618 // Type or member is obsolete

        WebAssemblyNavigationManager.Instance = new WebAssemblyNavigationManager(baseUri, uri);
    }
コード例 #7
0
        protected override async ValueTask <int> CopyFileDataIntoBuffer(long sourceOffset, Memory <byte> destination, CancellationToken cancellationToken)
        {
            await _jsRuntime.InvokeVoidAsync(InputFileInterop.EnsureArrayBufferReadyForSharedMemoryInterop, cancellationToken, _inputFileElement, File.Id);

            var readRequest = new ReadRequest
            {
                InputFileElementReferenceId = _inputFileElement.Id,
                FileId       = File.Id,
                SourceOffset = sourceOffset
            };

            if (MemoryMarshal.TryGetArray(destination, out ArraySegment <byte> destinationArraySegment))
            {
                readRequest.Destination       = destinationArraySegment.Array !;
                readRequest.DestinationOffset = destinationArraySegment.Offset;
                readRequest.MaxBytes          = destinationArraySegment.Count;
            }
            else
            {
                // Worst case, we need to copy to a temporary array.
                readRequest.Destination       = new byte[destination.Length];
                readRequest.DestinationOffset = 0;
                readRequest.MaxBytes          = destination.Length;

                destination.CopyTo(new Memory <byte>(readRequest.Destination));
            }

            return(_jsUnmarshalledRuntime.InvokeUnmarshalled <ReadRequest, int>(InputFileInterop.ReadFileDataSharedMemory, readRequest));
        }
コード例 #8
0
 public bool WsSend(string WsID, byte[] WsMessage)
 {
     return(_jsUnmarshalledRuntime.InvokeUnmarshalled <string, byte[], bool>(
                "BwsJsFunctions.WsSendBinary",
                WsID,
                WsMessage));
 }
コード例 #9
0
        public void ProcessList(List <BaseOperation> list)
        {
            int length = list.Count;

            foreach (BaseOperation operation in list)
            {
                length += operation.GetLength();
            }

            byte[]        array = new byte[length];
            OperationInfo info  = new OperationInfo();

            info.index = 0;

            try
            {
                foreach (BaseOperation operation in list)
                {
                    int opIndex = OpList.ops.IndexOf(operation.GetType());

                    array[info.index] = (byte)opIndex;
                    info.index++;

                    operation.Process(array, info);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception {e}");
            }

            //Console.WriteLine($"c# process {array.Length}");

            jsUnmarsh.InvokeUnmarshalled <byte[], object>("processDrawArray", array);
        }
コード例 #10
0
        public static void AllocateArray(int length, string a)
        {
            byte[] b = new byte[length];

            _jsUnmarshalledRuntime.InvokeUnmarshalled <byte[], bool>("BwsJsFunctions.GetBinaryData", b);

            HandleMessageBinary(b, a);
        }
コード例 #11
0
 public static string ToObjectUrlUnmarshalled(this byte[] Data)
 {
     //return Window.window.Url.CreateObjectUrl(new Blob(Data));
     js.EvalGlobal(
         @"
         var MNObjectUrl='';
         function MNToObjectUrl(ar){
             ar = Blazor.platform.toUint8Array(ar);
             MNObjectUrl = URL.createObjectURL(new Blob([ar],{type:'application/octet-stream'}));
         }");
     IJSUnmarshalledRuntime.InvokeUnmarshalled <byte[], object>("MNToObjectUrl", Data);
     return((string)Runtime.GetGlobalObject("MNObjectUrl"));
 }
コード例 #12
0
    public virtual async ValueTask LoadCurrentCultureResourcesAsync()
    {
        var culturesToLoad = GetCultures(CultureInfo.CurrentCulture);

        if (culturesToLoad.Count == 0)
        {
            return;
        }

        // Now that we know the cultures we care about, let WebAssemblyResourceLoader (in JavaScript) load these
        // assemblies. We effectively want to resovle a Task<byte[][]> but there is no way to express this
        // using interop. We'll instead do this in two parts:
        // getSatelliteAssemblies resolves when all satellite assemblies to be loaded in .NET are fetched and available in memory.
#pragma warning disable CS0618 // Type or member is obsolete
        var count = (int)await _invoker.InvokeUnmarshalled <string[], object?, object?, Task <object> >(
            GetSatelliteAssemblies,
            culturesToLoad.ToArray(),
            null,
            null);

        if (count == 0)
        {
            return;
        }

        // readSatelliteAssemblies resolves the assembly bytes
        var assemblies = _invoker.InvokeUnmarshalled <object?, object?, object?, object[]>(
            ReadSatelliteAssemblies,
            null,
            null,
            null);
#pragma warning restore CS0618 // Type or member is obsolete

        for (var i = 0; i < assemblies.Length; i++)
        {
            using var stream = new MemoryStream((byte[])assemblies[i]);
            AssemblyLoadContext.Default.LoadFromStream(stream);
        }
    }
コード例 #13
0
        public async Task <IJSUnmarshalledObjectReference> LoadUnmarshalled(string jsFileName)
        {
            var importModule = await _importModuleTask.Value;

            var importId = await importModule.InvokeAsync <string>("unmarshalledImport", $"../../{jsFileName}");

            var module = _jsUnmarshalledRuntime
                         .InvokeUnmarshalled <string, IJSUnmarshalledObjectReference>(
                "getUnmarshalledModule",
                importId);

            return(module);
        }
コード例 #14
0
        private static BrowserExtensionMode GetBrowserExtensionMode(IJSUnmarshalledRuntime jsRuntime)
        {
            var browserExtensionModeString = jsRuntime.InvokeUnmarshalled <string>($"BlazorBrowserExtension.BrowserExtension._getBrowserExtensionMode");

            if (Enum.TryParse <BrowserExtensionMode>(browserExtensionModeString, out var result))
            {
                return(result);
            }
            else
            {
                return(BrowserExtensionMode.Standard);
            }
        }
コード例 #15
0
            public override async ValueTask <int> ReadAsync(Memory <byte> buffer, System.Threading.CancellationToken cancellationToken = default)
            {
                if (webAssemblyJSRuntime != null)
                {
                    var tempBufferId = await jsRuntime.InvokeAsync <int>("logjoint.nativeFiles.readIntoTempBuffer", fileInfo.handle, position, buffer.Length);

                    var read = webAssemblyJSRuntime.InvokeUnmarshalled <int, byte[]>("logjoint.nativeFiles.readTempBuffer", tempBufferId);
                    read.CopyTo(buffer.Span);
                    position += read.Length;
                    return(read.Length);
                }
                else
                {
                    var str = await jsRuntime.InvokeAsync <string>("logjoint.nativeFiles.read", fileInfo.handle, position, buffer.Length);

                    var read = CopyStr(str, buffer);
                    position += read;
                    return(read);
                }
            }
コード例 #16
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);
        }
    }
コード例 #17
0
ファイル: WebGLContext.cs プロジェクト: Cryru/Emotion
 private int GetError()
 {
     return(_gl.InvokeUnmarshalled <int>("glGetError"));
 }
コード例 #18
0
 public static bool UpdateRowContentBatch(string[] updatepkg)
 {
     return(_jsUnmarshalledRuntime.InvokeUnmarshalled <string, bool>(
                "BVirtualGridCJsFunctions.UpdateRowContentBatch",
                JsonSerializer.Serialize(updatepkg)));
 }
コード例 #19
0
 private void InitializePersistedState(IJSUnmarshalledRuntime jsRuntime)
 {
     _persistedState = jsRuntime.InvokeUnmarshalled <string>("Blazor._internal.getPersistedState");
 }
コード例 #20
0
    private void InitializePersistedState(IJSUnmarshalledRuntime jsRuntime)
    {
#pragma warning disable CS0618 // Type or member is obsolete
        _persistedState = jsRuntime.InvokeUnmarshalled <string>("Blazor._internal.getPersistedState");
#pragma warning restore CS0618 // Type or member is obsolete
    }
コード例 #21
0
 public static void SetStringData(string variableName, string data)
 {
     _jsUnmarshalledRuntime.InvokeUnmarshalled <string, string, bool>(
         "BJSFDEJsFunctions.SetStringData", variableName, data);
 }
コード例 #22
0
 private static string PictureGetUnMarshalled(IJSUnmarshalledRuntime jS, string source)
 {
     return(jS.InvokeUnmarshalled <string, string>("BlazorBarcodeScanner.pictureGetBase64Unmarshalled", source));
 }
コード例 #23
0
 private static string CaptureGetUnMarshalled(IJSUnmarshalledRuntime jS)
 {
     return(jS.InvokeUnmarshalled <string>("BlazorBarcodeScanner.pictureGetBase64Unmarshalled"));
 }