private static string GetRelationships(EntityMetadataProxy entitymetadata, List <EntityMetadataProxy> includedentities, Settings settings) { var relationships = new List <string>(); if (settings.RelationShips) { foreach (var relationship in entitymetadata.Relationships.Where(r => r.Parent != entitymetadata && includedentities.Contains(r.Parent)).Distinct()) { relationships.Add(GetRelationShip(relationship, settings, (relationship.Metadata is ManyToManyRelationshipMetadata) ? settings.commonsettings.ManyManyRelationshipPrefix : settings.commonsettings.ManyOneRelationshipPrefix)); } foreach (var relationship in entitymetadata.Relationships.Where(r => r.Parent == entitymetadata && includedentities.Contains(r.Child)).Distinct()) { relationships.Add(GetRelationShip(relationship, settings, (relationship.Metadata is ManyToManyRelationshipMetadata) ? settings.commonsettings.ManyManyRelationshipPrefix : settings.commonsettings.OneManyRelationshipPrefix)); } } DeduplicateIdentifiers(ref relationships); var result = string.Join("\r\n", relationships); if (settings.Regions && !string.IsNullOrEmpty(result)) { return(Template.Region.Replace("{region}", "Relationships").Replace("{content}", result)); } return(result); }
public RelationshipMetadataProxy(List <EntityMetadataProxy> entities, EntityMetadataProxy originatingentity, ManyToManyRelationshipMetadata relationshipMetadata) { this.originatingentity = originatingentity; Parent = entities.FirstOrDefault(e => e.LogicalName == relationshipMetadata.Entity1LogicalName); Child = entities.FirstOrDefault(e => e.LogicalName == relationshipMetadata.Entity2LogicalName); Metadata = relationshipMetadata; }
private static string GetRelationships(EntityMetadataProxy entitymetadata, Settings settings) { var relationships = new List <string>(); if (settings.RelationShips && entitymetadata.Relationships != null) { foreach (var relationship in entitymetadata.Relationships.Where(r => r.Parent != entitymetadata && r.IsSelected).Distinct()) { relationships.Add(GetRelationShip(relationship, settings, (relationship.Metadata.RelationshipType == RelationshipType.ManyToManyRelationship) ? settings.commonsettings.ManyManyRelationshipPrefix : settings.commonsettings.ManyOneRelationshipPrefix)); } foreach (var relationship in entitymetadata.Relationships.Where(r => r.Parent == entitymetadata && r.IsSelected).Distinct()) { relationships.Add(GetRelationShip(relationship, settings, (relationship.Metadata.RelationshipType == RelationshipType.ManyToManyRelationship) ? settings.commonsettings.ManyManyRelationshipPrefix : settings.commonsettings.OneManyRelationshipPrefix)); } } DeduplicateIdentifiers(ref relationships); var result = string.Join("\r\n", relationships); if (settings.Regions && !string.IsNullOrEmpty(result)) { return(settings.commonsettings.Template.Region.Replace("{region}", "Relationships").Replace("{content}", result)); } return(result); }
private static string GetClass(EntityMetadataProxy entitymetadata, EntityMetadataProxy commonentity, Settings settings) { var template = settings.commonsettings.Template; var name = entitymetadata.GetNameTechnical(settings.ConstantName, settings); name = settings.commonsettings.EntityPrefix + name + settings.commonsettings.EntitySuffix; var description = entitymetadata.Description?.Replace("\n", "\n/// "); var summary = settings.XmlProperties && entitymetadata.LogicalName != "[common]" ? entitymetadata.GetEntityProperties(settings) : settings.XmlDescription ? description : string.Empty; var remarks = settings.XmlProperties && entitymetadata.LogicalName != "[common]" && settings.XmlDescription ? description : string.Empty; if (!string.IsNullOrEmpty(summary)) { summary = template.Summary.Replace("{summary}", summary); } if (!string.IsNullOrEmpty(remarks)) { remarks = template.Remarks.Replace("{remarks}", remarks); } var entity = template.EntityContainer .Replace("{entityname}", name) .Replace("{entitydetail}", GetEntity(entitymetadata, template)) .Replace("{type}", entitymetadata.Metadata.IsCustomEntity == true ? "custom" : "standard") .Replace("{summary}", summary) .Replace("{remarks}", remarks) .Replace("'", "\"") .Replace("{attributes}", GetAttributes(entitymetadata, commonentity, settings)) .Replace("{relationships}", GetRelationships(entitymetadata, settings)) .Replace("{optionsets}", GetOptionSets(entitymetadata, settings)); return(entity); }
private static string GetAttributes(EntityMetadataProxy entitymetadata, EntityMetadataProxy commonentity, Settings settings) { var attributes = new List <string>(); if (entitymetadata.Attributes != null) { if (entitymetadata.PrimaryKey?.IsSelected == true) { // First Primary Key attributes.Add(GetAttribute(entitymetadata.PrimaryKey, settings)); } if (entitymetadata.PrimaryName?.IsSelected == true) { // Then Primary Name attributes.Add(GetAttribute(entitymetadata.PrimaryName, settings)); } var commonattributes = commonentity?.Attributes?.Select(a => a.LogicalName) ?? new List <string>(); foreach (var attributemetadata in entitymetadata.Attributes .Where(a => (entitymetadata.LogicalName == "[common]") || (a.Selected && !commonattributes.Contains(a.LogicalName) && a.Metadata.IsPrimaryId != true && a.Metadata.IsPrimaryName != true))) { // Then all the rest var attribute = GetAttribute(attributemetadata, settings); attributes.Add(attribute); } } DeduplicateIdentifiers(ref attributes); var result = string.Join("\r\n", attributes); if (settings.Regions && attributes.Count > 0) { return(Template.Region.Replace("{region}", "Attributes").Replace("{content}", result)); } return(result); }
private static string GetClass(List <EntityMetadataProxy> selectedentities, EntityMetadataProxy entitymetadata, EntityMetadataProxy commonentity, Settings settings) { var name = entitymetadata.GetNameTechnical(settings.ConstantName, settings); name = settings.commonsettings.EntityPrefix + name + settings.commonsettings.EntitySuffix; var description = entitymetadata.Description?.Replace("\n", "\n/// "); var summary = settings.XmlProperties && entitymetadata.LogicalName != "[common]" ? entitymetadata.GetEntityProperties(settings) : settings.XmlDescription ? description : string.Empty; var remarks = settings.XmlProperties && entitymetadata.LogicalName != "[common]" && settings.XmlDescription ? description : string.Empty; var entity = new StringBuilder(); if (!string.IsNullOrEmpty(summary)) { entity.AppendLine($"/// <summary>{summary}</summary>"); } if (!string.IsNullOrEmpty(remarks)) { entity.AppendLine($"/// <remarks>{remarks}</remarks>"); } entity.AppendLine(Template.Class .Replace("{classname}", name) .Replace("{entity}", GetEntity(entitymetadata)) .Replace("'", "\"") .Replace("{attributes}", GetAttributes(entitymetadata, commonentity, settings)) .Replace("{relationships}", GetRelationships(entitymetadata, selectedentities, settings)) .Replace("{optionsets}", GetOptionSets(entitymetadata, settings))); return(entity.ToString()); }
private static string GetOptionSets(EntityMetadataProxy entitymetadata, Settings settings) { if (entitymetadata.LogicalName == "[common]") { return(string.Empty); } var optionsets = new List <string>(); if (settings.OptionSets && entitymetadata.Attributes != null) { foreach (var attributemetadata in entitymetadata.Attributes.Where(a => a.Selected && (a.Metadata is EnumAttributeMetadata))) { var optionset = GetOptionSet(attributemetadata, settings); optionsets.Add(optionset); } } DeduplicateIdentifiers(ref optionsets); var result = string.Join("\r\n", optionsets); if (settings.Regions && !string.IsNullOrEmpty(result)) { return(Template.Region.Replace("{region}", "OptionSets").Replace("{content}", result)); } return(result); }
private static string GetEntity(EntityMetadataProxy entitymetadata) { if (entitymetadata.LogicalName == "[common]") { return(string.Empty); } return(Template.Entity.Replace("{logicalname}", entitymetadata.LogicalName).Replace("{logicalcollectionname}", entitymetadata.LogicalCollectionName)); }
private void gridEntities_SelectionChanged(object sender, EventArgs e) { if (restoringselection) { return; } var newselectedEntity = GetSelectedEntity(); if (newselectedEntity != null && newselectedEntity != selectedEntity) { selectedEntity = newselectedEntity; DisplayAttributes(); } }
private static string GetOptionSets(EntityMetadataProxy entitymetadata, Settings settings) { var optionsets = new StringBuilder(); if (settings.OptionSets && entitymetadata.Attributes != null) { foreach (var attributemetadata in entitymetadata.Attributes.Where(a => a.Selected && (a.Metadata is EnumAttributeMetadata))) { string optionset = GetOptionSet(attributemetadata, settings); optionsets.AppendLine(optionset); } } return(optionsets.ToString()); }
private void LCG_ConnectionUpdated(object sender, ConnectionUpdatedEventArgs e) { LogInfo("Connection has changed to: {0}", e.ConnectionDetail.WebApplicationUrl); chkEntAll.Visible = false; chkAttAll.Visible = false; btnLoadConfig.Enabled = false; btnSaveConfig.Enabled = false; entities = null; selectedEntity = null; gridAttributes.DataSource = null; gridEntities.DataSource = null; LoadSettings(e.ConnectionDetail?.ConnectionName); LoadSolutions(); Enabled = true; }
private static string GetAttributes(EntityMetadataProxy entitymetadata, EntityMetadataProxy commonentity, Settings settings) { var attributes = new List <string>(); if (entitymetadata.Attributes != null) { if (entitymetadata.PrimaryKey?.IsSelected == true) { // First Primary Key attributes.Add(GetAttribute(entitymetadata.PrimaryKey, settings)); } attributes.Add(settings.commonsettings.AttributeSeparatorAfterPK); if (entitymetadata.PrimaryName?.IsSelected == true) { // Then Primary Name attributes.Add(GetAttribute(entitymetadata.PrimaryName, settings)); } var commonattributes = commonentity?.Attributes?.Select(a => a.LogicalName) ?? new List <string>(); var entityattributes = entitymetadata.Attributes .Where(a => (entitymetadata.LogicalName == "[common]") || (a.Selected && !commonattributes.Contains(a.LogicalName) && a != entitymetadata.PrimaryKey && a != entitymetadata.PrimaryName)); switch (settings.AttributeSortMode) { case AttributeSortMode.Alphabetical: entityattributes = entityattributes.OrderBy(a => a.GetNameTechnical(settings)); break; case AttributeSortMode.AlphabeticalAndRequired: entityattributes = entityattributes .OrderBy(a => a.GetNameTechnical(settings)) .OrderBy(OrderByRequiredLevel); break; } foreach (var attributemetadata in entityattributes) { // Then all the rest var attribute = GetAttribute(attributemetadata, settings); attributes.Add(attribute); } } DeduplicateIdentifiers(ref attributes); var result = string.Join("\r\n", attributes); if (settings.Regions && attributes.Count > 0) { return(settings.commonsettings.Template.Region.ReplaceIfNotEmpty("{region}", "Attributes").Replace("{content}", result)); } return(result); }
private void LoadAttributes(EntityMetadataProxy entity, Action callback) { entity.Attributes = null; WorkAsync(new WorkAsyncInfo { Message = $"Loading attributes for {entity}...", Work = (worker, args) => { args.Result = MetadataHelper.LoadEntityDetails(Service, entity.LogicalName); }, PostWorkCallBack = (completedArgs) => { if (completedArgs.Error != null) { MessageBox.Show(completedArgs.Error.Message); } else if (completedArgs.Result is RetrieveMetadataChangesResponse response) { var metaresponse = response.EntityMetadata; if (metaresponse.Count == 1) { entity.Attributes = new List <AttributeMetadataProxy>( metaresponse[0] .Attributes .Select(m => new AttributeMetadataProxy(entity, m)) .OrderBy(a => a.ToString())); foreach (var attribute in entity.Attributes) { attribute.PropertyChanged += Attribute_PropertyChanged; } } } UpdateUI(() => { callback?.Invoke(); }); } });
private static string GetAttributes(EntityMetadataProxy entitymetadata, Settings settings) { var attributes = new List <string>(); if (entitymetadata.Attributes != null) { if (entitymetadata.PrimaryKey?.IsSelected == true) { // First Primary Key attributes.Add(GetAttribute(entitymetadata.PrimaryKey, settings)); } if (entitymetadata.PrimaryName?.IsSelected == true) { // Then Primary Name attributes.Add(GetAttribute(entitymetadata.PrimaryName, settings)); } foreach (var attributemetadata in entitymetadata.Attributes .Where(a => a.Selected && a.Metadata.IsPrimaryId != true && a.Metadata.IsPrimaryName != true)) { // Then all the rest var attribute = GetAttribute(attributemetadata, settings); attributes.Add(attribute); } } return(string.Join("\r\n", attributes)); }
private bool GetSearchFilter(EntityMetadataProxy e) { return(string.IsNullOrWhiteSpace(txtEntSearch.Text) || e.Metadata.LogicalName.ToLowerInvariant().Contains(txtEntSearch.Text) || e.Metadata.DisplayName?.UserLocalizedLabel?.Label?.ToLowerInvariant().Contains(txtEntSearch.Text) == true); }
public AttributeMetadataProxy(EntityMetadataProxy entity, AttributeMetadata attributeMetadata) { this.entity = entity; Metadata = attributeMetadata; }
private bool GetIntersectFilter(EntityMetadataProxy e) { return(!e.Metadata.IsIntersect.GetValueOrDefault() || chkEntIntersect.Checked); }
private bool GetSelectedFilter(EntityMetadataProxy e) { return(!chkEntSelected.Checked || e.IsSelected); }
private static bool IsNotPrivate(EntityMetadataProxy e) { return(!e.Metadata.IsPrivate.GetValueOrDefault()); }
private bool GetManagedFilter(EntityMetadataProxy e) { return(rbEntMgdAll.Checked || rbEntMgdTrue.Checked && e.Metadata.IsManaged.GetValueOrDefault() || rbEntMgdFalse.Checked && !e.Metadata.IsManaged.GetValueOrDefault()); }
public RelationshipMetadataProxy(List <EntityMetadataProxy> entities, OneToManyRelationshipMetadata relationshipMetadata) { Parent = entities.FirstOrDefault(e => e.LogicalName == relationshipMetadata.ReferencedEntity); Child = entities.FirstOrDefault(e => e.LogicalName == relationshipMetadata.ReferencingEntity); Metadata = relationshipMetadata; }
private static EntityMetadataProxy GetCommonEntity(List <EntityMetadataProxy> selectedentities, Settings settings) { if (settings.CommonAttributes == CommonAttributesType.None) { return(null); } var attributes = new List <AttributeMetadataProxy>(); var selectedentitiesattributes = selectedentities.Select(e => e.Attributes?.Where(a => a.IsSelected && a.Metadata.IsPrimaryId != true && a.Metadata.IsPrimaryName != true)); switch (settings.CommonAttributes) { case CommonAttributesType.CommonInAny: { var alluniqueattributes = new List <string>(); foreach (var entityattributes in selectedentitiesattributes) { attributes.AddRange(entityattributes.Where(a => !attributes.Select(a2 => a2.LogicalName).Contains(a.LogicalName) && alluniqueattributes.Contains(a.LogicalName))); alluniqueattributes.AddRange(entityattributes.Select(a => a.LogicalName).Where(a => !alluniqueattributes.Contains(a))); } break; } case CommonAttributesType.CommonInAll: { attributes = selectedentitiesattributes.SelectMany(a => a).GroupBy(a => a.LogicalName).Select(a => a.First()).ToList(); foreach (var entityattributes in selectedentitiesattributes) { var entityattributenames = entityattributes.Select(a => a.LogicalName); var pos = 0; while (pos < attributes.Count) { if (entityattributenames.Contains(attributes[pos].LogicalName)) { pos++; } else { attributes.RemoveAt(pos); } } } break; } } var allselectedattributes = selectedentitiesattributes.SelectMany(a => a).ToList(); foreach (var attribute in attributes) { var entities = string.Join(", ", allselectedattributes.Where(a => a.IsSelected && a.LogicalName == attribute.LogicalName).Select(a => a.Entity.LogicalName)); attribute.AdditionalProperties = "Used by entities: " + entities; } var result = new EntityMetadataProxy(new EntityMetadata { LogicalName = "[common]" }) { Attributes = attributes.OrderBy(a => a.LogicalName).ToList() }; return(result); }
private bool GetCustomFilter(EntityMetadataProxy e) { return(rbEntCustomAll.Checked || rbEntCustomTrue.Checked && e.Metadata.IsCustomEntity.GetValueOrDefault() || rbEntCustomFalse.Checked && !e.Metadata.IsCustomEntity.GetValueOrDefault()); }