public CallResult <IList <ImageInfo> > GetMainImageFromUrl(string url, IWebPageParser pageParser, out long downloadedSize) { downloadedSize = 0; var html = String.Empty; try { /* * <div id="imgTagWrapperId" class="imgTagWrapper" style="height: 801.299px;"> * * <img alt="Sara's Prints Little Girls' Short Sleeve Nightie, Red/Pink Chevron, 2" * src="http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY879_.jpg" * data-old-hires="http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UL1500_.jpg" * class="a-dynamic-image a-stretch-vertical" id="landingImage" * data-a-dynamic-image="{"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY606_.jpg":[405,606],"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY879_.jpg":[587,879],"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY741_.jpg":[495,741],"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY445_.jpg":[297,445],"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY500_.jpg":[334,500],"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY679_.jpg":[453,679],"http://ecx.images-amazon.com/images/I/81YDdI2Rk0L._UY550_.jpg":[367,550]}" style="max-height: 801px; max-width: 587px;"> * * </div> */ var htmlResult = _htmlScraper.GetHtml(url, ProxyUseTypes.Amazon, (proxy, status, content) => { return(status == HttpStatusCode.OK && pageParser.ValidateHtml(content)); }); if (htmlResult.IsSuccess) { html = htmlResult.Data; downloadedSize = html.Length; return(pageParser.GetLargeImages(html)); } else { CallHelper.ThrowIfFail(htmlResult); } } catch (Exception ex) { _log.Error("Parsing html page issue, url=" + url, ex); _log.Info("HTML: " + html); return(new CallResult <IList <ImageInfo> >() { Status = CallStatus.Fail, Exception = ex, }); } return(new CallResult <IList <ImageInfo> >() { Status = CallStatus.Fail }); }
public void SendEmail(IUnitOfWork db, ILogService log, IEmailService emailService, IQuantityManager quantityManager, DateTime when, long?by) { CallResult <Exception> result; if (AppSettings.IsDemo) { result = CallResult <Exception> .Success(null); } else { result = emailService.SendEmail(this, CallSource.UI, by); } CallHelper.ThrowIfFail(result); Order order = null; switch (this.EmailType) { case EmailTypes.RequestFeedback: db.Orders.UpdateRequestedFeedback(this.OrderNumber); break; case EmailTypes.AddressVerify: db.Orders.UpdateRequestedAddressVerify(this.OrderNumber); break; case EmailTypes.LostPackage: break; case EmailTypes.LostPackage2: break; case EmailTypes.UndeliverableAsAddressed: break; case EmailTypes.ExchangeInstructions: if (ExchangeItems != null) { var exchangeToItems = ExchangeItems.Where(i => i.InputQuantity > 0).ToList(); if (exchangeToItems.Any()) { var model = new QuantityOperationDTO() { Type = (int)QuantityOperationType.ExchangeOnHold, OrderId = this.OrderNumber, Comment = "Sent Exchange Instruction", QuantityChanges = exchangeToItems.Select(i => new QuantityChangeDTO() { Quantity = i.InputQuantity, StyleId = i.ExchangeStyleId ?? 0, StyleItemId = i.ExchangeStyleItemId ?? 0, StyleString = i.ExchangeStyleString, ExpiredOn = when.AddDays(14), Tag = "Exchanged from: " + i.StyleString + ", styleItemId: " + i.StyleItemId, }).ToList(), }; quantityManager.AddQuantityOperation(db, model, when, by); } foreach (var item in ExchangeItems) { log.Info("Exchange item, from styleId=" + item.StyleId + " styleItemId=" + item.StyleItemId + " --- to styleId=" + item.ExchangeStyleId + ", styleItemId=" + item.ExchangeStyleItemId + ", quantity=" + item.InputQuantity); //TODO: save into DB } } break; } if (!String.IsNullOrEmpty(NewComment)) { AddOrderComment(db, OrderNumber, NewComment, when, by); } var emailNotifyType = EmailNotifyHelper.GetEmailNotifyFrom(this.EmailType); db.OrderEmailNotifies.Add(new OrderEmailNotify() { OrderNumber = this.OrderNumber, Reason = "User emailed, webpage", Type = (int)emailNotifyType, CreateDate = when, CreatedBy = by }); db.Commit(); if (ReplyToEmailId.HasValue) { var email = db.Emails.Get(ReplyToEmailId.Value); if (email != null) { email.ResponseStatus = (int)EmailResponseStatusEnum.Sent; db.Commit(); log.Info("Mark as responsed (as reply), emailId=" + email.Id); } } if (!String.IsNullOrEmpty(this.OrderNumber)) { var orderEmails = db.Emails.GetAllByOrderId(this.OrderNumber) .Where(e => e.FolderType == (int)EmailFolders.Inbox && ((String.IsNullOrEmpty(e.AnswerMessageID) && e.ResponseStatus == (int)EmailResponseStatusEnum.None) || e.ResponseStatus == (int)EmailResponseStatusEnum.ResponsePromised)) .ToList(); foreach (var email in orderEmails) { var dbEmail = db.Emails.Get(email.Id); dbEmail.ResponseStatus = (int)EmailResponseStatusEnum.Sent; log.Info("Mark as responsed (by orderNumber), emailId=" + email.Id); } db.Commit(); } }