public TableMappingDefinition(SourceTable sourceTable, DestinationTable destinationTable, List<FieldMappingConfiguration> explicitMappings = null) { _sourceTable = sourceTable; _destinationTable = destinationTable; bool hasExplicitMappings = explicitMappings != null; destinationTable.Fields.ForEach(f => { try { if(hasExplicitMappings) { var mappingConfig = explicitMappings.SingleOrDefault(m => m.DestinationFieldName.Equals(f.Name, StringComparison.InvariantCultureIgnoreCase)); if (mappingConfig != null) { var sourceField = sourceTable.GetField(mappingConfig.SourceFieldName); FieldMappingDefinitions.Add(new FieldMappingDefinition(sourceField, f, mappingConfig.Type) { BlobCategory = mappingConfig.BlobCategory, ForceValue = mappingConfig.ForceValue }); } else { var sourceField = sourceTable.GetField(f.Name); FieldMappingDefinitions.Add(new FieldMappingDefinition(sourceField, f)); } } else { var sourceField = sourceTable.GetField(f.Name); FieldMappingDefinitions.Add(new FieldMappingDefinition(sourceField, f)); } } catch(MigrationException ex) { if(ex.ErrorCode == MigrationExceptionCodes.DATABASE_ERROR_FIELD_NOT_FOUND) { // TODO: write log //Console.WriteLine(sourceTable.Name + " -> " + destinationTable.Name); } } }); }
public TableMappingDefinition(SourceTable sourceTable, DestinationTable destTable, List <FieldMappingConfiguration> explicitMappings = null) { _sourceTable = sourceTable; _destinationTable = destTable; bool hasExplicitMappings = explicitMappings != null; _destinationTable.Fields.ForEach(f => { if (hasExplicitMappings) { var mappingConfig = explicitMappings.SingleOrDefault(m => m.DestinationFieldName.Equals(f.Name, StringComparison.InvariantCultureIgnoreCase)); if (mappingConfig != null) { if (!string.IsNullOrEmpty(mappingConfig.GetBlobScriptPath)) { FieldMappingDefinitions.Add(new FieldMappingDefinition { DestinationField = f, SourceField = new Field { Name = mappingConfig.SourceFieldName }, Type = mappingConfig.Type, BlobCategory = mappingConfig.BlobCategory, ForceValue = mappingConfig.ForceValue, GetBlobScriptPath = mappingConfig.GetBlobScriptPath }); } else { Field srcField = _sourceTable.GetField(mappingConfig.SourceFieldName); if (srcField != null) { FieldMappingDefinitions.Add(new FieldMappingDefinition { DestinationField = f, SourceField = srcField, Type = mappingConfig.Type, BlobCategory = mappingConfig.BlobCategory, ForceValue = mappingConfig.ForceValue, GetBlobScriptPath = mappingConfig.GetBlobScriptPath }); } } } else { Field srcField = _sourceTable.GetField(f.Name); if (srcField != null) { FieldMappingDefinitions.Add(new FieldMappingDefinition { DestinationField = f, SourceField = srcField }); } } } else { Field srcField = _sourceTable.GetField(f.Name); if (srcField != null) { FieldMappingDefinitions.Add(new FieldMappingDefinition { DestinationField = f, SourceField = srcField }); } } }); }