public string GetUserCertificateBinaryData()
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            return(SqlScripts.ExecuteScalar <string>(ConnectionString, SqlScripts.SelectCertificateBinaryDataScript()));
        }
        public void CreateRemoteUser(string targetQueueFullName, string certificateBinaryData)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            Guid targetBroker = SqlScripts.GetBrokerId(targetQueueFullName);

            SqlScripts.ExecuteScript(ConnectionString, SqlScripts.CreateRemoteUserScript(targetBroker, certificateBinaryData));
        }
        public void CreateQueue(string name)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            Guid brokerId = SqlScripts.ExecuteScalar <Guid>(ConnectionString, SqlScripts.SelectServiceBrokerIdentifierScript());

            SqlScripts.ExecuteScript(ConnectionString, SqlScripts.CreateServiceQueueScript(brokerId, name));
        }
        public string ReceiveMessage(string queueFullName)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            string connectionString = AlterDatabaseConnectionString();
            string message          = SqlScripts.ExecuteScalar <string>(connectionString, SqlScripts.SimpleReceiveMessageScript(queueFullName));

            return(message);
        }
        public IMessageConsumer CreateMessageConsumer(string queueName)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            Guid   brokerId      = SqlScripts.ExecuteScalar <Guid>(ConnectionString, SqlScripts.SelectServiceBrokerIdentifierScript());
            string queueFullName = SqlScripts.CreateQueueName(brokerId, queueName);

            return(new MessageConsumer(CurrentServer, queueFullName));
        }
        public void SetupServiceBroker()
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            SqlScripts.ExecuteScript(ConnectionString, SqlScripts.CreateDatabaseScript());
            Guid brokerId = SqlScripts.ExecuteScalar <Guid>(ConnectionString, SqlScripts.SelectServiceBrokerIdentifierScript());

            SqlScripts.ExecuteScript(ConnectionString, SqlScripts.CreateDatabaseUserScript(brokerId));
            SqlScripts.ExecuteScript(ConnectionString, SqlScripts.CreateChannelsTableScript());
        }
        public void SendMessage(string routeName, string payload)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            Guid   handle = SqlScripts.ExecuteScalar <Guid>(ConnectionString, SqlScripts.SelectDialogHandleScript(routeName));
            string sql    = SqlScripts.SendMessageToChannelScript();
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("handle", handle);
            parameters.Add("message", payload);
            SqlScripts.ExecuteScript(ConnectionString, sql, parameters);
        }
        public void CreateRoute(string name, string sourceQueueFullName, string targetAddress, string targetQueueFullName)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            Guid   sourceBroker    = SqlScripts.GetBrokerId(sourceQueueFullName);
            Guid   targetBroker    = SqlScripts.GetBrokerId(targetQueueFullName);
            string sourceQueueName = SqlScripts.GetQueueName(sourceQueueFullName);
            string targetQueueName = SqlScripts.GetQueueName(targetQueueFullName);

            string script = SqlScripts.CreateRouteScript(name, sourceBroker, sourceQueueName, targetAddress, targetBroker, targetQueueName);

            SqlScripts.ExecuteScript(ConnectionString, script);
        }
示例#9
0
        private IList <string> DoReceive(int numberOfMessages, int timeoutMilliseconds)
        {
            List <string> messages = new List <string>();

            {
                SqlCommand    command = null;
                SqlDataReader reader  = null;
                try
                {
                    command             = _connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.ReceiveListOfMessagesScript(QueueName, numberOfMessages, timeoutMilliseconds);
                    command.Transaction = _transaction;

                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        // 0 - dialog_handle : uniqueidentifier
                        // 1 - message_type  : nvarchar(256)
                        if (!reader.IsDBNull(2))
                        {
                            messages.Add(reader.GetString(2)); // message_body
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (reader != null)
                    {
                        if (reader.HasRows)
                        {
                            command.Cancel();
                        }
                        reader.Dispose();
                    }
                    if (command != null)
                    {
                        command.Dispose();
                    }
                }
            }
            return(messages);
        }
示例#10
0
        private string DoReceive(int timeoutMilliseconds)
        {
            string message_body = null;

            {
                SqlCommand    command = null;
                SqlDataReader reader  = null;
                try
                {
                    command             = _connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = SqlScripts.ReceiveOneMessageScript(QueueName, timeoutMilliseconds);
                    command.Transaction = _transaction;

                    reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        if (!reader.IsDBNull(0))
                        {
                            message_body = (string)reader[0];
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    if (reader != null)
                    {
                        if (reader.HasRows)
                        {
                            command.Cancel();
                        }
                        reader.Dispose();
                    }
                    if (command != null)
                    {
                        command.Dispose();
                    }
                }
            }
            return(message_body);
        }
        public void CreatePublicEndpoint(string name, int port)
        {
            if (string.IsNullOrWhiteSpace(CurrentServer))
            {
                throw new InvalidOperationException(ERROR_SERVER_IS_NOT_DEFINED);
            }

            { /* start of limited scope */
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand    command    = connection.CreateCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = SqlScripts.CreatePublicEndpointScript(name, port);
                try
                {
                    connection.Open();
                    int result = command.ExecuteNonQuery();
                }
                catch (Exception error)
                {
                    // TODO: log error
                    _ = error.Message;
                    throw;
                }
                finally
                {
                    if (command != null)
                    {
                        command.Dispose();
                    }
                    if (connection != null)
                    {
                        connection.Dispose();
                    }
                }
            } /* end of limited scope */
        }