Esempio n. 1
0
 private void SetSecurity(AddVacancyRequestMessage request)
 {
     request.Security = new Security {
         UsernameToken = _usernameToken
     };
     request.Body.orgCode    = OrgCode;
     request.Body.siteCode   = SiteCode;
     request.Body.employerID = EmployerId;
 }
Esempio n. 2
0
        private void Add(JobAd jobAd)
        {
            const string method = "Add";

            var request = new AddVacancyRequestMessage {
                Body = _mapper.CreateAddRequestBody(jobAd)
            };

            SetSecurity(request);

            if (request.Body.daysToExpiry <= 2)
            {
                #region Log
                Logger.Raise(Event.Flow, method, "Job ad will not be published as it is about to expire.",
                             Event.Arg("jobAdId", jobAd.Id), Event.Arg("daysToExpiry", request.Body.daysToExpiry));
                #endregion

                return;
            }

            var channel = _channelManager.Create();
            AddVacancyResponseMessage response;
            try
            {
                response = channel.AddVacancy(request);
            }
            catch (Exception)
            {
                _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdExportPostEvent {
                    Success = false, IntegratorUserId = _integratorUser.Id, Failed = 1, JobAds = 1
                });
                _channelManager.Abort(channel);
                throw;
            }
            _channelManager.Close(channel);

            if (response.Header.executionStatus == EsiExecutionStatus.Failed)
            {
                var ser           = new System.Xml.Serialization.XmlSerializer(request.GetType());
                var requestStream = new StringWriter();
                ser.Serialize(requestStream, request);

                _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdExportPostEvent {
                    Success = false, IntegratorUserId = _integratorUser.Id, Failed = 1, JobAds = 1
                });

                #region Log
                Logger.Raise(Event.Error, method, response.Body.ErrorString,
                             Event.Arg("jobAdId", jobAd.Id),
                             Event.Arg("messages", Array.ConvertAll(response.Header.Messages, m => m.text)),
                             Event.Arg("request", requestStream));
                #endregion
                return;
            }

            _exportCommand.CreateJobSearchId(jobAd.Id, response.Body.vacancyID);

            _jobAdIntegrationReportsCommand.CreateJobAdIntegrationEvent(new JobAdExportPostEvent {
                Success = true, IntegratorUserId = _integratorUser.Id, Posted = 1, JobAds = 1
            });

            #region Log
            Logger.Raise(Event.Flow, method, "Job ad has been published.", Event.Arg("jobAdId", jobAd.Id));
            #endregion
        }