当前位置: 首页>>代码示例>>C#>>正文


C# NamespaceManager.GetRules方法代码示例

本文整理汇总了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();
                }
            }
        }
开发者ID:TiagoTerra,项目名称:cqrs-journey,代码行数:82,代码来源:ServiceBusConfig.cs


注:本文中的NamespaceManager.GetRules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。