public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request) { if (!await _authManager.HasSitePermissionsAsync(request.SiteId, AdvertisementUtils.PermissionsAdd)) { return(Unauthorized()); } Models.Advertisement advertisement; if (request.AdvertisementId > 0) { advertisement = await _advertisementRepository.GetAsync(request.SiteId, request.AdvertisementId); } else { if (await _advertisementRepository.IsExistsAsync(request.AdvertisementName, request.SiteId)) { return(this.Error("保存失败,已存在相同名称的广告!")); } advertisement = new Models.Advertisement(); } advertisement.SiteId = request.SiteId; advertisement.AdvertisementName = request.AdvertisementName; advertisement.AdvertisementType = request.AdvertisementType; advertisement.ScopeType = request.ScopeType; advertisement.ChannelIds = request.ChannelIds; advertisement.IsChannels = request.IsChannels; advertisement.IsContents = request.IsContents; advertisement.TemplateIds = request.TemplateIds; advertisement.IsDateLimited = request.IsDateLimited; advertisement.StartDate = request.StartDate; advertisement.EndDate = request.EndDate; advertisement.NavigationUrl = request.NavigationUrl; advertisement.ImageUrl = request.ImageUrl; advertisement.Width = request.Width; advertisement.Height = request.Height; advertisement.RollingType = request.RollingType; advertisement.PositionType = request.PositionType; advertisement.PositionX = request.PositionX; advertisement.PositionY = request.PositionY; advertisement.IsCloseable = request.IsCloseable; advertisement.Delay = request.Delay; if (advertisement.Id > 0) { await _advertisementRepository.UpdateAsync(advertisement); } else { await _advertisementRepository.InsertAsync(advertisement); } return(new BoolResult { Value = true }); }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <param name="actionAdExtracted"></param> /// <returns></returns> public Models.Advertisement.Advertisements ExtractAds(string htmlDocument, Action <Handlers.EventHandlers.AdExtractedEventArgs> actionAdExtracted) { Models.Advertisement.Advertisements _ads = null; try { HtmlAgilityPack.HtmlDocument _doc = new HtmlAgilityPack.HtmlDocument(); _doc.LoadHtml(htmlDocument); var _N = HtmlUtil.GetNode(_doc.DocumentNode, "ul", "id", "searchResultListings"); HtmlAgilityPack.HtmlNode[] _nodes = _N.Descendants("li") .Where(li => li.Attributes.Contains("class") && li.Attributes[@"class"].Value.Contains("listingContainer")) .ToArray(); if (_nodes != null && _nodes.Count() > 0) { _ads = new Models.Advertisement.Advertisements(); int _pgItemIdx = 0; foreach (HtmlAgilityPack.HtmlNode _n in _nodes) { Models.Advertisement _ad = new Models.Advertisement(); _pgItemIdx++; Stopwatch _stopwatch = new Stopwatch(); _stopwatch.Reset(); _stopwatch.Start(); _ad = this.EscrapeAdInfo(_n); if (_ad != null) { _ad = this.EscrapeAdInfoExtend(_ad); } _stopwatch.Stop(); _ads.Add(_ad); if (actionAdExtracted != null) { actionAdExtracted(new Handlers.EventHandlers.AdExtractedEventArgs(_ad, _stopwatch.Elapsed, _pgItemIdx)); } } } } catch (Exception ex) { if (this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "ExtractAds"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } return(_ads); }
public async Task <IActionResult> DeleteAdvertisement([FromRoute] int id) { Models.Advertisement deletedAdvertisement = await _advertisementService.DeleteAdvertisement(id); if (deletedAdvertisement == null) { return(NotFound()); } return(Ok(deletedAdvertisement)); }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <param name="actionAdExtracted"></param> /// <returns></returns> public Models.Advertisement.Advertisements ExtractAds(string htmlDocument, Action <Handlers.EventHandlers.AdExtractedEventArgs> actionAdExtracted) { Models.Advertisement.Advertisements _ads = null; try { HtmlAgilityPack.HtmlDocument _doc = new HtmlAgilityPack.HtmlDocument(); _doc.LoadHtml(htmlDocument); var _nodes = HtmlUtil.GetNodeCollection(_doc.DocumentNode, "div", "class", "ypgListing clearfix"); if (_nodes != null && _nodes.Count() > 0) { _ads = new Models.Advertisement.Advertisements(); int _pgItemIdx = 0; foreach (HtmlAgilityPack.HtmlNode _n in _nodes) { Models.Advertisement _ad = new Models.Advertisement(); _pgItemIdx++; Stopwatch _stopwatch = new Stopwatch(); _stopwatch.Reset(); _stopwatch.Start(); _ad = this.EscrapeAdInfo(_n); if (_ad != null) { _ad = this.EscrapeAdInfoExtend(_ad); } _stopwatch.Stop(); _ads.Add(_ad); if (actionAdExtracted != null) { actionAdExtracted(new Handlers.EventHandlers.AdExtractedEventArgs(_ad, _stopwatch.Elapsed, _pgItemIdx)); } } } } catch (Exception ex) { if (this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "ExtractAds"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } return(_ads); }
public async Task <Models.Advertisement> DeleteAdvertisement(int advertisementId) { Models.Advertisement existingAdvertisement = await _context.Advertisements.SingleOrDefaultAsync(advertisement => advertisement.ID == advertisementId); if (existingAdvertisement == null) { return(null); } EntityEntry <Models.Advertisement> deletingAdvertisement = _context.Advertisements.Remove(existingAdvertisement); await _context.SaveChangesAsync(); return(deletingAdvertisement.Entity); }
public async Task <Models.Advertisement> CreateAdvertisement(Models.Advertisement advertisement) { //Models.Advertisement creatingAdvertisement = new Models.Advertisement //{ // Login = user.Login, // Email = user.Email //}; //creatingUser.Password = new PasswordHasher<Models.User>().HashPassword(creatingUser, user.Password); EntityEntry <Models.Advertisement> createdAdvertisement = await _context.Advertisements.AddAsync(advertisement); await _context.SaveChangesAsync(); return(createdAdvertisement.Entity); }
public async Task <IActionResult> PostAdvertisement([FromBody] Advertisement advertisement) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } advertisement.UserID = int.Parse(User?.FindFirst("userId")?.Value); Models.Advertisement createdAdvertisement = await _advertisementService.CreateAdvertisement(advertisement); if (createdAdvertisement != null) { return(Ok(createdAdvertisement)); } return(BadRequest()); }
public async Task <IActionResult> PutAdvertisement([FromRoute] int id, [FromBody] Advertisement advertisement) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (!(int.Parse(User?.FindFirst("userId")?.Value)).Equals(id)) //{ // return Unauthorized(); //} Models.Advertisement updatedAdvertisement = await _advertisementService.UpdateAdvertisement(advertisement, id); if (updatedAdvertisement == null) { return(NotFound()); } return(Ok(updatedAdvertisement)); }
public static bool IsAdvertisement(IParseContext context, Models.Advertisement advertisement) { if (advertisement.IsDateLimited) { if (DateTime.Now < advertisement.StartDate || DateTime.Now > advertisement.EndDate) { return(false); } } if (advertisement.ScopeType == ScopeType.All) { return(true); } if (advertisement.ScopeType == ScopeType.Templates) { return(ListUtils.Contains(advertisement.TemplateIds, context.TemplateId)); } if (advertisement.ScopeType == ScopeType.Channels) { if (context.TemplateType == TemplateType.FileTemplate) { return(false); } if (!advertisement.IsChannels && (context.TemplateType == TemplateType.ContentTemplate || context.TemplateType == TemplateType.FileTemplate)) { return(false); } if (!advertisement.IsContents && context.TemplateType == TemplateType.ContentTemplate) { return(false); } return(ListUtils.Contains(advertisement.ChannelIds, context.ChannelId)); } return(false); }
private async Task <string> GetDisplayAsync(int siteId, Models.Advertisement ad) { var builder = new StringBuilder(); if (ad.ScopeType == ScopeType.Channels) { foreach (var channelId in ad.ChannelIds) { var channelName = await _channelRepository.GetChannelNameNavigationAsync(siteId, channelId); if (!string.IsNullOrEmpty(channelName)) { builder.Append(channelName); } builder.Append(","); } builder.Length--; } else if (ad.ScopeType == ScopeType.Templates) { if (ad.TemplateIds != null) { foreach (var templateId in ad.TemplateIds) { var templateName = await _templateRepository.GetTemplateNameAsync(templateId); if (!string.IsNullOrEmpty(templateName)) { builder.Append(templateName); } builder.Append(","); } builder.Length--; } } return(builder.Length > 0 ? $"{ad.ScopeType.GetDisplayName()} - {builder}" : ad.ScopeType.GetDisplayName()); }
/// <summary> /// /// </summary> /// <param name="adInf"></param> /// <returns></returns> public Models.Advertisement EscrapeAdInfoExtend(Models.Advertisement adInf) { if (adInf != null && !string.IsNullOrEmpty(adInf.AdvertiserLink)) { try { string _htmlDoc = HtmlUtil.GetPageDocument(adInf.AdvertiserLink); HtmlAgilityPack.HtmlDocument htmDocAg = new HtmlAgilityPack.HtmlDocument(); htmDocAg.LoadHtml(_htmlDoc); string _googMap = "[NA]"; string _keywords = "[NA]"; var _n = HtmlUtil.GetNode(htmDocAg.DocumentNode, "meta", "name", "keywords"); if (_n != null) { _keywords = _n.Attributes["content"].Value; } string _description = "[NA]"; HtmlAgilityPack.HtmlNode _metaDesc = HtmlUtil.GetNode(htmDocAg.DocumentNode, "meta", "name", "description"); if (_metaDesc != null) { _description = _metaDesc.Attributes["content"].Value; } string _emailAdd = "[NA]"; /* * <a id="mainEmailAddressLink" class="emailBusinessLink" rel="nofollow" href="/onlineSolution_emailBusiness.do?listingId=14074960&classification=MAIN&context=businessTypeSearch&referredBy=YOL" title="Contact Turner Freeman Lawyers"> * <img class="emailAddressIcon" src="/ui/standard/bpp/email_icon.png" alt="Main Email Address"> * <span>[email protected]</span> * </a> */ HtmlAgilityPack.HtmlNode _emailAdNode = HtmlUtil.GetNode(htmDocAg.DocumentNode, "a", "id", "mainEmailAddressLink"); if (_emailAdNode != null) { _emailAdd = _emailAdNode.Descendants("span").ToArray()[0].InnerText; } string _locations = "[NA]"; //string _dateAdded = "[NA]"; adInf.GoogleMap = _googMap; adInf.Keywords = _keywords; adInf.Description = _description; adInf.EmailAddress = _emailAdd; adInf.Locations = _locations; //adInf.DateAdded = _dateAdded; } catch (Exception ex) { if (this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "EscrapeAdInfoExtend"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } } return(adInf); }
/// <summary> /// /// </summary> /// <param name="htmNode"></param> /// <returns></returns> public Models.Advertisement EscrapeAdInfo(HtmlAgilityPack.HtmlNode htmNode) { Models.Advertisement _adInfo = null; if (htmNode != null) { try { HtmlAgilityPack.HtmlNode __n = null; string _businessName = "[ERROR]"; __n = HtmlUtil.GetNode(htmNode, "meta", "itemprop", "name"); _businessName = __n.Attributes["content"].Value; _businessName = Models.Advertisement.Resolve(_businessName); string _description = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "div", "class", "enhancedTextDesc paragraph"); if (__n != null) { _description = __n.InnerText; } string _phone = "[NA]"; try { /* <div class="preferredContact paragraph"> * <span class="prefix">ph:</span> * <span preferredcontact="1">(02) 8222 3333</span> * </div> */ _phone = HtmlUtil.GetNode(htmNode, "div", "class", "preferredContact paragraph").Descendants("span").ToArray()[1].InnerText; } catch { } string _fax = "[NA]"; //HtmlUtil.GetInnerText(_n, "div", "class", "phoneNumber"); /* * <span class="address">Level 11/ 75 Elizabeth St, Sydney NSW 2000</span> */ string _fullAddress = HtmlUtil.GetInnerText(htmNode, "span", "class", "address"); string _streetBlk = string.Empty; string _locality = string.Empty; string _region = string.Empty; string _postalCode = string.Empty; Parsers.SplitAddresses(_fullAddress, ref _streetBlk, ref _locality, ref _region, ref _postalCode); string _website = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "a", "name", "listing_website"); if (__n != null) { _website = Models.Advertisement.Resolve(__n.InnerText); } string _latitude = "[NA]"; string _longitude = "[NA]"; /*<li flagnumber="1" * class="gold mappableListing listingContainer omnitureListing" * longitude="151.210118" * latitude="-33.867857" * product=";473590701;;;;evar26=Turner_Freeman_Lawye|evar23=O|evar46=YOLDSOL-DC" listingposition="1">*/ _latitude = htmNode.Attributes["latitude"].Value; _longitude = htmNode.Attributes["longitude"].Value; /* * <div class="yelp-rating review-rating" review="5"></div> */ string _rating = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "div", "class", "yelp-rating review-rating"); if (__n != null) { _rating = __n.Attributes["review"].Value; } /* <a href="/nsw/sydney/edwards-barrie-13025623-listing.html?context=businessTypeSearch&referredBy=YOL" name="listing_name" class="omnitureListingNameLink" id="listing-name-link-25"> * <span id="listing-name-25">Edwards Barrie</span> * </a> */ string _adLink = "[ERROR]"; __n = HtmlUtil.GetNode(htmNode, "a", "class", "omnitureListingNameLink"); if (__n != null) { _adLink = __n.Attributes["href"].Value; } //-------------------------------------------------------- _adInfo = new Models.Advertisement() { BusinessName = _businessName, Description = _description, Phone = _phone, Fax = _fax, FullAddress = _fullAddress, StreetBlk = _streetBlk, Locality = _locality, Region = _region, PostalCode = _postalCode, Website = _website, Latitude = _latitude, Longtitude = _longitude, Rating = _rating, AdvertiserLink = string.Format("{0}{1}", this.directoryProviderSetting.BaseUrl, _adLink), }; } catch (Exception ex) { if (this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "EscrapeAdInfo"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } } return(_adInfo); }
public async Task <Models.Advertisement> UpdateAdvertisement(Models.Advertisement advertisement, int advertisementId)///TODO ads update??? { Models.Advertisement existingAdvertisement = await _context.Advertisements.SingleOrDefaultAsync(a => a.ID == advertisementId); if (advertisement.Latitude > 0) { existingAdvertisement.Latitude = advertisement.Latitude; } if (advertisement.Longitude > 0) { existingAdvertisement.Longitude = advertisement.Longitude; } if (advertisement.TotalArea > 0) { existingAdvertisement.TotalArea = advertisement.TotalArea; } if (advertisement.KitchenArea > 0) { existingAdvertisement.KitchenArea = advertisement.KitchenArea; } if (advertisement.KitchenArea > 0) { existingAdvertisement.KitchenArea = advertisement.KitchenArea; } if (advertisement.LivingArea > 0) { existingAdvertisement.LivingArea = advertisement.LivingArea; } if (advertisement.Balcony) { existingAdvertisement.Balcony = advertisement.Balcony; } if (advertisement.TV != null) { existingAdvertisement.TV = advertisement.TV; } existingAdvertisement.Balcony = advertisement.Balcony; existingAdvertisement.Elevator = advertisement.Elevator; existingAdvertisement.TV = advertisement.TV; existingAdvertisement.AirConditioner = advertisement.AirConditioner; existingAdvertisement.Fridge = advertisement.Fridge; existingAdvertisement.Stove = advertisement.Stove; if (advertisement.Type != null) { existingAdvertisement.Type = advertisement.Type; } if (!String.IsNullOrEmpty(advertisement.Region)) { existingAdvertisement.Region = advertisement.Region; } if (!String.IsNullOrEmpty(advertisement.Housing)) { existingAdvertisement.Housing = advertisement.Housing; } if (!String.IsNullOrEmpty(advertisement.City)) { existingAdvertisement.City = advertisement.City; } if (advertisement.House > 0) { existingAdvertisement.House = advertisement.House; } if (advertisement.Apartment > 0) { existingAdvertisement.Apartment = advertisement.Apartment; } if (!String.IsNullOrEmpty(advertisement.District)) { existingAdvertisement.District = advertisement.District; } if (!String.IsNullOrEmpty(advertisement.Street)) { existingAdvertisement.Street = advertisement.Street; } if (advertisement.RoomsNumber > 0) { existingAdvertisement.RoomsNumber = advertisement.RoomsNumber; } if (advertisement.ConstructionYear > 0) { existingAdvertisement.ConstructionYear = advertisement.ConstructionYear; } if (advertisement.Floor > 0) { existingAdvertisement.Floor = advertisement.Floor; } if (advertisement.TotalFloors > 0) { existingAdvertisement.TotalFloors = advertisement.TotalFloors; } if (advertisement.Cost > 0) { existingAdvertisement.Cost = advertisement.Cost; } existingAdvertisement.EditDate = DateTime.Now; EntityEntry <Models.Advertisement> updatedAdvertisement = _context.Advertisements.Update(existingAdvertisement); await _context.SaveChangesAsync(); return(updatedAdvertisement.Entity); }
/// <summary> /// /// </summary> /// <param name="adInf"></param> /// <returns></returns> public Models.Advertisement EscrapeAdInfoExtend(Models.Advertisement adInf) { if (adInf != null && !string.IsNullOrEmpty(adInf.AdvertiserLink)) { try { string _htmlDoc = HtmlUtil.GetPageDocument(adInf.AdvertiserLink); HtmlAgilityPack.HtmlDocument htmDocAg = new HtmlAgilityPack.HtmlDocument(); htmDocAg.LoadHtml(_htmlDoc); string _latitude = "[NA]"; string _longitude = "[NA]"; HtmlAgilityPack.HtmlNode _mapDatNode = HtmlUtil.GetNode(htmDocAg.DocumentNode, "div", "id", "ypgMapContainer"); if (_mapDatNode != null) { //latLong = new VELatLong(43.8087172232, -79.5469648855); map.CreateAndLoadMap string _mapDat = _mapDatNode.InnerText; int _mrkrStart = _mapDat.IndexOf("VELatLong", 0); int _mrkrEnd = _mapDat.IndexOf("map.CreateAndLoadMap", 0); _mapDat = _mapDat.Substring(_mrkrStart, _mrkrEnd - _mrkrStart); _mapDat = _mapDat .Replace("VELatLong(", "") .Replace("map.CreateAndLoadMap", "") .Replace(");", "") .Trim(); string[] _coords = _mapDat.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); _latitude = _coords[0]; _longitude = _coords[1]; } string _googMap = "[NA]"; string _keywords = "[NA]"; HtmlAgilityPack.HtmlNode _metaKeywords = HtmlUtil.GetNode(htmDocAg.DocumentNode, "meta", "name", "keywords"); if (_metaKeywords != null) { _keywords = _metaKeywords.Attributes["content"].Value; } string _description = "[NA]"; HtmlAgilityPack.HtmlNode _metaDesc = HtmlUtil.GetNode(htmDocAg.DocumentNode, "meta", "name", "description"); if (_metaDesc != null) { _description = _metaDesc.Attributes["content"].Value; } string _rating = "[NA]"; string _emailAdd = "[NA]"; HtmlAgilityPack.HtmlNode _emailAdNode = HtmlUtil.GetNode(htmDocAg.DocumentNode, "div", "class", "busCardLeftLinks"); if (_emailAdNode != null) { try { _emailAdd = _emailAdNode.Descendants("a").ToArray()[0].Attributes["content"].Value; } catch { } } string _locations = "[NA]"; //string _dateAdded = "[NA]"; adInf.Latitude = _latitude; adInf.Longtitude = _longitude; adInf.GoogleMap = _googMap; adInf.Keywords = _keywords; adInf.Description = _description; adInf.Rating = _rating; adInf.EmailAddress = _emailAdd; adInf.Locations = _locations; //adInf.DateAdded = _dateAdded; } catch (Exception ex) { if (this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "EscrapeAdInfoExtend"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } } return(adInf); }
/// <summary> /// /// </summary> /// <param name="htmNode"></param> /// <returns></returns> public Models.Advertisement EscrapeAdInfo(HtmlAgilityPack.HtmlNode htmNode) { Models.Advertisement _adInfo = null; if (htmNode != null) { try { string _businessName = HtmlUtil.GetInnerText(htmNode, "span", "class", "listingTitle"); _businessName = Models.Advertisement.Resolve(_businessName); string _phone = HtmlUtil.GetInnerText(htmNode, "div", "class", "phoneNumber"); string _fax = "[NA]"; //HtmlUtil.GetInnerText(_n, "div", "class", "phoneNumber"); string _fullAddress = HtmlUtil.GetInnerText(htmNode, "div", "class", "address"); string _streetBlk = string.Empty; string _locality = string.Empty; string _region = string.Empty; string _postalCode = string.Empty; Parsers.SplitAddresses(_fullAddress, ref _streetBlk, ref _locality, ref _region, ref _postalCode); HtmlAgilityPack.HtmlNode __n = null; string _website = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "ul", "class", "ypgListingLinks"); if (__n != null) { try { __n = HtmlUtil.GetNode(htmNode, "li", "class", "noPrint"); __n = __n.Descendants("a").ToArray()[0]; _website = __n.Attributes["href"].Value.Replace("/gourl/", string.Empty); } catch { } } string _adLink = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "h3", "class", "listingTitleLine"); if (__n != null) { __n = __n.Descendants("a").ToArray()[0]; _adLink = __n.Attributes["href"].Value; } //-------------------------------------------------------- _adInfo = new Models.Advertisement() { BusinessName = _businessName, Phone = _phone, Fax = _fax, FullAddress = _fullAddress, StreetBlk = _streetBlk, Locality = _locality, Region = _region, PostalCode = _postalCode, Website = _website, AdvertiserLink = string.Format("{0}{1}", this.directoryProviderSetting.BaseUrl, _adLink), }; } catch (Exception ex) { if (this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "EscrapeAdInfo"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } } return(_adInfo); }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <param name="actionAdExtracted"></param> /// <returns></returns> public Models.Advertisement.Advertisements ExtractAds(string htmlDocument, Action<Handlers.EventHandlers.AdExtractedEventArgs> actionAdExtracted) { Models.Advertisement.Advertisements _ads = null; try { HtmlAgilityPack.HtmlDocument _doc = new HtmlAgilityPack.HtmlDocument(); _doc.LoadHtml(htmlDocument); var _nodes = HtmlUtil.GetNodeCollection(_doc.DocumentNode, "div", "class", "ypgListing clearfix"); if(_nodes != null && _nodes.Count() > 0) { _ads = new Models.Advertisement.Advertisements(); int _pgItemIdx = 0; foreach(HtmlAgilityPack.HtmlNode _n in _nodes) { Models.Advertisement _ad = new Models.Advertisement(); _pgItemIdx++; Stopwatch _stopwatch = new Stopwatch(); _stopwatch.Reset(); _stopwatch.Start(); _ad = this.EscrapeAdInfo(_n); if(_ad != null) _ad = this.EscrapeAdInfoExtend(_ad); _stopwatch.Stop(); _ads.Add(_ad); if(actionAdExtracted != null) actionAdExtracted(new Handlers.EventHandlers.AdExtractedEventArgs(_ad, _stopwatch.Elapsed, _pgItemIdx)); } } } catch(Exception ex) { if(this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "ExtractAds"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } return _ads; }
/// <summary> /// /// </summary> /// <param name="htmNode"></param> /// <returns></returns> public Models.Advertisement EscrapeAdInfo(HtmlAgilityPack.HtmlNode htmNode) { Models.Advertisement _adInfo = null; if(htmNode != null) { try { string _businessName = HtmlUtil.GetInnerText(htmNode, "span", "class", "listingTitle"); _businessName = Models.Advertisement.Resolve(_businessName); string _phone = HtmlUtil.GetInnerText(htmNode, "div", "class", "phoneNumber"); string _fax = "[NA]"; //HtmlUtil.GetInnerText(_n, "div", "class", "phoneNumber"); string _fullAddress = HtmlUtil.GetInnerText(htmNode, "div", "class", "address"); string _streetBlk = string.Empty; string _locality = string.Empty; string _region = string.Empty; string _postalCode = string.Empty; Parsers.SplitAddresses(_fullAddress, ref _streetBlk, ref _locality, ref _region, ref _postalCode); HtmlAgilityPack.HtmlNode __n = null; string _website = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "ul", "class", "ypgListingLinks"); if(__n != null) { try { __n = HtmlUtil.GetNode(htmNode, "li", "class", "noPrint"); __n = __n.Descendants("a").ToArray()[0]; _website = __n.Attributes["href"].Value.Replace("/gourl/", string.Empty); } catch { } } string _adLink = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "h3", "class", "listingTitleLine"); if(__n != null) { __n = __n.Descendants("a").ToArray()[0]; _adLink = __n.Attributes["href"].Value; } //-------------------------------------------------------- _adInfo = new Models.Advertisement() { BusinessName = _businessName, Phone = _phone, Fax = _fax, FullAddress = _fullAddress, StreetBlk = _streetBlk, Locality = _locality, Region = _region, PostalCode = _postalCode, Website = _website, AdvertiserLink = string.Format("{0}{1}", this.directoryProviderSetting.BaseUrl, _adLink), }; } catch(Exception ex) { if(this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "EscrapeAdInfo"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } } return _adInfo; }
public async Task <int> InsertAsync(Models.Advertisement ad) { return(await _repository.InsertAsync(ad, Q.CachingRemove(GetCacheKey(ad.SiteId)))); }
public ScriptFloating(Models.Advertisement advertisement) { _advertisement = advertisement; }
/// <summary> /// /// </summary> /// <param name="htmlDocument"></param> /// <param name="actionAdExtracted"></param> /// <returns></returns> public Models.Advertisement.Advertisements ExtractAds(string htmlDocument, Action<Handlers.EventHandlers.AdExtractedEventArgs> actionAdExtracted) { Models.Advertisement.Advertisements _ads = null; try { HtmlAgilityPack.HtmlDocument _doc = new HtmlAgilityPack.HtmlDocument(); _doc.LoadHtml(htmlDocument); var _N = HtmlUtil.GetNode(_doc.DocumentNode, "ul", "id", "searchResultListings"); HtmlAgilityPack.HtmlNode[] _nodes = _N.Descendants("li") .Where(li => li.Attributes.Contains("class") && li.Attributes[@"class"].Value.Contains("listingContainer")) .ToArray(); if(_nodes != null && _nodes.Count() > 0) { _ads = new Models.Advertisement.Advertisements(); int _pgItemIdx = 0; foreach(HtmlAgilityPack.HtmlNode _n in _nodes) { Models.Advertisement _ad = new Models.Advertisement(); _pgItemIdx++; Stopwatch _stopwatch = new Stopwatch(); _stopwatch.Reset(); _stopwatch.Start(); _ad = this.EscrapeAdInfo(_n); if(_ad != null) _ad = this.EscrapeAdInfoExtend(_ad); _stopwatch.Stop(); _ads.Add(_ad); if(actionAdExtracted != null) actionAdExtracted(new Handlers.EventHandlers.AdExtractedEventArgs(_ad, _stopwatch.Elapsed, _pgItemIdx)); } } } catch(Exception ex) { if(this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "ExtractAds"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } return _ads; }
/// <summary> /// /// </summary> /// <param name="htmNode"></param> /// <returns></returns> public Models.Advertisement EscrapeAdInfo(HtmlAgilityPack.HtmlNode htmNode) { Models.Advertisement _adInfo = null; if(htmNode != null) { try { HtmlAgilityPack.HtmlNode __n = null; string _businessName = "[ERROR]"; __n = HtmlUtil.GetNode(htmNode, "meta", "itemprop", "name"); _businessName = __n.Attributes["content"].Value; _businessName = Models.Advertisement.Resolve(_businessName); string _description = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "div", "class", "enhancedTextDesc paragraph"); if(__n != null) { _description = __n.InnerText; } string _phone = "[NA]"; try { /* <div class="preferredContact paragraph"> * <span class="prefix">ph:</span> * <span preferredcontact="1">(02) 8222 3333</span> * </div> */ _phone = HtmlUtil.GetNode(htmNode, "div", "class", "preferredContact paragraph").Descendants("span").ToArray()[1].InnerText; } catch { } string _fax = "[NA]"; //HtmlUtil.GetInnerText(_n, "div", "class", "phoneNumber"); /* <span class="address">Level 11/ 75 Elizabeth St, Sydney NSW 2000</span> */ string _fullAddress = HtmlUtil.GetInnerText(htmNode, "span", "class", "address"); string _streetBlk = string.Empty; string _locality = string.Empty; string _region = string.Empty; string _postalCode = string.Empty; Parsers.SplitAddresses(_fullAddress, ref _streetBlk, ref _locality, ref _region, ref _postalCode); string _website = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "a", "name", "listing_website"); if(__n != null) { _website = Models.Advertisement.Resolve(__n.InnerText); } string _latitude = "[NA]"; string _longitude = "[NA]"; /*<li flagnumber="1" * class="gold mappableListing listingContainer omnitureListing" longitude="151.210118" latitude="-33.867857" product=";473590701;;;;evar26=Turner_Freeman_Lawye|evar23=O|evar46=YOLDSOL-DC" listingposition="1">*/ _latitude = htmNode.Attributes["latitude"].Value; _longitude = htmNode.Attributes["longitude"].Value; /* <div class="yelp-rating review-rating" review="5"></div> */ string _rating = "[NA]"; __n = HtmlUtil.GetNode(htmNode, "div", "class", "yelp-rating review-rating"); if(__n != null) { _rating = __n.Attributes["review"].Value; } /* <a href="/nsw/sydney/edwards-barrie-13025623-listing.html?context=businessTypeSearch&referredBy=YOL" name="listing_name" class="omnitureListingNameLink" id="listing-name-link-25"> <span id="listing-name-25">Edwards Barrie</span> </a> */ string _adLink = "[ERROR]"; __n = HtmlUtil.GetNode(htmNode, "a", "class", "omnitureListingNameLink"); if(__n != null) { _adLink = __n.Attributes["href"].Value; } //-------------------------------------------------------- _adInfo = new Models.Advertisement() { BusinessName = _businessName, Description = _description, Phone = _phone, Fax = _fax, FullAddress = _fullAddress, StreetBlk = _streetBlk, Locality = _locality, Region = _region, PostalCode = _postalCode, Website = _website, Latitude = _latitude, Longtitude = _longitude, Rating = _rating, AdvertiserLink = string.Format("{0}{1}", this.directoryProviderSetting.BaseUrl, _adLink), }; } catch(Exception ex) { if(this.frameworkExceptionInvoke != null) { Exception _ex = new Exception(string.Format("Exception in {0}.{1}(?)", this.directoryProviderSetting.ServicedCountry.ToString(), "EscrapeAdInfo"), ex); this.frameworkExceptionInvoke(new Handlers.EventHandlers.FrameworkExceptionEventArgs(_ex)); } } } return _adInfo; }
public ScriptOpenWindow(Models.Advertisement advertisement) { _advertisement = advertisement; }
public async Task <bool> UpdateAsync(Models.Advertisement ad) { return(await _repository.UpdateAsync(ad, Q.CachingRemove(GetCacheKey(ad.SiteId)))); }
public ScriptScreenDown(Models.Advertisement advertisement) { _advertisement = advertisement; }