예제 #1
0
        /// <summary>
        /// Adds a node to the treeview for the newly created entity.
        /// </summary>
        /// <param name="args">The ServiceBusHelperEventArgs object containing the reference to the newly created entity.</param>
        // ReSharper disable once FunctionComplexityOverflow
        void serviceBusHelper_OnCreate(ServiceBusHelperEventArgs args)
        {
            try
            {
                serviceBusTreeView.SuspendDrawing();
                serviceBusTreeView.SuspendLayout();
                // QueueDescription Entity
                if (args.EntityType == EntityType.Queue)
                {
                    var queue = args.EntityInstance as QueueDescription;
                    if (queue != null)
                    {
                        var queueListNode = FindNode(QueueEntities, rootNode);
                        var node = CreateNode(queue.Path, queue, queueListNode, false);
                        if (node == null)
                        {
                            return;
                        }
                        serviceBusTreeView.Sort();
                        panelMain.HeaderText = string.Format(ViewQueueFormat, queue.Path);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = node;
                            node.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                        else
                        {
                            queueListNode.Expand();
                        }
                    }
                    return;
                }
                // TopicDescription Entity
                if (args.EntityType == EntityType.Topic)
                {
                    var topic = args.EntityInstance as TopicDescription;
                    if (topic != null)
                    {
                        var topicListNode = FindNode(TopicEntities, rootNode);
                        var node = CreateNode(topic.Path, topic, topicListNode, false);
                        if (node == null)
                        {
                            return;
                        }
                        serviceBusTreeView.Sort();
                        panelMain.HeaderText = string.Format(ViewTopicFormat, topic.Path);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = node;
                            node.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                        else
                        {
                            topicListNode.Expand();
                        }
                    }
                    return;
                }
                // RelayDescription Entity
                if (args.EntityType == EntityType.Relay)
                {
                    var relay = args.EntityInstance as RelayDescription;
                    if (relay != null)
                    {
                        var relayListNode = FindNode(RelayEntities, rootNode);
                        var node = CreateNode(relay.Path, relay, relayListNode, false);
                        if (node == null)
                        {
                            return;
                        }
                        serviceBusTreeView.Sort();
                        panelMain.HeaderText = string.Format(ViewRelayFormat, relay.Path);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = node;
                            node.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                        else
                        {
                            relayListNode.Expand();
                        }
                    }
                    return;
                }
                // EventHubDescription Entity
                if (args.EntityType == EntityType.EventHub)
                {
                    var eventHub = args.EntityInstance as EventHubDescription;
                    if (eventHub != null)
                    {
                        var eventHubListNode = FindNode(EventHubEntities, rootNode);
                        var node = CreateNode(eventHub.Path, eventHub, eventHubListNode, false);
                        if (node == null)
                        {
                            return;
                        }
                        serviceBusTreeView.Sort();
                        panelMain.HeaderText = string.Format(ViewEventHubFormat, eventHub.Path);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = node;
                            node.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                        else
                        {
                            eventHubListNode.Expand();
                        }
                    }
                    return;
                }
                // NotificationHubDescription Entity
                if (args.EntityType == EntityType.NotificationHub)
                {
                    var notificationHub = args.EntityInstance as NotificationHubDescription;
                    if (notificationHub != null)
                    {
                        var notificationHubListNode = FindNode(NotificationHubEntities, rootNode);
                        var node = CreateNode(notificationHub.Path, notificationHub, notificationHubListNode, false);
                        if (node == null)
                        {
                            return;
                        }
                        serviceBusTreeView.Sort();
                        panelMain.HeaderText = string.Format(ViewNotificationHubFormat, notificationHub.Path);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = node;
                            node.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                        else
                        {
                            notificationHubListNode.Expand();
                        }
                    }
                    return;
                }
                // SubscriptionDescription Entity
                if (args.EntityType == EntityType.Subscription)
                {
                    var wrapper = args.EntityInstance as SubscriptionWrapper;
                    if (wrapper == null ||
                        wrapper.TopicDescription == null ||
                        wrapper.SubscriptionDescription == null)
                    {
                        return;
                    }
                    var topicListNode = FindNode(TopicEntities, rootNode);
                    var topicNode = FindNode(wrapper.TopicDescription.Path, topicListNode);
                    if (topicNode != null)
                    {
                        TreeNode subscriptionsNode;

                        if (topicNode.Nodes.ContainsKey(SubscriptionEntities))
                        {
                            subscriptionsNode = topicNode.Nodes[SubscriptionEntities];
                        }
                        else
                        {
                            subscriptionsNode = topicNode.Nodes.Add(SubscriptionEntities,
                                                                    SubscriptionEntities,
                                                                    wrapper.SubscriptionDescription.Status == EntityStatus.Active ? SubscriptionListIconIndex : GreySubscriptionIconIndex,
                                                                    wrapper.SubscriptionDescription.Status == EntityStatus.Active ? SubscriptionListIconIndex : GreySubscriptionIconIndex);
                            subscriptionsNode.ContextMenuStrip = subscriptionsContextMenuStrip;
                            subscriptionsNode.Tag = new SubscriptionWrapper(null, wrapper.TopicDescription, FilterExpressionHelper.SubscriptionFilterExpression);
                        }
                        var subscriptionNode = subscriptionsNode.Nodes.Add(wrapper.SubscriptionDescription.Name,
                                                                           showMessageCount ?
                                                                           string.Format(NameMessageCountFormat,
                                                                                         wrapper.SubscriptionDescription.Name,
                                                                                         wrapper.SubscriptionDescription.MessageCountDetails.ActiveMessageCount,
                                                                                         wrapper.SubscriptionDescription.MessageCountDetails.DeadLetterMessageCount) :
                                                                           wrapper.SubscriptionDescription.Name,
                                                                           wrapper.SubscriptionDescription.Status == EntityStatus.Active ? SubscriptionIconIndex : GreySubscriptionIconIndex,
                                                                           wrapper.SubscriptionDescription.Status == EntityStatus.Active ? SubscriptionIconIndex : GreySubscriptionIconIndex);
                        subscriptionNode.ContextMenuStrip = subscriptionContextMenuStrip;
                        subscriptionNode.Tag = new SubscriptionWrapper(wrapper.SubscriptionDescription, wrapper.TopicDescription);
                        subscriptionsNode.Expand();
                        panelMain.HeaderText = string.Format(ViewSubscriptionFormat, wrapper.SubscriptionDescription.Name);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = subscriptionsNode.Nodes[wrapper.SubscriptionDescription.Name];
                            serviceBusTreeView.SelectedNode.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                        var rules = serviceBusHelper.GetRules(wrapper.SubscriptionDescription);
                        var ruleDescriptions = rules as RuleDescription[] ?? rules.ToArray();
                        if (rules != null &&
                            ruleDescriptions.Any())
                        {
                            subscriptionNode.Nodes.Clear();
                            var rulesNode = subscriptionNode.Nodes.Add(RuleEntities, RuleEntities, RuleListIconIndex, RuleListIconIndex);
                            rulesNode.ContextMenuStrip = rulesContextMenuStrip;
                            rulesNode.Tag = new RuleWrapper(null, wrapper.SubscriptionDescription);
                            foreach (var rule in ruleDescriptions)
                            {
                                var ruleNode = rulesNode.Nodes.Add(rule.Name, rule.Name, RuleIconIndex, RuleIconIndex);
                                ruleNode.ContextMenuStrip = ruleContextMenuStrip;
                                ruleNode.Tag = new RuleWrapper(rule, wrapper.SubscriptionDescription);
                            }
                        }
                    }
                    return;
                }
                // RuleDescription Entity
                if (args.EntityType == EntityType.Rule)
                {
                    var wrapper = args.EntityInstance as RuleWrapper;
                    if (wrapper == null ||
                        wrapper.SubscriptionDescription == null ||
                        wrapper.RuleDescription == null)
                    {
                        return;
                    }
                    var topicListNode = FindNode(TopicEntities, rootNode);
                    var topicNode = FindNode(wrapper.SubscriptionDescription.TopicPath, topicListNode);
                    if (topicNode != null)
                    {
                        if (topicNode.Nodes.ContainsKey(SubscriptionEntities))
                        {
                            var subscriptionsNode = topicNode.Nodes[SubscriptionEntities];
                            if (subscriptionsNode.Nodes.ContainsKey(wrapper.SubscriptionDescription.Name))
                            {
                                var subscriptionNode = subscriptionsNode.Nodes[wrapper.SubscriptionDescription.Name];
                                TreeNode rulesNode;
                                if (subscriptionNode.Nodes.ContainsKey(RuleEntities))
                                {
                                    rulesNode = subscriptionNode.Nodes[RuleEntities];
                                }
                                else
                                {
                                    rulesNode = subscriptionNode.Nodes.Add(RuleEntities, RuleEntities, RuleListIconIndex, RuleListIconIndex);
                                    rulesNode.ContextMenuStrip = rulesContextMenuStrip;
                                    rulesNode.Tag = new RuleWrapper(null, wrapper.SubscriptionDescription);
                                }
                                var ruleNode = rulesNode.Nodes.Add(wrapper.RuleDescription.Name, wrapper.RuleDescription.Name, RuleIconIndex, RuleIconIndex);
                                ruleNode.ContextMenuStrip = ruleContextMenuStrip;
                                ruleNode.Tag = wrapper;
                                rulesNode.Expand();
                                panelMain.HeaderText = string.Format(ViewRuleFormat, wrapper.RuleDescription.Name);
                                if (!importing)
                                {
                                    serviceBusTreeView.SelectedNode = rulesNode.Nodes[wrapper.RuleDescription.Name];
                                    serviceBusTreeView.SelectedNode.EnsureVisible();
                                }
                            }
                        }
                    }
                }
                // ConsumerGroupDescription Entity
                if (args.EntityType == EntityType.ConsumerGroup)
                {
                    var consumerGroupDescription = args.EntityInstance as ConsumerGroupDescription;
                    if (consumerGroupDescription == null)
                    {
                        return;
                    }
                    var eventHubListNode = FindNode(EventHubEntities, rootNode);
                    var eventHubNode = FindNode(consumerGroupDescription.EventHubPath, eventHubListNode);
                    if (eventHubNode != null)
                    {
                        TreeNode consumerGroupsNode;

                        if (eventHubNode.Nodes.ContainsKey(ConsumerGroupEntities))
                        {
                            consumerGroupsNode = eventHubNode.Nodes[ConsumerGroupEntities];
                        }
                        else
                        {
                            consumerGroupsNode = eventHubNode.Nodes.Add(ConsumerGroupEntities, ConsumerGroupEntities, ConsumerGroupListIconIndex, ConsumerGroupListIconIndex);
                            consumerGroupsNode.ContextMenuStrip = consumerGroupsContextMenuStrip;
                            consumerGroupsNode.Tag = eventHubNode.Tag;
                        }
                        var eventHubDescription = eventHubNode.Tag as EventHubDescription;
                        if (eventHubDescription == null)
                        {
                            return;
                        }

                        var partitions = GetPartitionsFromDefaultConsumerGroup(eventHubNode) ??
                                         GetPartitionsFromPartitionIds(eventHubDescription);
                        var partitionDescriptions = partitions as IList<PartitionDescription> ?? partitions.ToList();
                        var consumerGroupNode = CreateEventHubConsumerGroupNode(eventHubDescription, consumerGroupDescription, partitionDescriptions, consumerGroupsNode);
                        if (consumerGroupNode == null)
                        {
                            return;
                        }
                        consumerGroupNode.ContextMenuStrip = consumerGroupContextMenuStrip;
                        consumerGroupNode.Tag = consumerGroupDescription;
                        consumerGroupsNode.Expand();
                        panelMain.HeaderText = string.Format(ViewConsumerGroupFormat, consumerGroupDescription.Name);
                        if (!importing)
                        {
                            serviceBusTreeView.SelectedNode = consumerGroupsNode.Nodes[consumerGroupDescription.Name];
                            serviceBusTreeView.SelectedNode.EnsureVisible();
                            HandleNodeMouseClick(serviceBusTreeView.SelectedNode);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                serviceBusTreeView.ResumeDrawing();
                serviceBusTreeView.ResumeLayout();
            }
        }
예제 #2
0
 /// <summary>
 /// Individuates and remove the node corresponding to the deleted entity.
 /// </summary>
 /// <param name="args">The ServiceBusHelperEventArgs object containing the reference to the deleted entity.</param>
 void serviceBusHelper_OnDelete(ServiceBusHelperEventArgs args)
 {
     try
     {
         serviceBusTreeView.SuspendDrawing();
         serviceBusTreeView.SuspendLayout();
         foreach (var userControl in panelMain.Controls.OfType<UserControl>())
         {
             userControl.Dispose();
         }
         panelMain.Controls.Clear();
         panelMain.BackColor = SystemColors.Window;
         panelMain.HeaderText = Entity;
         serviceBusTreeView.SelectedNode = rootNode;
         rootNode.EnsureVisible();
         // QueueDescription Entity
         if (args.EntityType == EntityType.Queue)
         {
             string queueName = null;
             if (args.EntityInstance is string)
             {
                 queueName = args.EntityInstance as string;
             }
             else
             {
                 var queueDescription = args.EntityInstance as QueueDescription;
                 if (queueDescription != null)
                 {
                     queueName = queueDescription.Path;
                 }
             }
             var queueListNode = FindNode(QueueEntities, rootNode);
             if (!string.IsNullOrWhiteSpace(queueName))
             {
                 DeleteNode(queueName, queueListNode);
             }
             else
             {
                 GetEntities(EntityType.Queue);
             }
             serviceBusTreeView.SelectedNode = queueListNode;
             queueListNode.EnsureVisible();
             HandleNodeMouseClick(queueListNode);
             return;
         }
         // TopicDescription Entity
         if (args.EntityType == EntityType.Topic)
         {
             string topicName = null;
             if (args.EntityInstance is string)
             {
                 topicName = args.EntityInstance as string;
             }
             else
             {
                 var topicDescription = args.EntityInstance as TopicDescription;
                 if (topicDescription != null)
                 {
                     topicName = topicDescription.Path;
                 }
             }
             var topicListNode = FindNode(TopicEntities, rootNode);
             if (!string.IsNullOrWhiteSpace(topicName))
             {
                 DeleteNode(topicName, topicListNode);
             }
             else
             {
                 GetEntities(EntityType.Topic);
             }
             serviceBusTreeView.SelectedNode = topicListNode;
             topicListNode.EnsureVisible();
             HandleNodeMouseClick(topicListNode);
             return;
         }
         // RelayDescription Entity
         if (args.EntityType == EntityType.Relay)
         {
             string relayName = null;
             if (args.EntityInstance is string)
             {
                 relayName = args.EntityInstance as string;
             }
             else
             {
                 var relayDescription = args.EntityInstance as RelayDescription;
                 if (relayDescription != null)
                 {
                     relayName = relayDescription.Path;
                 }
             }
             var relayListNode = FindNode(RelayEntities, rootNode);
             if (!string.IsNullOrWhiteSpace(relayName))
             {
                 DeleteNode(relayName, relayListNode);
             }
             else
             {
                 GetEntities(EntityType.Relay);
             }
             serviceBusTreeView.SelectedNode = relayListNode;
             relayListNode.EnsureVisible();
             HandleNodeMouseClick(relayListNode);
             return;
         }
         // EventHubDescription Entity
         if (args.EntityType == EntityType.EventHub)
         {
             string eventHubName = null;
             if (args.EntityInstance is string)
             {
                 eventHubName = args.EntityInstance as string;
             }
             else
             {
                 var eventHubDescription = args.EntityInstance as EventHubDescription;
                 if (eventHubDescription != null)
                 {
                     eventHubName = eventHubDescription.Path;
                 }
             }
             var eventHubListNode = FindNode(EventHubEntities, rootNode);
             if (!string.IsNullOrWhiteSpace(eventHubName))
             {
                 DeleteNode(eventHubName, eventHubListNode);
             }
             else
             {
                 GetEntities(EntityType.EventHub);
             }
             serviceBusTreeView.SelectedNode = eventHubListNode;
             eventHubListNode.EnsureVisible();
             HandleNodeMouseClick(eventHubListNode);
             return;
         }
         // NotificationHubDescription Entity
         if (args.EntityType == EntityType.NotificationHub)
         {
             string notificationHubName = null;
             if (args.EntityInstance is string)
             {
                 notificationHubName = args.EntityInstance as string;
             }
             else
             {
                 var notificationHubDescription = args.EntityInstance as NotificationHubDescription;
                 if (notificationHubDescription != null)
                 {
                     notificationHubName = notificationHubDescription.Path;
                 }
             }
             var notificationHubListNode = FindNode(NotificationHubEntities, rootNode);
             if (!string.IsNullOrWhiteSpace(notificationHubName))
             {
                 DeleteNode(notificationHubName, notificationHubListNode);
             }
             else
             {
                 GetEntities(EntityType.NotificationHub);
             }
             serviceBusTreeView.SelectedNode = notificationHubListNode;
             notificationHubListNode.EnsureVisible();
             HandleNodeMouseClick(notificationHubListNode);
             return;
         }
         // SubscriptionDescription Entity
         if (args.EntityType == EntityType.Subscription)
         {
             var topicListNode = FindNode(TopicEntities, rootNode);
             var subscription = args.EntityInstance as SubscriptionDescription;
             if (subscription != null &&
                 !string.IsNullOrWhiteSpace(subscription.TopicPath))
             {
                 var topicNode = FindNode(subscription.TopicPath, topicListNode);
                 if (topicNode == null)
                 {
                     GetEntities(EntityType.Topic);
                     return;
                 }
                 if (topicNode.Nodes.ContainsKey(SubscriptionEntities))
                 {
                     var subscriptionsNode = topicNode.Nodes[SubscriptionEntities];
                     if (subscriptionsNode.Nodes.ContainsKey(subscription.Name))
                     {
                         subscriptionsNode.Nodes.RemoveByKey(subscription.Name);
                         if (subscriptionsNode.Nodes.Count == 0)
                         {
                             topicNode.Nodes.Clear();
                             serviceBusTreeView.SelectedNode = topicNode;
                             topicNode.EnsureVisible();
                             HandleNodeMouseClick(topicNode);
                         }
                         else
                         {
                             subscriptionsNode.Expand();
                             serviceBusTreeView.SelectedNode = subscriptionsNode;
                             subscriptionsNode.EnsureVisible();
                             HandleNodeMouseClick(subscriptionsNode);
                         }
                     }
                     else
                     {
                         GetEntities(EntityType.Topic);
                         return;
                     }
                 }
                 else
                 {
                     GetEntities(EntityType.Topic);
                     return;
                 }
             }
             else
             {
                 GetEntities(EntityType.Topic);
                 return;
             }
             serviceBusTreeView.SelectedNode = null;
             return;
         }
         // RuleDescription Entity
         if (args.EntityType == EntityType.Rule)
         {
             var topicListNode = FindNode(TopicEntities, rootNode);
             var wrapper = args.EntityInstance as RuleWrapper;
             if (wrapper != null &&
                 wrapper.RuleDescription != null &&
                 wrapper.SubscriptionDescription != null &&
                 !string.IsNullOrWhiteSpace(wrapper.RuleDescription.Name) &&
                 !string.IsNullOrWhiteSpace(wrapper.SubscriptionDescription.TopicPath))
             {
                 var topicNode = FindNode(wrapper.SubscriptionDescription.TopicPath, topicListNode);
                 if (topicNode == null)
                 {
                     GetEntities(EntityType.Topic);
                     return;
                 }
                 if (topicNode.Nodes.ContainsKey(SubscriptionEntities))
                 {
                     var subscriptionsNode = topicNode.Nodes[SubscriptionEntities];
                     if (subscriptionsNode.Nodes.ContainsKey(wrapper.SubscriptionDescription.Name))
                     {
                         var subscriptionNode = subscriptionsNode.Nodes[wrapper.SubscriptionDescription.Name];
                         if (subscriptionNode.Nodes.ContainsKey(RuleEntities))
                         {
                             var rulesNode = subscriptionNode.Nodes[RuleEntities];
                             if (rulesNode.Nodes.ContainsKey(wrapper.RuleDescription.Name))
                             {
                                 rulesNode.Nodes.RemoveByKey(wrapper.RuleDescription.Name);
                                 if (rulesNode.Nodes.Count == 0)
                                 {
                                     subscriptionNode.Nodes.Clear();
                                     serviceBusTreeView.SelectedNode = subscriptionNode;
                                     subscriptionNode.EnsureVisible();
                                     HandleNodeMouseClick(subscriptionsNode);
                                 }
                                 else
                                 {
                                     rulesNode.Expand();
                                     serviceBusTreeView.SelectedNode = rulesNode;
                                     rulesNode.EnsureVisible();
                                     HandleNodeMouseClick(rulesNode);
                                 }
                             }
                         }
                         else
                         {
                             GetEntities(EntityType.Topic);
                             return;
                         }
                     }
                     else
                     {
                         GetEntities(EntityType.Topic);
                         return;
                     }
                 }
                 else
                 {
                     GetEntities(EntityType.Topic);
                     return;
                 }
             }
             else
             {
                 GetEntities(EntityType.Topic);
                 return;
             }
             serviceBusTreeView.SelectedNode = null;
         }
         // ConsumerGroupDescription Entity
         if (args.EntityType == EntityType.ConsumerGroup)
         {
             var eventHubListNode = FindNode(EventHubEntities, rootNode);
             var notificationHub = args.EntityInstance as ConsumerGroupDescription;
             if (notificationHub != null &&
                 !string.IsNullOrWhiteSpace(notificationHub.EventHubPath))
             {
                 var eventHubNode = FindNode(notificationHub.EventHubPath, eventHubListNode);
                 if (eventHubNode == null)
                 {
                     GetEntities(EntityType.EventHub);
                     return;
                 }
                 if (eventHubNode.Nodes.ContainsKey(ConsumerGroupEntities))
                 {
                     var notificationHubsNode = eventHubNode.Nodes[ConsumerGroupEntities];
                     if (notificationHubsNode.Nodes.ContainsKey(notificationHub.Name))
                     {
                         notificationHubsNode.Nodes.RemoveByKey(notificationHub.Name);
                         if (notificationHubsNode.Nodes.Count == 0)
                         {
                             eventHubNode.Nodes.Clear();
                             serviceBusTreeView.SelectedNode = eventHubNode;
                             eventHubNode.EnsureVisible();
                             HandleNodeMouseClick(eventHubNode);
                         }
                         else
                         {
                             notificationHubsNode.Expand();
                             serviceBusTreeView.SelectedNode = notificationHubsNode;
                             notificationHubsNode.EnsureVisible();
                             HandleNodeMouseClick(notificationHubsNode);
                         }
                     }
                     else
                     {
                         GetEntities(EntityType.EventHub);
                         return;
                     }
                 }
                 else
                 {
                     GetEntities(EntityType.EventHub);
                     return;
                 }
             }
             else
             {
                 GetEntities(EntityType.EventHub);
                 return;
             }
             serviceBusTreeView.SelectedNode = null;
         }
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
     finally
     {
         serviceBusTreeView.ResumeDrawing();
         serviceBusTreeView.ResumeLayout();
     }
 }