public void DirectoryReopenAsReadOnly_Test() { var fs = new PhysicalFileSystem(); var temp = Path.GetTempPath(); var pfs = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp)); string test = Path.GetRandomFileName(); IDirectory dir = new Directory(test, pfs, pfs.GetDirectoryEntry("/")); var file = dir.OpenDirectory("TestInnerDirectory").OpenFile("test.txt"); file.OpenStream().Close(); Assert.Single(dir.AsReadOnly().EnumerateFilesRecursive()); Assert.Throws <FileNotFoundException>(() => dir.AsReadOnly().OpenFile("NonExistentFile")); }
/// <inheritdoc/> public IPluginProvision GetProvision<T>(IModule composableModule) where T : class, IPlugin { var appDataPath = rootFs.ConvertPathFromInternal(this.contentDirectory.ApplicationData.FullName); var resourcePath = rootFs.ConvertPathFromInternal(composableModule.ContentsDirectory.FullName) / "resource"; var pluginAttr = typeof(T).GetTypeInfo().GetCustomAttribute<PluginAttribute>(); if (pluginAttr == null) { throw new InvalidOperationException( $"Can not load provision for {typeof(T)} without a PluginAttribute"); } if (pluginAttr.PluginName == "common") { throw new UnauthorizedAccessException("Plugin name can not be 'common'."); } var pluginResourceDirectory = resourcePath / pluginAttr.PluginName; var pluginCommonResourceDirectory = resourcePath / "common"; var pluginResourceFs = rootFs.GetOrCreateSubFileSystem(pluginResourceDirectory); var pluginResourceDir = new FS.Directory(pluginResourceFs); var pluginCommonFs = rootFs.GetOrCreateSubFileSystem(pluginCommonResourceDirectory); var pluginCommonDir = new FS.Directory(pluginCommonFs); var pluginJsonFile = pluginResourceDir.EnumerateFilesRecursive() .FirstOrDefault(f => f.Name == "plugin.json"); if (pluginJsonFile == null) { throw new FileNotFoundException($"Unable to find plugin.json for {pluginAttr.PluginName}"); } var props = JsonSerializer .Deserialize<PluginPropertiesData>(pluginJsonFile.ReadAllText(), jsonSerializerOptions); IPluginProperties properties = new PluginProperties(props.Strings, props.Dictionaries, props.Arrays); var pluginDataFs = rootFs.GetOrCreateSubFileSystem(appDataPath / "plugindata" / pluginAttr.PluginName); return new PluginProvision(this.logProvider.GetLogger($"Plugin:{pluginAttr.PluginName}"), properties, this.configurationStore, pluginAttr.PluginName, properties.Get(PluginInfoFields.Author) ?? pluginAttr.Author, properties.Get(PluginInfoFields.Description) ?? pluginAttr.Description, pluginAttr.Version, composableModule.ContentsDirectory, new FS.Directory(pluginDataFs), pluginCommonDir.AsReadOnly(), pluginResourceDir.AsReadOnly()); }