Beispiel #1
0
        public async Task <Item> GetProductAsync(string sku)
        {
            var webRequest = ( WebRequest )WebRequest.Create()
                             .Method(MagentoWebRequestMethod.Get)
                             .Path(MagentoServicePath.CreateProductsServicePath().AddCatalog(Uri.EscapeDataString(sku)))
                             .AuthToken(this.Token)
                             .Url(this.Url);

            return(await ActionPolicies.RepeatOnChannelProblemAsync.Get(async() =>
            {
                try
                {
                    using (var v = await webRequest.RunAsync(Mark.CreateNew()).ConfigureAwait(false))
                    {
                        return JsonConvert.DeserializeObject <Item>(new StreamReader(v, Encoding.UTF8).ReadToEnd());
                    }
                }
                catch (MagentoWebException exception)
                {
                    if (exception.IsNotFoundException())
                    {
                        return null;
                    }
                    throw;
                }
            }));
        }
        public async Task <RootObject> GetProductsAsync(DateTime updatedAt, string type, bool excludeType, PagingModel page, Mark mark = null)
        {
            var filterGroups = new List <FilterGroup>()
            {
            };

            if (!string.IsNullOrWhiteSpace(type))
            {
                filterGroups.Add(new FilterGroup()
                {
                    filters = new List <Filter> {
                        new Filter(@"type_id", type, excludeType ? Filter.ConditionType.NotEqual : Filter.ConditionType.Equals)
                    }
                });
            }
            if (updatedAt > DateTime.MinValue)
            {
                filterGroups.Add(new FilterGroup()
                {
                    filters = new List <Filter> {
                        new Filter(@"updated_at", updatedAt.ToRestParameterString(), Filter.ConditionType.GreaterThan)
                    }
                });
            }
            if (!filterGroups.Any())
            {
                filterGroups.Add(new FilterGroup()
                {
                    filters = new List <Filter>()
                });
            }

            var parameters = new SearchCriteria()
            {
                filter_groups = filterGroups,
                current_page  = page.CurrentPage,
                page_size     = page.ItemsPerPage
            };
            var webRequest = ( WebRequest )WebRequest.Create()
                             .Method(MagentoWebRequestMethod.Get)
                             .Path(MagentoServicePath.CreateProductsServicePath())
                             .Parameters(parameters)
                             .AuthToken(this.Token)
                             .Url(this.Url);

            return(await ActionPolicies.RepeatOnChannelProblemAsync.Get(async() =>
            {
                using (var v = await webRequest.RunAsync(mark).ConfigureAwait(false))
                {
                    var response = JsonConvert.DeserializeObject <RootObject>(new StreamReader(v, Encoding.UTF8).ReadToEnd());

                    if (response.items != null)
                    {
                        response.items = response.items.Where(i => !string.IsNullOrWhiteSpace(i.sku)).ToList();
                    }

                    return response;
                }
            }).ConfigureAwait(false));
        }
Beispiel #3
0
        public async Task <Item> GetProductAsync(string sku)
        {
            var webRequest = ( WebRequest )WebRequest.Create()
                             .Method(MagentoWebRequestMethod.Get)
                             .Path(MagentoServicePath.CreateProductsServicePath().AddCatalog(Uri.EscapeDataString(sku)))
                             .AuthToken(this.Token)
                             .Url(this.Url);

            return(await ActionPolicies.RepeatOnChannelProblemAsync.Get(async() =>
            {
                try
                {
                    using (var v = await webRequest.RunAsync(Mark.CreateNew()).ConfigureAwait(false))
                    {
                        return JsonConvert.DeserializeObject <Item>(new StreamReader(v, Encoding.UTF8).ReadToEnd());
                    }
                }
                catch (MagentoException exception)
                {
                    var webException = (exception as MagentoWebException)?.InnerException as WebException;
                    var response = webException?.Response as HttpWebResponse;
                    if (webException?.Status == WebExceptionStatus.ProtocolError && response?.StatusCode == HttpStatusCode.NotFound)
                    {
                        return null;
                    }

                    throw;
                }
            }));
        }
        public void GetOrders_StoreContainsOrders_ReceiveOrders2()
        {
            //------------ Arrange

            //------------ Act
            var sc = new SearchCriteria()
            {
                filter_groups = new List <FilterGroup>()
                {
                    new FilterGroup()
                    {
                        filters = new List <Filter>
                        {
                            new Filter(@"updated_at", @"2016-07-01 00:00:00", Filter.ConditionType.GreaterThan),
                        }
                    }
                },
                page_size = 100, current_page = 1
            };

            //------------ Assert
            var qwe = ( WebRequest )WebRequest.Create()
                      .Method(MagentoWebRequestMethod.Get)
                      .Path(MagentoServicePath.CreateProductsServicePath())
                      .Parameters(sc)
                      .Url(MagentoUrl.Create("http://xxx"))
            ;
            var res = qwe.RunAsync();

            res.Wait();
        }