public void SaveTextPluginSettings(TextPlugin plugin) { string version = plugin.Version; if (string.IsNullOrEmpty(version)) { version = "1.0.0"; } SiteConfigurationEntity entity = UnitOfWork.Find <SiteConfigurationEntity>() .FirstOrDefault(x => x.Id == plugin.DatabaseId); if (entity == null || entity.Id == Guid.Empty) { entity = new SiteConfigurationEntity(); entity.Id = plugin.DatabaseId; entity.Version = version; entity.Content = plugin.Settings.GetJson(); UnitOfWork.Add(entity); } else { entity.Version = version; entity.Content = plugin.Settings.GetJson(); } UnitOfWork.SaveChanges(); }
public ActionResult Edit(string id) { // Guards if (string.IsNullOrEmpty(id)) { return(RedirectToAction("Index")); } TextPlugin plugin = _pluginFactory.GetTextPlugin(id); if (plugin == null) { return(RedirectToAction("Index")); } PluginViewModel model = new PluginViewModel() { Id = plugin.Id, DatabaseId = plugin.DatabaseId, Name = plugin.Name, Description = plugin.Description, }; // Try to load the settings from the database, fall back to defaults model.SettingValues = new List <SettingValue>(plugin.Settings.Values); model.IsEnabled = plugin.Settings.IsEnabled; return(View(model)); }
/// <summary> /// Gets the cache key for a plugin's settings. /// </summary> /// <param name="plugin">The plugin. - its Id and Name is used in the cache key.</param> /// <returns>The cache key.</returns> public static string PluginSettingsKey(TextPlugin plugin) { string key = SITE_CACHE_PREFIX + PLUGIN_SETTINGS; key = key.Replace("{type}", plugin.GetType().Name); key = key.Replace("{id}", plugin.Id); return(key); }
public void gettextplugin_should_return_null_when_plugin_is_not_registered() { // Arrange PluginFactory factory = CreateFactory(); // Act TextPlugin plugin = factory.GetTextPlugin("doesntexist"); // Assert Assert.That(plugin, Is.Null); }
public void GetTextPlugin_Should_Return_Null_When_Plugin_Is_Not_Registered() { // Arrange PluginFactory factory = new PluginFactory(); // Act TextPlugin plugin = factory.GetTextPlugin("doesntexist"); // Assert Assert.That(plugin, Is.Null); }
public void RegisterTextPlugin_Should_Register_Plugin_And_GetTextPlugin_Should_Return_Plugin() { // Arrange PluginFactory factory = new PluginFactory(); TextPluginStub pluginStub = new TextPluginStub("randomid", "name", "desc"); // Act factory.RegisterTextPlugin(pluginStub); TextPlugin actualPlugin = factory.GetTextPlugin("randomid"); // Assert Assert.That(actualPlugin, Is.Not.Null); }
public void registertextplugin_should_register_plugin_and_gettextplugin_should_return_plugin() { // Arrange PluginFactory factory = CreateFactory(); TextPluginStub pluginStub = new TextPluginStub("randomid", "name", "desc"); // Act factory.RegisterTextPlugin(pluginStub); TextPlugin actualPlugin = factory.GetTextPlugin("randomid"); // Assert Assert.That(actualPlugin, Is.Not.Null); }
public void SaveTextPluginSettings(TextPlugin plugin) { int index = TextPlugins.IndexOf(plugin); if (index == -1) { TextPlugins.Add(plugin); } else { TextPlugins[index] = plugin; } }
public PluginViewModel(TextPlugin plugin) : this() { Id = plugin.Id; DatabaseId = plugin.DatabaseId; Name = plugin.Name; Description = plugin.Description; IsEnabled = plugin.Settings.IsEnabled; if (!string.IsNullOrEmpty(Description)) { Description = Description.Replace("\n", "<br/>"); Description = Description.Replace("\r", "<br/>"); } }
public void SaveTextPluginSettings(TextPlugin plugin) { SiteConfigurationEntity entity = Queryable <SiteConfigurationEntity>() .FirstOrDefault(x => x.Id == plugin.DatabaseId); if (entity == null) { entity = new SiteConfigurationEntity(); } entity.Id = plugin.DatabaseId; entity.Version = plugin.Version; entity.Content = plugin.Settings.GetJson(); SaveOrUpdate <SiteConfigurationEntity>(entity); }
public PluginSettings GetTextPluginSettings(Guid databaseId) { if (PluginSettings != null) { return(PluginSettings); } TextPlugin savedPlugin = TextPlugins.FirstOrDefault(x => x.DatabaseId == databaseId); if (savedPlugin != null) { return(savedPlugin._settings); // DON'T CALL Settings - you'll get a StackOverflowException } else { return(null); } }
public ActionResult Edit(PluginViewModel model) { TextPlugin plugin = _pluginFactory.GetTextPlugin(model.Id); if (plugin == null) { return(RedirectToAction("Index")); } // Update the plugin settings with the values from the summary plugin.Settings.IsEnabled = model.IsEnabled; foreach (SettingValue summaryValue in model.SettingValues) { SettingValue pluginValue = plugin.Settings.Values.FirstOrDefault(x => x.Name == summaryValue.Name); if (pluginValue != null) { pluginValue.Value = summaryValue.Value; } } // Update the plugin last saved date - this is important for 304 modified tracking // when the browser caching option is turned on. SiteSettings settings = SettingsService.GetSiteSettings(); settings.PluginLastSaveDate = DateTime.UtcNow; SettingsViewModel settingsViewModel = new SettingsViewModel(ApplicationSettings, settings); SettingsService.SaveSiteSettings(settingsViewModel); // Save and clear the cached settings _settingsRepository.SaveTextPluginSettings(plugin); _siteCache.RemovePluginSettings(plugin); // Clear all other caches if the plugin has been enabled or disabled. _viewModelCache.RemoveAll(); _listCache.RemoveAll(); return(RedirectToAction("Index")); }
public void SaveTextPluginSettings(TextPlugin plugin) { using (IDbConnection connection = _dbConnectionFactory.CreateConnection()) { connection.Open(); string sql = $"select * from {TableName} where id=@id"; SiteConfigurationEntity entity = connection.QueryFirstOrDefault <SiteConfigurationEntity>(sql, new { id = plugin.DatabaseId }); bool settingsExist = (entity != null); if (entity == null) { entity = new SiteConfigurationEntity(); } entity.Id = plugin.DatabaseId; entity.Version = ApplicationSettings.ProductVersion; entity.Content = plugin.Settings.GetJson(); sql = ""; if (settingsExist) { sql = $"update {TableName} set "; sql += "version=@Version, content=@Content "; sql += "where id=@Id"; } else { sql = $"insert into {TableName} "; sql += "(id, version, content) "; sql += "values (@Id, @Version, @Content)"; } connection.Execute(sql, entity); } }
public void RegisterTextPlugin(TextPlugin plugin) { TextPlugins.Add(plugin); }
public void UpdateInstance(TextPlugin plugin) { throw new NotImplementedException(); }
/// <summary> /// Updates the plugin settings. /// </summary> /// <param name="plugin">The text plugin.</param> public void UpdatePluginSettings(TextPlugin plugin) { _cache.Remove(CacheKeys.PluginSettingsKey(plugin)); _cache.Add(CacheKeys.PluginSettingsKey(plugin), plugin.Settings, new CacheItemPolicy()); }
/// <summary> /// Removes the settings for given plugin from the cache. /// </summary> /// <param name="plugin">The plugin to remove the cached settings for.</param> public void RemovePluginSettings(TextPlugin plugin) { _cache.Remove(CacheKeys.PluginSettingsKey(plugin)); }
/// <summary> /// Gets the plugin settings. /// </summary> /// <param name="plugin">The text plugin.</param> /// <returns> /// Returns the <see cref="Settings" /> or null if the plugin is not in the cache. /// </returns> public PluginSettings GetPluginSettings(TextPlugin plugin) { return(_cache.Get(CacheKeys.PluginSettingsKey(plugin)) as PluginSettings); }