public void should_write_and_read_from_file() { // given var storageHelper = new StoragePlugin(new EmptyLog()); storageHelper.Start(); var objects = new[] { new StorageObject { Id = 1, Description = "Doobee", NullableInt = 2123 }, new StorageObject { Id = 2, Description = "Minecraft", NullableInt = 543 }, new StorageObject { Id = 3, Description = "Crisps", NullableInt = 123 }, }; // when storageHelper.SaveFile("example", objects); StorageObject[] result = storageHelper.ReadFile <StorageObject>("example"); // then result.ShouldLookLike(objects); }
public StoragePlugin InitPluginStatus(string classPath, int status) { if (string.IsNullOrEmpty(classPath)) { throw new ArgumentNullException(classPath); } return(SqlQueryExecutor.Execute(() => { return _connectionProvider.DoInTransaction(() => { int?id; string selectQuery = string.Format(CultureInfo.InvariantCulture, "SELECT id FROM {0} WHERE classpath = @ClassPath", TableName); id = _connectionProvider.CurrentConnection.Query <int?>(selectQuery, new { ClassPath = classPath }).FirstOrDefault(); if (id != null) { string updateQuery = string.Format(CultureInfo.InvariantCulture, "UPDATE {0} SET status = @Status WHERE id = @Id", TableName); _connectionProvider.CurrentConnection.Execute(updateQuery, new { Status = status, Id = id.Value }); } else { string insertQuery = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {0} {1}; SELECT LAST_INSERT_ID();", TableName, InsertFieldList); id = (int)_connectionProvider.CurrentConnection.Query <long>(insertQuery, new { Status = status, ClassPath = classPath }).FirstOrDefault(); if (id.Value <= 0) { throw new MonsterDbException("Storage plugin insertion failed"); } } string fullSelectQuery = string.Format(CultureInfo.InvariantCulture, "SELECT {0} FROM {1} s WHERE id = @Id", SelectFieldList, TableName); StoragePlugin storage = _connectionProvider.CurrentConnection.Query <StoragePlugin>(fullSelectQuery, new { Id = id.Value }).FirstOrDefault(); return storage; }); })); }
public SchedulePlugin(StoragePlugin storagePlugin, INoobotCore noobotCore, StatsPlugin statsPlugin, ILog log) { _storagePlugin = storagePlugin; _noobotCore = noobotCore; _statsPlugin = statsPlugin; _log = log; }
public void InitStorges(IEnumerable <IStoragePlugin> storagePlugins) { if (storagePlugins == null) { throw new ArgumentNullException("storagePlugins"); } foreach (var storagePlugin in storagePlugins) { //updating db StoragePlugin pluginDescriptor = _storagePluginsRepository.InitPluginStatus(storagePlugin.GetType().FullName, (int)StorageStatus.Loaded); CachedStoragePlugins.Add(new CachedStoragePlugin(pluginDescriptor, storagePlugin)); } }
public void should_write_and_read_from_file() { // given var storageHelper = new StoragePlugin(new EmptyLog()); storageHelper.Start(); var objects = new[] { new StorageObject {Id = 1, Description = "Doobee", NullableInt = 2123}, new StorageObject {Id = 2, Description = "Minecraft", NullableInt = 543}, new StorageObject {Id = 3, Description = "Crisps", NullableInt = 123}, }; // when storageHelper.SaveFile("example", objects); StorageObject[] result = storageHelper.ReadFile<StorageObject>("example"); // then result.ShouldLookLike(objects); }
public CachedStoragePlugin(StoragePlugin pluginDescriptor, IStoragePlugin plugin) { PluginDescriptor = pluginDescriptor; Plugin = plugin; }
public PingPlugin(ISlackWrapper slackWrapper, StoragePlugin storagePlugin) { _slackWrapper = slackWrapper; _storagePlugin = storagePlugin; }
public PingPlugin(INoobotCore noobotCore, StoragePlugin storagePlugin) { _noobotCore = noobotCore; _storagePlugin = storagePlugin; }