public TempFile( string?extraDirectoryPaths = null, bool deleteAfter = true, bool createFolder = true, string?suffix = null, IFileSystem?fileSystem = null) { _fileSystem = fileSystem ?? IFileSystemExt.DefaultFilesystem; var path = $"{Path.GetRandomFileName()}{suffix}"; if (extraDirectoryPaths != null) { path = Path.Combine(extraDirectoryPaths, path); } File = new FilePath(Path.Combine(Path.GetTempPath(), path)); DeleteAfter = deleteAfter; if (createFolder && File.Directory != null && !_fileSystem.Directory.Exists(File.Directory.Value)) { _fileSystem.Directory.CreateDirectory(File.Directory.Value); } }
private IFileSystem?TryGetMountOrNext(ref UPath path, out UPath mountPath) { mountPath = UPath.Null; if (path.IsNull) { return(null); } IFileSystem?mountfs = null; foreach (var kvp in _mounts) { var remainingPath = GetRemaining(kvp.Key, path); if (remainingPath.IsNull) { continue; } mountPath = kvp.Key; mountfs = kvp.Value; path = remainingPath; break; } if (mountfs != null) { return(mountfs); } mountPath = UPath.Null; return(Fallback); }
public void Delete(IFileSystem?fileSystem = null) { fileSystem = fileSystem.GetOrDefault(); if (fileSystem.File.Exists(Path)) { fileSystem.File.Delete(Path); } }
public TemplateRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger <TemplateRepository> logger, FileSystems fileSystems, IIOHelper ioHelper, IShortStringHelper shortStringHelper, IViewHelper viewHelper) : base(scopeAccessor, cache, logger) { _ioHelper = ioHelper; _shortStringHelper = shortStringHelper; _viewsFileSystem = fileSystems.MvcViewsFileSystem; _viewHelper = viewHelper; }
public static async Task <Nuker> CreateAsync(string workingDirectory, IFileSystem?fileSystem = null, IGitFileList?gitFileList = null, IConsole?console = null) { fileSystem ??= new FileSystem(); gitFileList ??= new GitFileList(workingDirectory); console ??= new DefaultConsole(); var gitFiles = await gitFileList.GetAsync(); return(new Nuker(workingDirectory, fileSystem, gitFiles, console)); }
public StylesheetsTreeController( ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, FileSystems fileSystems, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, eventAggregator) { FileSystem = fileSystems.StylesheetsFileSystem; }
public IEnumerable <DirectoryPath> EnumerateDirectories( bool includeSelf, bool recursive, IFileSystem?fileSystem = null) { return(fileSystem.GetOrDefault().Directory.EnumerateDirectoryPaths( Path, includeSelf: includeSelf, recursive: recursive)); }
public IEnumerable <FilePath> EnumerateFiles( bool recursive = false, string?searchPattern = null, IFileSystem?fileSystem = null) { return(fileSystem.GetOrDefault().Directory.EnumerateFilePaths( Path, searchPattern: searchPattern, recursive: recursive)); }
public PartialViewMacrosTreeController( ILocalizedTextService localizedTextService, UmbracoApiControllerTypeCollection umbracoApiControllerTypeCollection, IMenuItemCollectionFactory menuItemCollectionFactory, FileSystems fileSystems, IEventAggregator eventAggregator) : base(localizedTextService, umbracoApiControllerTypeCollection, menuItemCollectionFactory, fileSystems, eventAggregator) { FileSystem = fileSystems.MacroPartialsFileSystem; }
private static MainModel CreateDefaultSettingModel(IFileSystem?fileSystem = null) { fileSystem ??= CreateMockFileSystem(); var model = new MainModel(fileSystem, Scheduler.Immediate); model.Initialize(); model.Setting.SearchFilePaths = new[] { targetDirPath }; return(model); }
public ModDirectoryFinder( ISettings settings, ILogger <ModDirectoryFinder> logger, IFileSystem?fileSystem = null) { _serverPath = settings.ServerDirectory !; _modsPath = settings.ModsDirectory !; _fileSystem = fileSystem ?? new FileSystem(); _logger = logger; }
/// <summary> /// Class prepares server configuration for given modset /// </summary> /// <param name="settings">Server Settings Object</param> /// TODO: Make factory, just as for ModsetConfig #pragma warning disable CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable. public ServerConfig( ISettings settings, ILogger <ServerConfig> logger, IFileSystem?fileSystem = null) #pragma warning restore CS8618 // Non-nullable field is uninitialized. Consider declaring as nullable. { _settings = settings; _logger = logger; _fileSystem = fileSystem ?? new FileSystem(); SetProperties(); }
public void DeleteEntireFolder( bool disableReadOnly = true, bool deleteFolderItself = true, IFileSystem?fileSystem = null) { fileSystem.GetOrDefault().Directory .DeleteEntireFolder( Path, disableReadOnly: disableReadOnly, deleteFolderItself: deleteFolderItself); }
public static TempFolder Factory( bool deleteAfter = true, bool throwIfUnsuccessfulDisposal = true, IFileSystem?fileSystem = null) { return(new TempFolder( new DirectoryPath(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName())), deleteAfter: deleteAfter, throwIfUnsuccessfulDisposal: throwIfUnsuccessfulDisposal, fileSystem: fileSystem)); }
public Settings( IConfigurationRoot?config = null, IFileSystem?fileSystem = null, IRegistryReader?registryReader = null) { _fileSystem = fileSystem ?? new FileSystem(); _config = config ?? LoadConfigFile(); _registryReader = registryReader ?? new RegistryReader(); LoadSettings(); }
public SqlServerBulkInserter( string connectionString, string dbName, Action <long> rowsCopied, IFileSystem?fileSystem = null) { _connectionString = connectionString; _dbName = dbName; _rowsCopied = rowsCopied; _fileSystem = fileSystem ?? new FileSystem(); }
public CsvFileRepositoryTests() { var mockInputFile = new MockFileData($"name,address_line1,address_line2{Environment.NewLine}Dave,Street,Town"); var mockFileSystem = new MockFileSystem(); mockFileSystem.AddFile("test.txt", mockInputFile); _mockFileSystem = mockFileSystem ?? throw new ArgumentNullException(nameof(mockFileSystem)); }
public StandardDbInitializer( IDbProvider?dbProvider, IRocksDbFactory?rocksDbFactory, IMemDbFactory?memDbFactory, IFileSystem?fileSystem = null, bool fullPruning = false) : base(dbProvider, rocksDbFactory, memDbFactory) { _fileSystem = fileSystem ?? new FileSystem(); _fullPruning = fullPruning; }
public GitFileList(string workingDirectory, IFileSystem?fileSystem = null, Func <Task <HashSet <string> > >?listFiles = null) { _workingDirectory = workingDirectory; _fileSystem = fileSystem ?? new FileSystem(); _listFiles = listFiles ?? ListFileAsync; var isCaseSensitiveFileSystem = _fileSystem.IsCaseSensitive(workingDirectory); _stringComparison = isCaseSensitiveFileSystem ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; _stringComparer = isCaseSensitiveFileSystem ? StringComparer.CurrentCulture : StringComparer.CurrentCultureIgnoreCase; }
private string?GetFileContent(IFileSystem?fs, string filename) { if (fs is null) { return(null); } using Stream stream = fs.OpenFile(filename); using var reader = new StreamReader(stream, Encoding.UTF8, true); return(reader.ReadToEnd()); }
/// <summary> /// Constructor that opens a read stream to a path /// </summary> /// <param name="path">Path to read from</param> /// <param name="metaData">Bundle of all related metadata for parsing</param> /// <param name="bufferSize">Size of internal buffer</param> /// <param name="offsetReference">Optional offset reference position to use</param> /// <param name="fileSystem">FileSystem to read from</param> public MutagenBinaryReadStream( FilePath path, ParsingBundle metaData, int bufferSize = 4096, long offsetReference = 0, IFileSystem?fileSystem = null) : base(fileSystem.GetOrDefault().File.OpenRead(path.Path), bufferSize) { this._path = path; this.MetaData = metaData; this.OffsetReference = offsetReference; }
public static TempFolder FactoryByPath( string path, bool deleteAfter = true, bool throwIfUnsuccessfulDisposal = true, IFileSystem?fileSystem = null) { return(new TempFolder( new DirectoryPath(path), deleteAfter: deleteAfter, throwIfUnsuccessfulDisposal: throwIfUnsuccessfulDisposal, fileSystem: fileSystem)); }
public static TempFolder FactoryByAddedPath( string addedFolderPath, bool deleteAfter = true, bool throwIfUnsuccessfulDisposal = true, IFileSystem?fileSystem = null) { return(new TempFolder( new DirectoryPath(Path.Combine(Path.GetTempPath(), addedFolderPath)), deleteAfter: deleteAfter, throwIfUnsuccessfulDisposal: throwIfUnsuccessfulDisposal, fileSystem: fileSystem)); }
private static App Start(string[]?args, IFileSystem?fileSystem = null) { var logger = new LoggerConfiguration() .WriteTo.Console(outputTemplate: "{Message:lj}{NewLine}{Exception}") .CreateLogger(); var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(value: 1)); var app = new App(args ?? Array.Empty <string>(), logger, fileSystem ?? new PhysicalFileSystem(), cancellationTokenSource); return(app); }
protected TempFolder( DirectoryPath dir, bool deleteAfter = true, bool throwIfUnsuccessfulDisposal = true, IFileSystem?fileSystem = null) { Dir = dir; _fileSystem = fileSystem ?? IFileSystemExt.DefaultFilesystem; DeleteAfter = deleteAfter; ThrowIfUnsuccessfulDisposal = throwIfUnsuccessfulDisposal; _fileSystem.Directory.CreateDirectory(Dir); }
/// <inheritdoc cref="IPluginListingsProvider"/> public static IEnumerable <IModListingGetter> ListingsFromPath( FilePath pluginTextPath, GameRelease game, DirectoryPath dataPath, bool throwOnMissingMods = true, IFileSystem?fileSystem = null) { return(PluginListingsProvider( new DataDirectoryInjection(dataPath), new GameReleaseInjection(game), new PluginListingsPathInjection(pluginTextPath), throwOnMissingMods, fileSystem ?? IFileSystemExt.DefaultFilesystem).Get()); }
public static IEnumerable <IModListingGetter> ListingsFromPath( FilePath cccFilePath, DirectoryPath dataPath, IFileSystem?fileSystem = null) { fileSystem ??= IFileSystemExt.DefaultFilesystem; var dataDirectoryInjection = new DataDirectoryInjection(dataPath); return(new CreationClubListingsProvider( fileSystem, dataDirectoryInjection, new CreationClubListingsPathInjection(cccFilePath), new CreationClubRawListingsReader()).Get()); }
private static BicepCliProxy CreateBicepCliProxy( IEnvironmentProxy?environmentProxy = null, IProcessProxy?processProxy = null, IFileSystem?fileSystem = null, ILogger?logger = null, IConsole?console = null) { environmentProxy ??= new MockEnvironmentProxy(); processProxy ??= StrictMock.Of <IProcessProxy>().Object; fileSystem ??= new MockFileSystem(); logger ??= MockLoggerFactory.CreateLogger(); console ??= new MockConsole(); return(new(environmentProxy, processProxy, fileSystem, logger, console)); }
/// <summary> /// Constructor that opens a read stream to a path /// </summary> /// <param name="path">Path to read from</param> /// <param name="release">Game Release the stream is for</param> /// <param name="bufferSize">Size of internal buffer</param> /// <param name="offsetReference">Optional offset reference position to use</param> /// <param name="fileSystem">FileSystem to read from</param> public MutagenBinaryReadStream( ModPath path, GameRelease release, int bufferSize = 4096, long offsetReference = 0, IFileSystem?fileSystem = null) : base(fileSystem.GetOrDefault().File.OpenRead(path), bufferSize) { this._path = path; this.MetaData = new ParsingBundle(release, MasterReferenceReader.FromPath(path, release, fileSystem: fileSystem)) { ModKey = path.ModKey }; this.OffsetReference = offsetReference; }
public bool CheckEmpty(IFileSystem?fileSystem = null) { if (!CheckExists(fileSystem)) { fileSystem = fileSystem.GetOrDefault(); if (fileSystem.File.Exists(Path)) { throw new IOException($"Tried to check if directory was empty on a file path: {Path}"); } return(true); } fileSystem = fileSystem.GetOrDefault(); return(!fileSystem.Directory.EnumerateFiles(Path).Any() && !fileSystem.Directory.EnumerateDirectories(Path).Any()); }