public static void StoreAttachmentFilesFromFolder(IObjectsToDatabase objectsToDatabase, SpringBaseDao baseDao, OrganizationDataType data, string folderPath)
        {
            if (data.Activity != null)
            {
                foreach (ActivityDataType activity in data.Activity)
                {
                    if (activity.AttachedBinaryObject != null)
                    {
                        foreach (AttachedBinaryObjectDataType attachment in activity.AttachedBinaryObject)
                        {
                            if (string.IsNullOrEmpty(attachment.BinaryObjectFileName))
                            {
                                throw new ArgException("An attachment for the activity with id \"{0}\" does not have an attachment name.",
                                                       activity.ActivityDescription.ActivityIdentifier);
                            }

                            string filePath = Path.Combine(folderPath, attachment.BinaryObjectFileName);
                            if (!File.Exists(filePath))
                            {
                                throw new ArgException("Failed to locate an attachment with the name \"{0}\" for the activity with id \"{1}\" in the temporary folder: \"{2}\"",
                                                       attachment.BinaryObjectFileName, activity.ActivityDescription.ActivityIdentifier, filePath);
                            }

                            byte[] content = CompressFile(folderPath, filePath);

                            int updateCount = baseDao.DoJDBCExecuteNonQuery("UPDATE WQX_ACTATTACHEDBINARYOBJECT SET BINARYOBJECTCONTENT = ? WHERE PARENTID = ? AND BINARYOBJECTFILE = ?",
                                                                            content, activity.RecordId, attachment.BinaryObjectFileName);
                            if (updateCount == 0)
                            {
                                throw new ArgException("Failed to update the content for an attachment with the name \"{0}\" for the activity with id \"{1}\"",
                                                       attachment.BinaryObjectFileName, activity.ActivityDescription.ActivityIdentifier);
                            }
                        }
                    }
                }
            }

            if (data.MonitoringLocation != null)
            {
                foreach (MonitoringLocationDataType monitoringLocation in data.MonitoringLocation)
                {
                    if (monitoringLocation.AttachedBinaryObject != null)
                    {
                        foreach (AttachedBinaryObjectDataType attachment in monitoringLocation.AttachedBinaryObject)
                        {
                            if (string.IsNullOrEmpty(attachment.BinaryObjectFileName))
                            {
                                throw new ArgException("An attachment for the monitoring location \"{0}\" with id \"{1}\" does not have an attachment name.",
                                                       monitoringLocation.WellInformation, monitoringLocation.MonitoringLocationIdentity.MonitoringLocationIdentifier);
                            }

                            string filePath = Path.Combine(folderPath, attachment.BinaryObjectFileName);
                            if (!File.Exists(filePath))
                            {
                                throw new ArgException("Failed to locate an attachment with the name \"{0}\" for the monitoring location \"{1}\" with id \"{2}\" in the temporary folder: \"{3}\"",
                                                       attachment.BinaryObjectFileName, monitoringLocation.WellInformation, monitoringLocation.MonitoringLocationIdentity.MonitoringLocationIdentifier, filePath);
                            }

                            byte[] content = CompressFile(folderPath, filePath);

                            int updateCount = baseDao.DoJDBCExecuteNonQuery("UPDATE WQX_MONLOCATTACHEDBINARYOBJECT SET BINARYOBJECTCONTENT = ? WHERE PARENTID = ? AND BINARYOBJECTFILE = ?",
                                                                            content, monitoringLocation.RecordId, attachment.BinaryObjectFileName);
                            if (updateCount == 0)
                            {
                                throw new ArgException("Failed to update the content for an attachment with the name \"{0}\" for the monitoring location with id \"{1}\"",
                                                       attachment.BinaryObjectFileName, monitoringLocation.MonitoringLocationIdentity.MonitoringLocationIdentifier);
                            }
                        }
                    }
                }
            }

            if (data.Project != null)
            {
                foreach (ProjectDataType project in data.Project)
                {
                    if (project.AttachedBinaryObject != null)
                    {
                        foreach (AttachedBinaryObjectDataType attachment in project.AttachedBinaryObject)
                        {
                            if (string.IsNullOrEmpty(attachment.BinaryObjectFileName))
                            {
                                throw new ArgException("An attachment for the project \"{0}\" with id \"{1}\" does not have an attachment name.",
                                                       project.ProjectDescriptionText, project.ProjectIdentifier);
                            }

                            string filePath = Path.Combine(folderPath, attachment.BinaryObjectFileName);
                            if (!File.Exists(filePath))
                            {
                                throw new ArgException("Failed to locate an attachment with the name \"{0}\" for the project \"{1}\" with id \"{2}\" in the temporary folder: \"{3}\"",
                                                       attachment.BinaryObjectFileName, project.ProjectDescriptionText, project.ProjectIdentifier, filePath);
                            }

                            byte[] content = CompressFile(folderPath, filePath);

                            int updateCount = baseDao.DoJDBCExecuteNonQuery("UPDATE WQX_PROJATTACHEDBINARYOBJECT SET BINARYOBJECTCONTENT = ? WHERE PARENTID = ? AND BINARYOBJECTFILE = ?",
                                                                            content, project.RecordId, attachment.BinaryObjectFileName);
                            if (updateCount == 0)
                            {
                                throw new ArgException("Failed to update the content for an attachment with the name \"{0}\" for the project with id \"{1}\"",
                                                       attachment.BinaryObjectFileName, project.ProjectIdentifier);
                            }
                        }
                    }
                }
            }
        }
        public static string StoreWqxDataToDatabase(IAppendAuditLogEvent appendAuditLogEvent, WQXDataType data, IObjectsToDatabase objectsToDatabase,
                                                    SpringBaseDao baseDao, string attachmentsFolderPath)
        {
            appendAuditLogEvent.AppendAuditLogEvent("Storing WQX data into the database ...");

            string countsString = string.Empty;

            baseDao.TransactionTemplate.Execute(delegate(Spring.Transaction.ITransactionStatus status)
            {
                OrganizationDataType org = data.Organization;

                appendAuditLogEvent.AppendAuditLogEvent("Storing WQX data into database for organization \"{0}\" ...", org.OrganizationDescription.OrganizationFormalName);

                appendAuditLogEvent.AppendAuditLogEvent(DatabaseHelper.GetWqxOrgCountsString(org));

                Dictionary <string, int> insertCounts = objectsToDatabase.SaveToDatabase(data, baseDao);

                DatabaseHelper.StoreAttachmentFilesFromFolder(objectsToDatabase, baseDao, data.Organization, attachmentsFolderPath);

                countsString += string.Format("Stored WQX data for organization \"{0}\" into the database with the following table row counts:{1}{2}",
                                              org.OrganizationDescription.OrganizationFormalName, Environment.NewLine, CreateTableRowCountsString(insertCounts));

                appendAuditLogEvent.AppendAuditLogEvent(countsString);

                return(null);
            });
            return(countsString);
        }