private bool LoadMappingFromFile(FieldMappingType fieldMappingType, List <FieldMapping> mapping)
        {
            var openFiledialog = new OpenFileDialog()
            {
                Filter = "XML-File | *.xml"
            };

            openFiledialog.ShowDialog();
            if (string.IsNullOrEmpty(openFiledialog.FileName))
            {
                return(false);
            }

            try
            {
                using (var stream = File.OpenRead(openFiledialog.FileName))
                {
                    var serializer   = new XmlSerializer(typeof(List <FieldMapping>));
                    var tempMappings = (List <FieldMapping>)serializer.Deserialize(stream);
                    mapping.Clear();

                    if (fieldMappingType == FieldMappingType.DOSSIER)
                    {
                        foreach (var tempDossierMapping in tempMappings)
                        {
                            if (string.IsNullOrEmpty(tempDossierMapping.DatabaseFieldName))
                            {
                                continue;
                            }
                            if (!_headersDossiers.Contains(tempDossierMapping.DatabaseFieldName, StringComparer.OrdinalIgnoreCase))
                            {
                                MessageBox.Show($"Er is een fout gevonden in het mappingbestand: Het veld {tempDossierMapping.DatabaseFieldName} is niet toegestaan in dossiermappings");
                                return(false);
                            }
                        }
                    }

                    if (fieldMappingType == FieldMappingType.RECORD)
                    {
                        foreach (var tempRecordMapping in tempMappings)
                        {
                            if (string.IsNullOrEmpty(tempRecordMapping.DatabaseFieldName))
                            {
                                continue;
                            }
                            if (!_headersRecords.Contains(tempRecordMapping.DatabaseFieldName, StringComparer.OrdinalIgnoreCase))
                            {
                                MessageBox.Show($"Er is een fout gevonden in het mappingbestand: Het veld {tempRecordMapping.DatabaseFieldName} is niet toegestaan in recordmappings");
                                return(false);
                            }
                        }
                    }

                    foreach (var tempDossierMapping in tempMappings)
                    {
                        if (!string.IsNullOrEmpty(tempDossierMapping.MappedFieldName) || !string.IsNullOrEmpty(tempDossierMapping.DatabaseFieldName))
                        {
                            mapping.Add(new FieldMapping()
                            {
                                MappedFieldName   = tempDossierMapping.MappedFieldName,
                                DatabaseFieldName = tempDossierMapping.DatabaseFieldName,
                                TMLO = tempDossierMapping.TMLO
                            });
                        }
                    }
                    _dataservice.SaveMappings(mapping, fieldMappingType);
                }
                return(true);
            }

            catch (Exception e)
            {
                MessageBox.Show($"Fout bij inlezen gegevens: {e.Message}");
                return(false);
            }
        }
 public FieldMappingDefinition(Field sourceField, Field destinationField, FieldMappingType type = FieldMappingType.Simple)
 {
     _sourceField      = sourceField;
     _destinationField = destinationField;
     _type             = type;
 }
 public FieldMappingDefinition(Field sourceField, Field destinationField, FieldMappingType type = FieldMappingType.Simple)
 {
     _sourceField = sourceField;
     _destinationField = destinationField;
     _type = type;
 }
Example #4
0
        private List <FieldMapping> GetPropertyInfoNames(PropertyInfo[] propertyInfos, FieldMappingType type)
        {
            // if (typeof(IEnumerable).IsAssignableFrom(pi.PropertyType))
            var listOfFields = propertyInfos.Where
                               (
                propertyInfo =>
                (
                    propertyInfo.PropertyType == typeof(string) ||
                    propertyInfo.PropertyType == typeof(Int64?) ||
                    propertyInfo.PropertyType == typeof(DateTime?)
                ) &&
                !HeaderClassification.OptionalHeaders.Contains(propertyInfo.Name) &&
                propertyInfo.PropertyType != typeof(ICollection <>))
                               .Select(propertyInfo => propertyInfo.Name);

            return(listOfFields.Select(listOfField => new FieldMapping()
            {
                DatabaseFieldName = listOfField, Type = type.ToString()
            }).ToList());
        }