public LegacyRevisionsImporter( IConvertorArgs args, IAccountCollection accountCollection, ILogManager logManager, PluginInitializer initializer) : base(args, accountCollection, logManager, initializer) { }
public LegacyProfileConvertor( IConvertorArgs args, IAccountCollection accountCollection, ILogManager logManager, PluginInitializer initializer) : base(args, accountCollection) { _log = logManager.GetLogger(GetType()); _initializer = initializer; }
public static string CreateMain() { //解析Assembly foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { var plugin = ass.GetCustomAttribute <XQPluginAttribute>(); if (plugin != null) { PluginInitializer.Init(ass); return(JsonSerializer.Serialize(new PluginInfo() { name = plugin.Name, pver = plugin.Version, sver = plugin.sdkv, author = plugin.Author, desc = plugin.Desc })); } } throw new Exception("未找到相关程序集"); }
public void TryMatchTest(string pluginKey, string route, bool expectedResult, Type expectedController, string expectedMethodName) { //Arrange AppDashTestContext dbContext = new AppDashTestContext(); dbContext.Database.EnsureDeleted(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IRepository <Plugin>, Repository <Plugin> >(e => _pluginRepositoryMock.Object); serviceCollection.AddSingleton <IRepository <Tile>, Repository <Tile> >(e => _tileRepositoryMock.Object); serviceCollection.AddSingleton <IRepository <PluginSettings>, Repository <PluginSettings> >(e => _pluginSettingsRepositoryMock.Object); serviceCollection.AddSingleton <DbContext, AppDashTestContext>(e => dbContext); _pluginRepositoryMock.SetupRepositoryMock(dbContext, options => { options.InsertNoTracking(new Plugin { UniqueIdentifier = typeof(TestPlugin.TestPlugin).FullName, Key = "TestKey", Name = "TestName" }); }); _tileRepositoryMock.SetupRepositoryMock(dbContext, options => { }); _pluginSettingsRepositoryMock.SetupRepositoryMock(dbContext, options => { options.InsertNoTracking(new PluginSettings { PluginKey = "TestKey", Data = JsonConvert.SerializeObject(new PluginData { Data = new Dictionary <string, Tuple <Type, object> >(new List <KeyValuePair <string, Tuple <Type, object> > > { new KeyValuePair <string, Tuple <Type, object> >("TestData", new Tuple <Type, object>(typeof(string), "TestValue")), new KeyValuePair <string, Tuple <Type, object> >("TestData2", new Tuple <Type, object>(typeof(string), "TestValue2")) }) }) }); }); var serviceProvider = serviceCollection.BuildServiceProvider(); var pluginResolver = new PluginResolver(); var pluginSettingsManager = new PluginSettingsManager(serviceProvider); PluginLoader pluginLoader = new PluginLoader(pluginResolver, serviceProvider); var pluginInitializer = new PluginInitializer(pluginResolver, pluginSettingsManager, serviceProvider); var pluginManager = new PluginManager(pluginResolver, pluginLoader, pluginInitializer); PluginControllerMatcher pluginControllerMatcher = new PluginControllerMatcher(pluginManager); //Act pluginLoader.LoadPlugins(Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "plugins")); pluginInitializer.InitializePlugins(); bool result = pluginControllerMatcher.TryMatch(pluginKey, route, out (IPluginController, MethodInfo)controller); //Assert Assert.Equal(expectedResult, result); if (expectedResult) { Assert.NotNull(controller.Item1); Assert.NotNull(controller.Item2); Assert.Equal(expectedController.FullName, controller.Item1.GetType().FullName); Assert.Equal(expectedMethodName, controller.Item2.Name); } else { Assert.Null(controller.Item1); Assert.Null(controller.Item2); } }
public override void Init(IApplication app) { PluginInitializer.Init(app); }
public Plugin(IApplication app) { PluginInitializer.Init(app); }
public Plugin(IApplication app) { PluginInitializer.Init(app, new ViewsFactory { app = app }); }
public Plugin(IApplication app) { PluginInitializer.Init(app.Model, app.Presentation, new ViewsFactory { app = app }); }
public void InitializePluginsTest() { //Arrange AppDashTestContext dbContext = new AppDashTestContext(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IRepository <Plugin>, Repository <Plugin> >(e => _pluginRepositoryMock.Object); serviceCollection.AddSingleton <IRepository <Tile>, Repository <Tile> >(e => _tileRepositoryMock.Object); serviceCollection.AddSingleton <IRepository <PluginSettings>, Repository <PluginSettings> >(e => _pluginSettingsRepositoryMock.Object); serviceCollection.AddSingleton <DbContext, AppDashTestContext>(e => dbContext); _pluginRepositoryMock.SetupRepositoryMock(dbContext, options => { options.InsertNoTracking(new Plugin { UniqueIdentifier = typeof(TestPlugin.TestPlugin).FullName, Key = "TestKey", Name = "TestName" }); }); _tileRepositoryMock.SetupRepositoryMock(dbContext, options => { }); _pluginSettingsRepositoryMock.SetupRepositoryMock(dbContext, options => { options.InsertNoTracking(new PluginSettings { PluginKey = "TestKey", Data = JsonConvert.SerializeObject(new PluginData { Data = new Dictionary <string, Tuple <Type, object> >(new List <KeyValuePair <string, Tuple <Type, object> > > { new KeyValuePair <string, Tuple <Type, object> >("TestData", new Tuple <Type, object>(typeof(string), "TestValue")), new KeyValuePair <string, Tuple <Type, object> >("TestData2", new Tuple <Type, object>(typeof(string), "TestValue2")) }) }) }); }); var serviceProvider = serviceCollection.BuildServiceProvider(); var pluginResolver = new PluginResolver(); var pluginSettingsManager = new PluginSettingsManager(serviceProvider); PluginLoader pluginLoader = new PluginLoader(pluginResolver, serviceProvider); PluginInitializer pluginInitializer = new PluginInitializer(pluginResolver, pluginSettingsManager, serviceProvider); //Act pluginLoader.LoadPlugins(Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "plugins")); pluginInitializer.InitializePlugins(); //Assert var plugin = pluginResolver.GetPlugin("TestKey"); //make sure the plugin exists Assert.NotNull(plugin); //make sure the plugin has the right key Assert.Equal("TestKey", plugin.PluginInstance.Key); Assert.Equal("TestKey", plugin.PluginKey); foreach (ITile pluginTile in pluginResolver.GetPluginTiles()) { //make sure tiles have correct data Assert.Equal("TestKey", pluginTile.PluginKey); Assert.NotEmpty(pluginTile.TileKey); Assert.NotNull(pluginTile.PluginSettings); Assert.NotNull(pluginTile.PluginSettings.GetData <string>("TestData")); Assert.NotNull(pluginTile.PluginSettings.GetData <string>("TestData2")); Assert.Throws <InvalidCastException>(() => { //make sure this throws an InvalidCastException since it should be a string int data = pluginTile.PluginSettings.GetData <int>("TestData"); }); } }
public void GetPluginSettingsTest(string pluginKey, bool shouldHaveData) { //Arrange AppDashTestContext dbContext = new AppDashTestContext(); dbContext.Database.EnsureDeleted(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton <IRepository <Plugin>, Repository <Plugin> >(e => _pluginRepositoryMock.Object); serviceCollection.AddSingleton <IRepository <Tile>, Repository <Tile> >(e => _tileRepositoryMock.Object); serviceCollection.AddSingleton <IRepository <PluginSettings>, Repository <PluginSettings> >(e => _pluginSettingsRepositoryMock.Object); serviceCollection.AddSingleton <DbContext, AppDashTestContext>(e => dbContext); _pluginRepositoryMock.SetupRepositoryMock(dbContext, options => { options.InsertNoTracking(new Plugin { UniqueIdentifier = typeof(TestPlugin.TestPlugin).FullName, Key = "TestKey", Name = "TestName" }); }); _tileRepositoryMock.SetupRepositoryMock(dbContext, options => { }); _pluginSettingsRepositoryMock.SetupRepositoryMock(dbContext, options => { options.InsertNoTracking(new PluginSettings { PluginKey = "TestKey", Data = JsonConvert.SerializeObject(new PluginData { Data = new Dictionary <string, Tuple <Type, object> >(new List <KeyValuePair <string, Tuple <Type, object> > > { new KeyValuePair <string, Tuple <Type, object> >("TestData", new Tuple <Type, object>(typeof(string), "TestValue")), new KeyValuePair <string, Tuple <Type, object> >("TestData2", new Tuple <Type, object>(typeof(string), "TestValue2")) }) }) }); }); var serviceProvider = serviceCollection.BuildServiceProvider(); var pluginResolver = new PluginResolver(); PluginLoader pluginLoader = new PluginLoader(pluginResolver, serviceProvider); PluginSettingsManager pluginSettingsManager = new PluginSettingsManager(serviceProvider); var pluginInitializer = new PluginInitializer(pluginResolver, pluginSettingsManager, serviceProvider); //Act pluginLoader.LoadPlugins(Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), "plugins")); pluginInitializer.InitializePlugins(); var pluginData = pluginSettingsManager.GetPluginSettings(pluginKey); //Assert if (shouldHaveData) { Assert.NotNull(pluginData); var testData = pluginData.GetData <string>("TestData"); var testData2 = pluginData.GetData <string>("TestData2"); Assert.NotEmpty(testData); Assert.NotEmpty(testData2); Assert.Equal(2, pluginData.Data.Count); var defaultData = pluginData.GetData <string>("InvalidData"); Assert.Equal(default, defaultData);