protected virtual async Task <SoapGetProductsResponse> GetProductsAsync(string productType, bool productTypeShouldBeExcluded, string productIdLike, DateTime?updatedFrom)
        {
            try
            {
                var filters = new filters {
                    filter = new associativeEntity[0], complex_filter = new complexFilter[0]
                };

                if (productType != null)
                {
                    AddFilter(filters, productType, "type", productTypeShouldBeExcluded ? "neq" : "eq");
                }
                if (updatedFrom.HasValue)
                {
                    AddFilter(filters, updatedFrom.Value.ToSoapParameterString(), "updated_at", "from");
                }
                if (!string.IsNullOrWhiteSpace(productIdLike))
                {
                    AddFilter(filters, productIdLike, "product_id", "like");
                }

                var store = string.IsNullOrWhiteSpace(this.Store) ? null : this.Store;

                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var res           = new catalogProductListResponse();
                var privateClient = this._clientFactory.GetClient();

                await ActionPolicies.GetAsync.Do(async() =>
                {
                    var statusChecker = new StatusChecker(maxCheckCount);
                    TimerCallback tcb = statusChecker.CheckStatus;

                    privateClient = this._clientFactory.RefreshClient(privateClient);
                    var sessionId = await this.GetSessionId().ConfigureAwait(false);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        res = await privateClient.catalogProductListAsync(sessionId.SessionId, filters, store).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new SoapGetProductsResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException(string.Format("An error occured during GetProductsAsync()"), exc);
            }
        }
예제 #2
0
        public virtual async Task <SoapGetProductsResponse> GetProductsAsync()
        {
            try
            {
                var filters = new filters {
                    filter = new associativeEntity[0]
                };

                var store = string.IsNullOrWhiteSpace(this.Store) ? null : this.Store;

                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var res           = new catalogProductListResponse();
                var privateClient = this.CreateMagentoServiceClient(this.BaseMagentoUrl);

                await ActionPolicies.GetAsync.Do(async() =>
                {
                    var statusChecker = new StatusChecker(maxCheckCount);
                    TimerCallback tcb = statusChecker.CheckStatus;

                    if (privateClient.State != CommunicationState.Opened &&
                        privateClient.State != CommunicationState.Created &&
                        privateClient.State != CommunicationState.Opening)
                    {
                        privateClient = this.CreateMagentoServiceClient(this.BaseMagentoUrl);
                    }

                    var sessionId = await this.GetSessionId().ConfigureAwait(false);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        res = await privateClient.catalogProductListAsync(sessionId.SessionId, filters, store).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new SoapGetProductsResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException(string.Format("An error occured during GetProductsAsync()"), exc);
            }
        }
예제 #3
0
 public SoapGetProductsResponse(catalogProductListResponse res)
 {
     this.Products = res.result.Select(x => new SoapProduct(x));
 }
        protected virtual async Task <SoapGetProductsResponse> GetProductsAsync(string productType, bool productTypeShouldBeExcluded, string productIdLike, DateTime?updatedFrom)

        {
            Func <bool, Task <catalogProductListResponse> > call = async(keepAlive) =>
            {
                var filtersTemp = new filters();

                if (productType != null)
                {
                    AddFilter(filtersTemp, productType, "type", productTypeShouldBeExcluded ? "neq" : "eq");
                }
                if (updatedFrom.HasValue)
                {
                    AddFilter(filtersTemp, updatedFrom.Value.ToSoapParameterString(), "updated_at", "from");
                }
                if (!string.IsNullOrWhiteSpace(productIdLike))
                {
                    AddFilter(filtersTemp, productIdLike, "product_id", "like");
                }

                var filters = filtersTemp;
                //var filters = new MagentoSoapServiceReference_v_1_14_1_EE.filters { filter = new MagentoSoapServiceReference_v_1_14_1_EE.associativeEntity[1]{associativeEntity} };
                var store = string.IsNullOrWhiteSpace(this.Store) ? null : this.Store;
                var res   = new catalogProductListResponse();

                const int     maxCheckCount    = 2;
                const int     delayBeforeCheck = 1800000;
                var           privateClient    = this._clientFactory.GetClient(keepAlive);
                var           statusChecker    = new StatusChecker(maxCheckCount);
                TimerCallback tcb = statusChecker.CheckStatus;

                privateClient = this._clientFactory.RefreshClient(privateClient, keepAlive);

                var sessionId = await this.GetSessionId().ConfigureAwait(false);

                using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                    res = await privateClient.catalogProductListAsync(sessionId.SessionId, filters, store).ConfigureAwait(false);

                return(res);
            };

            try
            {
                // keep alive is a crutch for 1 client, which has server that sloses connection after few minutes.
                var keepAlive = false;
                var res       = new catalogProductListResponse();
                await ActionPolicies.GetAsync.Do(async() =>
                {
                    try
                    {
                        res = await call(keepAlive).ConfigureAwait(false);
                        return;
                    }
                    catch (CommunicationException)
                    {
                        keepAlive = !keepAlive;
                    }
                    res = await call(keepAlive).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new SoapGetProductsResponse(res));
            }
            catch (Exception exc)
            {
                if (exc is CommunicationException)                  //crunch for fbeauty
                {
                    var r = exc as CommunicationException;
                    if (r.InnerException.Message.Contains("403"))
                    {
                        if (productIdLike.Contains("00"))
                        {
                            return(null);
                        }
                    }
                }
                throw new MagentoSoapException(string.Format("An error occured during GetProductsAsync()"), exc);
            }
        }