Beispiel #1
0
        public PostgreSqlTagsMonitoringApi(JobStorage postgreSqlStorage)
        {
            var monitoringApi = postgreSqlStorage.GetMonitoringApi();

            if (monitoringApi.GetType().Name != "PostgreSqlMonitoringApi")
            {
                throw new ArgumentException("The monitor API is not implemented using PostgreSql", nameof(monitoringApi));
            }

            _monitoringApi     = monitoringApi;
            _postgreSqlStorage = postgreSqlStorage;

            // 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)
            {
                _useConnection = postgreSqlStorage.GetType().GetTypeInfo().GetMethod(nameof(UseConnection),
                                                                                     BindingFlags.NonPublic | BindingFlags.Instance);
                _useStorage = true;
            }

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