Example #1
0
        public void LoadProviders(string path)
        {
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Processing \"{path}\" file"
            });

            int counter = 0;

            using (var sr = new StreamReader(path, true))
            {
                using (var csv = new CustomCsvReader(sr, _configuration))
                {
                    csv.Read();
                    csv.ReadHeader();

                    while (csv.Read())
                    {
                        var externalId = csv.GetField("identifiant");
                        if (!_existingReferences.Contains(externalId))
                        {
                            _companies.Add(externalId, new Company()
                            {
                                Reference   = externalId,
                                Designation = csv.GetField("denomination_sociale")
                            });
                            _existingReferences.Add(externalId);
                        }
                        counter++;
                    }
                }
            }

            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Found {counter} records in file \"{path}\"", Level = Level.Debug
            });
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"There are {_companies.Count} new companies", Level = Level.Debug
            });
        }
Example #2
0
        public void LoadProviders(string path)
        {
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Processing \"{path}\" file"
            });

            int counter = 0;

            using (var sr = new StreamReader(path, true))
            {
                using (var csv = new CustomCsvReader(sr, _configuration))
                {
                    csv.Configuration.Delimiter = ",";
                    csv.Read();
                    csv.ReadHeader();

                    using (var con = new SqlConnection(DbConnectionString))
                    {
                        con.Open();

                        #region AJOUT DES EN-TÊTES MANQUANTS
                        var header       = csv.Context.HeaderRecord;
                        var membersToAdd = header.Except(_existingMembers.Select(x => x.Key)).ToList();
                        if (membersToAdd != null && membersToAdd.Any())
                        {
                            foreach (var m in membersToAdd)
                            {
                                var member = new Member {
                                    Name = m
                                };
                                member.Id = con.InsertMember(member);
                                _existingMembers.Add(member.Name, member);
                            }
                        }
                        #endregion

                        while (csv.Read())
                        {
                            var externalId = csv.GetField("identifiant");
                            if (!_existingReferences.ContainsKey(externalId))
                            {
                                var entity = new Entity()
                                {
                                    Reference = externalId
                                };
                                entity.Id = con.InsertEntity(entity);

                                for (int i = 0; i < csv.Context.HeaderRecord.Length; i++)
                                {
                                    var col = csv.Context.HeaderRecord[i];
                                    var id  = con.InsertMetadata(entity.Id, _existingMembers[col].Id, csv[i].ToString());
                                }

                                _existingReferences.Add(entity.Reference, entity);
                                counter++;
                            }

                            _mainCounter++;
                        }
                    }
                }
            }

            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Found {_mainCounter} records in file \"{path}\"", Level = Level.Debug
            });
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"There are {counter} new companies", Level = Level.Debug
            });
        }
Example #3
0
        public void LoadLinks(string path)
        {
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Processing file \"{path}\""
            });

            int records          = 0;
            int counterCompanies = 0;
            int counterBenef     = 0;
            int counterBonds     = 0;

            using (var sr = new StreamReader(path, true))
            {
                using (var csv = new CustomCsvReader(sr, _configuration))
                {
                    csv.Configuration.Delimiter = ";";
                    csv.Read();
                    csv.ReadHeader();

                    var idx_entreprise_identifiant = csv.GetFieldIndex("entreprise_identifiant");
                    var idx_denomination_sociale   = csv.GetFieldIndex("denomination_sociale");

                    var idx_benef_identifiant_valeur = csv.GetFieldIndex("benef_identifiant_valeur");
                    var idx_benef_nom    = csv.GetFieldIndex("benef_nom");
                    var idx_benef_prenom = csv.GetFieldIndex("benef_prenom");

                    var idx_ligne_identifiant = csv.GetFieldIndex("ligne_identifiant");

                    while (csv.Read())
                    {
                        try
                        {
                            var date = csv.GetField(new string[] { "avant_date_signature", "conv_date_signature", "remu_date" })?.Trim();

                            var dateSignature = Convert.ToDateTime(date, _cultureFr);

                            if (dateSignature.Year == 2019 && !string.IsNullOrEmpty(csv.GetField(idx_benef_identifiant_valeur)))
                            {
                                Company company = null;
                                Person  benef   = null;
                                Link    link    = null;

                                var externalId = csv.GetField(idx_entreprise_identifiant);
                                if (!_existingReferences.Any(x => x == externalId))
                                {
                                    company = new Company()
                                    {
                                        Reference   = externalId,
                                        Designation = csv.GetField(idx_denomination_sociale)
                                    };
                                    _companies.Add(company.Reference, company);
                                    _existingReferences.Add(externalId);
                                    counterCompanies++;
                                }
                                else
                                {
                                    company = _companies[externalId];
                                }

                                externalId = csv.GetField(idx_benef_identifiant_valeur)?.Trim();
                                if (!_existingReferences.Any(x => x == externalId))
                                {
                                    var lastName  = csv.GetField(idx_benef_nom)?.Trim();
                                    var firstName = csv.GetField(idx_benef_prenom)?.Trim();

                                    benef = new Person()
                                    {
                                        Reference = externalId,
                                        FirstName = firstName,
                                        LastName  = lastName
                                    };
                                    _beneficiaries.Add(benef.Reference, benef);
                                    _existingReferences.Add(externalId);
                                    counterBenef++;
                                }
                                else
                                {
                                    benef = _beneficiaries[externalId];
                                }

                                externalId = csv.GetField(idx_ligne_identifiant).Trim();
                                if (!_existingReferences.Any(x => x == externalId))
                                {
                                    // remu_convention_liee
                                    var amount = csv.GetField(new string[] { "avant_montant_ttc", "conv_montant_ttc", "remu_montant_ttc" })?.Trim();
                                    var kind   = csv.GetField(new string[] { "avant_nature", "conv_objet" })?.Trim();

                                    link = new FinancialLink
                                    {
                                        Reference = externalId,
                                        Amount    = Convert.ToDecimal(amount, _cultureFr),
                                        Kind      = kind,
                                        Date      = Convert.ToDateTime(date, _cultureFr),
                                        From      = company,
                                        To        = benef,
                                    };
                                    _links.Add(link.Reference, link);
                                    _existingReferences.Add(externalId);
                                    counterBonds++;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            OnMessage?.Invoke(this, new MessageEventArgs {
                                Message = $"\"{path}\" {e.Message}: {csv.Context.RawRecord}"
                            });
                        }

                        _mainCounter++;
                        records++;
                    }
                }
            }

            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Read {records} records"
            });
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Added {counterCompanies} companies, {counterBenef} beneficiaries, {counterBonds} insterest bonds"
            });
            OnMessage?.Invoke(this, new MessageEventArgs {
                Message = $"Total {_companies.Count} companies, {_beneficiaries.Count} beneficiaries, {_links.Count} insterest links"
            });
        }