本文整理汇总了C#中NamespaceManager类的典型用法代码示例。如果您正苦于以下问题:C# NamespaceManager类的具体用法?C# NamespaceManager怎么用?C# NamespaceManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NamespaceManager类属于命名空间,在下文中一共展示了NamespaceManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNamespaceManagerWithCustomCredentials
public static NamespaceManager GetNamespaceManagerWithCustomCredentials(NetworkCredential credential)
{
Uri httpsUri = ServiceBusHelper.GetLocalHttpsEndpoint();
TokenProvider tokenProvider = TokenProvider.CreateOAuthTokenProvider(new Uri[] { httpsUri }, credential);
NamespaceManager nsManager = new NamespaceManager(httpsUri, tokenProvider);
return nsManager;
}
示例2: theres_a_namespace_manager_available
public void theres_a_namespace_manager_available()
{
var mf = TestConfigFactory.CreateMessagingFactory();
nm = TestConfigFactory.CreateNamespaceManager(mf);
_formatter = new AzureServiceBusMessageNameFormatter();
}
示例3: CreateTopicsAndSubscriptions
static void CreateTopicsAndSubscriptions(NamespaceManager namespaceManager)
{
Console.WriteLine("\nCreating a topic and 3 subscriptions.");
// Create a topic and 3 subscriptions.
TopicDescription topicDescription = namespaceManager.CreateTopic(Program.TopicName);
Console.WriteLine("Topic created.");
// Create a subscription for all messages sent to topic.
namespaceManager.CreateSubscription(topicDescription.Path, SubsNameAllMessages, new TrueFilter());
Console.WriteLine("Subscription {0} added with filter definition set to TrueFilter.", Program.SubsNameAllMessages);
// Create a subscription that'll receive all orders which have color "blue" and quantity 10.
namespaceManager.CreateSubscription(topicDescription.Path, SubsNameColorBlueSize10Orders, new SqlFilter("color = 'blue' AND quantity = 10"));
Console.WriteLine("Subscription {0} added with filter definition \"color = 'blue' AND quantity = 10\".", Program.SubsNameColorBlueSize10Orders);
//var ruleDesc = new RuleDescription();
//ruleDesc.Filter = new CorrelationFilter("high");
//ruleDesc.Action = new SbAction();
// Create a subscription that'll receive all high priority orders.
namespaceManager.CreateSubscription(topicDescription.Path, SubsNameHighPriorityOrders, new CorrelationFilter("high"));
Console.WriteLine("Subscription {0} added with correlation filter definition \"high\".", Program.SubsNameHighPriorityOrders);
Console.WriteLine("Create completed.");
}
示例4: QueueShouldExistAsync
private async static Task QueueShouldExistAsync(NamespaceManager ns, QueueDescription queueDescription)
{
if (!await ns.QueueExistsAsync(queueDescription.Path))
{
throw new MessagingEntityNotFoundException("Queue: " + queueDescription.Path);
}
}
示例5: ServiceBusConnectionContext
public ServiceBusConnectionContext(ServiceBusScaleoutConfiguration configuration,
NamespaceManager namespaceManager,
IList<string> topicNames,
TraceSource traceSource,
Action<int, IEnumerable<BrokeredMessage>> handler,
Action<int, Exception> errorHandler,
Action<int> openStream)
{
if (topicNames == null)
{
throw new ArgumentNullException("topicNames");
}
_namespaceManager = namespaceManager;
_configuration = configuration;
_subscriptions = new SubscriptionContext[topicNames.Count];
_topicClients = new TopicClient[topicNames.Count];
_trace = traceSource;
TopicNames = topicNames;
Handler = handler;
ErrorHandler = errorHandler;
OpenStream = openStream;
TopicClientsLock = new object();
SubscriptionsLock = new object();
}
示例6: Initialize
public void Initialize()
{
var retryStrategy = new Incremental(3, TimeSpan.FromMilliseconds(100), TimeSpan.FromSeconds(1));
var retryPolicy = new RetryPolicy<ServiceBusTransientErrorDetectionStrategy>(retryStrategy);
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(settings.TokenIssuer, settings.TokenAccessKey);
var serviceUri = ServiceBusEnvironment.CreateServiceUri(settings.ServiceUriScheme, settings.ServiceNamespace, settings.ServicePath);
var namespaceManager = new NamespaceManager(serviceUri, tokenProvider);
this.settings.Topics.AsParallel().ForAll(topic =>
{
retryPolicy.ExecuteAction(() => CreateTopicIfNotExists(namespaceManager, topic));
topic.Subscriptions.AsParallel().ForAll(subscription =>
{
retryPolicy.ExecuteAction(() => CreateSubscriptionIfNotExists(namespaceManager, topic, subscription));
retryPolicy.ExecuteAction(() => UpdateRules(namespaceManager, topic, subscription));
});
});
// Execute migration support actions only after all the previous ones have been completed.
foreach (var topic in this.settings.Topics)
{
foreach (var action in topic.MigrationSupport)
{
retryPolicy.ExecuteAction(() => UpdateSubscriptionIfExists(namespaceManager, topic, action));
}
}
this.initialized = true;
}
示例7: OnStart
public override bool OnStart()
{
ServicePointManager.DefaultConnectionLimit = 12;
var connectionString = CloudConfigurationManager.GetSetting("topicConnectionString");
var topicName = CloudConfigurationManager.GetSetting("topicName");
_nsMgr = NamespaceManager.CreateFromConnectionString(connectionString);
if (!_nsMgr.TopicExists(topicName))
{
_nsMgr.CreateTopic(topicName);
}
if (!_nsMgr.SubscriptionExists(topicName, "audit"))
{
_nsMgr.CreateSubscription(topicName, "audit");
}
_client = SubscriptionClient.CreateFromConnectionString(connectionString, topicName, "audit", ReceiveMode.ReceiveAndDelete);
var result = base.OnStart();
Trace.TraceInformation("NTM.Auditing has been started");
return result;
}
示例8: Init
public async void Init(MessageReceived messageReceivedHandler) {
this.random = new Random();
//ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.AutoDetect;
// Tcp mode does not work when I run in a VM (VirtualBox) and the host
// is using a wireless connection. Hard coding to Http.
ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;
string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
this.factory = MessagingFactory.CreateFromConnectionString(connectionString);
this.namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.TopicExists(topicName)) {
namespaceManager.CreateTopic(topicName);
}
this.subscriptionName = Guid.NewGuid().ToString();
// Not needed really, it's a GUID...
if (!namespaceManager.SubscriptionExists(topicName, subscriptionName)) {
namespaceManager.CreateSubscription(topicName, subscriptionName);
}
this.topicClient = factory.CreateTopicClient(topicName);
this.subClient = factory.CreateSubscriptionClient(topicName, subscriptionName);
while (true) {
await ReceiveMessageTaskAsync(messageReceivedHandler);
}
}
示例9: EventHubViewModel
public EventHubViewModel(string eventHubName, NamespaceManager nsm)
{
_nsm = nsm;
EventHubName = eventHubName;
Partitions = new ObservableCollection<PartitionViewModel>();
ConsumerGroups = new ObservableCollection<string>();
}
示例10: ServiceBusConnection
public ServiceBusConnection(ServiceBusScaleoutConfiguration configuration, TraceSource traceSource)
{
_trace = traceSource;
_connectionString = configuration.BuildConnectionString();
try
{
_namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString);
_factory = MessagingFactory.CreateFromConnectionString(_connectionString);
if (configuration.RetryPolicy != null)
{
_factory.RetryPolicy = configuration.RetryPolicy;
}
else
{
_factory.RetryPolicy = RetryExponential.Default;
}
}
catch (ConfigurationErrorsException)
{
_trace.TraceError("The configured Service Bus connection string contains an invalid property. Check the exception details for more information.");
throw;
}
_backoffTime = configuration.BackoffTime;
_idleSubscriptionTimeout = configuration.IdleSubscriptionTimeout;
_configuration = configuration;
}
示例11: Main
static void Main(string[] args)
{
try
{
// Connection String as can be found on the azure portal https://manage.windowsazure.com/microsoft.onmicrosoft.com#Workspaces/ServiceBusExtension/namespaces
//
// The needed Shared access policy is Manage, this can either be the RootManageSharedAccessKey or one create with Manage priviledges
// "Endpoint = sb://NAMESPACE.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=THISISMYKEY";
var policyName = "RootManageSharedAccessKey";
var policySharedAccessKey = "THISISMYKEY";
var serviceBusNamespace = "NAMESPACE";
var credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider(policyName, policySharedAccessKey);
// access the namespace
var serviceBusUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceBusNamespace, string.Empty);
var manager = new NamespaceManager(serviceBusUri, credentials);
// Create the eventhub if needed
var description = manager.CreateEventHubIfNotExists("MyHub");
Console.WriteLine("AT: " + description.CreatedAt + " EventHub:" + description.Path + " Partitions: " + description.PartitionIds);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
Console.ReadLine();
}
示例12: ServiceBusOperator
/// <summary>
///
/// </summary>
/// <param name="connectionString"></param>
/// <param name="longPollingTimeout"></param>
/// Turn it on if you know the limit will not be reached</param>
public ServiceBusOperator(string connectionString,
TimeSpan longPollingTimeout)
{
_longPollingTimeout = longPollingTimeout;
_namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
_clientProvider = new ClientProvider(connectionString, true);
}
示例13: Main
public static void Main(string[] args)
{
ServiceNamespace = ConfigurationManager.AppSettings["ServiceNamespace"];
// Issuer key
sasKeyValue = ConfigurationManager.AppSettings["SASKey"];
// Create management credentials
TokenProvider credentials = TokenProvider.CreateSharedAccessSignatureTokenProvider(sasKeyName, sasKeyValue);
NamespaceManager namespaceClient =
new NamespaceManager(
ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty),
credentials);
QueueDescription myQueue;
if (!namespaceClient.QueueExists(QUEUE))
{
myQueue = namespaceClient.CreateQueue(QUEUE);
}
MessagingFactory factory = MessagingFactory.Create(ServiceBusEnvironment.CreateServiceUri("sb", ServiceNamespace, string.Empty), credentials);
QueueClient myQueueClient = factory.CreateQueueClient(QUEUE);
// Send message
Poco poco = new Poco();
poco.Id = "001";
poco.content = "This is some content";
BrokeredMessage message = new BrokeredMessage();
message.Properties.Add("Id", poco.Id);
message.Properties.Add("Content", poco.content);
myQueueClient.Send(message);
}
示例14: TopicShouldExistAsync
private async static Task TopicShouldExistAsync(NamespaceManager ns, TopicDescription topicDescription)
{
if (!await ns.TopicExistsAsync(topicDescription.Path))
{
throw new MessagingEntityNotFoundException("Topic: " + topicDescription.Path);
}
}
示例15: Main
static void Main(string[] args)
{
GetUserCredentials();
TokenProvider tokenProvider = null;
Uri serviceUri = null;
CreateTokenProviderAndServiceUri(out tokenProvider, out serviceUri);
NamespaceManager namespaceManager = new NamespaceManager(serviceUri, tokenProvider);
Console.WriteLine("Creating Topic 'IssueTrackingTopic'...");
if (namespaceManager.TopicExists("IssueTrackingTopic"))
namespaceManager.DeleteTopic("IssueTrackingTopic");
MessagingFactory factory = null;
TopicDescription myTopic = namespaceManager.CreateTopic(TopicName);
// Criar duas Subscrições
Console.WriteLine("Creating Subscriptions 'AuditSubscription' and 'AgentSubscription'...");
SubscriptionDescription myAuditSubscription = namespaceManager.CreateSubscription((myTopic.Path, "AuditSubscription");
SubscriptionDescription myAgentSubscription = namespaceManager.CreateSubscription(myTopic.Path, "AgentSubscription");
TopicClient myTopicClient = CreateTopicClient(serviceUri, tokenProvider, myTopic, out factory);
List<BrokeredMessage> messageList = new List<BrokeredMessage>();
messageList.Add(CreateIssueMessage("1", "First message information"));
messageList.Add(CreateIssueMessage("2", "Second message information"));
messageList.Add(CreateIssueMessage("3", "Third message information"));
Console.WriteLine("\nSending messages to topic...");
SendListOfMessages(messageList, myTopicClient);
Console.WriteLine("\nFinished sending messages, press ENTER to clean up and exit.");
myTopicClient.Close();
Console.ReadLine();
namespaceManager.DeleteTopic(TopicName);
}