Пример #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);
        }
        public void UpdateTemplateKind(IT4File file)
        {
            Logger.Verbose("Updating template kind");
            var projectFile = file.PhysicalPsiSourceFile.ToProjectFile().NotNull();

            Solution.InvokeUnderTransaction(cookie =>
                                            TemplateMetadataManager.UpdateTemplateMetadata(cookie, projectFile, T4TemplateKind.Executable));
            // Apply the changes, just in case the template kind was different
            Solution.GetPsiServices().Files.CommitAllDocuments();
        }
Пример #4
0
        private void RemoveLastGenOutputIfDifferent(
            [NotNull] IT4File file,
            [NotNull] IProjectModelTransactionCookie cookie,
            [NotNull] FileSystemPath destinationLocation
            )
        {
            var projectFile = file.PhysicalPsiSourceFile?.ToProjectFile();

            if (projectFile == null)
            {
                return;
            }
            foreach (var suspect in TemplateMetadataManager
                     .FindLastGenOutput(projectFile)
                     .Where(it => it.Location != destinationLocation)
                     )
            {
                cookie.Remove(suspect);
            }
        }