public static bool Receive(string methodProxyJson) { if (string.IsNullOrEmpty(methodProxyJson)) { return(false); } InternalHelper.SetTimeout(() => { MethodProxy resultProxy = BridgeSerializer.Deserialize <MethodProxy>(methodProxyJson); var taskToReturn = MethodDispatcher.GetTaskDispatcher(resultProxy.TaskIdentity); MethodDispatcher.SetTaskResult(resultProxy.TaskIdentity, resultProxy); if (taskToReturn == null) { return; } taskToReturn.RunSynchronously(); MethodDispatcher.ClearTask(resultProxy.TaskIdentity); }, 10); return(true); }
private static bool MethodProxyReceiver(string methodProxyJson, bool socketSuccess) { MethodProxy resultProxy = null; try { resultProxy = BridgeSerializer.Deserialize <MethodProxy>(ref methodProxyJson); } catch (Exception ex) { //Actually if we have an exception here that can mean that the user data has seem class not deserializable //between native and Blazor side. As we are probably in a waiting Task scenario, we must try to forward //the exception to the waiting task by fetching it's TaskId. //It will be easier to debug then if (TryGetDefaultFallbackMethodProxy(methodProxyJson, ex, out MethodProxy defaultProxy)) { return(BlazorCommonDispatcher.Receive(defaultProxy, socketSuccess)); } //Otherwise returning false. The task may be blocked in a waiting state forever //TODO: We should implement some kind of CancellationToken in the future on interop method signatures //forcing the business code to continue return(false); } return(BlazorCommonDispatcher.Receive(resultProxy, socketSuccess)); }
internal static Task Send(MethodProxy methodProxy) { string csharpProxy = BridgeSerializer.Serialize(methodProxy); BlazorMobileComponent.GetJSRuntime().InvokeAsync <bool>("contextBridgeSend", csharpProxy); return(Task.CompletedTask); }
public static async Task Send(MethodProxy methodProxy) { string csharpProxy = BridgeSerializer.Serialize(methodProxy); InternalHelper.SetTimeout(async() => { await JSRuntime.Current.InvokeAsync <bool>("contextBridgeSend", csharpProxy); }, 100); }
/// <summary> /// Get resolved type from given AssemblyName & TypeName /// </summary> /// <returns></returns> public Type ResolvedType() { if (string.IsNullOrEmpty(SerializedData)) { throw new NullReferenceException(); } return(BridgeSerializer.Deserialize <Type>(this)); }
public static bool Receive(string methodProxyJson, bool socketSuccess) { if (string.IsNullOrEmpty(methodProxyJson)) { return(false); } InternalHelper.SetTimeout(() => { MethodProxy resultProxy = BridgeSerializer.Deserialize <MethodProxy>(ref methodProxyJson); var taskToReturn = MethodDispatcher.GetTaskDispatcher(resultProxy.TaskIdentity); if (taskToReturn == null) { return; } if (socketSuccess && resultProxy.TaskSuccess) { MethodDispatcher.SetTaskResult(resultProxy.TaskIdentity, resultProxy); } else { Exception exception = null; //If success value (from javascript) is false, like unable to connect to websocket //or if the native task failed with an exception, cancel the current task, that will throw if (!socketSuccess) { exception = new InvalidOperationException($"BlazorMobile was unable to connect to native through websocket server to execute task {resultProxy.TaskIdentity}"); } else if (resultProxy.ExceptionDescriptor != null) { //We have some message to send in this case exception = new Exception(resultProxy.ExceptionDescriptor.Message); } else { //Sending uncustomized message exception = new InvalidOperationException($"Task {resultProxy.TaskIdentity} has thrown an exception on native side. See log for more info."); } MethodDispatcher.SetTaskAsFaulted(resultProxy.TaskIdentity, exception); } taskToReturn.RunSynchronously(); //Clear task from task list. Should then call the task to execute. It will throw if it has been cancelled MethodDispatcher.ClearTask(resultProxy.TaskIdentity); }, 10); return(true); }
public static bool Receive(string methodProxyJson, bool socketSuccess) { if (string.IsNullOrEmpty(methodProxyJson)) { return(false); } try { MethodProxy resultProxy = BridgeSerializer.Deserialize <MethodProxy>(ref methodProxyJson); return(BlazorCommonDispatcher.Receive(resultProxy, socketSuccess)); } catch (Exception ex) { ConsoleHelper.WriteException(ex); return(false); } }
public static bool ReceiveFromXamarin(string methodProxyJson, bool socketSuccess) { if (string.IsNullOrEmpty(methodProxyJson)) { return(false); } try { ClientMethodProxy resultProxy = BridgeSerializer.Deserialize <ClientMethodProxy>(ref methodProxyJson); BlazorMobileComponent.GetJSRuntime().InvokeAsync <bool>("contextBridgeSendClient", resultProxy.InteropAssembly, resultProxy.InteropMethod, resultProxy.InteropParameters); return(true); } catch (Exception ex) { ConsoleHelper.WriteException(ex); return(false); } }
public static void Receive(string methodProxyJson) { if (string.IsNullOrEmpty(methodProxyJson)) { return; } MethodProxy resultProxy = BridgeSerializer.Deserialize <MethodProxy>(methodProxyJson); var taskToReturn = MethodDispatcher.GetTaskDispatcher(resultProxy.TaskIdentity); MethodDispatcher.SetTaskResult(resultProxy.TaskIdentity, resultProxy); if (taskToReturn == null) { return; } taskToReturn.RunSynchronously(); MethodDispatcher.ClearTask(resultProxy.TaskIdentity); }
private static bool MessageProxyReceiver(string methodProxyJson, bool socketSuccess) { if (string.IsNullOrEmpty(methodProxyJson)) { return(false); } try { MessageProxy resultProxy = BridgeSerializer.Deserialize <MessageProxy>(ref methodProxyJson); //Using JSInvokable API if (resultProxy.IsJSInvokable) { BlazorMobileService.SendMessageToJSInvokableMethod(resultProxy); } else { if (resultProxy.InteropParameters == null) { resultProxy.InteropParameters = new object[0]; } //This is more about atomicity as we don't want to do extensive test //We just only want to prevent to pass an empty / null value arguments that would maybe not be identifiable on its type after serialization / deserialization Type ArgsType = resultProxy.InteropArgsType.ResolvedType(); //Using delegate Messaging API BlazorMobileService.SendMessageToSubscribers(resultProxy.InteropMethod, ArgsType, resultProxy.InteropParameters); } return(true); } catch (Exception ex) { ConsoleHelper.WriteException(ex); return(false); } }
public static MethodProxy GetMethodProxyFromJSON(ref string json) { return(BridgeSerializer.Deserialize <MethodProxy>(ref json)); }
public TypeProxy(Type type) { SerializedData = BridgeSerializer.Serialize(type); }
private static void MessageForwarder(MessageProxy messageProxy) { BlazorContextBridge.Current.SendMessageToClient( BridgeSerializer.Serialize(messageProxy)); }
public static void Send(MethodProxy methodProxy) { string csharpProxy = BridgeSerializer.Serialize(methodProxy); RegisteredFunction.Invoke <string>("contextBridgeSend", csharpProxy); }