public bool CreateQueue(QueueInfo queue, out string errorMessage) { errorMessage = string.Empty; if (string.IsNullOrWhiteSpace(CurrentServer)) { errorMessage = ERROR_SERVER_IS_NOT_DEFINED; return(false); } if (string.IsNullOrWhiteSpace(CurrentDatabase)) { errorMessage = ERROR_DATABASE_IS_NOT_DEFINED; return(false); } try { Guid brokerId = SqlScripts.ExecuteScalar <Guid>(ConnectionString, SqlScripts.SelectServiceBrokerIdentifierScript(CurrentDatabase)); SqlScripts.ExecuteScript(ConnectionString, SqlScripts.CreateServiceQueueScript(brokerId, queue)); } catch (Exception ex) { errorMessage = ExceptionHelper.GetErrorText(ex); } return(string.IsNullOrEmpty(errorMessage)); }
public bool TryDeleteQueue(QueueInfo queue, out string errorMessage) { errorMessage = string.Empty; if (string.IsNullOrWhiteSpace(CurrentServer)) { errorMessage = ERROR_SERVER_IS_NOT_DEFINED; return(false); } UseDatabase(DAJET_MQ_DATABASE_NAME); try { Dictionary <string, object> parameters = new Dictionary <string, object>() { { "name", queue.Name } }; SqlScripts.ExecuteProcedure(ConnectionString, "sp_delete_queue", parameters, out int result); } catch (Exception ex) { errorMessage = ExceptionHelper.GetErrorText(ex); } return(string.IsNullOrEmpty(errorMessage)); }
public QueueInfo Copy() { QueueInfo copy = new QueueInfo(); this.CopyTo(copy); return(copy); }
public List <QueueInfo> SelectQueues(out string errorMessage) { errorMessage = string.Empty; List <QueueInfo> list = new List <QueueInfo>(); string sql = SqlScripts.SelectQueuesScript(); { SqlDataReader reader = null; SqlConnection connection = new SqlConnection(ConnectionString); SqlCommand command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = sql; try { connection.Open(); reader = command.ExecuteReader(); while (reader.Read()) { QueueInfo queue = new QueueInfo() { Name = reader.IsDBNull("name") ? string.Empty : reader.GetString("name"), Status = reader.IsDBNull("is_enqueue_enabled") ? false : reader.GetBoolean("is_enqueue_enabled"), Retention = reader.IsDBNull("is_retention_enabled") ? false : reader.GetBoolean("is_retention_enabled"), Activation = reader.IsDBNull("is_activation_enabled") ? false : reader.GetBoolean("is_activation_enabled"), ProcedureName = reader.IsDBNull("activation_procedure") ? string.Empty : reader.GetString("activation_procedure"), MaxQueueReaders = reader.IsDBNull("max_readers") ? (short)0 : reader.GetInt16("max_readers"), PoisonMessageHandling = reader.IsDBNull("is_poison_message_handling_enabled") ? false : reader.GetBoolean("is_poison_message_handling_enabled") }; queue.Name = string.IsNullOrWhiteSpace(queue.Name) ? string.Empty : GetQueueName(queue.Name); list.Add(queue); } } catch (Exception error) { errorMessage = ExceptionHelper.GetErrorText(error); } finally { if (reader != null) { if (reader.HasRows) { command.Cancel(); } reader.Dispose(); } if (command != null) { command.Dispose(); } if (connection != null) { connection.Dispose(); } } } return(list); }
public void CopyTo(QueueInfo database) { foreach (PropertyInfo property in typeof(QueueInfo).GetProperties()) { if (property.IsList()) { continue; } if (!property.CanWrite) { continue; } property.SetValue(database, property.GetValue(this)); } }
internal static string CreateServiceQueueScript(Guid brokerId, QueueInfo queue) { string queueName = queue.Name; // CreateQueueName(brokerId, queue.Name); string serviceName = CreateServiceName(brokerId, queue.Name); StringBuilder script = new StringBuilder(); script.AppendLine($"CREATE QUEUE [{queueName}] WITH STATUS = {(queue.Status ? "ON" : "OFF")}"); script.AppendLine(", RETENTION = OFF"); if (queue.Activation) { script.AppendLine(", ACTIVATION ("); script.AppendLine($" PROCEDURE_NAME = {queue.ProcedureName}"); script.AppendLine($", MAX_QUEUE_READERS = {queue.MaxQueueReaders}"); script.AppendLine(", EXECUTE AS OWNER)"); } script.AppendLine(", POISON_MESSAGE_HANDLING (STATUS = OFF);"); script.AppendLine($"CREATE SERVICE [{serviceName}] ON QUEUE [{queueName}] ([DEFAULT]);"); return(script.ToString()); }