コード例 #1
0
        public MySqlTagsMonitoringApi(IMonitoringApi monitoringApi)
        {
            if (monitoringApi.GetType().Name != "MySqlMonitoringApi")
            {
                throw new ArgumentException("The monitor API is not implemented using MySql", nameof(monitoringApi));
            }

            _monitoringApi = monitoringApi;
            // Other transaction type, clear cached methods
            if (_type != monitoringApi.GetType())
            {
                _useConnection = null;

                _type = monitoringApi.GetType();
            }

            if (_useConnection == null)
            {
                _useConnection = monitoringApi.GetType().GetTypeInfo().GetMethod(nameof(UseConnection),
                                                                                 BindingFlags.NonPublic | BindingFlags.Instance);
            }

            if (_useConnection == null)
            {
                throw new ArgumentException("The function UseConnection cannot be found.");
            }
        }
コード例 #2
0
        public RedisTagsMonitoringApi(IMonitoringApi monitoringApi, RedisStorageOptions options)
        {
            if (monitoringApi.GetType().Name != "RedisMonitoringApi")
            {
                throw new ArgumentException("The monitor API is not implemented using Redis", nameof(monitoringApi));
            }
            _monitoringApi = monitoringApi;

            // Dirty, but lazy...we would like to execute these commands in the same transaction, so we're resorting to reflection for now

            var databaseFactory = monitoringApi.GetType().GetTypeInfo().GetField("_databaseFactory",
                                                                                 BindingFlags.NonPublic | BindingFlags.Instance);

            if (databaseFactory == null)
            {
                throw new ArgumentException("The field _databaseFactory cannot be found.");
            }

            var getJobsWithPropertiesMethod = monitoringApi.GetType()
                                              .GetMethod("GetJobsWithProperties", BindingFlags.Instance | BindingFlags.NonPublic);

            if (getJobsWithPropertiesMethod == null)
            {
                throw new ArgumentException("The method GetJobsWithPropertiesMethod cannot be found.");
            }

            _getJobsWithPropertiesMethod = getJobsWithPropertiesMethod.MakeGenericMethod(typeof(MatchingJobDto));

            var factory    = (Func <object>)databaseFactory.GetValue(monitoringApi);
            var objFactory = factory.Invoke();

            _wrapper = new DatabaseWrapper(objFactory, options);
        }
コード例 #3
0
        public RedisTagsMonitoringApi(IMonitoringApi monitoringApi)
        {
            if (monitoringApi.GetType().Name != "RedisMonitoringApi")
            {
                throw new ArgumentException("The monitor API is not implemented using Redis", nameof(monitoringApi));
            }
            _monitoringApi = monitoringApi;

            // Dirty, but lazy...we would like to execute these commands in the same transaction, so we're resorting to reflection for now

            // Other transaction type, clear cached methods
            if (_type != monitoringApi.GetType())
            {
                _useConnection = null;

                _type = monitoringApi.GetType();
            }

            if (_useConnection == null)
            {
                _useConnection = monitoringApi.GetType().GetTypeInfo().GetMethod(nameof(UseConnection),
                                                                                 BindingFlags.NonPublic | BindingFlags.Instance);
            }

            if (_useConnection == null)
            {
                throw new ArgumentException("The function UseConnection cannot be found.");
            }
        }