private FileSystemPath TryFindTemporaryTargetFile([NotNull] IT4File file) { string name = file.GetSourceFile().NotNull().Name.WithOtherExtension(".*"); var candidates = GetTemporaryTargetFileFolder(file).GetChildFiles(name); return(candidates.FirstOrDefault()); }
private FileSystemPath GetDestinationLocation([NotNull] IT4File file, [NotNull] string temporaryName) { Locks.AssertReadAccessAllowed(); var sourceFile = file.GetSourceFile().NotNull(); return(sourceFile.ToProjectFile().NotNull().Location.Parent.Combine(temporaryName)); }
public void SavePreprocessResults(IT4File file, string text) { Locks.AssertReadAccessAllowed(); var sourceFile = file.GetSourceFile().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); }
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.GetSourceFile().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); }
private string GetPreprocessingTargetFileName([NotNull] IT4File file) { Locks.AssertReadAccessAllowed(); var sourceFile = file.GetSourceFile().NotNull(); string name = sourceFile.Name; return(name.WithOtherExtension("cs")); }
private string GetExpectedTargetFileName([NotNull] IT4File file) { Locks.AssertReadAccessAllowed(); var sourceFile = file.GetSourceFile().NotNull(); string name = sourceFile.Name; string targetExtension = file.GetTargetExtension(); return(name.WithOtherExtension(targetExtension)); }
public static string GetEncoding([NotNull] IT4File file) { var sourceFile = file.GetSourceFile(); if (sourceFile == null) { return(Encoding.UTF8.CodePage.ToString()); } return(sourceFile.Document.Encoding.CodePage.ToString()); }
private void Execute([NotNull] IT4File file, [NotNull] ISolution solution) { Statistics.TrackAction(T4StatisticIdBundle.RunSilently); var manager = solution.GetComponent <IT4TemplateExecutionManager>(); if (manager.IsExecutionRunning(file.GetSourceFile().NotNull())) { return; } manager.ExecuteSilently(file); }
private IProjectFile CreateSameDestinationFile( [NotNull] IProjectModelTransactionCookie cookie, [NotNull] IT4File file, [NotNull] string destinationName ) { Locks.AssertWriteAccessAllowed(); var projectFile = file.GetSourceFile().ToProjectFile().NotNull(); var folder = projectFile.ParentFolder.NotNull(); var targetLocation = folder.Location.Combine(destinationName); var parameters = T4MSBuildProjectUtil.CreateTemplateMetadata(projectFile); return(cookie.AddFile(folder, targetLocation, parameters)); }
public FileSystemPath GetTemporaryExecutableLocation(IT4File file) { var projectFile = file.GetSourceFile().ToProjectFile(); var project = projectFile?.GetProject(); if (project == null) { return(FileSystemPath.Empty); } var relativePath = projectFile.Location.MakeRelativeTo(project.Location.Parent); var ttLocation = project.GetIntermediateDirectory(project.GetCurrentTargetFrameworkId()) .Combine("TextTemplating") .Combine(relativePath); return(ttLocation.Parent.Combine(ttLocation.Name.WithoutExtension()).Combine("GeneratedTransformation.exe")); }
private IProjectFile GetSameDestinationFile([NotNull] IT4File file, [NotNull] string temporaryName) { Locks.AssertWriteAccessAllowed(); var sourceFile = file.GetSourceFile().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()); }
private string GetNamespace() { IPsiSourceFile sourceFile = _file.GetSourceFile(); IProjectFile projectFile = sourceFile?.ToProjectFile(); if (projectFile == null || !projectFile.IsPreprocessedT4Template()) { return(null); } string ns = projectFile.GetCustomToolNamespace(); if (!String.IsNullOrEmpty(ns)) { return(ns); } return(sourceFile.Properties.GetDefaultNamespace()); }
private void RemoveLastGenOutputIfDifferent( [NotNull] IT4File file, [NotNull] IProjectModelTransactionCookie cookie, [NotNull] FileSystemPath destinationLocation ) { var projectFile = file.GetSourceFile()?.ToProjectFile(); if (projectFile == null) { return; } foreach (var suspect in TemplateMetadataManager .FindLastGenOutput(projectFile) .Where(it => it.Location != destinationLocation) ) { cookie.Remove(suspect); } }
private void CreateOrUpdateData([NotNull] IT4File t4File) { IPsiSourceFile sourceFile = t4File.GetSourceFile(); if (sourceFile == null || !sourceFile.LanguageType.Is <T4ProjectFileType>()) { return; } var newData = new T4FileData(t4File, _directiveInfoManager); T4FileData existingData; lock (_fileDataBySourceFile) { _fileDataBySourceFile.TryGetValue(sourceFile, out existingData); _fileDataBySourceFile[sourceFile] = newData; } T4FileDataDiff diff = newData.DiffWith(existingData); if (diff != null) { _fileDataChanged.Fire(Pair.Of(sourceFile, diff)); } }
protected string GetNamespace() => File.GetSourceFile()?.Properties.GetDefaultNamespace();