예제 #1
0
        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());
        }