/// <summary>
        /// Internal method for ExportCompanies().
        /// </summary>
        private void ExportCompanies_Internal()
        {
            WriteBusinessAttributes();

            using (var dtCommunications = GetTableData(SqlQueries.COMPANY_COMMUNICATIONS))
                using (var dtCompanies = GetTableData(SqlQueries.COMPANY, true))
                {
                    foreach (DataRow row in dtCompanies.Rows)
                    {
                        var business = F1Business.Translate(row, dtCommunications);

                        if (business != null)
                        {
                            ImportPackage.WriteToPackage(business);
                        }
                    }

                    // export Phone Numbers
                    foreach (DataRow row in dtCommunications.Rows)
                    {
                        var importNumber = F1BusinessPhone.Translate(row);

                        if (importNumber != null)
                        {
                            ImportPackage.WriteToPackage(importNumber);
                        }
                    }

                    // Cleanup - Remember not to Clear() any cached tables.
                    dtCommunications.Clear();
                    GC.Collect();
                }

            using (var dtAddress = GetTableData(SqlQueries.COMPANY_ADDRESSES))
            {
                foreach (DataRow row in dtAddress.Rows)
                {
                    var importAddress = F1BusinessAddress.Translate(row);

                    if (importAddress != null)
                    {
                        ImportPackage.WriteToPackage(importAddress);
                    }
                }

                // Cleanup - Remember not to Clear() any cached tables.
                dtAddress.Clear();
                GC.Collect();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Internal method for ExportCompanies().
        /// </summary>
        private void ExportCompanies_Internal()
        {
            WriteBusinessAttributes();

            var dtCompany = _db.Table("Company").Data;

            if (dtCompany.Rows.Count == 0)
            {
                // Nothing to export.
                return;
            }

            DataView dvCommunication = _db.Table("Communication").Data.DefaultView;

            dvCommunication.Sort = "LastUpdatedDate"; // Communications must be sorted by LastUpdatedDate to ensure we get the right values.

            var companyCommunications = (from table1 in dvCommunication.ToTable().AsEnumerable()
                                         join table2 in dtCompany.AsEnumerable()
                                         on(int) table1["household_id"] equals(int) table2["household_id"]
                                         select table1);

            var dtCompanyCommunications = companyCommunications.CopyToDataTable_Safe(_db.Table("Communication").Data);

            foreach (DataRow row in dtCompany.Rows)
            {
                var business = F1Business.Translate(row, dtCompanyCommunications);

                if (business != null)
                {
                    ImportPackage.WriteToPackage(business);
                }
            }

            // export Phone Numbers
            foreach (DataRow row in dtCompanyCommunications.Rows)
            {
                var importNumber = F1BusinessPhone.Translate(row);

                if (importNumber != null)
                {
                    ImportPackage.WriteToPackage(importNumber);
                }
            }

            // Cleanup.
            dtCompanyCommunications.Clear();
            GC.Collect();

            var dtAddress = _db.Table("Household_Address").Data;

            var companyAddresses = (from table1 in dtAddress.AsEnumerable()
                                    join table2 in dtCompany.AsEnumerable()
                                    on(int) table1["household_id"] equals(int) table2["household_id"]
                                    select table1);

            var dtCompanyAddresses = companyAddresses.CopyToDataTable_Safe(dtAddress);

            foreach (DataRow row in dtCompanyAddresses.Rows)
            {
                var importAddress = F1BusinessAddress.Translate(row);

                if (importAddress != null)
                {
                    ImportPackage.WriteToPackage(importAddress);
                }
            }

            // Cleanup.
            dtCompanyAddresses.Clear();
            GC.Collect();
        }