Beispiel #1
0
        /// <summary>
        /// Gets the job matching the supplied id
        /// </summary>
        /// <param name="jobId"></param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public async Task <Job> ReadJob(string jobId)
        {
            if (String.IsNullOrEmpty(jobId))
            {
                return(null);
            }
            if (_advertUrl == null)
            {
                throw new InvalidOperationException("You must specify advertUrl when creating this instance to read an individual job");
            }
            if (_jobAdvertParser == null)
            {
                throw new InvalidOperationException("You must specify jobAdvertParser when creating this instance to read an individual job");
            }

            var queryString = HttpUtility.ParseQueryString(_advertUrl.Query);

            UpdateQueryString(queryString, "nPostingTargetID", jobId);
            var sourceUrl  = new StringBuilder(_advertUrl.Scheme).Append("://").Append(_advertUrl.Authority).Append(_advertUrl.AbsolutePath).Append("?").Append(queryString);
            var htmlStream = await ReadHtml(new Uri(sourceUrl.ToString()), _proxy);

            using (var reader = new StreamReader(htmlStream))
            {
                return(await _jobAdvertParser.ParseJob(reader.ReadToEnd(), jobId));
            }
        }
        /// <summary>
        /// Gets the job matching the supplied id
        /// </summary>
        /// <param name="jobId"></param>
        /// <returns></returns>
        public async Task <Job> ReadJob(string jobId)
        {
            if (String.IsNullOrEmpty(jobId))
            {
                return(null);
            }
            if (_advertUrl == null)
            {
                throw new InvalidOperationException("You must specify advertUrl when creating this instance to read an individual job");
            }
            if (_jobAdvertParser == null)
            {
                throw new InvalidOperationException("You must specify jobAdvertParser when creating this instance to read an individual job");
            }

            var advertUrl = new Uri(String.Format(CultureInfo.InvariantCulture, _advertUrl.ToString(), jobId));

            var stream = await ReadXml(advertUrl, _proxy);

            using (var reader = new StreamReader(stream))
            {
                return(await _jobAdvertParser.ParseJob(reader.ReadToEnd(), jobId));
            }
        }