private static string GetFieldProperty(CrmField field) { return($@" [CrmField(""{field.InternalName}"")] public {field.Type.GetDotnetType()} {field.DisplayName.SplitterByUnderscore()} {{ get; set; }} "); }
public void StoreAttributePrimaryKey(string primaryAttribute, CrmField crmField) { if (crmField.FieldName.Equals(primaryAttribute, StringComparison.InvariantCulture)) { crmField.PrimaryKey = true; } }
public void GetExportFetchXmlNonPrimaryKey() { var entityName = "account"; var crmField = new CrmField() { LookupType = entityName, FieldName = "name" }; var list = new Dictionary <string, List <string> > { { "name", new List <string> { "testname" } } }; var lookupMappings = new Dictionary <string, Dictionary <string, List <string> > > { { entityName, list } }; systemUnderTest = new MappingAliasedValueFetchCreator(lookupMappings); var actual = systemUnderTest.GetExportFetchXML(entityName, crmField); actual.Should().NotBeEmpty(); }
private static string GetFieldConstant(CrmField field) { return($@" /// <summary> /// {field.Type} /// </summary> public const string {field.DisplayName.SplitterByUnderscore()} = ""{field.InternalName}"";"); }
public string GetExportFetchXML(string entityName, CrmField field) { field.ThrowArgumentNullExceptionIfNull(nameof(field)); var lookupMapping = allLookupMappings.ContainsKey(entityName) ? allLookupMappings[entityName] : null; string retValue = string.Empty; if (lookupMapping != null && lookupMapping.ContainsKey(field.FieldName)) { var rootBUfilter = string.Empty; if (field?.LookupType == "businessunit") { StringBuilder fetch = new StringBuilder(); fetch.AppendLine("<filter>"); fetch.AppendLine(" <condition attribute='parentbusinessunitid' operator='not-null' />"); fetch.Append("</filter>"); rootBUfilter = fetch.ToString(); } if (field.PrimaryKey) { if (field.FieldName == "systemuserid") { entityName = "systemuser"; } StringBuilder pkeyFetch = new StringBuilder(); pkeyFetch.AppendLine($@"<link-entity name='{entityName}' alias='map.{field.FieldName}.{entityName}' from='{field.FieldName}' to='{field.FieldName}' link-type='outer' >"); foreach (string atrFieldName in lookupMapping[field.FieldName]) { pkeyFetch.AppendLine($" <attribute name='{atrFieldName}' alias='map.{field.FieldName}.{entityName}.{atrFieldName}' />"); } pkeyFetch.Append("</link-entity>"); retValue = pkeyFetch.ToString(); } else { StringBuilder fetch = new StringBuilder(); GenerateLinkEntityFetchXml(field, lookupMapping, rootBUfilter, fetch); retValue = fetch.ToString(); } } return(retValue); }
public void GetExportFetchXmlEmptyMappings() { var crmField = new CrmField() { LookupType = "account", FieldName = "contacaccount" }; Dictionary <string, Dictionary <string, List <string> > > lookupMappings = new Dictionary <string, Dictionary <string, List <string> > >(); systemUnderTest = new MappingAliasedValueFetchCreator(lookupMappings); var actual = systemUnderTest.GetExportFetchXML("contact", crmField); actual.Should().BeEmpty(); }
public void GetExportFetchXmlNullMappings() { var crmField = new CrmField() { LookupType = "account", FieldName = "contacaccount" }; Dictionary <string, Dictionary <string, List <string> > > lookupMappings = null; systemUnderTest = new MappingAliasedValueFetchCreator(lookupMappings); FluentActions.Invoking(() => systemUnderTest.GetExportFetchXML("contact", crmField)) .Should() .Throw <NullReferenceException>(); }
private static void GenerateLinkEntityFetchXml(CrmField field, Dictionary <string, List <string> > lookupMapping, string rootBUfilter, StringBuilder fetch) { fetch.AppendLine($@"<link-entity name='{field.LookupType}' alias='map.{field.FieldName}.{field.LookupType}' from='{field.LookupType}id' to='{field.FieldName}' link-type='outer' >"); foreach (string atrFieldName in lookupMapping[field.FieldName]) { fetch.AppendLine($" <attribute name='{atrFieldName}' alias='map.{field.FieldName}.{field.LookupType}.{atrFieldName}' />"); } if (!string.IsNullOrWhiteSpace(rootBUfilter)) { fetch.AppendLine(rootBUfilter); } fetch.Append("</link-entity>"); }
public void StoreLookUpAttribute(AttributeMetadata attribute, CrmField crmField, INotificationService notificationService) { if (crmField.FieldType.Equals("entityreference", StringComparison.InvariantCulture)) { if (attribute is LookupAttributeMetadata lookUpAttribute) { if (lookUpAttribute.Targets != null && lookUpAttribute.Targets.Any()) { crmField.LookupType = lookUpAttribute.Targets[0]; } } else { notificationService.DisplayFeedback("The supplied attribute is null. Expecting an Entity Reference!"); } } }
public string GetExportFetchXML(string entityName, CrmField field) { string retValue = string.Empty; if (field?.LookupType == "businessunit") { StringBuilder fetch = new StringBuilder(); fetch.AppendLine($@"<link-entity name='businessunit' from='businessunitid' to='{field.FieldName}' link-type='outer'>"); fetch.AppendLine($" <attribute name='name' alias='map.{field.FieldName}.isRootBU.name' />"); fetch.AppendLine("<filter>"); fetch.AppendLine(" <condition attribute='parentbusinessunitid' operator='null' />"); fetch.AppendLine("</filter>"); fetch.Append("</link-entity>"); retValue = fetch.ToString(); } return(retValue); }
public void StoreAttributeMetadata(AttributeMetadata attribute, EntityMetadata entityMetadata, string primaryAttribute, List <CrmField> crmFieldList, Dictionary <string, HashSet <string> > inputEntityAttributes, AttributeTypeMapping inputAttributeMapping, INotificationService notificationService) { if (inputEntityAttributes != null && inputEntityAttributes.ContainsKey(entityMetadata.LogicalName)) { var crmField = new CrmField(); foreach (var attributeLogicalName in inputEntityAttributes[entityMetadata.LogicalName]) { if (attribute.LogicalName.Equals(attributeLogicalName, StringComparison.InvariantCulture)) { crmField.DisplayName = attribute.DisplayName.UserLocalizedLabel == null ? string.Empty : attribute.DisplayName.UserLocalizedLabel.Label; crmField.FieldName = attribute.LogicalName; inputAttributeMapping.AttributeMetadataType = attribute.AttributeTypeName.Value.ToString(CultureInfo.InvariantCulture); inputAttributeMapping.GetMapping(notificationService); crmField.FieldType = inputAttributeMapping.AttributeMetadataTypeResult; StoreLookUpAttribute(attribute, crmField, notificationService); StoreAttributePrimaryKey(primaryAttribute, crmField); crmFieldList.Add(crmField); } } } }