/// <summary> /// Inspect a response and apply appropriate bit flags /// </summary> /// <param name="r"></param> private KeepaRecordType InspectResponse(Response r, KeepaRecordType type) { if (r.bestSellersList != null) { //add best seller flag type |= KeepaRecordType.BestSellerRecord; } if (r.deals != null) { //add deal flag type |= KeepaRecordType.DealRecord; } if (r.categories != null) { //add category flag type |= KeepaRecordType.CategoryLookupRecord; } if (r.notifications != null) { //add notification flag type |= KeepaRecordType.NotificationRecord; } if (r.products != null) { // add product flag type |= KeepaRecordType.ProductRecord; } if (r.trackings != null) { //add tracking flag type |= KeepaRecordType.TrackingRecord; } if (r.sellers != null) { //add seller flag type |= KeepaRecordType.SellerRecord; } if (r.sellerIdList != null) { //add sellers id list flag type |= KeepaRecordType.TopSellerRecord; } return(type); }
/// <summary> /// Method to markup and create database records from response objects /// </summary> /// <param name="r"></param> /// <returns></returns> public List <IRecord> Create(Response response) { //list of records List <IRecord> recList = new List <IRecord>(); BufferBlock <IRecord> reListBlock = new BufferBlock <IRecord>(); //case to appropriate response type Response r = response; //Default type KeepaRecordType type = KeepaRecordType.Default; //Determine Appropriate record type var responseFlags = InspectResponse(r, type); //Generate appropriate records from response if (responseFlags.HasFlag(KeepaRecordType.BestSellerRecord)) { //passing recList by ref to update the recList we already have with void methods CreateBestSeller(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.DealRecord)) { CreateDeal(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.MarketplaceOfferRecord)) { CreateMarketplaceOffer(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.NotificationRecord)) { CreateNotification(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.ProductRecord)) { //create base product record var guidlist = CreateProduct(r, ref recList); //inspect product property of response here KeepaRecordType productProperties = KeepaRecordType.Default; productProperties = InspectResponse(r.products[0], productProperties); //Create associated records from objects if (productProperties.HasFlag(KeepaRecordType.PriceHistoryRecord)) { CreatePriceHistory(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.StatisitcsRecord)) { CreateStatistics(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.CategoryRecord)) { CreateCategory(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.EanRecord)) { CreateEan(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.EbayListingRecord)) { CreateEbayListing(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.FeaturesRecord)) { CreateFeatures(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.FrequentlyBoughtTogetherRecord)) { CreateFreqBoughtTgthr(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.LanguagesRecord)) { CreateLanguages(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.LiveOffersOrderRecord)) { CreateLiveOfferOrder(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.OffersRecord)) { CreateOffers(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.PromotionsRecord)) { CreatePromotion(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.UpcRecord)) { CreateUpc(r.products, ref recList, ref guidlist); } if (productProperties.HasFlag(KeepaRecordType.VariationsRecord)) { CreateVariations(r.products, ref recList, ref guidlist); } } if (responseFlags.HasFlag(KeepaRecordType.SellerRecord)) { CreateSeller(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.TopSellerRecord)) { CreateTopSeller(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.TrackingCreationRecord)) { CreateTrackingCreation(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.TrackingRecord)) { CreateTracking(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.CategoryLookupRecord)) { CreateCategoryLookupRecord(r, ref recList); } if (responseFlags.HasFlag(KeepaRecordType.CategoryTreeRecord)) { CreateCategoryTreeRecord(r, ref recList); } return(recList); }
/// <summary> /// Inspect a responses product property and apply appropriate bit flags /// </summary> /// <param name="p"></param> /// <param name="type"></param> /// <returns></returns> private KeepaRecordType InspectResponse(Product p, KeepaRecordType type) { if (p.categories != null) { //categories flag type |= KeepaRecordType.CategoryRecord; } if (p.eanList != null) { //eanlist flag type |= KeepaRecordType.EanRecord; } if (p.ebayListingIds != null) { //ebaylists flag type |= KeepaRecordType.EbayListingRecord; } if (p.features != null) { //features flag type |= KeepaRecordType.FeaturesRecord; } if (p.frequentlyBoughtTogether != null) { //frequently bought together flag type |= KeepaRecordType.FrequentlyBoughtTogetherRecord; } if (p.languages != null) { //languages flag type |= KeepaRecordType.LanguagesRecord; } if (p.liveOffersOrder != null) { //live offers order flag type |= KeepaRecordType.LiveOffersOrderRecord; } if (p.offers != null) { //offers flag type |= KeepaRecordType.OffersRecord; } if (p.promotions != null) { //promotions flag type |= KeepaRecordType.PromotionsRecord; } if (p.stats != null) { //stats flag type |= KeepaRecordType.StatisitcsRecord; } if (p.upcList != null) { //upc list flag type |= KeepaRecordType.UpcRecord; } if (p.variations != null) { //Variations flag type |= KeepaRecordType.VariationsRecord; } if (p.csv != null) { //price history flag type |= KeepaRecordType.PriceHistoryRecord; } if (p.fbaFees != null) { //fba fees flag type |= KeepaRecordType.FbaFeesRecord; } return(type); }