Beispiel #1
0
        async Task InitializeCompilationWorkspaceAsync(CancellationToken cancellationToken)
        {
            WorkingDirectory = Workbook.WorkingBasePath;
            if (!WorkingDirectory.DirectoryExists)
            {
                WorkingDirectory = Uri.WorkingDirectory;
            }
            if (!WorkingDirectory.DirectoryExists)
            {
                WorkingDirectory = FilePath.Empty;
            }

            if (agent.IsConnected)
            {
                await GacCache.InitializingTask;

                CompilationWorkspace = await WorkspaceServiceFactory.CreateWorkspaceServiceAsync(
                    "csharp",
                    await WorkspaceConfiguration.CreateAsync(
                        Agent.Api.EvaluationContextManager,
                        SessionKind,
                        cancellationToken),
                    cancellationToken);
            }

            await RefreshForAgentIntegration();

            if (CompilationWorkspace == null)
            {
                throw new Exception("Unable to get compilation workspace for agent.");
            }

            var dependencyResolver = CompilationWorkspace.Configuration.DependencyResolver;

            if (WorkingDirectory.DirectoryExists)
            {
                dependencyResolver.BaseDirectory = WorkingDirectory;
                dependencyResolver.AddAssemblySearchPath(WorkingDirectory);
            }

            Workbook.WorkingPathChanged += (o, e) => {
                if (dependencyResolver != null)
                {
                    dependencyResolver.RemoveAssemblySearchPath(WorkingDirectory);
                    dependencyResolver.RemoveAssemblySearchPath(e.OldBasePath);

                    WorkingDirectory = e.NewBasePath;
                    dependencyResolver.BaseDirectory = WorkingDirectory;
                    dependencyResolver.AddAssemblySearchPath(WorkingDirectory);
                }
            };

            PostEvent(ClientSessionEventKind.CompilationWorkspaceAvailable);
        }
Beispiel #2
0
        public async Task TwoPlusTwo()
        {
            var evaluationContextManager = new EvaluationContextManager(
                new RepresentationManager(RepresentationManagerOptions.YieldOriginal)
                );

            var workspaceConfiguration = await WorkspaceConfiguration
                                         .CreateAsync(evaluationContextManager);

            var workspaceService = await WorkspaceServiceFactory
                                   .CreateWorkspaceServiceAsync("csharp", workspaceConfiguration);

            var evaluationService = new EvaluationService(
                workspaceService,