Esempio n. 1
0
        public Task Send(IList <Message> messages)
        {
            if (messages == null || messages.Count == 0)
            {
                return(Task.FromResult <object>(null));
            }

            var parameter = _dbProviderFactory.CreateParameter();

            parameter.ParameterName = "Payload";
            parameter.DbType        = DbType.Binary;
            parameter.Value         = SqlPayload.ToBytes(messages);

            var operation = new DbOperation(_connectionString, _insertDml, _logger, parameter);

            return(operation.ExecuteNonQueryAsync());
        }
Esempio n. 2
0
        public void Install()
        {
            _logger.LogInformation("Start installing SignalR SQL objects");

            if (!IsSqlEditionSupported(_connectionString))
            {
                throw new PlatformNotSupportedException(Resources.Error_UnsupportedSqlEdition);
            }

            var script = GetType().GetTypeInfo().Assembly.StringResource("install.sql");

            script = script.Replace("SET @SCHEMA_NAME = 'SignalR';", "SET @SCHEMA_NAME = '" + SqlMessageBus.SchemaName + "';");
            script = script.Replace("SET @SCHEMA_TABLE_NAME = 'Schema';", "SET @SCHEMA_TABLE_NAME = '" + SchemaTableName + "';");
            script = script.Replace("SET @TARGET_SCHEMA_VERSION = 1;", "SET @TARGET_SCHEMA_VERSION = " + SchemaVersion + ";");
            script = script.Replace("SET @MESSAGE_TABLE_COUNT = 1;", "SET @MESSAGE_TABLE_COUNT = " + _tableCount + ";");
            script = script.Replace("SET @MESSAGE_TABLE_NAME = 'Messages';", "SET @MESSAGE_TABLE_NAME = '" + _messagesTableNamePrefix + "';");

            var operation = new DbOperation(_connectionString, script, _logger);

            operation.ExecuteNonQuery();

            _logger.LogInformation("SignalR SQL objects installed");
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 private void ProcessRecord(IDataRecord record, DbOperation dbOperation)