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); }
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)); } }
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); }
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); }
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); }
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); }
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)); }
public bool WsSend(string WsID, byte[] WsMessage) { return(_jsUnmarshalledRuntime.InvokeUnmarshalled <string, byte[], bool>( "BwsJsFunctions.WsSendBinary", WsID, WsMessage)); }
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); }
public static void AllocateArray(int length, string a) { byte[] b = new byte[length]; _jsUnmarshalledRuntime.InvokeUnmarshalled <byte[], bool>("BwsJsFunctions.GetBinaryData", b); HandleMessageBinary(b, a); }
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")); }
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); } }
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); }
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); } }
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); } }
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); } }
private int GetError() { return(_gl.InvokeUnmarshalled <int>("glGetError")); }
public static bool UpdateRowContentBatch(string[] updatepkg) { return(_jsUnmarshalledRuntime.InvokeUnmarshalled <string, bool>( "BVirtualGridCJsFunctions.UpdateRowContentBatch", JsonSerializer.Serialize(updatepkg))); }
private void InitializePersistedState(IJSUnmarshalledRuntime jsRuntime) { _persistedState = jsRuntime.InvokeUnmarshalled <string>("Blazor._internal.getPersistedState"); }
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 }
public static void SetStringData(string variableName, string data) { _jsUnmarshalledRuntime.InvokeUnmarshalled <string, string, bool>( "BJSFDEJsFunctions.SetStringData", variableName, data); }
private static string PictureGetUnMarshalled(IJSUnmarshalledRuntime jS, string source) { return(jS.InvokeUnmarshalled <string, string>("BlazorBarcodeScanner.pictureGetBase64Unmarshalled", source)); }
private static string CaptureGetUnMarshalled(IJSUnmarshalledRuntime jS) { return(jS.InvokeUnmarshalled <string>("BlazorBarcodeScanner.pictureGetBase64Unmarshalled")); }