Example #1
0
        /// <summary>
        /// Reads the jobs from pages of data provided by the <see cref="IJobsDataProvider"/>
        /// </summary>
        /// <returns></returns>
        public async Task <JobSearchResult> ReadJobs(JobSearchQuery query)
        {
            if (_jobResultsParser == null)
            {
                throw new InvalidOperationException("You must specify jobResultsParser when creating this instance to read jobs");
            }

            var jobs = new JobSearchResult()
            {
                Jobs = new List <Job>()
            };

            var currentPage = 1;

            while (true)
            {
                Stream stream = null;
                try
                {
                    stream = await ReadJobsFromTalentLink(currentPage, query).ConfigureAwait(false);

                    if (_saveHtml)
                    {
                        stream = SaveHtml(query, currentPage, stream);
                    }

                    var parseResult = await _jobResultsParser.Parse(stream).ConfigureAwait(false);

                    if (parseResult.Jobs.Count > 0)
                    {
                        jobs.Jobs.AddRange(parseResult.Jobs);
                    }

                    if (parseResult.IsLastPage)
                    {
                        break;
                    }
                    else
                    {
                        currentPage++;
                    }
                }
                finally
                {
                    stream?.Dispose();
                }
            }
            return(jobs);
        }
        /// <summary>
        /// Reads the jobs from pages of data provided by the <see cref="IJobsDataProvider"/>
        /// </summary>
        /// <returns></returns>
        public async Task <JobSearchResult> ReadJobs(JobSearchQuery query)
        {
            if (_jobResultsParser == null)
            {
                throw new InvalidOperationException("You must specify jobResultsParser when creating this instance to read jobs");
            }

            var jobs = new JobSearchResult()
            {
                Jobs = new List <Job>()
            };

            foreach (var resultsUrl in _resultsUrls)
            {
                var stream = await ReadXml(resultsUrl, _proxy).ConfigureAwait(false);

                jobs.Jobs.AddRange((await _jobResultsParser.Parse(stream)).Jobs);
            }
            return(jobs);
        }