protected override void OnSessionAvailable()
        {
            if (workbookPageViewHost == null)
            {
                workbookPageViewHost = new WorkbookWebPageViewHost(webView.XcbWebView);
            }

            Session.InitializeAsync(workbookPageViewHost).Forget();
        }
Exemplo n.º 2
0
        public async Task InitializeAsync(IWorkbookPageHost workbookPageViewHost = null)
        {
            var genericLoadingMessage = SessionKind == ClientSessionKind.Workbook
                ? Catalog.GetString("Loading workbook…")
                : Catalog.GetString("Loading session…");

            var initializers = new List <ClientSessionTask> {
                ClientSessionTask.CreateRequired(genericLoadingMessage, LoadWorkbookAsync)
            };

            if (workbookPageViewHost != null)
            {
                initializers.AddRange(
                    workbookPageViewHost
                    .GetClientSessionInitializationTasks(clientWebServerUri)
                    .Select(t => ClientSessionTask.CreateRequired(genericLoadingMessage, t)));

                Task LoadWorkbookPageViewAsync(CancellationToken cancellationToken)
                {
                    var pageViewModel = workbookPageViewHost.CreatePageViewModel(this, Workbook.IndexPage);

                    EvaluationService = pageViewModel;

                    pageViewModel.LoadWorkbookPage();

                    if (pageViewModel is IObserver <ClientSessionEvent> observer)
                    {
                        Subscribe(observer);
                    }

                    return(Task.CompletedTask);
                }

                initializers.Add(ClientSessionTask.CreateRequired(genericLoadingMessage, LoadWorkbookPageViewAsync));
            }

            var initializeException = await RunInitializers(initializers);

            if (isDisposed)
            {
                return;
            }

            if (initializeException == null)
            {
                await InitializeAgentConnectionAsync();

                try {
                    await ConfigureNewWorkbookFeatures();
                } catch (Exception e) {
                    var message = Catalog.GetString(
                        "Unable to configure optional workbook features.");
                    Log.Warning(TAG, message, e);
                    ViewControllers.Messages.PushMessage(Message.CreateErrorStatus(
                                                             message,
                                                             e.Message));
                }

                return;
            }

            var genericErrorMessage = SessionKind == ClientSessionKind.Workbook
                ? Catalog.GetString("Unable to load workbook.")
                : Catalog.GetString("Unable to initialize live inspection session.");

            ViewControllers.Messages.PushMessage(Message.CreateErrorStatus(genericErrorMessage));

            ViewControllers.Messages.PushMessage(initializeException
                                                 .ToAlertMessage(genericErrorMessage)
                                                 .WithAction(new MessageAction(
                                                                 MessageActionKind.Affirmative,
                                                                 "close",
                                                                 Catalog.GetString("Close")))
                                                 .WithActionResponseHandler((message, action) => {
                message.Dispose();
                Dispose();
            }));
        }