本文整理汇总了C#中NamespaceManager.GetRules方法的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager.GetRules方法的具体用法?C# NamespaceManager.GetRules怎么用?C# NamespaceManager.GetRules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NamespaceManager
的用法示例。
在下文中一共展示了NamespaceManager.GetRules方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GuardAgainstSubscriptionReuseAcrossLogicalEndpoints
static void GuardAgainstSubscriptionReuseAcrossLogicalEndpoints(string subscriptionname,
NamespaceManager namespaceClient, string topicPath, string filter)
{
var rules = namespaceClient.GetRules(topicPath, subscriptionname);
foreach (var rule in rules)
{
var sqlFilter = rule.Filter as SqlFilter;
if (sqlFilter != null && sqlFilter.SqlExpression != filter)
{
throw new SubscriptionAlreadyInUseException(
"Looks like this subscriptionname is already taken by another logical endpoint as the sql filter does not match the subscribed eventtype, please choose a different subscription name!");
}
}
}
开发者ID:danielmarbach,项目名称:NServiceBus.AzureServiceBus,代码行数:14,代码来源:AzureServicebusSubscriptionCreator.cs
示例2: UpdateSqlFilter
private static void UpdateSqlFilter(NamespaceManager namespaceManager, string sqlExpression, string subscriptionName, string topicPath)
{
bool needsReset = false;
List<RuleDescription> existingRules;
try
{
existingRules = namespaceManager.GetRules(topicPath, subscriptionName).ToList();
}
catch (MessagingEntityNotFoundException)
{
// the subscription does not exist, no need to update rules.
return;
}
if (existingRules.Count != 1)
{
needsReset = true;
}
else
{
var existingRule = existingRules.First();
if (sqlExpression != null && existingRule.Name == RuleDescription.DefaultRuleName)
{
needsReset = true;
}
else if (sqlExpression == null && existingRule.Name != RuleDescription.DefaultRuleName)
{
needsReset = true;
}
else if (sqlExpression != null && existingRule.Name != RuleName)
{
needsReset = true;
}
else if (sqlExpression != null && existingRule.Name == RuleName)
{
var filter = existingRule.Filter as SqlFilter;
if (filter == null || filter.SqlExpression != sqlExpression)
{
needsReset = true;
}
}
}
if (needsReset)
{
MessagingFactory factory = null;
try
{
factory = MessagingFactory.Create(namespaceManager.Address, namespaceManager.Settings.TokenProvider);
SubscriptionClient client = null;
try
{
client = factory.CreateSubscriptionClient(topicPath, subscriptionName);
// first add the default rule, so no new messages are lost while we are updating the subscription
TryAddRule(client, new RuleDescription(RuleDescription.DefaultRuleName, new TrueFilter()));
// then delete every rule but the Default one
foreach (var existing in existingRules.Where(x => x.Name != RuleDescription.DefaultRuleName))
{
TryRemoveRule(client, existing.Name);
}
if (sqlExpression != null)
{
// Add the desired rule.
TryAddRule(client, new RuleDescription(RuleName, new SqlFilter(sqlExpression)));
// once the desired rule was added, delete the default rule.
TryRemoveRule(client, RuleDescription.DefaultRuleName);
}
}
finally
{
if (client != null) client.Close();
}
}
finally
{
if (factory != null) factory.Close();
}
}
}