Beispiel #1
0
        private bool IsSqlEditionSupported(string connectionString)
        {
            var operation = new DbOperation(connectionString, "SELECT SERVERPROPERTY ( 'EngineEdition' )", _logger);
            var edition   = (int)operation.ExecuteScalar();

            return(edition >= SqlEngineEdition.Standard && edition <= SqlEngineEdition.Express);
        }
        private void Receive(object state)
        {
            var tcs = (TaskCompletionSource <object>)state;

            if (!_lastPayloadId.HasValue)
            {
                var lastPayloadIdOperation = new DbOperation(_connectionString, _maxIdSql, _logger)
                {
                    LoggerPrefix = _loggerPrefix
                };

                try
                {
                    _lastPayloadId = (long?)lastPayloadIdOperation.ExecuteScalar();
                    Queried();

                    _logger.LogDebug(String.Format("{0}SqlReceiver started, initial payload id={1}", _loggerPrefix, _lastPayloadId));

                    // Complete the StartReceiving task as we've successfully initialized the payload ID
                    tcs.TrySetResult(null);
                }
                catch (Exception ex)
                {
                    _logger.LogError(String.Format("{0}SqlReceiver error starting: {1}", _loggerPrefix, ex));

                    tcs.TrySetException(ex);
                    return;
                }
            }

            // NOTE: This is called from a BG thread so any uncaught exceptions will crash the process
            lock (this)
            {
                if (_disposed)
                {
                    return;
                }

                var parameter = _dbProviderFactory.CreateParameter();
                parameter.ParameterName = "PayloadId";
                parameter.Value         = _lastPayloadId.Value;

                _dbOperation = new ObservableDbOperation(_connectionString, _selectSql, _logger, parameter)
                {
                    LoggerPrefix = _loggerPrefix
                };
            }

            _dbOperation.Queried += () => Queried();
            _dbOperation.Faulted += ex => Faulted(ex);
#if NET451
            _dbOperation.Changed += () =>
            {
                _logger.LogInformation("{0}Starting receive loop again to process updates", _loggerPrefix);

                _dbOperation.ExecuteReaderWithUpdates(ProcessRecord);
            };
#endif
            _logger.LogDebug(String.Format("{0}Executing receive reader, initial payload ID parameter={1}", _loggerPrefix, _dbOperation.Parameters[0].Value));

            _dbOperation.ExecuteReaderWithUpdates(ProcessRecord);

            _logger.LogInformation("{0}SqlReceiver.Receive returned", _loggerPrefix);
        }