Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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;
                });
            }));
        }
Exemplo n.º 3
0
 public SchedulePlugin(StoragePlugin storagePlugin, INoobotCore noobotCore, StatsPlugin statsPlugin, ILog log)
 {
     _storagePlugin = storagePlugin;
     _noobotCore = noobotCore;
     _statsPlugin = statsPlugin;
     _log = log;
 }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public CachedStoragePlugin(StoragePlugin pluginDescriptor, IStoragePlugin plugin)
 {
     PluginDescriptor = pluginDescriptor;
     Plugin           = plugin;
 }
Exemplo n.º 7
0
 public PingPlugin(ISlackWrapper slackWrapper, StoragePlugin storagePlugin)
 {
     _slackWrapper  = slackWrapper;
     _storagePlugin = storagePlugin;
 }
Exemplo n.º 8
0
 public PingPlugin(INoobotCore noobotCore, StoragePlugin storagePlugin)
 {
     _noobotCore = noobotCore;
     _storagePlugin = storagePlugin;
 }