public void AutoMap(IEnumerable <string> csvColumns) { CsvColumns = csvColumns.ToArray(); foreach (var propertyMap in PropertyMaps) { var entityColumnName = propertyMap.EntityColumnName; var betterMatchCsvColumn = csvColumns.Select(x => new { csvColumn = x, distance = x.ComputeLevenshteinDistance(entityColumnName) }) .Where(x => x.distance < 2) .OrderBy(x => x.distance) .Select(x => x.csvColumn) .FirstOrDefault(); if (betterMatchCsvColumn != null) { propertyMap.CsvColumnName = betterMatchCsvColumn; propertyMap.CustomValue = null; } else { propertyMap.CsvColumnName = null; } } //All not mapped properties may be a product property PropertyCsvColumns = csvColumns.Except(PropertyMaps.Where(x => x.CsvColumnName != null).Select(x => x.CsvColumnName)).ToArray(); //Generate ETag for identifying csv format ETag = string.Join(";", CsvColumns).GetMD5Hash(); }
public string[] GetUnmappedPropertyNames() { Func <PropertyMap, string> getFunc = pm => ConfiguredMemberList == MemberList.Destination ? pm.DestMember.Name : pm.CustomExpression == null && pm.SrcMember != null ? pm.SrcMember.Name : pm.DestMember.Name; var autoMappedProperties = PropertyMaps.Where(pm => pm.IsMapped()) .Select(getFunc).ToList(); var inheritedProperties = _inheritedMaps.Where(pm => pm.IsMapped()) .Select(getFunc).ToList(); IEnumerable <string> properties; if (ConfiguredMemberList == MemberList.Destination) { properties = DestinationTypeDetails.PublicWriteAccessors .Select(p => p.Name) .Except(autoMappedProperties) .Except(inheritedProperties); } else { var redirectedSourceMembers = PropertyMaps .Where(pm => pm.IsMapped() && pm.SrcMember != null && pm.SrcMember.Name != pm.DestMember.Name) .Select(pm => pm.SrcMember.Name); var ignoredSourceMembers = _sourceMemberConfigs .Where(smc => smc.IsIgnored()) .Select(pm => pm.SourceMember.Name).ToList(); properties = SourceTypeDetails.PublicReadAccessors .Select(p => p.Name) .Except(autoMappedProperties) .Except(inheritedProperties) .Except(redirectedSourceMembers) .Except(ignoredSourceMembers); } return(properties.Where(memberName => !IgnorePropertiesStartingWith.Any(memberName.StartsWith)).ToArray()); }
public string[] GetUnmappedPropertyNames() { var autoMappedProperties = GetPropertyNames(PropertyMaps); IEnumerable <string> properties; if (ConfiguredMemberList == MemberList.Destination) { properties = DestinationTypeDetails.PublicWriteAccessors .Select(p => p.Name) .Except(autoMappedProperties) .Except(PathMaps.Select(p => p.MemberPath.First.Name)); } else { var redirectedSourceMembers = PropertyMaps .Where(pm => pm.IsMapped && pm.SourceMember != null && pm.SourceMember.Name != pm.DestinationName) .Select(pm => pm.SourceMember.Name); var ignoredSourceMembers = SourceMemberConfigs .Where(smc => smc.IsIgnored()) .Select(pm => pm.SourceMember.Name).ToList(); properties = SourceTypeDetails.PublicReadAccessors .Select(p => p.Name) .Except(autoMappedProperties) .Except(redirectedSourceMembers) .Except(ignoredSourceMembers); } return(properties.Where(memberName => !Profile.GlobalIgnores.Any(memberName.StartsWith)).ToArray()); string GetPropertyName(PropertyMap pm) => ConfiguredMemberList == MemberList.Destination ? pm.DestinationName : pm.SourceMember != null ? pm.SourceMember.Name : pm.DestinationName; string[] GetPropertyNames(IEnumerable <PropertyMap> propertyMaps) => propertyMaps.Where(pm => pm.IsMapped).Select(GetPropertyName).ToArray(); }