示例#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));
        }
        public void JsonPluginProperties_InvalidTests()
        {
            var propRoot =
                JsonConvert.DeserializeObject <JObject>(TestUtilities.GetStringResource("Loader.plugin.json"));
            IPluginProperties properties = new JsonPluginProperties(propRoot);

            Assert.Equal(String.Empty, properties.Get("notInObject"));
            Assert.Empty(properties.GetEnumerable("notInObject"));
            Assert.Empty(properties.GetDictionary("notInObject"));
        }
        public void JsonPluginProperties_Tests()
        {
            var propRoot =
                JsonConvert.DeserializeObject <JObject>(TestUtilities.GetStringResource("Loader.plugin.json"));
            IPluginProperties properties = new JsonPluginProperties(propRoot);

            Assert.Equal("TestString", properties.Get("someString"));
            Assert.Contains("One", properties.GetEnumerable("someArray"));
            Assert.Contains("Two", properties.GetEnumerable("someArray"));
            Assert.Contains("one", properties.GetDictionary("someDictionary").Keys);
            Assert.Contains("two", properties.GetDictionary("someDictionary").Keys);
        }
示例#4
0
        /// <inheritdoc/>
        public IPluginProvision GetProvision <T>(IModule composableModule)
            where T : IPlugin
        {
            var resourceDirectory = composableModule.ContentsDirectory
                                    .CreateSubdirectory("resource"); // todo: check for missing directory!!
            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       = resourceDirectory.CreateSubdirectory(pluginAttr.PluginName);
            var pluginCommonResourceDirectory = resourceDirectory.CreateSubdirectory("common");
            var pluginJsonFile = pluginResourceDirectory.GetFiles()
                                 .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(File.ReadAllText(pluginJsonFile.FullName)),
                                                                                new JsonSerializer {
                Culture = CultureInfo.InvariantCulture
            }));
            var pluginDataDirectory = this.contentDirectory.ApplicationData.CreateSubdirectory("plugincontents")
                                      .CreateSubdirectory(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, pluginDataDirectory, pluginCommonResourceDirectory, pluginResourceDirectory));
        }