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

            return(SqlScripts.ExecuteScalar <string>(ConnectionString, SqlScripts.SelectCertificateBinaryDataScript()));
        }
        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);
        }