Skip to content

Commit

Permalink
Add Log method to baseclass and make OnCreated/OnDeleted generic
Browse files Browse the repository at this point in the history
  • Loading branch information
supereddie committed Dec 27, 2024
1 parent 5a1ad00 commit 516593a
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 141 deletions.
54 changes: 0 additions & 54 deletions src/Common/WindowsAzure/IServiceBusQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,80 +8,26 @@ namespace ServiceBusExplorer.WindowsAzure
{
internal interface IServiceBusQueue : IServiceBusEntity
{
/// <summary>
/// Creates a new queue in the service namespace with the given name.
/// </summary>
/// <param name="description">A QueueDescription object describing the attributes with which the new queue will be created.</param>
/// <returns>Returns a newly-created QueueDescription object.</returns>
QueueDescription CreateQueue(QueueDescription description);

/// <summary>.
/// Creates a new queue in the service namespace with the given name.
/// </summary>
/// <param name="path">Path of the queue relative to the service namespace base address.</param>
/// <returns>Returns a newly-created QueueDescription object.</returns>
QueueDescription CreateQueue(string path);

/// <summary>
/// Deletes the queue passed as a argument.
/// </summary>
/// <param name="queueDescription">The queue to delete.</param>
Task DeleteQueue(QueueDescription queueDescription);

/// <summary>
/// Deletes the queue described by the relative name of the service namespace base address.
/// </summary>
/// <param name="path">Path of the queue relative to the service namespace base address.</param>
Task DeleteQueue(string path);

/// <summary>
/// Deletes all the queues in the list.
/// <param name="queues">A list of queues to delete.</param>
/// </summary>
Task DeleteQueues(IEnumerable<string> queues);

/// <summary>
/// Retrieves the queue from the service namespace.
/// </summary>
/// <param name="path">Path of the queue relative to the service namespace base address.</param>
/// <returns>A QueueDescription handle to the queue, or null if the queue does not exist in the service namespace. </returns>
QueueDescription GetQueue(string path);

/// <summary>
/// Gets the uri of the deadletter queue for a given queue.
/// </summary>
/// <param name="queuePath">The name of a queue.</param>
/// <returns>the absolute uri of the deadletter queue.</returns>
Uri GetQueueDeadLetterQueueUri(string queuePath);

/// <summary>
/// Retrieves an enumerable collection of all queues in the service bus namespace.
/// </summary>
/// <param name="filter">OData filter.</param>
/// <returns>Returns an IEnumerable<QueueDescription/> collection of all queues in the service namespace, or
/// an empty collection if no queue exists in this service namespace.</returns>
IEnumerable<QueueDescription> GetQueues(string filter, int timeoutInSeconds);

/// <summary>
/// Gets the uri of a queue.
/// </summary>
/// <param name="queuePath">The name of a queue.</param>
/// <returns>The absolute uri of the queue.</returns>
Uri GetQueueUri(string queuePath);

/// <summary>
/// Renames a queue inside a namespace.
/// </summary>
/// <param name="path">The path to an existing queue.</param>
/// <param name="newPath">The new path to the renamed queue.</param>
/// <returns>Returns a QueueDescription with the new name.</returns>
QueueDescription RenameQueue(string path, string newPath);

/// <summary>
/// Updates a queue in the service namespace with the given name.
/// </summary>
/// <param name="description">A QueueDescription object describing the attributes with which the new queue will be updated.</param>
/// <returns>Returns an updated QueueDescription object.</returns>
QueueDescription UpdateQueue(QueueDescription description);
}
}
50 changes: 0 additions & 50 deletions src/Common/WindowsAzure/IServiceBusTopic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,24 @@ namespace ServiceBusExplorer.WindowsAzure
{
internal interface IServiceBusTopic : IServiceBusEntity
{
/// <summary>
/// Creates a new topic in the service namespace with the given name.
/// </summary>
/// <param name="path">Path of the topic relative to the service namespace base address.</param>
/// <returns>Returns a newly-created TopicDescription object.</returns>
TopicDescription CreateTopic(string path);

/// <summary>
/// Creates a new topic in the service namespace with the given name.
/// </summary>
/// <param name="topicDescription">A TopicDescription object describing the attributes with which the new topic will be created.</param>
/// <returns>Returns a newly-created TopicDescription object.</returns>
TopicDescription CreateTopic(TopicDescription topicDescription);

/// <summary>
/// Deletes the topic described by the relative name of the service namespace base address.
/// </summary>
/// <param name="path">Path of the topic relative to the service namespace base address.</param>
Task DeleteTopic(string path);

/// <summary>
/// Deletes the topic passed as a argument.
/// </summary>
/// <param name="topic">The topic to delete.</param>
Task DeleteTopic(TopicDescription topic);


/// <summary>
/// Deletes all the topics in the list.
/// <param name="topics">A list of topics to delete.</param>
/// </summary>
Task DeleteTopics(IEnumerable<string> topics);

/// <summary>
/// Retrieves the topic from the service namespace.
/// </summary>
/// <param name="path">Path of the topic relative to the service namespace base address.</param>
/// <returns>A TopicDescription handle to the topic, or null if the topic does not exist in the service namespace.</returns>
TopicDescription GetTopic(string path);

/// <summary>
/// Retrieves an enumerable collection of all topics in the service bus namespace.
/// </summary>
/// <param name="filter">OData filter.</param>
/// <returns>Returns an IEnumerable<TopicDescription/> collection of all topics in the service namespace.
/// Returns an empty collection if no topic exists in this service namespace.</returns>
IEnumerable<TopicDescription> GetTopics(string filter, int timeoutInSeconds);

/// <summary>
/// Gets the uri of a topic.
/// </summary>
/// <param name="topicPath">The name of a topic.</param>
/// <returns>The absolute uri of the topic.</returns>
Uri GetTopicUri(string topicPath);

/// <summary>
/// Renames a topic inside a namespace.
/// </summary>
/// <param name="path">The path to an existing topic.</param>
/// <param name="newPath">The new path to the renamed topic.</param>
/// <returns>Returns a TopicDescription with the new name.</returns>
TopicDescription RenameTopic(string path, string newPath);

/// <summary>
/// Updates a topic in the service namespace with the given name.
/// </summary>
/// <param name="topicDescription">A TopicDescription object describing the attributes with which the new topic will be updated.</param>
/// <returns>Returns an updated TopicDescription object.</returns>
TopicDescription UpdateTopic(TopicDescription topicDescription);
}
}
19 changes: 14 additions & 5 deletions src/Common/WindowsAzure/ServiceBusEntity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using ServiceBusExplorer.Enums;
using ServiceBusExplorer.Helpers;
using ServiceBusExplorer.Utilities.Helpers;

Expand All @@ -20,7 +22,7 @@ internal abstract class ServiceBusEntity : IServiceBusEntity
private readonly string ns;
private string scheme = DefaultScheme;

public ServiceBusEntity(ServiceBusNamespace serviceBusNamespace, NamespaceManager namespaceManager)
protected ServiceBusEntity(ServiceBusNamespace serviceBusNamespace, NamespaceManager namespaceManager)
{
this.ServiceBusNamespace = serviceBusNamespace;
this.NamespaceManager = namespaceManager;
Expand Down Expand Up @@ -51,14 +53,21 @@ public string Scheme

protected string Namespace { get { return ns; } }

protected void OnCreated(ServiceBusHelperEventArgs args)
protected abstract EntityType EntityType { get; }

protected void OnCreated<T>(T entityInstance) where T : EntityDescription
{
OnCreate?.Invoke(new ServiceBusHelperEventArgs(entityInstance, EntityType));
}

protected void OnDeleted<T>(T entityInstance) where T : EntityDescription
{
OnCreate?.Invoke(args);
OnDelete?.Invoke(new ServiceBusHelperEventArgs(entityInstance, EntityType));
}

protected void OnDeleted(ServiceBusHelperEventArgs args)
protected void Log(string message)
{
OnDelete?.Invoke(args);
WriteToLog?.Invoke(message);
}

protected bool IsCloudNamespace()
Expand Down
Loading

0 comments on commit 516593a

Please sign in to comment.