コード例 #1
0
        public void SavePreprocessResults(IT4File file, string text)
        {
            Locks.AssertReadAccessAllowed();
            var sourceFile  = file.PhysicalPsiSourceFile.NotNull();
            var projectFile = sourceFile.ToProjectFile().NotNull();

            Locks.AssertWriteAccessAllowed();
            FileSystemPath destinationLocation = null;
            IProjectFile   destination         = null;

            Solution.InvokeUnderTransaction(cookie =>
            {
                string destinationName = GetPreprocessingTargetFileName(file);
                destination            = GetOrCreateSameDestinationFile(cookie, file, destinationName);
                destinationLocation    = destination.Location;
                RemoveLastGenOutputIfDifferent(file, cookie, destinationLocation);
                TemplateMetadataManager.UpdateTemplateMetadata(
                    cookie,
                    projectFile,
                    T4TemplateKind.Preprocessed,
                    destinationLocation
                    );
                TemplateMetadataManager.UpdateGeneratedFileMetadata(cookie, destination, projectFile);
            });
            destinationLocation.WriteAllText(text);
            OutputFileRefresher.Refresh(destination);
        }
コード例 #2
0
        public void TryProcessExecutionResults(IT4File file)
        {
            Locks.AssertReadAccessAllowed();
            Locks.AssertWriteAccessAllowed();
            var temporary = TryFindTemporaryTargetFile(file);

            if (temporary == null)
            {
                return;
            }
            var destinationLocation = GetDestinationLocation(file, temporary.Name);

            destinationLocation.DeleteFile();
            File.Move(temporary.FullPath, destinationLocation.FullPath);
            var          sourceFile  = file.PhysicalPsiSourceFile.NotNull();
            var          projectFile = sourceFile.ToProjectFile().NotNull();
            IProjectFile destination = null;

            Solution.InvokeUnderTransaction(cookie =>
            {
                destination = UpdateProjectModel(file, destinationLocation, cookie);
                RemoveLastGenOutputIfDifferent(file, cookie, destinationLocation);
                TemplateMetadataManager.UpdateTemplateMetadata(
                    cookie,
                    projectFile,
                    T4TemplateKind.Executable,
                    destinationLocation
                    );
                TemplateMetadataManager.UpdateGeneratedFileMetadata(cookie, destination, projectFile);
            });
            OutputFileRefresher.Refresh(destination);
        }
コード例 #3
0
        private IProjectFile UpdateProjectModel(
            [NotNull] IT4File file,
            [NotNull] FileSystemPath result,
            [NotNull] IProjectModelTransactionCookie cookie
            )
        {
            Locks.AssertReadAccessAllowed();
            Locks.AssertWriteAccessAllowed();
            var destination = GetOrCreateSameDestinationFile(cookie, file, result);

            return(destination);
        }
コード例 #4
0
        private IProjectFile CreateSameDestinationFile(
            [NotNull] IProjectModelTransactionCookie cookie,
            [NotNull] IT4File file,
            [NotNull] string destinationName
            )
        {
            Locks.AssertWriteAccessAllowed();
            var projectFile    = file.PhysicalPsiSourceFile.ToProjectFile().NotNull();
            var folder         = projectFile.ParentFolder.NotNull();
            var targetLocation = folder.Location.Combine(destinationName);
            var parameters     = T4MSBuildProjectUtil.CreateTemplateMetadata(projectFile);

            return(cookie.AddFile(folder, targetLocation, parameters));
        }
コード例 #5
0
        private IProjectFile GetOrCreateSameDestinationFile(
            [NotNull] IProjectModelTransactionCookie cookie,
            [NotNull] IT4File file,
            [NotNull] string destinationName
            )
        {
            Locks.AssertWriteAccessAllowed();
            var existingFile = GetSameDestinationFile(file, destinationName);

            if (existingFile != null)
            {
                return(existingFile);
            }
            return(CreateSameDestinationFile(cookie, file, destinationName));
        }
コード例 #6
0
        private IProjectFile GetSameDestinationFile([NotNull] IT4File file, [NotNull] string temporaryName)
        {
            Locks.AssertWriteAccessAllowed();
            var sourceFile = file.PhysicalPsiSourceFile.NotNull();
            var candidates = sourceFile
                             .ToProjectFile()
                             ?.ParentFolder
                             ?.GetSubItems(temporaryName)
                             .ToList()
                             .OfType <IProjectFile>()
                             .AsList();

            Assertion.AssertNotNull(candidates, "candidates != null");
            Assertion.Assert(candidates.Count <= 1, "candidates.Value.Length <= 1");
            return(candidates.SingleOrDefault());
        }