Example #1
0
        async void HandleDataReceived(object sender, object e)
        {
            var    container = e as JContainer;
            string type      = (string)container["Type"];

            if (type == typeof(EvalRequestMessage).Name)
            {
                await HandleEvalRequest(container.ToObject <EvalRequestMessage>());
            }
            else if (type == typeof(ErrorMessage).Name)
            {
                var errorMessage = container.ToObject <ErrorMessage>();
                await uiToolkit.RunInUIThreadAsync(async() =>
                {
                    errorViewModel.SetError("Oh no! An exception!", errorMessage.Exception);
                    await previewer.NotifyError(errorViewModel);
                });
            }
        }
Example #2
0
        async Task HandleEvalRequest(EvalRequest request)
        {
            EvalResponse evalResponse = new EvalResponse();
            EvalResult   result;

            try
            {
                result = await vm.Eval(request, mainScheduler, CancellationToken.None);

                if (result.HasResult)
                {
                    var tcs = new TaskCompletionSource <bool>();
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        try
                        {
                            await previewer.Preview(result);
                            tcs.SetResult(true);
                        }
                        catch (Exception ex)
                        {
                            errorViewModel.SetError("Oh no! An exception!", ex);
                            await previewer.NotifyError(errorViewModel);
                            tcs.SetException(ex);
                        }
                    });
                    await tcs.Task;
                }
                else
                {
                    Xamarin.Forms.Device.BeginInvokeOnMainThread(async() =>
                    {
                        errorViewModel.SetError("Oh no! An evaluation error!", result);
                        await previewer.NotifyError(errorViewModel);
                    });
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }