Ejemplo n.º 1
0
 public override void ProcessPerson(string pnr)
 {
     BrokerContext.Current = brokerContext;
     try
     {
         CprBroker.Engine.Local.Admin.LogFormattedSuccess("Converting person <{0}> from DPR", pnr);
         using (var dprDataContext = new DPRDataContext(OtherConnectionString))
         {
             var pId = new PersonIdentifier()
             {
                 CprNumber = pnr, UUID = UuidCache.GetUuid(pnr)
             };
             var personInfo = PersonInfo.GetPersonInfo(dprDataContext, decimal.Parse(pnr));
             var reg        = personInfo.ToRegisteringType1(UuidCache.GetUuid, dprDataContext);
             UpdateDatabase.UpdatePersonRegistration(pId, reg);
         }
     }
     catch (Exception ex)
     {
         Admin.LogException(ex);
         throw ex;
     }
 }
Ejemplo n.º 2
0
        public static void ConvertPersons(int batchSize)
        {
            Admin.LogFormattedSuccess("ExtractManager.ConvertPersons() started, batch size <{0}>", batchSize);
            List <Guid> succeeded = new List <Guid>(), failed = new List <Guid>();

            using (var dataContext = new ExtractDataContext())
            {
                var dataLoadOptions = new System.Data.Linq.DataLoadOptions();
                dataLoadOptions.LoadWith <ExtractItem>(ei => ei.Extract);
                dataContext.LoadOptions = dataLoadOptions;

                var persons = ExtractPersonStaging.SelectTop(dataContext, batchSize);
                Admin.LogFormattedSuccess("ExtractManager.ConvertPersons() - <{0}> persons found", persons.Length);

                var conversionExtracts = ExtractConversion.CreateFromPersonStagings(persons);
                ExtractConversion.FillExtractItems(conversionExtracts, dataContext);

                // Preload UUIDs
                var pnrs  = ExtractConversion.AllPNRs(conversionExtracts);
                var cache = new UuidCache();
                cache.FillCache(pnrs);

                int personIndex = 0;
                foreach (var personGroup in conversionExtracts)
                {
                    Admin.LogFormattedSuccess("ExtractManager.ConvertPersons() - converting persons from extract <{0}>", personGroup.Extract.ExtractId);
                    foreach (var person in personGroup.Persons)
                    {
                        personIndex++;
                        try
                        {
                            Admin.LogFormattedSuccess("ExtractManager.ConvertPersons() - processing PNR <{0}>, person <{1}> of <{2}>", person.ExtractPersonStaging.PNR, personIndex, persons.Length);
                            var uuid             = cache.GetUuid(person.ExtractPersonStaging.PNR);
                            var response         = Extract.ToIndividualResponseType(person.ExtractPersonStaging.Extract, person.ExtractItems.AsQueryable(), Constants.DataObjectMap);
                            var oioPerson        = response.ToRegistreringType1(cache.GetUuid);
                            var personIdentifier = new Schemas.PersonIdentifier()
                            {
                                CprNumber = person.ExtractPersonStaging.PNR, UUID = uuid
                            };
                            UpdateDatabase.UpdatePersonRegistration(personIdentifier, oioPerson);

                            succeeded.Add(person.ExtractPersonStaging.ExtractPersonStagingId);
                            Admin.LogFormattedSuccess("ExtractManager.ConvertPersons() - finished PNR <{0}>, person <{1}> of <{2}>", person.ExtractPersonStaging.PNR, personIndex, persons.Length);
                        }
                        catch (Exception ex)
                        {
                            failed.Add(person.ExtractPersonStaging.ExtractPersonStagingId);
                            Admin.LogException(ex);
                        }
                    }
                }
            }

            // Delete the staging tables from a new data context to maximize performance
            using (var dataContext = new ExtractDataContext())
            {
                var persons = dataContext.ExtractPersonStagings.Where(ep => succeeded.Contains(ep.ExtractPersonStagingId));
                dataContext.ExtractPersonStagings.DeleteAllOnSubmit(persons);
                dataContext.SubmitChanges();
            }
            Admin.LogFormattedSuccess("ExtractManager.ConvertPersons() ending, batch size: <{0}>, succeeded: <{1}>, failed: <{2}>", batchSize, succeeded.Count, failed.Count);
        }