public MyPluginControl() { InitializeComponent(); MyPluginFactory = new Factories.MyPluginFactory(); AttributeMetadataHandler = MyPluginFactory.NewAttributeMetadataHandler(this); CoreToolsDownloader = MyPluginFactory.NewCoreToolsDownloader(this); EntityGeneratorHandler = MyPluginFactory.NewEntityGeneratorHandler(this, metadataTree); EntityMetadataHandler = MyPluginFactory.NewEntityMetadataHandler(this, metadataTree); RelationshipMetadataHandler = MyPluginFactory.NewRelationshipMetadataHandler(this); treeEventHandler = new TreeViewAdvBeforeCheckEventHandler(this.MetadataTree_BeforeCheck); this.metadataTree.BeforeCheck += treeEventHandler; }
public MyPluginControl() { InitializeComponent(); MyPluginFactory = new Factories.MyPluginFactory(); AttributeMetadataHandler = MyPluginFactory.NewAttributeMetadataHandler(this); CoreToolsDownloader = MyPluginFactory.NewCoreToolsDownloader(this); EntityGeneratorHandler = MyPluginFactory.NewEntityGeneratorHandler(this, metadataTree, txtOutput); EntityMetadataHandler = MyPluginFactory.NewEntityMetadataHandler(this, metadataTree); RelationshipMetadataHandler = MyPluginFactory.NewRelationshipMetadataHandler(this); pluginViewModel = MyPluginFactory.NewPluginViewModel(); treeEventHandler = new TreeViewAdvBeforeCheckEventHandler(this.MetadataTree_BeforeCheck); this.metadataTree.BeforeCheck += treeEventHandler; btnGenerateEntities.Enabled = pluginViewModel.Generate_Enabled; btnGetMetadata.Enabled = pluginViewModel.ActiveConnection; DataBind(); }
public MyPluginControl() { InitializeComponent(); MyPluginFactory = Factories.MyPluginFactory.GetMyPluginFactory(this); pluginViewModel = MyPluginFactory.NewPluginViewModel(); BackgroundWorkHandler = MyPluginFactory.NewBackgroundWorkHandler(); AttributeMetadataHandler = MyPluginFactory.NewAttributeMetadataHandler(); CoreToolsDownloader = MyPluginFactory.NewCoreToolsDownloader(); EntityGeneratorHandler = MyPluginFactory.NewEntityGeneratorHandler(metadataTree, txtOutput); RelationshipMetadataHandler = MyPluginFactory.NewRelationshipMetadataHandler(); EntitySelectionHandler = MyPluginFactory.NewEntitySelectionHandler(metadataTree, AttributeMetadataHandler, RelationshipMetadataHandler); EntityMetadataHandler = MyPluginFactory.NewEntityMetadataHandler(metadataTree, EntitySelectionHandler); treeEventHandler = new TreeViewAdvBeforeCheckEventHandler(this.MetadataTree_BeforeCheck); this.metadataTree.BeforeCheck += treeEventHandler; btnGenerateEntities.Enabled = pluginViewModel.Generate_Enabled; mnuSelectGenerated.Visible = pluginViewModel.Generate_Enabled; mnuSelectNone.Visible = pluginViewModel.Generate_Enabled; btnGetMetadata.Enabled = pluginViewModel.ActiveConnection; mnuGetMetadata.Enabled = pluginViewModel.ActiveConnection; mnuSelectAll.Enabled = pluginViewModel.ActiveConnection; mnuCopyCommand.Enabled = pluginViewModel.LaunchCommandEnabled; DataBind(); }
private void MetadataTree_BeforeCheck(object sender, TreeNodeAdvBeforeCheckEventArgs e) { if (e.Node.Tag is RelationshipMetadataBase) { string entity1; string entity2; string schemaName; MessageBox.Show($"{sender}"); if (e.Node.Tag is OneToManyRelationshipMetadata) { var metadata = (OneToManyRelationshipMetadata)e.Node.Tag; entity1 = metadata.ReferencingEntity; entity2 = metadata.ReferencedEntity; schemaName = metadata.SchemaName; } else { var metadata = (ManyToManyRelationshipMetadata)e.Node.Tag; entity1 = metadata.Entity1LogicalName; entity2 = metadata.Entity2LogicalName; schemaName = metadata.SchemaName; } MessageBox.Show($"{schemaName} {entity1} {entity2}"); foreach (TreeNodeAdv entity in metadataTree.Nodes) { var entityName = ((EntityMetadata)entity.Tag).LogicalName; if (entityName == entity1 || entityName == entity2) { foreach (TreeNodeAdv item in entity.Nodes) { if (item.Text == "Relationships") { if (!item.ExpandedOnce) { WorkAsync(new WorkAsyncInfo { Message = $"Getting relationships for entity {entityName}", Work = (worker, args) => { args.Result = Service.Execute(new RetrieveEntityRequest() { EntityFilters = EntityFilters.Relationships, LogicalName = entityName }); }, PostWorkCallBack = (args) => { if (args.Error != null) { MessageBox.Show(args.Error.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } var result = args.Result as RetrieveEntityResponse; if (result != null) { item.ExpandedOnce = true; foreach (var relationship in result.EntityMetadata.ManyToManyRelationships.Union <RelationshipMetadataBase>( result.EntityMetadata.OneToManyRelationships).Union( result.EntityMetadata.ManyToOneRelationships).OrderBy(x => x.SchemaName)) { TreeNodeAdv node = new TreeNodeAdv($"{relationship.SchemaName}") { ExpandedOnce = true, ShowCheckBox = true, Tag = relationship }; if (schemaName == relationship.SchemaName) { node.CheckState = e.NewCheckState; } item.Nodes.Add(node); } } } }); } else { foreach (TreeNodeAdv relationship in item.Nodes) { if (relationship == e.Node) { continue; } if (((RelationshipMetadataBase)relationship.Tag).SchemaName == schemaName) { MessageBox.Show($"{schemaName} {entityName}"); this.metadataTree.BeforeCheck -= treeEventHandler; relationship.CheckState = e.NewCheckState; treeEventHandler = new TreeViewAdvBeforeCheckEventHandler(this.MetadataTree_BeforeCheck); this.metadataTree.BeforeCheck += treeEventHandler; } } } } } } } } }
private void MetadataTree_BeforeCheck(object sender, TreeNodeAdvBeforeCheckEventArgs e) { if (e.Node.Tag as RelationshipMetadataBase != null) { if (!options.CoupledRelationships) { return; } string entity1 = ""; string entity2 = ""; string schemaName = ""; if (e.Node.Tag is OneToManyRelationshipMetadata oneToMany) { entity1 = oneToMany.ReferencingEntity; entity2 = oneToMany.ReferencedEntity; schemaName = oneToMany.SchemaName; } else if (e.Node.Tag is ManyToManyRelationshipMetadata manyToMany) { entity1 = manyToMany.Entity1LogicalName; entity2 = manyToMany.Entity2LogicalName; schemaName = manyToMany.SchemaName; } foreach (TreeNodeAdv entity in metadataTree.Nodes) { var entityName = ((EntityMetadata)entity.Tag).LogicalName; if (entityName == entity1 || entityName == entity2) { foreach (TreeNodeAdv item in entity.Nodes) { if (item.Text == "Relationships") { if (!item.ExpandedOnce) { BackgroundWorkHandler.EnqueueBackgroundWork( AlBackgroundWorkerFactory.NewWorker <string, RetrieveEntityResponse>( work: RetrieveRelationships, argument: entityName, workFinished: (string argument, RetrieveEntityResponse value, Exception exception) => { try { if (exception != null) { MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (value is RetrieveEntityResponse result) { item.ExpandedOnce = true; var entityMetadata = entityMetadatas.FirstOrDefault(x => x.LogicalName == entityName); entityMetadata.SetPrivateValue(x => x.ManyToManyRelationships, result.EntityMetadata.ManyToManyRelationships); entityMetadata.SetPrivateValue(x => x.OneToManyRelationships, result.EntityMetadata.OneToManyRelationships); entityMetadata.SetPrivateValue(x => x.ManyToOneRelationships, result.EntityMetadata.ManyToOneRelationships); foreach (var relationship in result.EntityMetadata.ManyToManyRelationships.Union <RelationshipMetadataBase>( result.EntityMetadata.OneToManyRelationships).Union( result.EntityMetadata.ManyToOneRelationships).OrderBy(x => x.SchemaName)) { TreeNodeAdv node = new TreeNodeAdv($"{relationship.SchemaName}") { ExpandedOnce = true, ShowCheckBox = true, Tag = relationship }; if (schemaName == relationship.SchemaName) { node.CheckState = e.NewCheckState; } item.Nodes.Add(node); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }).WithViewModel(pluginViewModel).WithMessage(this, string.Format(CultureInfo.CurrentCulture, Resources.GETTING_RELATIONSHIPS, entityName))); } else { foreach (TreeNodeAdv relationship in item.Nodes) { if (relationship == e.Node) { continue; } if (((RelationshipMetadataBase)relationship.Tag).SchemaName == schemaName) { this.metadataTree.BeforeCheck -= treeEventHandler; relationship.CheckState = e.NewCheckState; treeEventHandler = new TreeViewAdvBeforeCheckEventHandler(this.MetadataTree_BeforeCheck); this.metadataTree.BeforeCheck += treeEventHandler; } } } } } } } } else if (e.Node.Text == "Attributes" && e.NewCheckState == CheckState.Checked && !e.Node.ExpandedOnce) { AttributeMetadataHandler.GetAttributes(((EntityMetadata)e.Node.Parent.Tag).LogicalName, e.Node, checkedState: true); } else if (e.Node.Text == "Relationships" && e.NewCheckState == CheckState.Checked && !e.Node.ExpandedOnce) { RelationshipMetadataHandler.GetRelationships(((EntityMetadata)e.Node.Parent.Tag).LogicalName, e.Node, checkedState: true); } }