Esempio n. 1
0
    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);
        }
    }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 public void Delete(IFileSystem?fileSystem = null)
 {
     fileSystem = fileSystem.GetOrDefault();
     if (fileSystem.File.Exists(Path))
     {
         fileSystem.File.Delete(Path);
     }
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
        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;
 }
Esempio n. 7
0
 public IEnumerable <DirectoryPath> EnumerateDirectories(
     bool includeSelf,
     bool recursive,
     IFileSystem?fileSystem = null)
 {
     return(fileSystem.GetOrDefault().Directory.EnumerateDirectoryPaths(
                Path,
                includeSelf: includeSelf,
                recursive: recursive));
 }
Esempio n. 8
0
 public IEnumerable <FilePath> EnumerateFiles(
     bool recursive         = false,
     string?searchPattern   = null,
     IFileSystem?fileSystem = null)
 {
     return(fileSystem.GetOrDefault().Directory.EnumerateFilePaths(
                Path,
                searchPattern: searchPattern,
                recursive: recursive));
 }
Esempio n. 9
0
 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;
 }
Esempio n. 12
0
        /// <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();
        }
Esempio n. 13
0
 public void DeleteEntireFolder(
     bool disableReadOnly    = true,
     bool deleteFolderItself = true,
     IFileSystem?fileSystem  = null)
 {
     fileSystem.GetOrDefault().Directory
     .DeleteEntireFolder(
         Path,
         disableReadOnly: disableReadOnly,
         deleteFolderItself: deleteFolderItself);
 }
Esempio n. 14
0
 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));
 }
Esempio n. 15
0
        public Settings(
            IConfigurationRoot?config      = null,
            IFileSystem?fileSystem         = null,
            IRegistryReader?registryReader = null)
        {
            _fileSystem     = fileSystem ?? new FileSystem();
            _config         = config ?? LoadConfigFile();
            _registryReader = registryReader ?? new RegistryReader();

            LoadSettings();
        }
Esempio n. 16
0
 public SqlServerBulkInserter(
     string connectionString,
     string dbName,
     Action <long> rowsCopied,
     IFileSystem?fileSystem = null)
 {
     _connectionString = connectionString;
     _dbName           = dbName;
     _rowsCopied       = rowsCopied;
     _fileSystem       = fileSystem ?? new FileSystem();
 }
Esempio n. 17
0
        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));
        }
Esempio n. 18
0
 public StandardDbInitializer(
     IDbProvider?dbProvider,
     IRocksDbFactory?rocksDbFactory,
     IMemDbFactory?memDbFactory,
     IFileSystem?fileSystem = null,
     bool fullPruning       = false)
     : base(dbProvider, rocksDbFactory, memDbFactory)
 {
     _fileSystem  = fileSystem ?? new FileSystem();
     _fullPruning = fullPruning;
 }
Esempio n. 19
0
        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;
        }
Esempio n. 20
0
    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());
    }
Esempio n. 21
0
 /// <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;
 }
Esempio n. 22
0
 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));
 }
Esempio n. 23
0
 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));
 }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
    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);
    }
Esempio n. 26
0
 /// <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());
        }
Esempio n. 28
0
        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));
        }
Esempio n. 29
0
 /// <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;
 }
Esempio n. 30
0
 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());
 }