Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public Task WriteLine(string message)
        {
            //Dispatch message on browser
            Console.WriteLine(message);

            //Dispatch message on native
            return(MethodDispatcher.CallVoidMethodAsync(MethodBase.GetCurrentMethod(), message));
        }
        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);
        }
Exemplo n.º 4
0
 public Task <string> GetRuntimePlatform()
 {
     return(MethodDispatcher.CallMethodAsync <string>(MethodBase.GetCurrentMethod()));
 }
Exemplo n.º 5
0
 public Task StartupMetadataForElectron(string baseURL, string userDataFolder)
 {
     return(MethodDispatcher.CallVoidMethodAsync(MethodBase.GetCurrentMethod(), baseURL, userDataFolder));
 }
Exemplo n.º 6
0
 public Task <bool> IsElectronActive()
 {
     return(MethodDispatcher.CallMethodAsync <bool>(MethodBase.GetCurrentMethod()));
 }