예제 #1
0
        public static async void ImportClients(ICompanyAppService companyService, IProjectMetaDataService metaDataService)
        {
            var newClient = new NewCEIDGApiProd.NewDataStoreProviderClient(EndpointConfiguration.BasicHttpBinding_INewDataStoreProvider);

            try
            {
                var configuration    = ConfigurationHelper.Get(Directory.GetCurrentDirectory(), null, true);
                var dateOfLastImport = metaDataService.GetDateOfLastImport(ProviderType.CEIDG);

                newClient.InnerChannel.OperationTimeout = TimeSpan.MaxValue;

                var result = await newClient.GetMigrationDataExtendedAddressInfoAsync(
                    configuration.GetValue <string>("CEIDGApiKey"), //key
                    null,                                           //nip
                    null,                                           //regon
                    null,                                           //nip_sc
                    null,                                           //regon_sc
                    null,                                           //name
                    Voivodeships,                                   // provinces,
                    null,                                           //county
                    null,                                           //commune
                    null,                                           //city
                    null,                                           //street
                    null,                                           //postcode
                    null,                                           //date from
                    null,                                           //date to
                    null,                                           //pkd
                    new List <int> {
                    1
                },                                                                            //status
                    null,                                                                     //unique id
                    dateOfLastImport == DateTime.MinValue?(DateTime?)null : dateOfLastImport, //migration date from
                    null);                                                                    //migration date to

                var importedCompanies = ParseCompanies(result);

                companyService.AddCompanies(importedCompanies, dateOfLastImport == DateTime.MinValue);

                metaDataService.SetDateOfLastImport(ProviderType.CEIDG, DateTime.Now);
            }
            catch (Exception ex)
            {
                ErrorLog.Save(ex);
                throw;
            }
            finally
            {
                if (newClient.State == CommunicationState.Faulted)
                {
                    newClient.Abort();
                }
                else
                {
                    await newClient.CloseAsync();
                }
            }
        }