コード例 #1
0
        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);
                    }
                }
            });
        }
コード例 #2
0
        private bool CanMap(DestinationTable table)
        {
            bool result = true;
            if (table.IsMapped)
            {
                result = false;
            }
            else
            {
                List<Reference> configIngoreReference = null;
                if (this._ignoreCircleReferences.ContainsKey(table.Name))
                {
                    configIngoreReference = this._ignoreCircleReferences[table.Name];
                }

                var referenceFields = table.Fields.Where(f => f.Type.HasFlag(FieldType.ForeignKey)).ToList();
                foreach (Field field in referenceFields)
                {
                    if (configIngoreReference != null && configIngoreReference.Any(r => r.ReferenceTableName.Equals(field.Reference.ReferenceTableName)))
                    {
                        continue;
                    }

                    DestinationTable referenceTable = _destinationDatabase.GetTable(field.Reference.ReferenceTableName);
                    if (referenceTable.IsMapped == false)
                    {
                        result = false;
                        break;
                    }
                }
            }

            return result;
        }