Пример #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.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);
            }
        }
Пример #2
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);
            }
        }
        public virtual async Task <CatalogProductInfoResponse> GetProductInfoAsync(CatalogProductInfoRequest catalogProductInfoRequest, bool throwException = true)
        {
            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

                var res           = new catalogProductRepositoryV1GetResponse1();
                var privateClient = this._clientFactory.CreateMagentoCatalogProductRepositoryServiceClient();

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

                    privateClient = this._clientFactory.RefreshMagentoCatalogProductRepositoryServiceClient(privateClient);

                    // we don't need them, since Magento 2.0 returns all attributes
                    //var attributes = new catalogProductRequestAttributes { additional_attributes = custAttributes ?? new string[ 0 ] };

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                    {
                        var catalogProductRepositoryV1GetRequest = new CatalogProductRepositoryV1GetRequest()
                        {
                            sku = catalogProductInfoRequest.Sku
                        };
                        res = await privateClient.catalogProductRepositoryV1GetAsync(catalogProductRepositoryV1GetRequest).ConfigureAwait(false);
                    }
                }).ConfigureAwait(false);

                return(new CatalogProductInfoResponse(res));
            }
            catch (Exception exc)
            {
                if (throwException)
                {
                    throw new MagentoSoapException($"An error occured during GetProductInfoAsync({catalogProductInfoRequest.ToJson()})", exc);
                }
                else
                {
                    return(new CatalogProductInfoResponse(exc));
                }
            }
        }