public List <int> GetDistinctParentIDs() { List <int> parentProductIDs = new List <int>(); string reqUri, nextUri; JObject result; reqUri = $"https://api.channeladvisor.com/v1/Products/?access_token={DevInfo.GetAccessToken()}&$filter=LastSaleDateUtc lt 2016-05-01"; result = _channelAdvisor.RetrieveProductsFromAPI(reqUri); var noSaleProducts = (JArray)result["value"]; nextUri = (string)result["@odata.nextLink"]; foreach (JToken product in noSaleProducts) { parentProductIDs.Add(Convert.ToInt32(product["ParentProductID"])); } while (nextUri != null) { result = _channelAdvisor.RetrieveProductsFromAPI(nextUri); noSaleProducts = (JArray)result["value"]; nextUri = (string)result["@odata.nextLink"]; foreach (JToken product in noSaleProducts) { int parentProductId; Int32.TryParse(Convert.ToString(product["ParentProductID"]), out parentProductId); parentProductIDs.Add(parentProductId); } } return(parentProductIDs.Distinct().ToList()); }
public void GetAndStoreProductInfo(List <string> filterToGetChilds, List <string> filterToGetParents) { List <Task> tasks = new List <Task>(); string reqUri, nextUri; string filterToGetChild, filterToGetParent; JObject result; filterToGetChild = String.Join(" or ", filterToGetChilds.ToArray()); filterToGetParent = String.Join(" or ", filterToGetParents.ToArray()); filterToGetChilds.Clear(); filterToGetParents.Clear(); // Get Parents tasks.Add(Task.Run(() => { reqUri = $"https://api.channeladvisor.com/v1/Products?access_token={DevInfo.GetAccessToken()}&$filter={filterToGetParent}&$expand=Attributes,Labels,DCQuantities"; result = _channelAdvisor.RetrieveProductsFromAPI(reqUri); _product.AddProducts((JArray)result["value"]); })); // Get Childs tasks.Add(Task.Run(() => { reqUri = $"https://api.channeladvisor.com/v1/Products?access_token={DevInfo.GetAccessToken()}&$filter=({filterToGetChild}) and TotalAvailableQuantity gt 0&$expand=Attributes,Labels,DCQuantities"; result = _channelAdvisor.RetrieveProductsFromAPI(reqUri); _product.AddProducts((JArray)result["value"]); nextUri = (string)result["@odata.nextLink"]; while (nextUri != null) { result = _channelAdvisor.RetrieveProductsFromAPI(nextUri); _product.AddProducts((JArray)result["value"]); nextUri = (string)result["@odata.nextLink"]; } })); Task.WaitAll(tasks.ToArray()); }