示例#1
0
        /// <inheritdoc/>
        public IPluginProvision GetProvision <T>(IModule composableModule)
            where T : 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}");
            }

            IPluginProperties properties = new JsonPluginProperties(JObject
                                                                    .FromObject(JsonConvert
                                                                                .DeserializeObject(pluginJsonFile.ReadAllText()),
                                                                                new JsonSerializer {
                Culture = CultureInfo.InvariantCulture
            }));

            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, pluginResourceDir));
        }
示例#2
0
        public void DirectoryRecursiveFileOpen_Test()
        {
            var fs   = new PhysicalFileSystem();
            var temp = Path.GetTempPath();
            var pfs  = fs.GetOrCreateSubFileSystem(fs.ConvertPathFromInternal(temp));
            var dir  = new FS.Directory(Path.GetRandomFileName(), pfs, pfs.GetDirectoryEntry("/"));
            var file = dir.OpenFile("test.txt");

            file.OpenStream().Close();
            dir.OpenDirectory(Path.GetRandomFileName()).OpenFile("test2.txt").OpenStream().Close();
            var iter = dir.EnumerateFilesRecursive();

            Assert.True(iter.Count() >= 2);
        }
示例#3
0
        public void DirectoryRecursiveFileOpen_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 file = dir.OpenFile("test.txt");

            Assert.True(dir.ContainsFile(".manifest"));
            Assert.Equal(file.FileGuid, dir.GetGuid("test.txt"));
            file.OpenStream().Close();
            dir.OpenDirectory("next_test").OpenFile("test2.txt").OpenStream().Close();
            var iter = dir.EnumerateFilesRecursive();

            Assert.True(iter.Count() >= 2);
        }