Skip to content

Commit

Permalink
Closed #53 Filter to exclude various "internal" attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Feb 1, 2020
1 parent 2f912fa commit ac64e6e
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 206 deletions.
9 changes: 3 additions & 6 deletions LCG-UDG/Generation/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,16 @@ private static bool AddBlankLineBetween(string lastline, string line)

public static string CamelCaseIt(this string name, Settings settings)
{
var words = settings.commonsettings.CamelCaseWords.Split(',').Select(w => w.Trim());
var endwords = settings.commonsettings.CamelCaseWordEnds.Split(',').Select(w => w.Trim());

bool WordBeginOrEnd(string text, int i)
{
var last = text.Substring(0, i).ToLowerInvariant();
var next = text.Substring(i).ToLowerInvariant();
foreach (var word in words)
foreach (var word in settings.commonsettings.CamelCaseWords)
{
if (last.EndsWith(word) || next.StartsWith(word))
{ // Found a "word" in the string (for example "count"
var isunbreakable = false;
foreach (var unbreak in words)
foreach (var unbreak in settings.commonsettings.CamelCaseWords)
{ // Check that this word is not also part of a bigger word (for example "account"
var len = unbreak.Length;
var pos = text.ToLowerInvariant().IndexOf(unbreak);
Expand All @@ -169,7 +166,7 @@ bool WordBeginOrEnd(string text, int i)
}
}
}
foreach (var word in endwords)
foreach (var word in settings.commonsettings.CamelCaseWordEnds)
{
if (next.Equals(word))
{
Expand Down
43 changes: 23 additions & 20 deletions LCG-UDG/LCG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ private void ApplySettings()
chkAttPrimaryKey.Checked = settings.AttributeFilter?.PrimaryKey == true;
chkAttPrimaryAttribute.Checked = settings.AttributeFilter?.PrimaryAttribute == true;
chkAttLogical.Checked = settings.AttributeFilter?.Logical == true;
chkAttInternal.Checked = settings.AttributeFilter?.Internal == true;
chkRelCheckAll.Checked = settings.RelationshipFilter?.CheckAll != false;
rbRelCustomAll.Checked = settings.RelationshipFilter?.CustomAll != false;
rbRelCustomFalse.Checked = settings.RelationshipFilter?.CustomFalse == true;
Expand Down Expand Up @@ -584,36 +585,42 @@ private bool GetFileSettings()

private IEnumerable<AttributeMetadataProxy> GetFilteredAttributes()
{
bool GetCustomFilter(AttributeMetadataProxy e)
bool GetCustomFilter(AttributeMetadataProxy a)
{
return rbAttCustomAll.Checked ||
rbAttCustomTrue.Checked && e.Metadata.IsCustomAttribute.GetValueOrDefault() ||
rbAttCustomFalse.Checked && !e.Metadata.IsCustomAttribute.GetValueOrDefault();
rbAttCustomTrue.Checked && a.Metadata.IsCustomAttribute.GetValueOrDefault() ||
rbAttCustomFalse.Checked && !a.Metadata.IsCustomAttribute.GetValueOrDefault();
}
bool GetManagedFilter(AttributeMetadataProxy e)
bool GetManagedFilter(AttributeMetadataProxy a)
{
return rbAttMgdAll.Checked ||
rbAttMgdTrue.Checked && e.Metadata.IsManaged.GetValueOrDefault() ||
rbAttMgdFalse.Checked && !e.Metadata.IsManaged.GetValueOrDefault();
rbAttMgdTrue.Checked && a.Metadata.IsManaged.GetValueOrDefault() ||
rbAttMgdFalse.Checked && !a.Metadata.IsManaged.GetValueOrDefault();
}
bool GetSearchFilter(AttributeMetadataProxy e)
bool GetSearchFilter(AttributeMetadataProxy a)
{
return string.IsNullOrWhiteSpace(txtAttSearch.Text) ||
e.Metadata.LogicalName.ToLowerInvariant().Contains(txtAttSearch.Text) ||
e.Metadata.DisplayName?.UserLocalizedLabel?.Label?.ToLowerInvariant().Contains(txtAttSearch.Text) == true;
a.Metadata.LogicalName.ToLowerInvariant().Contains(txtAttSearch.Text) ||
a.Metadata.DisplayName?.UserLocalizedLabel?.Label?.ToLowerInvariant().Contains(txtAttSearch.Text) == true;
}
bool GetLogicalFilter(AttributeMetadataProxy e)
bool GetLogicalFilter(AttributeMetadataProxy a)
{
return chkAttLogical.Checked ||
e.Metadata.IsLogical != true;
a.Metadata.IsLogical != true;
}
bool GetInternalFilter(AttributeMetadataProxy a)
{
return chkAttInternal.Checked ||
!commonsettings.InternalAttributes.Contains(a.LogicalName);
}

return selectedEntity.Attributes
.Where(
e => GetCustomFilter(e)
&& GetManagedFilter(e)
&& GetSearchFilter(e)
&& GetLogicalFilter(e));
a => GetCustomFilter(a)
&& GetManagedFilter(a)
&& GetSearchFilter(a)
&& GetLogicalFilter(a)
&&GetInternalFilter(a));
}

private IEnumerable<EntityMetadataProxy> GetFilteredEntities()
Expand Down Expand Up @@ -913,11 +920,7 @@ private void LoadCommonSettings()
{
LogInfo("Common Settings found and loaded");
}
if (commonsettings.Template.TemplateVersion != new Template(isUML).TemplateVersion)
{
//MessageBox.Show("Template has been updated.\nAny customizations will need to be recreated.", "Template", MessageBoxButtons.OK, MessageBoxIcon.Information);
commonsettings.Template = new Template(isUML);
}
commonsettings.MigrateFromOldConfig(isUML);
commonsettings.SetFixedValues(isUML);
}

Expand Down
Loading

0 comments on commit ac64e6e

Please sign in to comment.