PostReport IJobAdPostsManager.PostJobAds(IntegratorUser integratorUser, IEmployer jobPoster, IEmployer integratorJobPoster, IEnumerable <JobAd> jobAds, bool closeAllOtherJobAds) { // Read the jobads. var report = new PostReport(); // Process them. jobPoster = jobPoster ?? integratorJobPoster; foreach (var jobAd in jobAds) { ProcessJobAd(integratorUser.Id, jobPoster, jobAd, report); } if (!closeAllOtherJobAds) { return(report); } var jobAdIds = _jobAdIntegrationQuery.GetJobAdIds(integratorUser.Id, jobPoster.Id); var closeJobAdIds = jobAdIds.Except(report.ProcessedJobAdIds).ToList(); var closeJobAds = _jobAdsQuery.GetJobAds <JobAd>(closeJobAdIds); foreach (var closeJobAd in closeJobAds) { _jobAdsCommand.CloseJobAd(closeJobAd); } report.Closed += closeJobAdIds.Count(); return(report); }
private static string GetResponseXml(PostReport report) { var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { using (var xmlWriter = new XmlTextWriter(writer)) { xmlWriter.WriteStartElement("JobAds"); xmlWriter.WriteAttributeString("added", report.Posted.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteAttributeString("updated", report.Updated.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteAttributeString("closed", report.Closed.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteAttributeString("failed", report.Failed.ToString(CultureInfo.InvariantCulture)); xmlWriter.WriteEndElement(); } } return(sb.ToString()); }
private void CreateJobAd(IEmployer jobPoster, JobAd jobAd, PostReport report) { try { if (!CleanJobAd(jobAd, report)) { return; } // Need to check whether the same job ad has come in through any other integrator. if (!_externalJobAdsCommand.CanCreateJobAd(jobAd)) { return; } // Create the job ad. var status = jobAd.Status; jobAd.Features = _jobAdIntegrationQuery.GetDefaultFeatures(); jobAd.FeatureBoost = _jobAdIntegrationQuery.GetDefaultFeatureBoost(); _employerJobAdsCommand.CreateJobAd(jobPoster, jobAd); report.ProcessedJobAdIds.Add(jobAd.Id); // Only open those that require opening. if (status == JobAdStatus.Open) { _employerJobAdsCommand.OpenJobAd(jobPoster, jobAd, false); } report.Posted++; } catch (Exception ex) { AddErrors(ex, report); report.Failed++; } }
private static bool CleanJobAd(JobAd jobAd, PostReport report) { if (jobAd == null) { throw new ArgumentNullException("jobAd"); } // Strip marquees, blinking text, etc. try { jobAd.Description.Summary = jobAd.Description.Summary.FixExtraTextAndTrim(true, false); jobAd.Description.Content = jobAd.Description.Content.FixExtraTextAndTrim(false, false); } catch (Exception) { var error = string.Format("Failed to strip extra text from job ad '{0}'" + " (external reference ID '{1}').", jobAd.Title, jobAd.Integration.ExternalReferenceId); report.Errors.Add(error); report.Failed++; return(false); } return(true); // OK }
private void UpdateJobAd(IEmployer jobPoster, JobAd jobAd, JobAd existingJobAd, PostReport report) { try { report.ProcessedJobAdIds.Add(existingJobAd.Id); if (CleanJobAd(jobAd, report)) { CopyTo(jobAd, existingJobAd); _employerJobAdsCommand.UpdateJobAd(jobPoster, existingJobAd); // Make sure the job is open if needed. if (jobAd.Status == JobAdStatus.Open) { _employerJobAdsCommand.OpenJobAd(jobPoster, existingJobAd, false); } report.Updated++; } } catch (UserException ex) { AddErrors(ex, report); report.Failed++; } }
private void ProcessJobAd(Guid integratorUserId, IEmployer jobPoster, JobAd jobAd, PostReport report) { jobAd.Integration.IntegratorUserId = integratorUserId; // Check whether it already exists. if (string.IsNullOrEmpty(jobAd.Integration.ExternalReferenceId)) { // Nothing to check against so just create a new job ad. CreateJobAd(jobPoster, jobAd, report); } else { // Look for an existing job ad. var existingJobAd = GetExistingJobAd(jobPoster.Id, jobAd); if (existingJobAd != null) { // Update it. UpdateJobAd(jobPoster, jobAd, existingJobAd, report); } else { // Create it. CreateJobAd(jobPoster, jobAd, report); } } }