Exemplo n.º 1
0
        void HandleAgentDisconnected()
        {
            var disconnectedAgent = agent;

            ResetAgentConnection();
            WorkbookPageViewModel.OutdateAllCodeCells();

            PostEvent(ClientSessionEventKind.AgentDisconnected);

            var title = Catalog.GetString("Session Disconnected");

            Message message;

            if (SessionKind == ClientSessionKind.Workbook)
            {
                message = WithReconnectSessionAction(
                    Message.CreateErrorAlert(title, Catalog.GetString(
                                                 "The Workbook host application has terminated.")));
            }
            else
            {
                message = Message.CreateInfoAlert(
                    title,
                    Catalog.Format(Catalog.GetString(
                                       "Inspector is no longer connected to {0}. You may review and close " +
                                       "the session window at your leisure. A new Inspector session may be " +
                                       "attached via the debugger in your IDE."),
                                   disconnectedAgent.Identity.ApplicationName));
            }

            ViewControllers.Messages.PushMessage(message);
        }
Exemplo n.º 2
0
        async Task ReferenceTopLevelPackageAsync(
            InteractivePackage package,
            CancellationToken cancellationToken)
        {
            if (package.AssemblyReferences.Count == 0)
            {
                return;
            }

            var referenceBuffer = new StringBuilder();

            foreach (var packageAssemblyReference in package.AssemblyReferences)
            {
                var resolvedAssembly = CompilationWorkspace
                                       .DependencyResolver
                                       .ResolveWithoutReferences(packageAssemblyReference);
                if (resolvedAssembly == null)
                {
                    continue;
                }

                if (BannedReferencePrefixes.Any(resolvedAssembly.AssemblyName.Name.StartsWith))
                {
                    continue;
                }

                // Don't add #r for integration assemblies.
                if (HasIntegration(resolvedAssembly))
                {
                    continue;
                }

                if (referenceBuffer.Length > 0)
                {
                    referenceBuffer.AppendLine();
                }

                referenceBuffer
                .Append("#r \"")
                .Append(resolvedAssembly.AssemblyName.Name)
                .Append("\"");
            }

            if (referenceBuffer.Length > 0)
            {
                await WorkbookPageViewModel.EvaluateAsync(referenceBuffer.ToString(), cancellationToken);
            }
        }
Exemplo n.º 3
0
        void WorkbookTargets_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            WorkbookPageViewModel.OutdateAllCodeCells();

            var selectedTarget = ViewControllers.WorkbookTargets.SelectedTarget;

            if (selectedTarget == null)
            {
                TerminateAgentConnection();
            }
            else if (selectedTarget.AgentType != agent.Type)
            {
                agent = agent.WithAgentType(selectedTarget.AgentType);
                InitializeAgentConnectionAsync().Forget();
            }
        }
Exemplo n.º 4
0
        public void Dispose()
        {
            if (isDisposed)
            {
                return;
            }

            isDisposed = true;

            if (agent.IsConnected)
            {
                agent.Api.AssociateClientSession(ClientSessionAssociationKind.Dissociating)
                .ContinueWith(task => Workbook.Close());
            }
            else
            {
                Workbook.Close();
            }

            ResetAgentConnection();
            cancellationTokenSource.Cancel();
            observable.Observers.OnCompleted();
            WorkbookPageViewModel?.Dispose();
        }
Exemplo n.º 5
0
        async Task LoadPackageIntegrationsAsync(
            InteractivePackage package,
            CancellationToken cancellationToken)
        {
            // Forms is special-cased because we own it and load the extension from our framework.
            if (PackageIdComparer.Equals(package.Identity.Id, "Xamarin.Forms"))
            {
                await CompilationWorkspaceFactory.LoadFormsAgentExtensions(
                    package.Identity.Version.Version,
                    this,
                    CompilationWorkspace.DependencyResolver,
                    CompilationWorkspace.EvaluationContextId,
                    Agent.IncludePeImage);
            }

            var assembliesToLoadOnAgent = new List <ResolvedAssembly> ();

            // Integration assemblies are not expected to be in a TFM directory—we look for them in
            // the `xamarin.interactive` folder inside the NuGet package.
            var packagePath = Workbook
                              .Packages
                              .GetPackageInstallPath(package);

            var interactivePath = packagePath.Combine("xamarin.interactive");

            if (interactivePath.DirectoryExists)
            {
                var interactiveAssemblies = interactivePath.EnumerateFiles("*.dll");
                foreach (var interactiveReference in interactiveAssemblies)
                {
                    var resolvedAssembly = CompilationWorkspace
                                           .DependencyResolver
                                           .ResolveWithoutReferences(interactiveReference);

                    if (HasIntegration(resolvedAssembly))
                    {
                        assembliesToLoadOnAgent.Add(resolvedAssembly);

                        foreach (var dependency in resolvedAssembly.ExternalDependencies)
                        {
                            if (!(dependency is WebDependency))
                            {
                                continue;
                            }

                            if (AddNuGetWebResource(dependency.Location, out var id))
                            {
                                await WorkbookPageViewModel.LoadWorkbookDependencyAsync($"/static/{id}");
                            }
                        }
                    }
                }
            }

            if (assembliesToLoadOnAgent.Count > 0)
            {
                var assembliesToLoad = assembliesToLoadOnAgent.Select(dep => {
                    var peImage = Agent.IncludePeImage
                        ? GetFileBytes(dep.Path)
                        : null;
                    var syms = Agent.IncludePeImage
                        ? GetDebugSymbolsFromAssemblyPath(dep.Path)
                        : null;
                    return(new AssemblyDefinition(
                               dep.AssemblyName,
                               dep.Path,
                               peImage: peImage,
                               debugSymbols: syms
                               ));
                }).ToArray();

                await Agent.Api.LoadAssembliesAsync(
                    CompilationWorkspace.EvaluationContextId,
                    assembliesToLoad);
            }

            await RefreshForAgentIntegration();
        }
Exemplo n.º 6
0
 async Task InitializeAgentConnectionAsync()
 {
     using (WorkbookPageViewModel.InhibitEvaluate())
         await DoInitalizeAgentConnectionAsync();
 }
Exemplo n.º 7
0
        public async Task InitializeAsync(IWorkbookPageHost workbookPageViewHost)
        {
            if (workbookPageViewHost == null)
            {
                throw new ArgumentNullException(nameof(workbookPageViewHost));
            }

            var genericLoadingMessage = SessionKind == ClientSessionKind.Workbook
                ? Catalog.GetString("Loading workbook…")
                : Catalog.GetString("Loading session…");

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

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

            Task LoadWorkbookPageViewAsync(CancellationToken cancellationToken)
            {
                WorkbookPageViewModel = workbookPageViewHost.CreatePageViewModel(this, Workbook.IndexPage);
                WorkbookPageViewModel.LoadWorkbookPage();
                Subscribe(WorkbookPageViewModel);
                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();
            }));
        }