private void TreeViewAdv1_BeforeExpand(object sender, TreeViewAdvCancelableNodeEventArgs e)
        {
            if (e.Node.ExpandedOnce)
            {
                return;
            }
            metadataTree.BeginUpdate();
            var metadata = (EntityMetadata)e.Node.Parent.Tag;

            if (e.Node.Text == "Attributes")
            {
                AttributeMetadataHandler.GetAttributes(metadata.LogicalName, e.Node);
            }
            else if (e.Node.Text == "Relationships")
            {
                RelationshipMetadataHandler.GetRelationships(metadata.LogicalName, e.Node);
            }
            metadataTree.EndUpdate(true);
        }
 public void SelectEntities(string input, Dictionary <string, EntitySelection> value, Exception exception)
 {
     try
     {
         if (exception != null)
         {
             MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else if (value is Dictionary <string, EntitySelection> entitySelection && entitySelection.Any())
         {
             foreach (TreeNodeAdv entityNode in metadataTree.Nodes)
             {
                 EntityMetadata entity = entityNode.Tag as EntityMetadata;
                 if (entitySelection.TryGetValue(entity.LogicalName, out EntitySelection thisSelection))
                 {
                     foreach (TreeNodeAdv node in entityNode.Nodes)
                     {
                         if (node.Text == "Attributes")
                         {
                             if (thisSelection.AllAttributes)
                             {
                                 node.Checked = true;
                             }
                             else if (thisSelection.SelectedAttributes.Any() && !node.ExpandedOnce)
                             {
                                 attributeMetadataHandler.GetAttributes(entity.LogicalName, node, false, thisSelection.SelectedAttributes);
                             }
                             else if (thisSelection.SelectedAttributes.Any() && node.ExpandedOnce)
                             {
                                 foreach (TreeNodeAdv attributeNode in node.Nodes)
                                 {
                                     if (attributeNode.Tag is AttributeMetadata attribute)
                                     {
                                         attributeNode.Checked = thisSelection.SelectedAttributes.Contains(attribute.LogicalName);
                                     }
                                 }
                             }
                         }
                         else if (node.Text == "Relationships")
                         {
                             if (thisSelection.AllRelationships)
                             {
                                 node.Checked = true;
                             }
                             else if (thisSelection.SelectedRelationships.Any() && !node.ExpandedOnce)
                             {
                                 relationshipMetadataHandler.GetRelationships(entity.LogicalName, node, false, thisSelection.SelectedRelationships);
                             }
                             else if (thisSelection.SelectedRelationships.Any() && node.ExpandedOnce)
                             {
                                 foreach (TreeNodeAdv relationshipNode in node.Nodes)
                                 {
                                     if (relationshipNode.Tag is RelationshipMetadataBase relationshipMetadata)
                                     {
                                         relationshipNode.Checked = thisSelection.SelectedRelationships.Contains(relationshipMetadata.SchemaName);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }