/// <summary> /// Актуализация разрешений в RabbitMQ. /// </summary> /// <param name="clientId">ID клиента для актуализации разрешений.</param> public void SynchronizeSendingPermissions(string clientId = null) { if (string.IsNullOrEmpty(clientId)) { List <Task> tasks = new List <Task>(); List <SendingPermission> esbPermissions = _dataService.Query <SendingPermission>(SendingPermission.Views.ServiceBusView).ToList(); List <string> usersIds = esbPermissions.Select(p => p.Client.ID).Distinct().ToList(); foreach (string id in usersIds) { _mqSubscriptionsManager.CreateClient(id, id); User user = _managementClient.GetUserAsync(id).Result; tasks.Add(SynchronizePermissionsForClient(user, esbPermissions)); } List <Permission> mqPermissions = _managementClient.GetPermissionsAsync().Result.Where(p => !usersIds.Contains(p.User) && p.User != ConfigurationManager.AppSettings["DefaultRmqUserName"]).ToList(); foreach (Permission mqPermission in mqPermissions) { User user = _managementClient.GetUserAsync(mqPermission.User).Result; tasks.Add(_managementClient.CreatePermissionAsync(CreatePermissionInfo(user))); } Task.WaitAll(tasks.ToArray()); } else { User user = _managementClient.GetUserAsync(clientId).Result; SynchronizePermissionsForClient(user).Wait(); } }