public InMemoryFileSystem(string root, IPhysicalFileSystem basis) { _basis = basis; _root = new FileSystemDirectory(Path.GetFileName(root.TrimEnd('/', '\\')), root); IsPathInCone(root, out root); _root = new FileSystemDirectory(Path.GetFileName(root.TrimEnd('/', '\\')), root); }
public StaticFilesTreeController(ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IEventAggregator eventAggregator, IPhysicalFileSystem fileSystem) : base(localizedTextService, umbracoApiControllerTypeCollection, eventAggregator) { _fileSystem = fileSystem; }
public TemplateProcessor(string rootPath) { _rootPath = rootPath; _fileSystem = new PhysicalFileSystem(); _projectTemplate = InitProjectTemplateFromJsonConfig(); ProcessTemplate(); }
public FilesTreeController( ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, IPhysicalFileSystem fileSystem, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator) =>
public FileSystemDirectory(IMountPoint mountPoint, string fullPath, string name, string physicalPath) : base(mountPoint, EnsureTrailingSlash(fullPath), name) { _physicalPath = physicalPath; _paths = new SettingsFilePaths(mountPoint.EnvironmentSettings); _fileSystem = mountPoint.EnvironmentSettings.Host.FileSystem; }
internal static JObject ReadObject(this IPhysicalFileSystem fileSystem, string path) { using (var fileStream = fileSystem.OpenRead(path)) using (var textReader = new StreamReader(fileStream, System.Text.Encoding.UTF8, true)) using (var jsonReader = new JsonTextReader(textReader)) { return(JObject.Load(jsonReader)); } }
internal static void WriteObject(this IPhysicalFileSystem fileSystem, string path, object obj) { using (var fileStream = fileSystem.CreateFile(path)) using (var textWriter = new StreamWriter(fileStream, System.Text.Encoding.UTF8)) using (var jsonWriter = new JsonTextWriter(textWriter)) { var serializer = new JsonSerializer(); serializer.Serialize(jsonWriter, obj); } }
private static bool CheckDirectoryDoesNotExist(IPhysicalFileSystem fs, JObject config, string outputPath) { string path = Path.Combine(outputPath, config["path"].ToString()); if (!fs.DirectoryExists(path)) { return true; } Console.Error.WriteLine($"Expected a directory {path} to not exist but it did"); return false; }
internal IReadOnlyList <string> FindProjFileAtOrAbovePath(IPhysicalFileSystem fileSystem, string startPath, HashSet <string> extensionLimiters) { if (extensionLimiters.Count == 0) { return(FileFindHelpers.FindFilesAtOrAbovePath(fileSystem, startPath, "*.*proj")); } else { return(FileFindHelpers.FindFilesAtOrAbovePath(fileSystem, startPath, "*.*proj", (filename) => extensionLimiters.Contains(Path.GetExtension(filename)))); } }
private static bool CheckFileExists(IPhysicalFileSystem fs, JObject config, string outputPath) { string path = Path.Combine(outputPath, config["path"].ToString()); if(fs.FileExists(path)) { return true; } Console.Error.WriteLine($"Expected a file {path} to exist but it did not"); return false; }
private static bool CheckFileDoesNotContain(IPhysicalFileSystem fs, JObject config, string outputPath) { string path = Path.Combine(outputPath, config["path"].ToString()); string text = fs.ReadAllText(path); if (!text.Contains(config["text"].ToString())) { return true; } Console.Error.WriteLine($"Expected {path} to not contain {config["text"].ToString()} but it did"); return false; }
internal IReadOnlyList <string> FindProjFileAtOrAbovePath(IPhysicalFileSystem fileSystem, string startPath, HashSet <string> extensionLimiters) { string directory; if (fileSystem.DirectoryExists(startPath)) { directory = startPath; } else { directory = Path.GetDirectoryName(startPath); } do { List <string> filesInDir = fileSystem.EnumerateFileSystemEntries(directory, "*.*proj", SearchOption.TopDirectoryOnly).ToList(); List <string> matches = new List <string>(); if (extensionLimiters.Count == 0) { matches = filesInDir; } else { foreach (string filename in filesInDir) { string extension = Path.GetExtension(filename); if (extensionLimiters.Contains(extension)) { matches.Add(filename); } } } if (matches.Count > 0) { return(matches); } if (Path.GetPathRoot(directory) != directory) { directory = Directory.GetParent(directory).FullName; } else { directory = null; } } while (directory != null); return(new List <string>()); }
// Attempt to get the search metadata file from cloud storage and place it in the expected search location. // Return true on success, false on failure. // Implement If-None-Match/ETag headers to avoid re-downloading the same content over and over again. private async Task <bool> TryAcquireFileFromCloudAsync(IEngineEnvironmentSettings environmentSettings, Paths paths, string searchMetadataFileLocation) { try { using (HttpClient client = new HttpClient()) { string etagFileLocation = searchMetadataFileLocation + ETagFileSuffix; if (paths.FileExists(etagFileLocation)) { string etagValue = paths.ReadAllText(etagFileLocation); client.DefaultRequestHeaders.Add(IfNoneMatchHeaderName, $"\"{etagValue}\""); } using (HttpResponseMessage response = client.GetAsync(_searchMetadataUri).Result) { if (response.IsSuccessStatusCode) { string resultText = await response.Content.ReadAsStringAsync(); paths.WriteAllText(searchMetadataFileLocation, resultText); IEnumerable <string> etagValues; if (response.Headers.TryGetValues(ETagHeaderName, out etagValues)) { if (etagValues.Count() == 1) { paths.WriteAllText(etagFileLocation, etagValues.First()); } } return(true); } else if (response.StatusCode == HttpStatusCode.NotModified) { IPhysicalFileSystem fileSystem = environmentSettings.Host.FileSystem; if (fileSystem is IFileLastWriteTimeSource lastWriteTimeSource) { lastWriteTimeSource.SetLastWriteTimeUtc(searchMetadataFileLocation, DateTime.UtcNow); } return(true); } return(false); } } } catch { return(false); } }
private static string CreateTargetDir(IPhysicalFileSystem fileSystem, string sourceRel, string targetDir, IGlobalRunSpec spec) { if (!spec.TryGetTargetRelPath(sourceRel, out string targetRel)) { targetRel = sourceRel; } string targetPath = Path.Combine(targetDir, targetRel); string fullTargetDir = Path.GetDirectoryName(targetPath); fileSystem.CreateDirectory(fullTargetDir); return(targetPath); }
private static bool CheckFileContains(IPhysicalFileSystem fs, JObject config, string outputPath) { string path = Path.Combine(outputPath, config["path"].ToString()); string text = fs.ReadAllText(path); if (text.Contains(config["text"].ToString())) { return(true); } Console.Error.WriteLine($"Expected {path} to contain {config["text"].ToString()} but it did not"); Console.Error.WriteLine($"Actual content = {text}"); return(false); }
private static string ResolveExecutableFilePath(IPhysicalFileSystem fileSystem, string executableFileName, string outputBasePath) { if (!string.IsNullOrEmpty(outputBasePath) && fileSystem.DirectoryExists(outputBasePath)) { string executableCombinedFileName = Path.Combine(Path.GetFullPath(outputBasePath), executableFileName); if (fileSystem.FileExists(executableCombinedFileName)) { return(executableCombinedFileName); } } // The executable has not been found in the template folder, thus do not use the full path to the file. // The executable will be further searched in the directories from the PATH environment variable. return(executableFileName); }
private static bool RunVerifications(JArray verifications, IPhysicalFileSystem fs, string outputPath) { bool success = true; foreach(JObject verification in verifications) { string kind = verification["kind"].ToString(); if (!VerificationLookup.TryGetValue(kind, out Func<IPhysicalFileSystem, JObject, string, bool> func)) { Console.Error.WriteLine($"Unable to find a verification handler for {kind}"); return false; } success &= func(fs, verification, outputPath); } return success; }
// Walks up the directory path looking for files that match the matchPattern and the secondary filter (if provided) // Returns all the matching files in the first directory that has any matched files. public static IReadOnlyList <string> FindFilesAtOrAbovePath(IPhysicalFileSystem fileSystem, string startPath, string matchPattern, Func <string, bool> secondaryFilter = null) { string directory; if (fileSystem.DirectoryExists(startPath)) { directory = startPath; } else { directory = Path.GetDirectoryName(startPath); } do { List <string> filesInDir = fileSystem.EnumerateFileSystemEntries(directory, matchPattern, SearchOption.TopDirectoryOnly).ToList(); List <string> matches = new List <string>(); if (secondaryFilter == null) { matches = filesInDir; } else { matches = filesInDir.Where(x => secondaryFilter(x)).ToList(); } if (matches.Count > 0) { return(matches); } if (Path.GetPathRoot(directory) != directory) { directory = Directory.GetParent(directory).FullName; } else { directory = null; } } while (directory != null); return(new List <string>()); }
private bool ShouldDownloadFileFromCloud(IEngineEnvironmentSettings environmentSettings, string metadataFileTargetLocation) { IPhysicalFileSystem fileSystem = environmentSettings.Host.FileSystem; if (fileSystem is IFileLastWriteTimeSource lastWriteTimeSource) { if (fileSystem.FileExists(metadataFileTargetLocation)) { DateTime utcNow = DateTime.UtcNow; DateTime lastWriteTimeUtc = lastWriteTimeSource.GetLastWriteTimeUtc(metadataFileTargetLocation); if (lastWriteTimeUtc.AddHours(CachedFileValidityInHours) > utcNow) { return(false); } } } return(true); }
private static bool CheckFileContains(IPhysicalFileSystem fs, JObject config, string outputPath) { string path = Path.Combine(outputPath, config["path"].ToString()); string text = fs.ReadAllText(path); string expectedText = config["text"].ToString(); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { expectedText = expectedText.Replace("\r\n", "\n"); } if (text.Contains(expectedText)) { return(true); } Console.Error.WriteLine($"Expected {path} to contain {expectedText} but it did not"); Console.Error.WriteLine($"Actual content = {text}"); return(false); }
internal static IReadOnlyList <string> FindSolutionFilesAtOrAbovePath(IPhysicalFileSystem fileSystem, string outputBasePath) { return(FileFindHelpers.FindFilesAtOrAbovePath(fileSystem, outputBasePath, "*.sln")); }
public MonitoredFileSystem(IPhysicalFileSystem baseFileSystem) { _baseFileSystem = baseFileSystem; }
public Orchestrator(ILogger logger, IPhysicalFileSystem fileSystem) { _logger = logger; _fileSystem = fileSystem; }