private FileChangedEventArgs Remap(FileSystemEventArgs args) { var newChangeType = args.ChangeType; var newPath = _fileSystem.ConvertPathFromInternal(args.FullPath); return(new FileChangedEventArgs(FileSystem, newChangeType, newPath)); }
public static Zio.IFileSystem Getfs(string path) { #pragma warning disable CA2000 // Dispose objects before losing scope var fs = new PhysicalFileSystem(); #pragma warning restore CA2000 // Dispose objects before losing scope fs.CreateDirectory(fs.ConvertPathFromInternal(path)); return(new SubFileSystem(fs, fs.ConvertPathFromInternal(path), true)); }
public async Task CopyFile_Test() { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var temp2 = Path.GetTempFileName(); await System.IO.File.WriteAllBytesAsync(temp2, Data); // Execute the results. await foreach (var res in EmitCopyResult(temp2, dir)) { Assert.Equal(await res.Description, $"Copied {new FileInfo(temp2).FullName} to directory {dir.Name}"); Assert.Equal(await res.Description, $"Copied {new FileInfo(temp2).FullName} to directory {dir.Name}"); } Assert.True(dir.ContainsFile(Path.GetFileName(temp2))); using (var stream = dir.OpenFile(Path.GetFileName(temp2)).OpenStream()) { Assert.Equal(Data.Length, stream.Length); } dir.OpenFile(Path.GetFileName(temp2)).Delete(); Assert.False(dir.ContainsFile(Path.GetFileName(temp2))); }
public void LinkRename_Test() { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var tempFile = Path.GetTempFileName(); var tempFile2 = Path.GetTempFileName(); using (var str = new FileInfo(tempFile).OpenWrite()) { str.WriteByte(255); } var link = dir.LinkFrom(new FileInfo(tempFile)); Guid oldGuid = link.FileGuid; Assert.True(dir.ContainsFile(".manifest")); link.Rename(tempFile2); Assert.Equal(Path.GetFileName(tempFile2), link.Name); Assert.Equal(link.FileGuid, dir.OpenFile(tempFile2).FileGuid); Assert.True(new FileInfo(tempFile).Exists); }
public void LinkOverwritesCreatedFile_Test() { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var tempFile = Path.GetTempFileName(); using (var str = new FileInfo(tempFile).OpenWrite()) { str.WriteByte(255); } var file = dir.OpenFile(tempFile); using (var f = file.OpenStream()) { f.WriteByte(254); } Assert.Throws <IOException>(() => dir.LinkFrom(new FileInfo(tempFile))); var link = dir.LinkFrom(new FileInfo(tempFile), true); Assert.IsAssignableFrom <Link>(link); using (var str = link.OpenReadStream()) { Assert.Equal(255, str.ReadByte()); } Assert.Equal(file.FileGuid, link.FileGuid); }
private static void CreateAndSharePC() { var my = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var dic = Path.Combine(my, "TestConsoleApp", "webapps"); var t1 = new SimpleConfigStorage( Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TestConsoleApp", Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture))); var fs = new PhysicalFileSystem(); var subfs = new SubFileSystem(fs, fs.ConvertPathFromInternal(t1.RootPath), true); pcservice = new PCLocalService(t1, loggerFactory, subfs, dic); Directory.CreateDirectory(dic); pcservice.InstallApps().Wait(); pcservice.StartService(); pc = pcservice.CreatePersonalCloud("test", "test1"); var ret = pcservice.SharePersonalCloud(pc); Console.WriteLine($"Share code is {ret}"); }
public void InputTemplateToAbstractConfigurationNodeCfgSerializer_Test() { var mapcol = new ControllerElementMappingProfile("Keyboard", "TEST_CONTROLLER", InputDriver.Keyboard, IDeviceEnumerator.VirtualVendorID, new XInputDeviceInstance(0).DefaultLayout); IDeviceInputMapping mapping = new TestInputMapping(); var input = new InputConfiguration <IRetroArchInput>(mapcol); var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var context = new ConfigurationTraversalContext(); var list = context.TraverseInputTemplate(input, mapping, 0); var cfgSerializer = new SimpleCfgConfigurationSerializer(); string outputCfg = cfgSerializer.Visit(list); Assert.NotEqual(string.Empty, outputCfg); // todo: test cfg parse }
public void DirectoryMoveFromManaged_Test() { var fs = new PhysicalFileSystem(); var fs2 = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var dir2 = new FS.Directory("test2", pfs, pfs.GetDirectoryEntry("/")); var tempFile = Path.GetTempFileName(); var file = dir.OpenFile(tempFile); Guid oldGuid = file.FileGuid; Assert.True(dir.ContainsFile(".manifest")); using (var str = file.OpenStream()) { str.WriteByte(255); }// safe the file var file2 = dir2.CopyFrom(file); Assert.Throws <IOException>(() => dir2.MoveFrom(file)); Assert.Equal(1, dir2.MoveFrom(file, true).Length); Assert.Equal(oldGuid, file2.FileGuid); Assert.Equal(1, file2.Length); Assert.False(file.Created); Assert.False(dir.ContainsFile(file.Name)); }
public void CollectionToAbstractConfigurationNodeXmlSerializer_Test() { var configuration = new ConfigurationCollection <ExampleConfigurationCollection>(new ConfigurationValueCollection()); var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); string test = Path.GetRandomFileName(); var dir = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/")); dir.OpenDirectory("program") .OpenFile("RMGE01.wbfs").OpenStream().Close(); configuration.Configuration.ExampleConfiguration.FullscreenResolution = FullscreenResolution.Resolution1152X648; var context = new ConfigurationTraversalContext(("game", dir)); var list = context.TraverseCollection(configuration); IAbstractConfigurationNode dolphinList = list["#dolphin"]; var xmlSerializer = new SimpleXmlConfigurationSerializer("Config"); string outputXml = xmlSerializer.Visit(dolphinList); XDocument doc = XDocument.Parse(outputXml); Assert.NotEmpty(doc.Nodes()); }
public async Task DirectoryCopyFromAsyncManaged_Test() { var fs = new PhysicalFileSystem(); var fs2 = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")); var dir2 = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")); var tempFile = Path.GetTempFileName(); var file = dir.OpenFile(tempFile); Assert.NotEqual(Guid.Empty, file.FileGuid); using (var str = file.OpenStream()) { str.WriteByte(255); }// safe the file var file2 = await dir2.CopyFromAsync(file); Assert.Equal(file.FileGuid, file2.FileGuid); Assert.True(file.Created); Assert.Equal(1, file2.Length); await Assert.ThrowsAsync <IOException>(async() => await dir2.CopyFromAsync(file)); Assert.Equal(1, (await dir2.CopyFromAsync(file, true)).Length); }
private static IFileSystem GetDefaultFileSystem() { var fs = new PhysicalFileSystem(); var subfs = new SubFileSystem(fs, fs.ConvertPathFromInternal(Environment.CurrentDirectory)); return(subfs); }
public void TestDirectory() { var fs = new PhysicalFileSystem(); var pathInfo = fs.ConvertPathFromInternal(SystemPath); var pathToCreate = pathInfo / "TestCreateDirectory"; var systemPathToCreate = fs.ConvertPathToInternal(pathToCreate); var movedDirectory = pathInfo / "TestCreateDirectoryMoved"; var systemMovedDirectory = fs.ConvertPathToInternal(movedDirectory); try { // CreateDirectory Assert.False(Directory.Exists(systemPathToCreate)); fs.CreateDirectory(pathToCreate); Assert.True(Directory.Exists(systemPathToCreate)); // DirectoryExists Assert.True(fs.DirectoryExists(pathToCreate)); Assert.False(fs.DirectoryExists(pathToCreate / "not_found")); // MoveDirectory fs.MoveDirectory(pathToCreate, movedDirectory); Assert.False(Directory.Exists(systemPathToCreate)); Assert.True(fs.DirectoryExists(movedDirectory)); // Delete the directory fs.DeleteDirectory(movedDirectory, false); Assert.False(Directory.Exists(systemMovedDirectory)); } finally { SafeDeleteDirectory(systemPathToCreate); SafeDeleteDirectory(systemMovedDirectory); } }
public void DirectoryMoveFromManagedAndRename_Test() { var fs = new PhysicalFileSystem(); var fs2 = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")); var dir2 = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")); var tempFile = Path.GetTempFileName(); var file = dir.OpenFile(tempFile); Guid oldGuid = file.FileGuid; using (var str = file.OpenStream()) { str.WriteByte(255); }// safe the file var newFile = dir2.MoveFrom(file, "newNonConflictingName", false); Assert.Throws <FileNotFoundException>(() => dir2.MoveFrom(file)); Assert.Equal(1, newFile.Length); Assert.False(file.Created); Assert.False(dir.ContainsFile(file.Name)); Assert.True(newFile.Created); Assert.Equal(newFile.FileGuid, file.FileGuid); Assert.Equal(newFile.FileGuid, dir2.OpenFile("newNonConflictingName").FileGuid); }
public void Setup() { TestRoot = Path.Combine(GetFolderPath(SpecialFolder.MyDocuments), "Personal Cloud"); Directory.CreateDirectory(TestRoot); TestRoot = Path.Combine(TestRoot, "Test Container"); if (Directory.Exists(TestRoot)) { Assert.Inconclusive("Previous test session may have failed. Please ensure \"" + Path.GetDirectoryName(TestRoot) + "\" is empty before starting a new session."); return; } Directory.CreateDirectory(TestRoot); #pragma warning disable CA2000 // Dispose objects before losing scope var fs = new PhysicalFileSystem(); #pragma warning restore CA2000 // Dispose objects before losing scope var subfs = new SubFileSystem(fs, fs.ConvertPathFromInternal(TestRoot), true); Server = new HttpProvider(10240, subfs); Server.Start(); Client = new TopFolderClient($"http://localhost:10240", new byte[32], ""); }
public static void SetupFS(string absolutePath) { if (string.IsNullOrWhiteSpace(absolutePath)) { RootPath = null; _CloudFileSystem = new MemoryFileSystem(); } else { RootPath = absolutePath; #pragma warning disable CA2000 // Dispose objects before losing scope var fs = new PhysicalFileSystem(); #pragma warning restore CA2000 // Dispose objects before losing scope Directory.CreateDirectory(absolutePath); _CloudFileSystem = new SubFileSystem(fs, fs.ConvertPathFromInternal(absolutePath), true); if (CloudService != null) { CloudService.FileSystem = CloudFileSystem; } } if (CloudService != null) { CloudService.BroadcastingIveChanged(); } }
public async Task CopyFileJobQueue_Test() { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var temp2 = Path.GetTempFileName(); await System.IO.File.WriteAllBytesAsync(temp2, Data); // Execute the results. var tq = new AsyncJobQueue <TaskResult <IFile> >(); var token = await tq.QueueJob(EmitCopyResult(temp2, dir)); for ((TaskResult <IFile> val, bool next) = await tq.GetNext(token); next; (val, next) = await tq.GetNext(token)) { } Assert.True(dir.ContainsFile(Path.GetFileName(temp2))); using (var stream = dir.OpenFile(Path.GetFileName(temp2)).OpenStream()) { Assert.Equal(Data.Length, stream.Length); } dir.OpenFile(Path.GetFileName(temp2)).Delete(); Assert.False(dir.ContainsFile(Path.GetFileName(temp2))); }
public void InputTemplateToAbstractConfigurationNodeXmlSerializer_Test() { var mapcol = new ControllerElementMappingProfile("Keyboard", "TEST_CONTROLLER", InputDriver.Keyboard, IDeviceEnumerator.VirtualVendorID, new XInputDeviceInstance(0).DefaultLayout); IDeviceInputMapping mapping = new TestInputMapping(); var input = new InputTemplate <IRetroArchInput>(mapcol).Template; var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var context = new ConfigurationTraversalContext(); var list = context.TraverseInputTemplate(input, mapping, 0); var xmlSerializer = new SimpleXmlConfigurationSerializer("Config"); string outputXml = xmlSerializer.Transform(list); XDocument doc = XDocument.Parse(outputXml); Assert.NotEmpty(doc.Nodes()); }
public void 建立資料夾() { using var fileSystem = new PhysicalFileSystem(); var executingAssembly = Assembly.GetExecutingAssembly(); var rootPath = Path.GetDirectoryName(executingAssembly.Location); var rootUPath = fileSystem.ConvertPathFromInternal(rootPath); var subName = "TestFolder"; var subPath = $"{rootUPath}/{subName}"; var subPath1 = $"{subPath}/1"; var subPath1_1 = $"{subPath}/1/1_1"; var subPath1_1_1 = $"{subPath}/1/1_1/1_1_1"; var subPath2 = $"{subPath}/2"; var content = "This is test string"; if (fileSystem.DirectoryExists(subPath1_1_1) == false) { fileSystem.CreateDirectory(subPath1_1_1); } if (fileSystem.DirectoryExists(subPath2) == false) { fileSystem.CreateDirectory(subPath2); } Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1)); Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1_1)); Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1_1_1)); Assert.AreEqual(true, fileSystem.DirectoryExists(subPath2)); fileSystem.DeleteDirectory(subPath, true); }
public void DirectoryCopyFromManaged_Test() { var fs = new PhysicalFileSystem(); var fs2 = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")); var dir2 = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/")); var tempFile = Path.GetTempFileName(); var file = dir.OpenFile(tempFile); using (var str = file.OpenStream()) { str.WriteByte(255); }// safe the file var file2 = dir2.CopyFrom(file); Assert.Equal(file.FileGuid, file2.FileGuid); Assert.Equal(1, file2.Length); Assert.Throws <IOException>(() => dir2.CopyFrom(file)); Assert.Equal(1, dir2.CopyFrom(file, true).Length); }
public void InputTemplateToAbstractConfigurationNodeXmlSerializer_Test() { var testmappings = new StoneProvider().Controllers["XBOX_CONTROLLER"]; var realmapping = JsonConvert.DeserializeObject <ControllerLayout>( TestUtilities.GetStringResource("InputMappings.xinput_device.json")); var mapcol = ControllerElementMappings.GetDefaultMappings(realmapping, testmappings); string _mapping = TestUtilities.GetStringResource("InputMappings.DirectInput.XINPUT_DEVICE.json"); IInputMapping mapping = JsonConvert.DeserializeObject <InputMapping>(_mapping); var input = new InputTemplate <IRetroArchInput>(mapcol).Template; var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); var context = new ConfigurationTraversalContext(); var list = context.TraverseInputTemplate(input, mapping, 0); var xmlSerializer = new SimpleXmlConfigurationSerializer("Config"); string outputXml = xmlSerializer.Transform(list); XDocument doc = XDocument.Parse(outputXml); Assert.NotEmpty(doc.Nodes()); }
/// <summary> /// Determine what kind of filesystem to use. /// After this point we *should theoretically* not need to use System.IO.Path. /// </summary> public static (IFileSystem, DirectoryEntry) DetermineFileSystem(string path, bool readOnly = false) { var emptyPath = string.IsNullOrWhiteSpace(path); var extension = Path.GetExtension(path); Log.Debug($"Determining file system for {path}"); IFileSystem fileSystem; DirectoryEntry baseEntry; if (emptyPath) { fileSystem = new PhysicalFileSystem(); baseEntry = fileSystem.GetDirectoryEntry( fileSystem.ConvertPathFromInternal(Directory.GetCurrentDirectory())); } else { // resolve path (relative to absolute) path = Path.GetFullPath(path); if (Directory.Exists(path) || extension == string.Empty) { var physicalFileSystem = new PhysicalFileSystem(); var internalPath = physicalFileSystem.ConvertPathFromInternal(path); physicalFileSystem.CreateDirectory(internalPath); fileSystem = new SubFileSystem(physicalFileSystem, internalPath); baseEntry = fileSystem.GetDirectoryEntry(UPath.Root); } else { // ensure parent directory exists on disk Directory.CreateDirectory(Path.GetDirectoryName(path)); switch (extension) { case "." + SqlitePattern: throw new PlatformNotSupportedException("See https://github.com/QutEcoacoustics/audio-analysis/issues/289"); /* * fileSystem = new SqliteFileSystem( * path, * readOnly ? OpenMode.ReadOnly : OpenMode.ReadWriteCreate); */ break; default: throw new NotSupportedException( $"Cannot determine file system for given extension {extension}"); } baseEntry = new DirectoryEntry(fileSystem, UPath.Root); } } Log.Debug($"Filesystem for {path} is {fileSystem.GetType().Name}"); return(fileSystem, baseEntry); }
public static SubFileSystem GetWorkFileSystem() { var fs = new PhysicalFileSystem(); var path = fs.ConvertPathFromInternal(AppDomain.CurrentDomain.BaseDirectory); var subfs = new SubFileSystem(fs, path); return(subfs); }
private static UPath CreateRootPath() { using var fileSystem = new PhysicalFileSystem(); var executingAssembly = Assembly.GetExecutingAssembly(); var rootPath = Path.GetDirectoryName(executingAssembly.Location); return(fileSystem.ConvertPathFromInternal(rootPath)); }
internal static IDirectory GetTemporaryDirectory(string tag) { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); return(new Filesystem.Directory($"snowflake-test-{tag}-{Guid.NewGuid()}", pfs, pfs.GetDirectoryEntry("/"))); }
public void CollectionToAbstractConfigurationNode_Test() { var configuration = new ConfigurationCollection <ExampleConfigurationCollection>(new ConfigurationValueCollection()); var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory("test", pfs, pfs.GetDirectoryEntry("/")); configuration.Configuration.ExampleConfiguration.FullscreenResolution = FullscreenResolution.Resolution1152X648; var context = new ConfigurationTraversalContext(("game", dir)); var list = context.TraverseCollection(configuration.Configuration); Assert.Equal(2, list.Count); Assert.Equal(2, list["#dolphin"].Value.Count); Assert.DoesNotContain("TestCycle1", list.Keys); Assert.DoesNotContain("TestCycle2", list.Keys); var dolphinList = list["#dolphin"]; foreach (var node in dolphinList.Value) { if (node.Key == "Display") { var confList = (node as ListConfigurationNode).Value; Assert.Equal(7, confList.Count); Assert.Equal("FullscreenResolution", confList[0].Key); Assert.IsType <EnumConfigurationNode>(confList[0]); Assert.Equal("1152x648", ((EnumConfigurationNode)confList[0]).Value); Assert.Equal(FullscreenResolution.Resolution1152X648, confList[0].Value); Assert.Equal("Fullscreen", confList[1].Key); Assert.IsType <BooleanConfigurationNode>(confList[1]); Assert.Equal("RenderToMain", confList[2].Key); Assert.IsType <BooleanConfigurationNode>(confList[2]); Assert.Equal("RenderWindowWidth", confList[3].Key); Assert.IsType <IntegralConfigurationNode>(confList[3]); Assert.Equal("RenderWindowHeight", confList[4].Key); Assert.IsType <IntegralConfigurationNode>(confList[4]); Assert.Equal("ISOPath0", confList[5].Key); Assert.IsType <StringConfigurationNode>(confList[5]); Assert.Equal("InternalCpuRatio", confList[6].Key); Assert.IsType <DecimalConfigurationNode>(confList[6]); } if (node.Key == "TestNestedSection") { Assert.Equal("TestNestedNestedSection", (node as ListConfigurationNode).Value[0].Key); } } }
public void Compose(IModule module, Loader.IServiceRepository serviceContainer) { var contentDirectory = serviceContainer.Get <IContentDirectoryProvider>(); string sqlitePath = Path.Combine(contentDirectory.ApplicationData.FullName, "library.db"); var optionsBuilder = new DbContextOptionsBuilder <DatabaseContext>(); optionsBuilder .UseSqlite($"Data Source={sqlitePath}"); using (var context = new DatabaseContext(optionsBuilder.Options)) { var connection = context.Database.GetDbConnection(); connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "PRAGMA journal_mode=WAL;"; command.ExecuteNonQuery(); } } // game library dependency tree var gameRecordLibrary = new GameRecordLibrary(optionsBuilder); var gameLibrary = new GameLibrary(gameRecordLibrary); var configStore = new ConfigurationCollectionStore(optionsBuilder); var fileLibrary = new FileRecordLibrary(optionsBuilder); var physicalFs = new PhysicalFileSystem(); var appDataPath = physicalFs.ConvertPathFromInternal(contentDirectory.ApplicationData.FullName); var gameFs = physicalFs.GetOrCreateSubFileSystem(appDataPath / "games"); // Add default extensions gameLibrary.AddExtension <IGameFileExtensionProvider, IGameFileExtension>(new GameFileExtensionProvider(fileLibrary, gameFs)); gameLibrary.AddExtension <IGameConfigurationExtensionProvider, IGameConfigurationExtension>(new GameConfigurationExtensionProvider(configStore)); // register game library. serviceContainer.Get <IServiceRegistrationProvider>() .RegisterService <IGameLibrary>(gameLibrary); var pluginLibrary = new PluginConfigurationStore(optionsBuilder); // plugin config store serviceContainer.Get <IServiceRegistrationProvider>() .RegisterService <IPluginConfigurationStore>(pluginLibrary); // controller elements var inputStore = new ControllerElementMappingsStore(optionsBuilder); serviceContainer.Get <IServiceRegistrationProvider>() .RegisterService <IControllerElementMappingsStore>(inputStore); }
public void 列舉根路徑內的子資料夾() { using var fileSystem = new PhysicalFileSystem(); var executingAssembly = Assembly.GetExecutingAssembly(); var rootPath = Path.GetDirectoryName(executingAssembly.Location); var rootUPath = fileSystem.ConvertPathFromInternal(rootPath); var rootUPath1 = fileSystem.ConvertPathToInternal(rootUPath); var subName = "TestFolder"; var subPath = $"{rootUPath}/{subName}"; var subPath1 = $"{subPath}/1"; var subFile1 = $"{subPath}/1/1.txt"; var subPath1_1 = $"{subPath}/1/1_1"; var subFile1_1 = $"{subPath}/1/1_1/1_1.txt"; var subPath1_1_1 = $"{subPath}/1/1_1/1_1_1"; var subPath2 = $"{subPath}/2"; var content = "This is test string"; var contentBytes = Encoding.UTF8.GetBytes(content); if (fileSystem.DirectoryExists(subPath1_1_1) == false) { fileSystem.CreateDirectory(subPath1_1_1); } if (fileSystem.DirectoryExists(subPath2) == false) { fileSystem.CreateDirectory(subPath2); } if (fileSystem.FileExists(subFile1) == false) { using var stream = fileSystem.OpenFile(subFile1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); stream.Write(contentBytes, 0, contentBytes.Length); } if (fileSystem.FileExists(subFile1_1) == false) { using var stream = fileSystem.OpenFile(subFile1_1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); stream.Write(contentBytes, 0, contentBytes.Length); } var directoryEntries = fileSystem.EnumerateDirectoryEntries(subPath); foreach (var entry in directoryEntries) { Console.WriteLine(entry.Path); } Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1)); Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1_1)); Assert.AreEqual(true, fileSystem.DirectoryExists(subPath1_1_1)); Assert.AreEqual(true, fileSystem.DirectoryExists(subPath2)); fileSystem.DeleteDirectory(subPath, true); }
public async Task ExtractZipJobQueue_Test() { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); string test = Path.GetRandomFileName(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); var dir = new FS.Directory(test, pfs, pfs.GetDirectoryEntry("/")); var dirToCopy = new DirectoryInfo(temp).CreateSubdirectory(Path.GetRandomFileName()); var subDirToCopy = dirToCopy.CreateSubdirectory(Path.GetRandomFileName()); string fileName; using (var file = System.IO.File.Create(Path.Combine(subDirToCopy.FullName, Path.GetRandomFileName()))) { fileName = Path.GetFileName(file.Name); await file.WriteAsync(Data, 0, Data.Length); } var subSubDirToCopy = subDirToCopy .CreateSubdirectory(Path.GetRandomFileName()); string zipFile = Path.GetTempFileName(); System.IO.File.Delete(zipFile); // hack to get around file existing. ZipFile.CreateFromDirectory(dirToCopy.FullName, zipFile, CompressionLevel.Fastest, true); var tq = new AsyncJobQueue <TaskResult <IFile> >(); var token = await tq.QueueJob(EmitZipResult(zipFile, dir)); await foreach (var res in tq.AsEnumerable(token)) { var val = await res; if (res.Error != null) { throw res.Error.InnerException; } } Assert.True(dir.ContainsDirectory(dirToCopy.Name), "Did not extract parent successfully"); Assert.True(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not copy file successfully"); using (var file = dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).OpenFile(fileName).OpenStream()) { Assert.Equal(Data.Length, file.Length); } Assert.True(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsDirectory(subSubDirToCopy.Name), "Did not copy nested folder successfully"); dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).OpenFile(fileName).Delete(); Assert.False(dir.OpenDirectory(dirToCopy.Name).OpenDirectory(subDirToCopy.Name).ContainsFile(fileName), "Did not cleanup file successfully"); try { // nothing to do with tests here if this fails System.IO.File.Delete(zipFile); } catch { } }
public PhysicalDirectoryHelper(string rootPath) { _compatDirectory = new DirectoryInfo(Path.Combine(rootPath, "Physical-" + Guid.NewGuid())); _compatDirectory.Create(); var pfs = new PhysicalFileSystem(); PhysicalFileSystem = new SubFileSystem(pfs, pfs.ConvertPathFromInternal(_compatDirectory.FullName)); }
private static CodeWriter GetCodeWriter(string subPath) { var fs = new PhysicalFileSystem(); var destFolder = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, SrcFolderRelative, subPath)); var subfs = new SubFileSystem(fs, fs.ConvertPathFromInternal(destFolder)); var codeWriter = new CodeWriter(new CodeWriterOptions(subfs)); return(codeWriter); }