public static Task <WorkspaceConfiguration> CreateAsync( IEvaluationContextManager evaluationContextManager, CancellationToken cancellationToken = default) => CreateAsync( evaluationContextManager, ClientSessionKind.Workbook, cancellationToken);
internal static async Task <WorkspaceConfiguration> CreateAsync( IEvaluationContextManager evaluationContextManager, ClientSessionKind sessionKind, CancellationToken cancellationToken = default) { if (evaluationContextManager == null) { throw new ArgumentNullException(nameof(evaluationContextManager)); } var configuration = await evaluationContextManager .CreateEvaluationContextAsync(cancellationToken) .ConfigureAwait(false); if (configuration == null) { throw new Exception( $"{nameof (IEvaluationContextManager)}." + $"{nameof (IEvaluationContextManager.CreateEvaluationContextAsync)} " + $"returned null"); } var dependencyResolver = CreateDependencyResolver(configuration); // Only do this for Inspector sessions. Workbooks will do their own Forms init later. if (sessionKind == ClientSessionKind.LiveInspection) { var formsReference = configuration .InitialReferences .FirstOrDefault(ra => ra.Name.Name == "Xamarin.Forms.Core"); if (formsReference != null) { await LoadFormsAgentExtensions( formsReference.Name.Version, configuration, evaluationContextManager, dependencyResolver).ConfigureAwait(false); } } dependencyResolver.AddDefaultReferences(configuration.InitialReferences); var globalStateType = ResolveHostObjectType( dependencyResolver, configuration); configuration = configuration.With(globalStateType: configuration .GlobalStateType .WithResolvedType(globalStateType)); return(new WorkspaceConfiguration(configuration, dependencyResolver)); }
internal static async Task LoadFormsAgentExtensions( Version formsVersion, TargetCompilationConfiguration configuration, IEvaluationContextManager evaluationContextManager, DependencyResolver dependencyResolver) { var formsAssembly = InteractiveInstallation.Default.LocateFormsAssembly(configuration.Sdk?.Id); if (string.IsNullOrWhiteSpace(formsAssembly)) { return; } var deps = dependencyResolver.Resolve(new [] { new FilePath(formsAssembly) }); var includePeImage = configuration.IncludePEImagesInDependencyResolution; var assembliesToLoad = deps.Select(dep => { var peImage = includePeImage ? GetFileBytes(dep.Path) : null; var syms = includePeImage ? GetDebugSymbolsFromAssemblyPath(dep.Path) : null; return(new AssemblyDefinition( dep.AssemblyName, dep.Path, peImage: peImage, debugSymbols: syms )); }).ToArray(); var results = await evaluationContextManager.LoadAssembliesAsync( configuration.EvaluationContextId, assembliesToLoad); var failed = results.Where(p => !p.Success); if (failed.Any()) { var failedLoads = string.Join(", ", failed.Select(p => p.AssemblyName.Name)); Log.Warning( TAG, $"Xamarin.Forms reference detected, but integration may not have" + $" loaded properly. Assemblies that did not load: {failedLoads}"); } }
public void NotifyEvaluationContextManagerChanged(IEvaluationContextManager evaluationContextManager);
public EvaluationService(IWorkspaceService workspace, EvaluationEnvironment evaluationEnvironment, IEvaluationContextManager evaluationContextManager = null);
public static Task <WorkspaceConfiguration> CreateAsync(IEvaluationContextManager evaluationContextManager, CancellationToken cancellationToken = default(CancellationToken));
async Task LoadPackageIntegrationsAsync( AgentType agentType, TargetCompilationConfiguration targetCompilationConfiguration, IEvaluationContextManager evaluationContextManager, 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 WorkspaceConfiguration.LoadFormsAgentExtensions( package.Identity.Version.Version, targetCompilationConfiguration, evaluationContextManager, dependencyResolver); } 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 = packageManager.GetPackageInstallPath(package); var interactivePath = packagePath.Combine("xamarin.interactive"); if (interactivePath.DirectoryExists) { var interactiveAssemblies = interactivePath.EnumerateFiles("*.dll"); foreach (var interactiveReference in interactiveAssemblies) { var resolvedAssembly = dependencyResolver.ResolveWithoutReferences(interactiveReference); if (HasIntegration(resolvedAssembly)) { assembliesToLoadOnAgent.Add(resolvedAssembly); } } } if (assembliesToLoadOnAgent.Count > 0) { var includePeImage = targetCompilationConfiguration.IncludePEImagesInDependencyResolution; var assembliesToLoad = assembliesToLoadOnAgent.Select(dep => { var peImage = includePeImage ? GetFileBytes(dep.Path) : null; var syms = includePeImage ? GetDebugSymbolsFromAssemblyPath(dep.Path) : null; return(new AssemblyDefinition( dep.AssemblyName, dep.Path, peImage: peImage, debugSymbols: syms )); }).ToArray(); await evaluationContextManager.LoadAssembliesAsync( targetCompilationConfiguration.EvaluationContextId, assembliesToLoad, cancellationToken); } await getAgentConnectionHandler(true, cancellationToken); }
internal static async Task LoadFormsAgentExtensions( Version formsVersion, TargetCompilationConfiguration configuration, IEvaluationContextManager evaluationContextManager, DependencyResolver dependencyResolver) { var formsAssembly = InteractiveInstallation.Default.LocateFormsAssembly(configuration.Sdk?.Id); if (string.IsNullOrWhiteSpace(formsAssembly)) { return; } var deps = dependencyResolver.Resolve(new [] { new FilePath(formsAssembly) }); // Now dig out the resolved assembly that is Xamarin.Forms.Core, and compare it to the // default ref. var resolvedFormsAssembly = deps.FirstOrDefault(d => d.AssemblyName.Name == "Xamarin.Forms.Core"); if (resolvedFormsAssembly == null) { Log.Warning(TAG, "Cannot enable Forms integration because Forms cannot be " + "resolved. Check log for assembly search path issues."); return; } var ourVersion = resolvedFormsAssembly.AssemblyName.Version; var theirVersion = formsVersion; if (ourVersion.Major != theirVersion.Major) { Log.Warning( TAG, "Assembly version mismatch between app's Xamarin.Forms.Core and" + $"our referenced Xamarin.Forms.Core. Our version: {ourVersion}, " + $"their version: {theirVersion}. Won't load Xamarin.Forms agent " + "integration, as it probably won't work." ); return; } var includePeImage = configuration.IncludePEImagesInDependencyResolution; var assembliesToLoad = deps.Select(dep => { var peImage = includePeImage ? GetFileBytes(dep.Path) : null; var syms = includePeImage ? GetDebugSymbolsFromAssemblyPath(dep.Path) : null; return(new AssemblyDefinition( dep.AssemblyName, dep.Path, peImage: peImage, debugSymbols: syms )); }).ToArray(); var results = await evaluationContextManager.LoadAssembliesAsync( configuration.EvaluationContextId, assembliesToLoad); var failed = results.Where(p => !p.Success); if (failed.Any()) { var failedLoads = string.Join(", ", failed.Select(p => p.AssemblyName.Name)); Log.Warning( TAG, $"Xamarin.Forms reference detected, but integration may not have" + $" loaded properly. Assemblies that did not load: {failedLoads}"); } }