Skip to content

Commit

Permalink
Merge pull request #15 from CrossBreezeNL/feature/name-unique-issue
Browse files Browse the repository at this point in the history
Solved duplicate name issue and added diagram creation with auto-layout
  • Loading branch information
harmen-xb committed Feb 23, 2023
2 parents 18e0b14 + b6fe29e commit c821120
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 15 deletions.
24 changes: 24 additions & 0 deletions PowerDesigner_OData_AddIn/PdHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,39 @@ public static PdPDM.Package GetOrCreatePackage(PdPDM.BasePackage pdmModel, strin
// If the package wasn't found, create it.
else
{
// Create a new package and set the Name and Code.
PdPDM.Package pdmPackage = (PdPDM.Package)pdmModel.Packages.CreateNew();
pdmPackage.Name = packageNameToFind;
pdmPackage.SetNameToCode();

// Add the new package to the model.
pdmModel.Packages.Add(pdmPackage);

// Return the new package.
return pdmPackage;
}

}

public static void UpdateDiagramResursively(PdPDM.BasePackage packageOrModel)
{
// First update all diagrams in child-packages.
foreach (PdPDM.BasePackage childPackage in packageOrModel.Packages)
{
UpdateDiagramResursively(childPackage);
}

// Set the name of the default diagram to the package name.
PdPDM.PhysicalDiagram defautlDiagram = (PdPDM.PhysicalDiagram)packageOrModel.DefaultDiagram;
defautlDiagram.Name = packageOrModel.Name;
defautlDiagram.SetNameToCode();

// Creates a symbol for each object in package which can be displayed in current diagram.
defautlDiagram.AttachAllObjects();
// Perform auto-layout on the diagram.
defautlDiagram.AutoLayout();
}

public static PdPDM.Package GetPackage(PdPDM.BasePackage pdmModel, string packageNameToFind)
{
var pdmPackageObject = pdmModel.FindChildByName(packageNameToFind, (int)PdPDM.PdPDM_Classes.cls_Package);
Expand Down
3 changes: 3 additions & 0 deletions PowerDesigner_OData_AddIn/PdODataModelUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ public PdPDM.Model CreatePdmModelFromODataMetadata(string pdmModelName, string o
}
}

// Update the all diagrams in the model.
PdHelper.UpdateDiagramResursively(oImportDataModel);

return oImportDataModel;
}

Expand Down
20 changes: 12 additions & 8 deletions PowerDesigner_OData_AddIn/PdODataV3Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode

// Create a new PDM table object for the EntityType.
PdPDM.Table pdmTypeTable = (PdPDM.Table)pdmTypePackage.Tables.CreateNew();
pdmTypeTable.Name = structuredTypeElement.Name;
pdmTypeTable.Name = string.Format("{0}.{1}", structuredTypeElement.Namespace, structuredTypeElement.Name);
pdmTypeTable.Comment = structuredTypeElement.Name;
pdmTypeTable.SetNameToCode();

// Add the columns to the table based on the declared properties.
Expand All @@ -87,10 +88,11 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
logger.Error(string.Format("The type package '{0}' was not found!", entityElement.Namespace));
throw new PdODataException("The type package was not found!");
}
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, entityElement.Name);
string tableName = string.Format("{0}.{1}", entityElement.Namespace, entityElement.Name);
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, tableName);
if (typeTable == null)
{
logger.Error(string.Format("The type table '{0}' was not found!", entityElement.Name));
logger.Error(string.Format("The type table '{0}' was not found!", tableName));
throw new PdODataException("The type table was not found!");
}

Expand All @@ -108,10 +110,11 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
logger.Error(string.Format("The targeted type package '{0}' was not found!", targetedEntityType.Namespace));
throw new PdODataException("The targeted type package was not found!");
}
PdPDM.Table targetedTypeTable = PdHelper.GetTable(pdmTargetEntityTypePackage, targetedEntityType.Name);
string targetedTableName = string.Format("{0}.{1}", targetedEntityType.Namespace, targetedEntityType.Name);
PdPDM.Table targetedTypeTable = PdHelper.GetTable(pdmTargetEntityTypePackage, targetedTableName);
if (targetedTypeTable == null)
{
logger.Error(string.Format("The targeted type table '{0}' was not found!", targetedEntityType.Name));
logger.Error(string.Format("The targeted type table '{0}' was not found!", targetedTableName));
throw new PdODataException("The targeted type table was not found!");
}

Expand Down Expand Up @@ -149,7 +152,7 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
// Find the schema to entity type belongs to, so the table can be added in the right package.
PdPDM.Package pdmEntitySetPackage = PdHelper.GetOrCreatePackage(pdmModel, edmEntitySet.Container.Namespace);
PdPDM.View pdmView = (PdPDM.View)pdmEntitySetPackage.Views.CreateNew();
pdmView.Name = string.Format("{0}.{1}", edmEntitySet.Container.Namespace, edmEntitySet.Name);
pdmView.Name = edmEntitySet.Name;
pdmView.SetNameToCode();

// Find the table which represents the underlying type.
Expand All @@ -159,10 +162,11 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
logger.Error(string.Format("The type package '{0}' was not found!", entityType.Namespace));
throw new PdODataException("The type package was not found!");
}
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, entityType.Name);
string typeTableName = string.Format("{0}.{1}", entityType.Namespace, entityType.Name);
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, typeTableName);
if (typeTable == null)
{
logger.Error(string.Format("The type table '{0}' was not found!", entityType.Name));
logger.Error(string.Format("The type table '{0}' was not found!", typeTableName));
throw new PdODataException("The type table was not found!");
}
// Get a list of the column names.
Expand Down
18 changes: 11 additions & 7 deletions PowerDesigner_OData_AddIn/PdODataV4Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode

// Create a new PDM table object for the EntityType.
PdPDM.Table pdmTypeTable = (PdPDM.Table)pdmTypePackage.Tables.CreateNew();
pdmTypeTable.Name = structuredTypeElement.Name;
pdmTypeTable.Name = string.Format("{0}.{1}", structuredTypeElement.Namespace, structuredTypeElement.Name);
pdmTypeTable.Comment = structuredTypeElement.Name;
pdmTypeTable.SetNameToCode();

// Add the columns to the table based on the declared properties.
Expand All @@ -86,10 +87,11 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
logger.Error(string.Format("The type package '{0}' was not found!", structuredTypeElement.Namespace));
throw new PdODataException("The type package was not found!");
}
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, structuredTypeElement.Name);
string tableName = string.Format("{0}.{1}", structuredTypeElement.Namespace, structuredTypeElement.Name);
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, tableName);
if (typeTable == null)
{
logger.Error(string.Format("The type table '{0}' was not found!", structuredTypeElement.Name));
logger.Error(string.Format("The type table '{0}' was not found!", tableName));
throw new PdODataException("The type table was not found!");
}

Expand All @@ -106,10 +108,11 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
logger.Error(string.Format("The targeted type package '{0}' was not found!", targetedEntityType.Namespace));
throw new PdODataException("The targeted type package was not found!");
}
PdPDM.Table targetedTypeTable = PdHelper.GetTable(pdmTargetEntityTypePackage, targetedEntityType.Name);
string targetedTableName = string.Format("{0}.{1}", targetedEntityType.Namespace, targetedEntityType.Name);
PdPDM.Table targetedTypeTable = PdHelper.GetTable(pdmTargetEntityTypePackage, targetedTableName);
if (targetedTypeTable == null)
{
logger.Error(string.Format("The targeted type table '{0}' was not found!", targetedEntityType.Name));
logger.Error(string.Format("The targeted type table '{0}' was not found!", targetedTableName));
throw new PdODataException("The targeted type table was not found!");
}

Expand Down Expand Up @@ -156,10 +159,11 @@ public static void CreatePdmObjects(XmlReader oDataMetadataXmlReader, PdPDM.Mode
logger.Error(string.Format("The type package '{0}' was not found!", entityType.Namespace));
throw new PdODataException("The type package was not found!");
}
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, entityType.Name);
string typeTableName = string.Format("{0}.{1}", entityType.Namespace, entityType.Name);
PdPDM.Table typeTable = PdHelper.GetTable(pdmEntityTypePackage, typeTableName);
if (typeTable == null)
{
logger.Error(string.Format("The type table '{0}' was not found!", entityType.Name));
logger.Error(string.Format("The type table '{0}' was not found!", typeTableName));
throw new PdODataException("The type table was not found!");
}
// Get a list of the column names.
Expand Down

0 comments on commit c821120

Please sign in to comment.