public void StartHandler(string IdUser) { serviceBusManager = new ServiceBusManager(); try { TimeSpan RenewTimeout = TimeSpan.FromSeconds(1); OnMessageOptions options = new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1, AutoRenewTimeout = RenewTimeout }; serviceBusManager.GetClient().OnMessageAsync(async brokerMessage => { try { if (brokerMessage.SessionId == (IdUser)) { var message = brokerMessage.GetBody <Stream>(); serviceBusManager.Message = JsonConvert.DeserializeObject <KindAds.Common.Models.Notification>(new StreamReader(message, true).ReadToEnd()); notification = serviceBusManager.Message; await brokerMessage.CompleteAsync(); serviceBusManager.Close(); //Send to client SendNotification(notification.Title, notification.Message); } } catch (Exception e) { brokerMessage.Abandon(); } }, options); } catch (Exception e) { var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetry.Critical(messageException); } }
public async Task <ActionResult> AddDirectory(string name, string parentNodeId) { if (parentNodeId == "") { return(RedirectToAction("Index")); } Node root = AddNode(name, parentNodeId); var documenDBManager = new DocumentDBManager(); Document doc = await documenDBManager.CreateOrReplaceDocumentAsync(Settings.Default.DocumenDBDatabaseName, Settings.Default.DocumentDBCollectionName, root); HomeController.root = root; string parentName = root.Descendants().Where(n => n.NodeId == parentNodeId).First().Name; ServiceBusManager.Log("Subdirectory named " + name + " added to " + parentName + " directory by " + User.Identity.Name); return(RedirectToAction("Index")); }
public async Task <IActionResult> Close(ActivityActionViewModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(HttpContext.User); var userId = _userRepository.GetIdByIdentity(user.Id); var id = model.Id; var activity = _activityRepository.Get(id); if (activity.Status == 1) { var queue = new ServiceBusManager(_configuration["ServiceBusConnectionString"], _configuration["ServiceBusQueueName"]); await queue.SendMessage(new QueueElement <object> { Type = "ActivityClose", Data = new ActivityIdViewModel() { Id = id, IdUser = userId }, }); } } return(RedirectToAction("Index")); }
private Azure(RestClient restClient, string subscriptionId, string tenantId, IAuthenticated authenticated) { resourceManager = ResourceManager.Fluent.ResourceManager.Authenticate(restClient).WithSubscription(subscriptionId); storageManager = StorageManager.Authenticate(restClient, subscriptionId); computeManager = ComputeManager.Authenticate(restClient, subscriptionId); networkManager = NetworkManager.Authenticate(restClient, subscriptionId); batchManager = BatchManager.Authenticate(restClient, subscriptionId); keyVaultManager = KeyVaultManager.Authenticate(restClient, subscriptionId, tenantId); trafficManager = TrafficManager.Fluent.TrafficManager.Authenticate(restClient, subscriptionId); dnsZoneManager = DnsZoneManager.Authenticate(restClient, subscriptionId); sqlManager = SqlManager.Authenticate(restClient, subscriptionId); redisManager = RedisManager.Authenticate(restClient, subscriptionId); cdnManager = CdnManager.Authenticate(restClient, subscriptionId); appServiceManager = AppServiceManager.Authenticate(restClient, subscriptionId, tenantId); searchManager = SearchManager.Authenticate(restClient, subscriptionId); serviceBusManager = ServiceBusManager.Authenticate(restClient, subscriptionId); containerInstanceManager = ContainerInstanceManager.Authenticate(restClient, subscriptionId); registryManager = RegistryManager.Authenticate(restClient, subscriptionId); containerServiceManager = ContainerServiceManager.Authenticate(restClient, subscriptionId); cosmosDBManager = CosmosDBManager.Authenticate(restClient, subscriptionId); authorizationManager = AuthorizationManager.Authenticate(restClient, subscriptionId); msiManager = MsiManager.Authenticate(restClient, subscriptionId); batchAIManager = BatchAIManager.Authenticate(restClient, subscriptionId); monitorManager = MonitorManager.Authenticate(restClient, subscriptionId); eventHubManager = EventHubManager.Authenticate(restClient, subscriptionId); SubscriptionId = subscriptionId; this.authenticated = authenticated; }
public void SetManager(string connectionString) { try { if (_manager != null) { Queues.CollectionChanged -= Queues_CollectionChanged; Topics.CollectionChanged -= Topics_CollectionChanged; } _manager = new ServiceBusManager(connectionString); Queues = _manager.Queues; Topics = _manager.Topics; Queues.CollectionChanged += Queues_CollectionChanged; Topics.CollectionChanged += Topics_CollectionChanged; ContentViewModel = null; } catch (Exception e) { _manager = null; Queues = null; Topics = null; OpenConnectionStringManager(e.Message); } NotifyOfPropertyChange(() => CanAddNew); NotifyOfPropertyChange(() => CanCopyAll); NotifyOfPropertyChange(() => Connected); NotifyOfPropertyChange(() => CanRefreshList); NotifyOfPropertyChange(() => Queues); NotifyOfPropertyChange(() => Topics); }
public TopicViewModel(TopicDescription topicInstance, ServiceBusManager manager) { _manager = manager; Instance = topicInstance; Users = new TopicUsersViewModel(manager, topicInstance); Subscriptions = new ObservableCollection <SubscriptionDescription>(manager.GetSubscriptions(topicInstance)); }
static RuntimeBase() { var busConfiguration = new BusConfigurationSection(); busConfiguration.Bus.Endpoint = "msmq://localhost/Dagent.nuget"; ServiceBusManager.SetProvider(() => new RhinoServiceBusAbstractor(busConfiguration)); }
public async Task <ActionResult> DeleteDirectory(string nodeId, string parentNodeId) { if (nodeId == "" || parentNodeId == "" || nodeId == "undefined" || parentNodeId == "undefined") { return(RedirectToAction("Index")); } try { var nodes = root.Descendants(); string name = nodes.Where(n => n.NodeId == nodeId).First().Name; string parentName = nodes.Where(n => n.NodeId == parentNodeId).First().Name; Node root1 = DeleteNode(nodeId, parentNodeId); var documenDBManager = new DocumentDBManager(); Document doc = await documenDBManager.CreateOrReplaceDocumentAsync(Settings.Default.DocumenDBDatabaseName, Settings.Default.DocumentDBCollectionName, root1); root = root1; ServiceBusManager.Log("Subdirectory named " + name + " removed from " + parentName + " directory by " + User.Identity.Name); } catch (Exception ex) { if (ex.Message != "Cannot delete") { throw; } } return(RedirectToAction("Index")); }
public async Task TestMethod1() { ServiceBusConfiguration config = new ServiceBusConfiguration(); //config.ConnectionString = "Endpoint=sb://restorder.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=xwradxwyM1GusLWGxwOYXjLwMOoFRWQUyMK3XwOvObM="; config.ConnectionString = "Endpoint=sb://restorder2.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=u7jx+8mXYgSIDu4zL6TXayqkIy/F/tqW/mAAxggHvZs="; config.Topic = new TopicConfiguration() { Name = "order", Subscription = new SubscriptionConfiguration() { Name = "outofstock", AutoComplete = false, MaxConcurrentCalls = 1 } }; ServiceBusTopicSender serviceBusTopicSender = new ServiceBusTopicSender(config); ServiceBusTopicSubscription serviceBusTopicSubscription = new ServiceBusTopicSubscription(config); IServiceBusManager mgr = new ServiceBusManager(serviceBusTopicSender, serviceBusTopicSubscription); try { ICollection <OrderMenu> menus = new List <OrderMenu>(); menus.Add(new OrderMenu { MenuId = 1, Price = 10 }); for (int i = 1; i <= 2; i++) { //mgr.SendMessage<OrderEntity>(new OrderEntity //{ // CustomerId = i, // DeliveryAddress = "Subramanyapura", // OrderMenuDetails = menus, // RestaurantId = i //}); await mgr.SendMessage <string>("First message"); } //mgr.RecieveMessage<OrderEntity>(async order => //{ // Console.WriteLine("Order received", order.RestaurantId, order.OrderMenuDetails.First().MenuId); // await Task.CompletedTask; //}); mgr.RecieveMessage <string>(async order => { Console.WriteLine("Order received", order); await Task.CompletedTask; }); Assert.IsTrue(true); } catch (System.Exception ex) { Console.WriteLine("Excpetion occured", ex); throw; } }
public static IServiceBusManager CreateServiceBusManager() { return(CreateMockedManager(c => ServiceBusManager .Configure() .WithDelegatingHandlers(GetHandlers()) .WithLogLevel(HttpLoggingDelegatingHandler.Level.BodyAndHeaders) .Authenticate(c, c.DefaultSubscriptionId))); }
public ServiceBusService() { var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(Constant.CLIENT_ID, Constant.CLIENT_SECRET, Constant.TENANT_ID, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, Constant.SUBSCRIPTION_ID); serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(Constant.RESOURCE_GROUP, Constant.RESOURCE_NAME); }
/// <summary> /// Called when [end start]. /// </summary> protected override void OnEndStart() { base.OnEndStart(); ServiceBusManager.SetProvider(() => new RhinoServiceBusAbstractor(_locator, GetInstance <Rhino.ServiceBus.IServiceBus>())) .RegisterWithServiceLocator(_locator, _name); // also opens to connection, thus registering IServiceBus Open(ServiceBusManager.Current); }
public void Constructor() { // set service bus ServiceBusManager.SetProvider(() => new AppServiceBus() .Add <MyMessageHandler>() ); }
public void StartHandlerConversation(string IdUser) { string serviceBusTopicName = "conversationtopicdev"; //Obtenerlo del web.config serviceBusManager = new ServiceBusManager(serviceBusTopicName); try { TimeSpan RenewTimeout = TimeSpan.FromSeconds(1); OnMessageOptions options = new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1, AutoRenewTimeout = RenewTimeout }; // Create the Observable var collection = new ObservableCollection <string>(); IObservable <BrokeredMessage> notifications = Observable.Create <BrokeredMessage>( observer => { serviceBusManager.GetClient().OnMessage(observer.OnNext, options); return(Disposable.Empty); }).Publish().RefCount(); // Filtro para CampaignValidation IDisposable porposalMessage = notifications.Where( brokerMessage => { return(brokerMessage.Label == NotificationLabels.ConversationMessage); }).Subscribe( x => //OnNext { //split sessionIds var authorizeUsers = x.SessionId.Split('|'); try { if (authorizeUsers[0] == IdUser || authorizeUsers[1] == IdUser) { var message = x.GetBody <Stream>(); serviceBusManager.Message = JsonConvert.DeserializeObject <ConversationMessageNotification>(new StreamReader(message, true).ReadToEnd()); conversationNotification = serviceBusManager.Message; x.CompleteAsync(); serviceBusManager.Close(); //Send to client SendChatMessage(conversationNotification); } } catch (Exception e) { x.Abandon(); } }, x => Console.WriteLine(x.Message), //OnError () => Console.WriteLine("Complete")); //OnComplete } catch (Exception e) { var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetry.Critical(messageException); } }
/// <summary> /// Get the service bus namespace /// </summary> /// <param name="configuration">IConfiguration</param> /// <returns></returns> public static IServiceBusNamespace GetServiceBusNamespace(this IConfiguration configuration) { var config = configuration.GetSection("serviceBus").Get <ServiceBusConfiguration>(); var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(config.ClientId, config.ClientSecret, config.TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId); return(serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName)); }
public static IServiceBusNamespace GetServiceBusNamespace(this IConfiguration configuration) { //ref: https://tomasherceg.com/blog/post/azure-servicebus-in-net-core-managing-topics-queues-and-subscriptions-from-the-code var config = configuration.GetSection("serviceBus").Get <ServiceBusConfiguration>(); var credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(config.ClientId, config.ClientSecret, config.TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId); return(serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName)); }
public override void Configure(IFunctionsHostBuilder builder) { var clientID = Environment.GetEnvironmentVariable("Azure_ClientID"); var clientSecret = Environment.GetEnvironmentVariable("Azure_ClientSecret"); var tenantId = Environment.GetEnvironmentVariable("Azure_TenantID"); var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(clientID, clientSecret, tenantId, AzureEnvironment.AzureGlobalCloud); var subscriptionId = Environment.GetEnvironmentVariable("Azure_SubscriptionID"); var serviceBusManager = ServiceBusManager.Authenticate(credentials, subscriptionId); builder.Services.AddSingleton <IServiceBusManager>((s) => serviceBusManager); }
public void StartHandlerProposal(string IdUser) { serviceBusManager = new ServiceBusManager("proposaltopicdev"); try { TimeSpan RenewTimeout = TimeSpan.FromSeconds(1); OnMessageOptions options = new OnMessageOptions { AutoComplete = false, MaxConcurrentCalls = 1, AutoRenewTimeout = RenewTimeout }; // Create the Observable var collection = new ObservableCollection <string>(); IObservable <BrokeredMessage> notifications = Observable.Create <BrokeredMessage>( observer => { serviceBusManager.GetClient().OnMessage(observer.OnNext, new OnMessageOptions()); return(Disposable.Empty); }).Publish().RefCount(); // Filtro para CampaignValidation IDisposable porposalMessage = notifications.Where( brokerMessage => { return(brokerMessage.SessionId == (IdUser) && brokerMessage.Label == NotificationLabels.Proposal); }).Subscribe( x => //OnNext { try { if (x.SessionId == (IdUser)) { var message = x.GetBody <Stream>(); serviceBusManager.Message = JsonConvert.DeserializeObject <ProposalNotification>(new StreamReader(message, true).ReadToEnd()); var notification = serviceBusManager.Message; x.CompleteAsync(); serviceBusManager.Close(); //Send to client SendNotification(notification.message, notification.message); } } catch (Exception e) { x.Abandon(); } }, x => Console.WriteLine(x.Message), //OnError () => Console.WriteLine("Complete")); //OnComplete } catch (Exception e) { var messageException = telemetry.MakeMessageException(e, System.Reflection.MethodBase.GetCurrentMethod().Name); telemetry.Critical(messageException); } }
private IServiceBusNamespace GetServiceBusNamespace() { var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal( _configuration["serviceBus:clientId"], _configuration["serviceBus:clientSecret"], _configuration["serviceBus:tenantId"], AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, _configuration["serviceBus:subscriptionId"]); return(serviceBusManager.Namespaces.GetByResourceGroup(_configuration["serviceBus:resourceGroup"], _configuration["serviceBus:namespaceName"])); }
public IServiceBusNamespace GetServiceBusNamespace() { var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal( this.ClientId, this.ClientSecret, this.TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, this.SubscriptionId); return(serviceBusManager.Namespaces.GetByResourceGroup(this.ResourceGroup, this.NamespaceName)); }
public WorkerManagerService() { _log = LogManager.GetLogger(typeof(WorkerManagerService)); _targetProcessingSla = int.Parse(System.Configuration.ConfigurationManager.AppSettings["TargetProcessingSla"]); _minimumWorkerCount = int.Parse(System.Configuration.ConfigurationManager.AppSettings["MinimumWorkerCount"]); _httpClient.BaseAddress = new Uri(System.Configuration.ConfigurationManager.AppSettings["ImageAPIBaseAddress"]); _serviceBusManager = new ServiceBusManager(System.Configuration.ConfigurationManager.AppSettings["ServiceBusConnectionString"], System.Configuration.ConfigurationManager.AppSettings["ServiceBusQueueName"]); _workerPoolMonitor = new WorkerPoolMonitor(System.Configuration.ConfigurationManager.AppSettings["AzureAuthFileLocation"]); if (_minimumWorkerCount > TotalWorkerCount()) { _minimumWorkerCount = TotalWorkerCount(); } }
public void Verify() { try { _toManager = new ServiceBusManager(ConnectionString); Message = string.Empty; VerifyQueues(_fromManager.Queues, _toManager.Queues); VerifyTopics(_fromManager.Topics, _toManager.Topics); } catch (Exception e) { Message = e.Message; } NotifyOfPropertyChange(() => CanCopy); }
static void Main(string[] args) { ServiceLocatorManager.SetProvider(() => new UnityServiceLocator()); ServiceBusManager.SetProvider(() => new RhinoServiceBusAbstractor()) .AddMessageHandler(null) .AddMessageHandler(null); var serviceBus = ServiceBusManager.Current; serviceBus.Send <Message>(x => { x.Name = "George"; }); }
private IServiceBusNamespace GetServiceBusNamespace(ServiceBusConfiguration configuration) { try { var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(configuration.ClientId, configuration.ClientSecret, configuration.TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, configuration.SubscriptionId); return(serviceBusManager.Namespaces.GetByResourceGroup(configuration.ResourceGroupName, configuration.ResourceName)); } catch (Exception) { return(null); } }
public async Task <IActionResult> Create(ActivityCreateViewModel model) { if (ModelState.IsValid) { //await _client.PostRequest<object>($"Activity/Create", model); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userManager.GetUserAsync(HttpContext.User); var userData = _userRepository.GetUserByIdentity(user.Id); model.IdUser = userData.Id; // Failsafe if (model.Type != 2 || !userData.IsOrganizer) { model.Type = 1; } if (Program.UseEventHub) { await _eventHub.SendMessage(new QueueElement <ActivityCreateViewModel> { Type = "ActivityCreate", Data = model, }); } else { var queue = new ServiceBusManager(_configuration["ServiceBusConnectionString"], _configuration["ServiceBusQueueName"]); await queue.SendMessage(new QueueElement <ActivityCreateViewModel> { Type = "ActivityCreate", Data = model, }); } return(RedirectToAction("Index")); } else { return(BadRequest(ModelState)); } }
public async Task <ActionResult> Join(ActivityJoinViewModel model) { if (ModelState.IsValid) { //await _client.GetRequest<object>($"Activity/{model.IdActivity}/Join"); // Post var user = await _userManager.GetUserAsync(HttpContext.User); var userId = _userRepository.GetIdByIdentity(user.Id); var id = model.IdActivity; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //model.IdUser = userId; if (Program.UseEventHub) { await _eventHub.SendMessage(new QueueElement <ActivityJoinViewModel> { Type = "ActivityJoin", Data = new ActivityJoinViewModel() { IdActivity = id, IdUser = userId }, }); } else { var queue = new ServiceBusManager(_configuration["ServiceBusConnectionString"], _configuration["ServiceBusQueueName"]); await queue.SendMessage(new QueueElement <ActivityJoinViewModel> { Type = "ActivityJoin", Data = new ActivityJoinViewModel() { IdActivity = id, IdUser = userId }, }); } return(RedirectToAction("Index")); } return(BadRequest(ModelState)); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { serviceBusManager = _componentContext.Resolve <ServiceBusManager>(); var serviceBusHelper = serviceBusManager.InitHelper(ServiceBusManager.QUEUE1); serviceBusHelper.OnException = ExceptionReceivedHandler; serviceBusHelper.Receive((messageArgs, token) => { Console.WriteLine("ServiceBus: received: {0}", messageArgs.GetDataAsString()); return(Task.FromResult(true)); }); while (!stoppingToken.IsCancellationRequested) { await Task.Delay(60000, stoppingToken); } }
public AzureServiceBus() { _messages = new List <Message>(); _taskExceptions = new List <Task>(); var config = ConfigurationManager.Configuration.GetSection("serviceBus").Get <ServiceBusConfiguration>(); var credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(config.ClientId, config.ClientSecret, config.TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, config.SubscriptionId); _serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(config.ResourceGroup, config.NamespaceName); }
public Deploy(ILogger Logger) { var Deploy_ClientId = ConfigurationManager.AppSettings["Deploy_ClientId"]; var Deploy_ClientSecret = ConfigurationManager.AppSettings["Deploy_ClientSecret"]; var Deploy_TenantId = ConfigurationManager.AppSettings["Deploy_TenantId"]; var Deploy_SubscriptionId = ConfigurationManager.AppSettings["Deploy_SubscriptionId"]; var Deploy_ResourceGroupName = ConfigurationManager.AppSettings["Deploy_ResourceGroupName"]; var Deploy_ServiceBusNamespaceName = ConfigurationManager.AppSettings["Deploy_ServiceBusNamespaceName"]; var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(Deploy_ClientId, Deploy_ClientSecret, Deploy_TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager.Authenticate(credentials, Deploy_SubscriptionId); _serviceBusNamespace = serviceBusManager.Namespaces.GetByResourceGroup(Deploy_ResourceGroupName, Deploy_ServiceBusNamespaceName); _log = Logger; }
static async Task Main() { // Build configuration var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .Build(); IConfiguration configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); config = builder.GetSection("serviceBus").Get <ServiceBusConfiguration>(); var credentials = SdkContext.AzureCredentialsFactory .FromServicePrincipal(config.ClientId, config.ClientSecret, config.TenantId, AzureEnvironment.AzureGlobalCloud); var serviceBusManager = ServiceBusManager .Authenticate(credentials, config.SubscriptionId); serviceBus = serviceBusManager.Namespaces .GetByResourceGroup(config.ResourceGroup, config.NamespaceName); Console.WriteLine("Reconhecimento de Rotulos:"); Console.Write("Insira o caminho completo da imagem e de enter"); string imageFilePath = Console.ReadLine(); if (File.Exists(imageFilePath)) { Console.WriteLine("\n Aguarde os resultados.\n"); await MakeOCRRequest(imageFilePath); } else { Console.WriteLine("\nCaminho inválido"); } Console.WriteLine("\nPressione ENTER para sair..."); Console.ReadLine(); }