Exemple #1
0
        public void ProjectSnapshotHandleJsonConverter_Serialization_CanKindaRoundTrip()
        {
            // Arrange
            var snapshot = new ProjectSnapshotHandle(
                "Test.csproj",
                new ProjectSystemRazorConfiguration(
                    RazorLanguageVersion.Version_1_1,
                    "Test",
                    new[]
            {
                new ProjectSystemRazorExtension("Test-Extension1"),
                new ProjectSystemRazorExtension("Test-Extension2"),
            }),
                ProjectId.CreateFromSerialized(Guid.NewGuid(), "Test"));

            // Act
            var json = JsonConvert.SerializeObject(snapshot, Converters);
            var obj  = JsonConvert.DeserializeObject <ProjectSnapshotHandle>(json, Converters);

            // Assert
            Assert.Equal(snapshot.FilePath, obj.FilePath);
            Assert.Equal(snapshot.Configuration.ConfigurationName, obj.Configuration.ConfigurationName);
            Assert.Collection(
                snapshot.Configuration.Extensions.OrderBy(e => e.ExtensionName),
                e => Assert.Equal("Test-Extension1", e.ExtensionName),
                e => Assert.Equal("Test-Extension2", e.ExtensionName));
            Assert.Equal(snapshot.Configuration.LanguageVersion, obj.Configuration.LanguageVersion);
            Assert.Equal(snapshot.WorkspaceProjectId.Id, obj.WorkspaceProjectId.Id);
        }
Exemple #2
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var project = (ProjectSnapshot)value;
            var handle  = new ProjectSnapshotHandle(project.FilePath, project.Configuration);

            ProjectSnapshotHandleJsonConverter.Instance.WriteJson(writer, handle, serializer);
        }
Exemple #3
0
        protected virtual Task <ProjectSnapshot> GetProjectSnapshotAsync(ProjectSnapshotHandle projectHandle, CancellationToken cancellationToken)
        {
            if (projectHandle == null)
            {
                throw new ArgumentNullException(nameof(projectHandle));
            }

            return(Task.FromResult <ProjectSnapshot>(new SerializedProjectSnapshot(projectHandle.FilePath, projectHandle.Configuration, projectHandle.RootNamespace)));
        }
        public void ProjectSnapshotHandleJsonConverter_SerializationWithNulls_CanKindaRoundTrip()
        {
            // Arrange
            var snapshot = new ProjectSnapshotHandle("Test.csproj", null);

            // Act
            var json = JsonConvert.SerializeObject(snapshot, Converters);
            var obj  = JsonConvert.DeserializeObject <ProjectSnapshotHandle>(json, Converters);

            // Assert
            Assert.Equal(snapshot.FilePath, obj.FilePath);
            Assert.Null(obj.Configuration);
        }
        protected virtual async Task <ProjectSnapshot> GetProjectSnapshotAsync(ProjectSnapshotHandle projectHandle, CancellationToken cancellationToken)
        {
            if (projectHandle == null)
            {
                throw new ArgumentNullException(nameof(projectHandle));
            }

            var solution = await GetSolutionAsync(cancellationToken).ConfigureAwait(false);

            var workspaceProject = solution.GetProject(projectHandle.WorkspaceProjectId);

            return(new SerializedProjectSnapshot(projectHandle.FilePath, projectHandle.Configuration, workspaceProject));
        }
        public async Task <TagHelperResolutionResult> GetTagHelpersAsync(ProjectSnapshotHandle projectHandle, string factoryTypeName, CancellationToken cancellationToken = default)
        {
            var projectSnapshot = await GetProjectSnapshotAsync(projectHandle, cancellationToken).ConfigureAwait(false);

            var solution = await GetSolutionAsync(cancellationToken);

            var workspaceProject = solution
                                   .Projects
                                   .FirstOrDefault(project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));

            if (workspaceProject == null)
            {
                return(TagHelperResolutionResult.Empty);
            }

            return(await RazorServices.TagHelperResolver.GetTagHelpersAsync(workspaceProject, projectHandle.Configuration, factoryTypeName, cancellationToken));
        }
Exemple #7
0
        protected virtual async Task <TagHelperResolutionResult> ResolveTagHelpersOutOfProcessAsync(IProjectEngineFactory factory, Project workspaceProject, ProjectSnapshot projectSnapshot, CancellationToken cancellationToken)
        {
            // We're being overly defensive here because the OOP host can return null for the client/session/operation
            // when it's disconnected (user stops the process).
            //
            // This will change in the future to an easier to consume API but for VS RTM this is what we have.
            var remoteClient = await RazorRemoteHostClient.TryGetClientAsync(_workspace.Services, RazorServiceDescriptors.TagHelperProviderServiceDescriptors, RazorRemoteServiceCallbackDispatcherRegistry.Empty, cancellationToken);

            if (remoteClient == null)
            {
                // Could not resolve
                return(null);
            }

            var projectHandle = new ProjectSnapshotHandle(projectSnapshot.FilePath, projectSnapshot.Configuration, projectSnapshot.RootNamespace);
            var result        = await remoteClient.TryInvokeAsync <IRemoteTagHelperProviderService, TagHelperResolutionResult>(
                workspaceProject.Solution,
                (service, solutionInfo, innerCancellationToken) => service.GetTagHelpersAsync(solutionInfo, projectHandle, factory?.GetType().AssemblyQualifiedName, innerCancellationToken),
                cancellationToken
                );

            return(result.HasValue ? result.Value : null);
        }
Exemple #8
0
        public async Task <TagHelperResolutionResult> GetTagHelpersAsync(ProjectSnapshotHandle projectHandle, string factoryTypeName, CancellationToken cancellationToken = default)
        {
            var project = await GetProjectSnapshotAsync(projectHandle, cancellationToken).ConfigureAwait(false);

            return(await RazorServices.TagHelperResolver.GetTagHelpersAsync(project, factoryTypeName, cancellationToken));
        }
Exemple #9
0
        private async ValueTask <TagHelperResolutionResult> GetTagHelpersCoreAsync(RazorPinnedSolutionInfoWrapper solutionInfo, ProjectSnapshotHandle projectHandle, string factoryTypeName, CancellationToken cancellationToken)
        {
            if (projectHandle is null)
            {
                throw new ArgumentNullException(nameof(projectHandle));
            }

            if (string.IsNullOrEmpty(factoryTypeName))
            {
                throw new ArgumentException($"'{nameof(factoryTypeName)}' cannot be null or empty.", nameof(factoryTypeName));
            }

            var solution = await solutionInfo.GetSolutionAsync(ServiceBrokerClient, cancellationToken).ConfigureAwait(false);

            var projectSnapshot = await GetProjectSnapshotAsync(projectHandle, cancellationToken).ConfigureAwait(false);

            var workspaceProject = solution
                                   .Projects
                                   .FirstOrDefault(project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));

            if (workspaceProject == null)
            {
                return(TagHelperResolutionResult.Empty);
            }

            var resolutionResult = await RazorServices.TagHelperResolver.GetTagHelpersAsync(workspaceProject, projectHandle.Configuration, factoryTypeName, cancellationToken).ConfigureAwait(false);

            return(resolutionResult);
        }
Exemple #10
0
 public ValueTask <TagHelperResolutionResult> GetTagHelpersAsync(RazorPinnedSolutionInfoWrapper solutionInfo, ProjectSnapshotHandle projectHandle, string factoryTypeName, CancellationToken cancellationToken = default)
 => RazorBrokeredServiceImplementation.RunServiceAsync(cancellationToken => GetTagHelpersCoreAsync(solutionInfo, projectHandle, factoryTypeName, cancellationToken), cancellationToken);
        public async ValueTask <TagHelperDeltaResult> GetTagHelpersDeltaCoreAsync(RazorPinnedSolutionInfoWrapper solutionInfo, ProjectSnapshotHandle projectHandle, string factoryTypeName, int lastResultId, CancellationToken cancellationToken)
        {
            var tagHelperResolutionResult = await GetTagHelpersCoreAsync(solutionInfo, projectHandle, factoryTypeName, cancellationToken).ConfigureAwait(false);

            var currentTagHelpers = tagHelperResolutionResult.Descriptors;
            var deltaResult       = _tagHelperDeltaProvider.GetTagHelpersDelta(projectHandle.FilePath, lastResultId, currentTagHelpers);

            return(deltaResult);
        }
        private async ValueTask <TagHelperResolutionResult> GetTagHelpersCoreAsync(RazorPinnedSolutionInfoWrapper solutionInfo, ProjectSnapshotHandle projectHandle, string factoryTypeName, CancellationToken cancellationToken)
        {
            if (projectHandle is null)
            {
                throw new ArgumentNullException(nameof(projectHandle));
            }

            if (string.IsNullOrEmpty(factoryTypeName))
            {
                throw new ArgumentException($"'{nameof(factoryTypeName)}' cannot be null or empty.", nameof(factoryTypeName));
            }

            // We should replace the below call: https://github.com/dotnet/razor-tooling/issues/6316
#pragma warning disable CS0618 // Type or member is obsolete
            var solution = await solutionInfo.GetSolutionAsync(ServiceBrokerClient, cancellationToken).ConfigureAwait(false);

#pragma warning restore CS0618 // Type or member is obsolete
            var projectSnapshot = await GetProjectSnapshotAsync(projectHandle, cancellationToken).ConfigureAwait(false);

            var workspaceProject = solution
                                   .Projects
                                   .FirstOrDefault(project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));

            if (workspaceProject is null)
            {
                return(TagHelperResolutionResult.Empty);
            }

            var resolutionResult = await RazorServices.TagHelperResolver.GetTagHelpersAsync(workspaceProject, projectHandle.Configuration, factoryTypeName, cancellationToken).ConfigureAwait(false);

            return(resolutionResult);
        }
 public ValueTask <TagHelperDeltaResult> GetTagHelpersDeltaAsync(RazorPinnedSolutionInfoWrapper solutionInfo, ProjectSnapshotHandle projectHandle, string factoryTypeName, int lastResultId, CancellationToken cancellationToken)
 => RazorBrokeredServiceImplementation.RunServiceAsync(cancellationToken => GetTagHelpersDeltaCoreAsync(solutionInfo, projectHandle, factoryTypeName, lastResultId, cancellationToken), cancellationToken);