internal static async void AddJob(string fileName, JobViewModel job) { var file = await GetFileFromFileName(fileName); using (var readStream = await file.OpenAsync(FileAccessMode.ReadWrite)) { var xmldoc = XDocument.Load(readStream.AsStreamForRead()); var root = xmldoc.Root; root.Add(new XElement("job", new XElement("jobid", job.JobID), new XElement("jobtitle", job.JobTitle), new XElement("jobdescription", job.JobDescription), new XElement("jobdate", job.JobDate), new XElement("jobcity", job.JobCity), new XElement("company", new XElement("companyid", job.Company.CompanyID), new XElement("companyname", job.Company.CompanyName), new XElement("companylogourl", job.Company.CompanyLogoURL) ))); //await readStream.FlushAsync(); readStream.Size = 0; readStream.Seek(0); root.Document.Save(readStream.AsStreamForWrite()); //root.Document.Save(readStream.AsStreamForWrite()); } }
internal void HandleAddJobToFavoritesCommand(JobViewModel parameter) { //if (parameter != null && !this.favoriteJobsCollection.Contains(parameter,EqualityComparer<JobViewModel>.Default)) if (parameter != null && !this.favoriteJobsCollection.Any(x => (x.JobID == parameter.JobID))) { //if(this.favoriteJobsCollection.Any(x=>(x.JobID == parameter.JobID)); this.favoriteJobsCollection.Add(parameter); DataPersister.AddJob(favoriteJobsFilename, parameter); } }
internal void HandleRemoveJobCommand(JobViewModel parameter) { //if (parameter != null && this.favoriteJobsCollection.Contains(parameter)) if (parameter != null && this.favoriteJobsCollection.Any(x => (x.JobID == parameter.JobID))) { this.favoriteJobsCollection.Remove(parameter); DataPersister.RemoveJob(favoriteJobsFilename, parameter.JobID); DisplayJobsCollection = this.favoriteJobsCollection; //this.OnPropertyChanged("FavoriteJobsCollection"); //this.OnPropertyChanged("ResultJobsCollection"); //this.OnPropertyChanged("DisplayJobsCollection"); } }
public static IEnumerable <JobViewModel> SearchForJobsInCollection( SearchQueryViewModel searchQuery, IEnumerable <JobViewModel> Jobs) { var result = new LinkedList <JobViewModel>(); if (Jobs != null)//&& Jobs.Count > 0 { foreach (var item in Jobs) { item.CurrJobMatch = JobViewModel.ChechMatchings(item, searchQuery.LookupSkills, searchQuery.NotMandatoryLookupSkills); if (item.CurrJobMatch.Count() >= searchQuery.LookupSkills.Count) { result.AddLast(item); } } } return(result); }
public static ICollection <SkillViewModel> ChechMatchings( JobViewModel jobToCheck, ICollection <SkillViewModel> lookup, ICollection <SkillViewModel> notMandLookup) { var MatchingList = new List <SkillViewModel>(); if (!String.IsNullOrEmpty(jobToCheck.JobDescription)) { string textToSearch = jobToCheck.JobDescription.ToLower(); foreach (var item in lookup) { if (textToSearch.Contains(item.SkillName.ToLower())) { MatchingList.Add(item); } } if (MatchingList.Count == lookup.Count) { IEnumerable <SkillViewModel> differenceQuery = notMandLookup.Except(lookup); foreach (var item in differenceQuery) { if (textToSearch.Contains(item.SkillName.ToLower())) { MatchingList.Add(item); } } } else { return(new List <SkillViewModel>()); } } return(MatchingList); }
//private static SearchQueryViewModel lastSearchQuery = null; //public static List<JobViewModel> lastResult = null; //last=0&str_regions=&str_locations=&tab=jobs&old_country=&country=-1®ion=0&l_category%5B%5D=0&keyword= public static async Task <ICollection <JobViewModel> > SearchForJobs(SearchQueryViewModel searchQuery)//ICollection<JobViewModel> prevResults = null { //if (lastSearchQuery == null || !(lastSearchQuery.Equals(searchQuery)))//|| (lastResult == null || lastResult.Count() == 0) //{ //if (lastSearchQuery != null) //{ // var debug = (lastSearchQuery== searchQuery); //} List <JobViewModel> testResult = new List <JobViewModel>(); var skipResults = searchQuery.SkipPages; var keyword = searchQuery.Keyword; var dateFilter = searchQuery.PublishDate; var lookupSkills = searchQuery.LookupSkills; var notMandatoryLookupSkills = searchQuery.NotMandatoryLookupSkills; var baseAddress = "http://www.jobs.bg/front_job_search.php?"; //lastSearchQuery = searchQuery; //if (lastSearchQuery == null) //{ // lastSearchQuery = new SearchQueryViewModel( // keyword, // dateFilter, // lookupSkills, // notMandatoryLookupSkills, // skipResults // ); //} //else //{ // lastSearchQuery.Keyword = keyword; // lastSearchQuery.PublishDate = dateFilter; // lastSearchQuery.LookupSkills = lookupSkills; // lastSearchQuery.NotMandatoryLookupSkills = notMandatoryLookupSkills; // lastSearchQuery.SkipPages = skipResults; //} lastSkipResults += skipResults; if (lastSkipResults < 0) { lastSkipResults = 0; } var fullUri = String.Format("{0}frompage={3}&last={1}&keyword={2}", baseAddress, dateFilter.PublishDateValue, keyword, lastSkipResults); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(fullUri); var response = await client.GetAsync(""); //var responseTextAsStream = await response.Content.ReadAsStreamAsync(); var responseText = await response.Content.ReadAsStringAsync(); HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); // There are various options, set as needed htmlDoc.OptionFixNestedTags = false; // filePath is a path to a file containing the html //htmlDoc.Load(responseTextAsStream); htmlDoc.LoadHtml(responseText); // Use: htmlDoc.LoadHtml(xmlString); to load from a string (was htmlDoc.LoadXML(xmlString) // ParseErrors is an ArrayList containing any errors from the Load statement //if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) //{ // // Handle any parse errors as required //} //else if (htmlDoc.DocumentNode != null) { //List<HtmlAgilityPack.HtmlNode> bodyNode = htmlDoc.DocumentNode.Descendants("table").Where(x=>((x.Descendants("table").Count()) > 2)).ToList();// ("//body"); if (htmlDoc.DocumentNode.Descendants("td") != null) { var tableNode = (htmlDoc.DocumentNode.Descendants("td").Where( d => (d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("listTitle")) ).FirstOrDefault()); if (tableNode != null && tableNode.ParentNode != null && tableNode.ParentNode.ParentNode != null) { tableNode = tableNode.ParentNode.ParentNode; } if (tableNode != null) { var jobOfferRows = tableNode.Descendants("tr"); foreach (var row in jobOfferRows) { var cells = row.Elements("td").Where(d => (d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("offerslistRow"))).ToList(); if (cells.Count() == 5) { JobViewModel newOffer = null; try { newOffer = await CreateJobOfferFromRow(cells); } catch (Exception e) { throw new InvalidOperationException("Parsing Job Offer Failed", e); } //item.CurrJobMatch = item.ChechMatchings(parameter.LookupSkills, parameter.NotMandatoryLookupSkills); //if (newOffer != null) //{ // newOffer.CurrJobMatch = JobViewModel.ChechMatchings(newOffer, lookupSkills, notMandatoryLookupSkills); // if (newOffer.CurrJobMatch.Count() >= lookupSkills.Count) // { // testResult.Add(newOffer); // } //} if (newOffer != null) { testResult.Add(newOffer); } } } } } } //lastResult = testResult; return(testResult); //} //else //{ // return lastResult; //} }
private static async Task <JobViewModel> CreateJobOfferFromRow(List <HtmlNode> cells) { try { //var tempRest = cells[0].InnerHtml; //var tempRest1 = cells[1].InnerHtml; //var tempRest2 = cells[2].InnerHtml; //var tempRest3 = cells[3].InnerHtml; //var tempRest4 = cells[4].InnerHtml; var date = cells[0].InnerText; if (date == "днес") { date = (DateTime.Today).Date.ToString("dd.MM.yy"); } else if (date == "вчера") { date = (DateTime.Today.AddDays(-1)).Date.ToString("dd.MM.yy"); } var jobTitle = PurifyString(cells[2].Element("a").InnerText); var city = PurifyString(cells[2].LastChild.InnerText); var jobID = cells[2].Element("a").Attributes["href"].Value; string companyLogo; if (cells[3].Element("a") != null) { if (cells[3].Element("a").Element("img") != null) { if (cells[3].Element("a").Element("img").Attributes["src"].Value != null) { companyLogo = cells[3].Element("a").Element("img").Attributes["src"].Value; } else { companyLogo = "anonymousLogo"; } } else { companyLogo = "anonymousLogo"; } } else { companyLogo = "anonymousLogo"; } string companyID; string companyName; if (cells[4].Descendants("a") != null) { var tmpElement = cells[4].Descendants("a").FirstOrDefault(); if (tmpElement != null) { companyID = tmpElement.Attributes["href"].Value; companyName = PurifyString(tmpElement.InnerText); } companyID = "anonymousID"; companyName = PurifyString(cells[4].InnerText); } else { companyID = "anonymousID"; companyName = PurifyString(cells[4].InnerText); } JobViewModel newOffer = new JobViewModel(); newOffer.JobID = jobID; newOffer.JobTitle = jobTitle; newOffer.JobCity = city; newOffer.JobDate = date; newOffer.JobDescription = await GetJobDescription(jobID); newOffer.Company = new CompanyViewModel(); newOffer.Company.CompanyID = companyID; newOffer.Company.CompanyName = companyName; newOffer.Company.CompanyLogoURL = companyLogo; return(newOffer); } catch (Exception e) { throw new InvalidOperationException("Error while creating JobModel from Row", e); } }