/// <summary> /// Methode pour la serialisation des elements en XML. /// </summary> /// <param name="Chiffrement">Chiffrement du fichier</param> /// <param name="Arborescence">Arborescence que l'on veut chiffrer</param> public void Serialise(Rijndael Chiffrement, Dossier Arborescence) { XmlSerializer Serialiser = new XmlSerializer(Arborescence.GetType(), new Type[] { typeof(Dossier) }); TextWriter Fichier = new StreamWriter(Constantes.CheminFichierNonChiffrer); Serialiser.Serialize(Fichier, Arborescence); Fichier.Close(); CryptographieFichier.ChiffrementFichier(Chiffrement); }
public void SaveDossiers(List <FieldMapping> mappingsDossiers, StreamReader dossierStream) { var readLineAsHeader = dossierStream.ReadLine(); if (readLineAsHeader == null) { ErrorMessage = "File is leeg"; return; } ; var headersSource = readLineAsHeader.Split(';'); while (dossierStream.Peek() > 0) { var dossier = new Dossier(); var fieldsSource = dossierStream.ReadLine()?.Split(';'); try { if (fieldsSource == null) { ErrorMessage = "Unexpected end of stream"; return; } if (string.IsNullOrEmpty(fieldsSource[0])) { continue; // skip rows without id } if (headersSource.Length != fieldsSource.Length) { ErrorsImportDossiers.AppendLine($"ERROR: Dossier {fieldsSource?[0]} kon niet worden ingelezen, aantal kolommen is onjuist. Dit kan ontstaan door gebruik van puntkomma's in tekstvelden"); continue; } ComplexLink complexLink = null; for (var index = 0; index <= headersSource.Length - 1; index++) { var mappedfield = (from f in mappingsDossiers where f.MappedFieldName == headersSource[index] select f.DatabaseFieldName).FirstOrDefault(); if (mappedfield == null) { continue; } if (mappedfield.StartsWith("ComplexlinkNummer")) { complexLink = new ComplexLink() { ComplexLinkNummer = fieldsSource[index] } } ; var propertyInfo = dossier.GetType().GetProperty(mappedfield); if (propertyInfo != null) { propertyInfo.SetValue(dossier, fieldsSource[index], null); } } if (_enableValidation) { var dossiervalidator = new DossierValidator(dossier); var isValidated = dossiervalidator.Validate(); if (isValidated) { if (complexLink != null) { ComplexLinksFound = true; dossier.ComplexLinks.Add(complexLink); } if (!_dataservice.SaveDossier(dossier)) { ErrorsImportDossiers.AppendLine(_dataservice.ErrorMessage); } NrOfDossiers++; } else { foreach (var validatorValidationError in dossiervalidator.ValidationErrors) { ErrorsImportDossiers.AppendLine(validatorValidationError); } } } } catch (Exception e) { ErrorsImportDossiers.AppendLine($"Dossier {fieldsSource?[0]} kon niet worden geïmporteerd: {e.Message}"); } } }