Skip to content

Sdk migration ServiceBus Queues #750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Common/Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</PropertyGroup>
<ItemGroup>

<PackageReference Include="Azure.Identity" Version="1.10.3" />

<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="1.0.9" />
<PackageReference Include="Microsoft.Azure.Relay" Version="2.0.15596" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
210 changes: 210 additions & 0 deletions src/Common/Helpers/AuthorizationRuleWrapper2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#region Copyright
//=======================================================================================
// Microsoft Azure Customer Advisory Team
//
// This sample is supplemental to the technical guidance published on my personal
// blog at http://blogs.msdn.com/b/paolos/.
//
// Author: Paolo Salvatori
//=======================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// LICENSED UNDER THE APACHE LICENSE, VERSION 2.0 (THE "LICENSE"); YOU MAY NOT USE THESE
// FILES EXCEPT IN COMPLIANCE WITH THE LICENSE. YOU MAY OBTAIN A COPY OF THE LICENSE AT
// http://www.apache.org/licenses/LICENSE-2.0
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE DISTRIBUTED UNDER THE
// LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
// PERMISSIONS AND LIMITATIONS UNDER THE LICENSE.
//=======================================================================================
#endregion

#region Using Directives

using System;
using System.Linq;
using Azure.Messaging.ServiceBus.Administration;

#endregion


namespace ServiceBusExplorer.Helpers
{
public class AuthorizationRuleWrapper2
{
#region Private Fields
private bool manage;
private bool send;
private bool listen;
private string keyName;
private string primaryKey;
private string secondaryKey;
private string issuerName;
#endregion

#region Public Constructor
public AuthorizationRuleWrapper2()
{
}

public AuthorizationRuleWrapper2(AuthorizationRule rule)
{
KeyName = rule.KeyName;
if (rule is SharedAccessAuthorizationRule)
{
var sharedAccessAuthorizationRule = rule as SharedAccessAuthorizationRule;
PrimaryKey = sharedAccessAuthorizationRule.PrimaryKey;
SecondaryKey = sharedAccessAuthorizationRule.SecondaryKey;
}
Manage = rule.Rights.Contains(AccessRights.Manage);
Send = rule.Rights.Contains(AccessRights.Send);
Listen = rule.Rights.Contains(AccessRights.Listen);
IssuerName = rule.KeyName;
CreatedTime = rule.CreatedTime;
ModifiedTime = rule.ModifiedTime;
AuthorizationRule = rule;
}
#endregion

#region Public Properties
public string KeyName
{
get
{
return keyName;
}
set
{
keyName = value;
if (AuthorizationRule != null)
{
AuthorizationRule.KeyName = value;
}
}
}

public string PrimaryKey
{
get
{
return primaryKey;
}
set
{
primaryKey = value;
var rule = AuthorizationRule as SharedAccessAuthorizationRule;
if (rule != null)
{
rule.PrimaryKey = value;
}
}
}

public string SecondaryKey
{
get
{
return secondaryKey;
}
set
{
secondaryKey = value;
var rule = AuthorizationRule as SharedAccessAuthorizationRule;
if (rule != null)
{
rule.SecondaryKey = value;
}
}
}

public string IssuerName
{
get
{
return issuerName;
}
set
{
issuerName = value;
if (AuthorizationRule != null)
{
AuthorizationRule.KeyName = value;
}
}
}

public DateTimeOffset CreatedTime { get; private set; }
public DateTimeOffset ModifiedTime { get; private set; }
public AuthorizationRule AuthorizationRule { get; }

public bool Manage
{
get
{
return manage;
}
set
{
manage = value;
if (!value)
{
return;
}
Send = true;
Listen = true;
if (AuthorizationRule != null &&
!AuthorizationRule.Rights.Contains(AccessRights.Manage))
{
AuthorizationRule.Rights = new[] {AccessRights.Manage, AccessRights.Send, AccessRights.Listen}.ToList();
}
}
}

public bool Send
{
get
{
return send;
}
set
{
send = value;
if (!value && manage)
{
Manage = false;
}
if (AuthorizationRule == null || AuthorizationRule.Rights.Contains(AccessRights.Send))
{
return;
}
var list = AuthorizationRule.Rights.ToList();
list.Add(AccessRights.Send);
AuthorizationRule.Rights = list;
}
}

public bool Listen
{
get
{
return listen;
}
set
{
listen = value;
if (!value && manage)
{
Manage = false;
}
if (AuthorizationRule == null || AuthorizationRule.Rights.Contains(AccessRights.Listen))
{
return;
}
var list = AuthorizationRule.Rights.ToList();
list.Add(AccessRights.Listen);
AuthorizationRule.Rights = list;
}
}
#endregion
}
}
22 changes: 12 additions & 10 deletions src/Common/Helpers/DeadLetterMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

namespace ServiceBusExplorer.Helpers
{
using Azure.Messaging.ServiceBus.Administration;

public class DeletedDlqMessagesResult
{
#region Public constructor
Expand All @@ -52,8 +54,8 @@ public DeletedDlqMessagesResult(bool timedOut, List<long> deletedSequenceNumbers
public class DeadLetterMessageHandler
{
#region Private Fields
// Either queueDescription or subscriptionWrapper is used - but never both.
readonly QueueDescription sourceQueueDescription;
// Either queueProperties or subscriptionWrapper is used - but never both.
readonly QueueProperties sourceQueueProperties;
readonly SubscriptionWrapper sourceSubscriptionWrapper;
readonly int receiveTimeoutInSeconds;
readonly ServiceBusHelper serviceBusHelper;
Expand All @@ -62,10 +64,10 @@ public class DeadLetterMessageHandler

#region Public Constructors
public DeadLetterMessageHandler(WriteToLogDelegate writeToLog, ServiceBusHelper serviceBusHelper,
int receiveTimeoutInSeconds, QueueDescription queueDescription)
int receiveTimeoutInSeconds, QueueProperties queueProperties)
: this(writeToLog, serviceBusHelper, receiveTimeoutInSeconds)
{
sourceQueueDescription = queueDescription;
sourceQueueProperties = queueProperties;
}

public DeadLetterMessageHandler(WriteToLogDelegate writeToLog, ServiceBusHelper serviceBusHelper,
Expand Down Expand Up @@ -335,9 +337,9 @@ public string GetFailureExplanation(DeletedDlqMessagesResult result, int targetM
#region Private methods
private double GetLockDurationInSeconds()
{
if (sourceQueueDescription != null)
if (sourceQueueProperties != null)
{
return sourceQueueDescription.LockDuration.TotalSeconds;
return sourceQueueProperties.LockDuration.TotalSeconds;
}

return sourceSubscriptionWrapper.SubscriptionDescription.LockDuration.TotalSeconds;
Expand All @@ -348,9 +350,9 @@ private int GetMaxOperationTimeInSeconds()
// Allocate three seconds for final operations;
const int FinalActionsTime = 3;

if (sourceQueueDescription != null)
if (sourceQueueProperties != null)
{
return (int)sourceQueueDescription.LockDuration.TotalSeconds - FinalActionsTime;
return (int)sourceQueueProperties.LockDuration.TotalSeconds - FinalActionsTime;
}

return (int)sourceSubscriptionWrapper.SubscriptionDescription.LockDuration.TotalSeconds
Expand All @@ -359,9 +361,9 @@ private int GetMaxOperationTimeInSeconds()

string GetDlqEntityPath()
{
if (sourceQueueDescription != null)
if (sourceQueueProperties != null)
{
return QueueClient.FormatDeadLetterPath(sourceQueueDescription.Path);
return QueueClient.FormatDeadLetterPath(sourceQueueProperties.Name);
}

return SubscriptionClient.FormatDeadLetterPath(
Expand Down
31 changes: 31 additions & 0 deletions src/Common/Helpers/IReceivedMessageInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#region Copyright
//=======================================================================================
// Microsoft Azure Customer Advisory Team
//
// This sample is supplemental to the technical guidance published on my personal
// blog at http://blogs.msdn.com/b/paolos/.
//
// Author: Paolo Salvatori
//=======================================================================================
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// LICENSED UNDER THE APACHE LICENSE, VERSION 2.0 (THE "LICENSE"); YOU MAY NOT USE THESE
// FILES EXCEPT IN COMPLIANCE WITH THE LICENSE. YOU MAY OBTAIN A COPY OF THE LICENSE AT
// http://www.apache.org/licenses/LICENSE-2.0
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE DISTRIBUTED UNDER THE
// LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, EITHER EXPRESS OR IMPLIED. SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING
// PERMISSIONS AND LIMITATIONS UNDER THE LICENSE.
//=======================================================================================
#endregion

namespace ServiceBusExplorer.Helpers
{
using Azure.Messaging.ServiceBus;

public interface IReceivedMessageInspector
{
ServiceBusReceivedMessage BeforeSendMessage(ServiceBusReceivedMessage message);
ServiceBusReceivedMessage AfterReceiveMessage(ServiceBusReceivedMessage message);
}
}
Loading