Esempio n. 1
0
        public virtual async Task <CatalogProductInfoResponse> GetProductInfoAsync(CatalogProductInfoRequest request, bool throwException = true)
        {
            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var res           = new catalogProductInfoResponse();
                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);
                    var attributes = new catalogProductRequestAttributes {
                        additional_attributes = request.custAttributes ?? new string[0]
                    };

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        res = await privateClient.catalogProductInfoAsync(sessionId.SessionId, request.ProductId, "0", attributes, "1").ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new CatalogProductInfoResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during GetProductInfoAsync({request.ToJson()})", exc);
            }
        }
Esempio n. 2
0
        public CatalogProductInfoResponse(catalogProductInfoResponse catalogProductInfoResponse)
        {
            Description      = catalogProductInfoResponse.result.description;
            ShortDescription = catalogProductInfoResponse.result.short_description;
            Price            = catalogProductInfoResponse.result.price;
            SpecialPrice     = catalogProductInfoResponse.result.special_price;
            Weight           = catalogProductInfoResponse.result.weight;
            ProductId        = catalogProductInfoResponse.result.product_id;
            CategoryIds      = catalogProductInfoResponse.result.category_ids;

            if (catalogProductInfoResponse.result.additional_attributes != null && catalogProductInfoResponse.result.additional_attributes.Any())
            {
                Attributes = catalogProductInfoResponse.result.additional_attributes.Select(x => new ProductAttribute(x.key, x.value)).ToList();
            }
        }
Esempio n. 3
0
        public virtual async Task <CatalogProductInfoResponse> GetProductInfoAsync(CatalogProductInfoRequest request, bool throwException = true)
        {
            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var res           = new catalogProductInfoResponse();
                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);
                    var attributes = new catalogProductRequestAttributes {
                        additional_attributes = request.custAttributes ?? new string[0]
                    };

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        res = await privateClient.catalogProductInfoAsync(sessionId.SessionId, request.ProductId, "0", attributes, "1").ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new CatalogProductInfoResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException(string.Format("An error occured during GetProductInfoAsync({0})", request.ToJson()), exc);
            }
        }