Example #1
0
 internal PreparedProduct(Product p)
 {
     Id = p.Id;
     Url = p.Url;
     CrawlTime = p.CrawlTime;
     ChangeTime = p.ChangeTime;
     Name = Cliver.PrepareField.Html.GetDbField(p.Name);
     Sku = Cliver.PrepareField.Html.GetDbField(p.Sku);
     Price = Cliver.PrepareField.Html.GetDbField(p.Price);
     Description = Cliver.PrepareField.Html.GetDbField(p.Description);
     ImageUrls = string.Join(Cliver.Fhr.ProductOffice.DataApi.Product.IMAGE_URL_SEPARATOR, p.ImageUrls);
     if (p.CategoryBranch != null)//for legacy comaptibility
     {
         List<string> cs = new List<string>();
         foreach (string c in p.CategoryBranch)
         {
             string s = Cliver.PrepareField.Html.GetDbField(c);
             s = Regex.Replace(s, Regex.Escape(Cliver.Fhr.ProductOffice.DataApi.Product.CATEGORY_SEPARATOR), "-", RegexOptions.Singleline | RegexOptions.Compiled);
             cs.Add(s);
         }
         Category = string.Join(Cliver.Fhr.ProductOffice.DataApi.Product.CATEGORY_SEPARATOR, cs);
     }
     else
         Category = "";
     Stock = p.Stock;
 }
            public override void PROCESSOR(BotCycle bc)
            {
                CustomBot cb = (CustomBot)bc.Bot;
                if (!cb.HR.Get(Url))
                    throw new ProcessorException(ProcessorExceptionType.RESTORE_AS_NEW, "Could not get: " + Url);

                DataSifter.Capture gc = cb.product.Parse(cb.HR.HtmlResult);

                decimal stock = (decimal)Fhr.CrawlerHost.Product.StockValue.NOT_SET;
                if (gc.ValueOf("Stock") != null)
                    if (!decimal.TryParse(gc.ValueOf("Stock"), out stock))
                        stock = (decimal)Fhr.CrawlerHost.Product.StockValue.CANNOT_PARSE;

                Fhr.CrawlerHost.Product product = new Fhr.CrawlerHost.Product(
                    id: gc.ValueOf("Id"),
                    url: Url,
                    name: gc.ValueOf("Name"),
                    sku: gc.ValueOf("Sku"),
                    price: gc.ValueOf("Price"),
                    category_branch: gc.ValuesOf("Category"),
                    image_urls: Spider.GetAbsoluteUrls(gc.ValuesOf("ImageUrl"), Url, cb.HR.HtmlResult),
                    stock: stock,
                    description: gc.ValueOf("Description")
                    );
                if (!Fhr.CrawlerHost.CrawlerApi.SaveProductAsJson(product))
                    throw new ProcessorException(ProcessorExceptionType.ERROR, "Product was not saved.");
            }