public static QueueStatusDTO FromServerAndQueue(Server server, Queue queue) { var result = new QueueStatusDTO { ServerName = server.Name, QueueName = queue.Name, Messages = queue.Messages, Rates = queue.Rates, IsEnable = queue.IsEnable, YellowThreshold = queue.YellowThreshold, RedThreshold = queue.RedThreshold }; return result; }
public static Queue ForServer(Server server, string queueName, string friendlyName) { return new Queue { Name = queueName, FriendlyName = friendlyName, ServerId = server.ServerId, VirtualHost = server.VirtualHost, LastUpdatedOn = DateTime.Now }; }
private async Task RefreshServers(Server server) { try { using (var repository = _repositoryFactory()) { OnReport(this, new DataEventArgs<string>(string.Format("Updating Server: [{0}]", server.Name))); using (var adapter = new RabbitServiceBusAdapter()) { adapter.ConnectTo(server.Address, server.UserName, server.Password); OnReport(this, new DataEventArgs<string>("Connected to Server")); server.IsAlive = adapter.IsServerAlive(server.VirtualHost); server.LastUpdatedOn = DateTime.Now; repository.Update(server); if (server.IsAlive) { RefreshServerQueues(server, repository, adapter); } } IntroduceFakeDelayToSimulateConcurrency(); await repository.Context.SaveChangesAsync(); } } catch (Exception e) { OnError(this, new DataEventArgs<Exception>(e)); } }
private void RefreshServerQueues(Server server, RabbitMonitorRepository repository, RabbitServiceBusAdapter adapter) { var queuesInStore = repository.GetQueues().Where(x => x.ServerId == server.ServerId); var queues = adapter.GetServerQueues(); OnReport(this, new DataEventArgs<string>(string.Format("Updating [{0}] Queues", queues.Count()))); queues.ToList().ForEach(x => { var storeQueue = queuesInStore.FirstOrDefault(q => q.Name == x.Name); if (storeQueue == null) { storeQueue = Queue.ForServer(server, x.Name, x.Name); repository.Create<Queue>(storeQueue); repository.Context.SaveChanges(); } if (storeQueue.IsEnable) { storeQueue.Messages = new Messages(x.MessagesReady, x.MessagesUnacknowledged); storeQueue.Rates = new MessageRates(x.BackingQueueStatus.AvgIngressRate, x.BackingQueueStatus.AvgEgressRate, x.BackingQueueStatus.AvgAckEgressRate); storeQueue.Status = String.IsNullOrWhiteSpace(x.IdleSince) ? QueueStatus.Active : QueueStatus.Idle; storeQueue.LastUpdatedOn = DateTime.Now; repository.Update<Queue>(storeQueue); } }); repository.Context.SaveChanges(); }