Esempio n. 1
0
        public virtual async Task <GetMagentoInfoResponse> GetMagentoInfoAsync(bool suppressException, Mark mark = null)
        {
            try
            {
                const int maxCheckCount    = 2;
                const int delayBeforeCheck = 1800000;

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

                await ActionPolicies.GetWithMarkAsync(mark).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.magentoInfoAsync(sessionId.SessionId).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new GetMagentoInfoResponse(res, this.GetServiceVersion()));
            }
            catch (Exception exc)
            {
                if (suppressException)
                {
                    return(null);
                }
                throw new MagentoSoapException(string.Format("An error occured during GetMagentoInfoAsync()"), exc);
            }
        }
        private async Task <TResult> GetWithAsync <TResult, TServerResponse, TClient>(Func <TServerResponse, TResult> converter, Func <TClient, string, Task <TServerResponse> > action, int abortAfter, Func <TClient> clientFactory, Func <TClient, TClient> clientRecreateFactory, bool suppressException = false, Mark mark = null, [CallerMemberName] string callerName = null) where TServerResponse : new() where TClient : class
        {
            try
            {
                var res           = new TServerResponse();
                var privateClient = clientFactory();
                await ActionPolicies.GetWithMarkAsync(mark).Do(async() =>
                {
                    privateClient = clientRecreateFactory(privateClient);
                    var sessionId = await this.GetSessionId().ConfigureAwait(false);

                    var temp = await ClientBaseActionRunner.RunWithAbortAsync(
                        abortAfter,
                        async() => res = await action(privateClient, sessionId.SessionId).ConfigureAwait(false),
                        privateClient).ConfigureAwait(false);

                    if (temp.Item2)
                    {
                        throw new TaskCanceledException();
                    }
                }).ConfigureAwait(false);

                return(converter(res));
            }
            catch (Exception exc)
            {
                if (suppressException)
                {
                    return(default(TResult));
                }
                throw new MagentoSoapException($"An error occured during{callerName}->{nameof( this.GetWithAsync )}", exc);
            }
        }
        public virtual async Task <OrderInfoResponse> GetOrderAsync(string incrementId, Mark mark = null)
        {
            try
            {
                //var frameworkSearchFilterGroups = new List< FrameworkSearchFilterGroup >
                //{
                //	new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "increment_id", conditionType = "eq", value = incrementId } } },
                //};
                //if( string.IsNullOrWhiteSpace( this.Store ) )
                //	frameworkSearchFilterGroups.Add( new FrameworkSearchFilterGroup() { filters = new[] { new FrameworkFilter() { field = "store_Id", conditionType = "eq", value = this.Store } } } );

                var filters = new SalesOrderRepositoryV1GetRequest
                {
                    id = int.Parse(incrementId)
                };

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

                var res = new salesOrderRepositoryV1GetResponse1();

                var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient();

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

                    privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        try
                        {
                            res = await privateClient.salesOrderRepositoryV1GetAsync(filters).ConfigureAwait(false);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.ToLower() == "requested entity doesn't exist")
                            {
                                res = null;
                                return;
                            }
                            throw;
                        }
                }).ConfigureAwait(false);

                return(res == null ? null : new OrderInfoResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during GetOrderAsync(incrementId:{incrementId}) ", exc, mark);
            }
        }
        public virtual async Task <OrderInfoResponse> GetOrderAsync(string incrementId, Mark mark = null)
        {
            try
            {
                var filters = new SalesOrderRepositoryV1GetRequest
                {
                    id = int.Parse(incrementId)
                };

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

                var res = new salesOrderRepositoryV1GetResponse1();

                var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient();

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

                    privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient);

                    using (var stateTimer = new Timer(tcb, privateClient, 1000, delayBeforeCheck))
                        try
                        {
                            res = await privateClient.salesOrderRepositoryV1GetAsync(filters).ConfigureAwait(false);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.ToLower() == "requested entity doesn't exist")
                            {
                                res = null;
                                return;
                            }
                            throw;
                        }
                }).ConfigureAwait(false);

                return(res == null ? null : new OrderInfoResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during GetOrderAsync(incrementId:{incrementId}) ", exc, mark);
            }
        }
Esempio n. 5
0
        private async Task <salesOrderRepositoryV1GetListResponse1> GetOrdersPageByFilter(SalesOrderRepositoryV1GetListRequest filters, Mark mark)
        {
            const int maxCheckCount    = 2;
            const int delayBeforeCheck = 1800000;

            var res = new salesOrderRepositoryV1GetListResponse1();

            var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient();

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

                privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient);

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

            return(res);
        }
        public virtual async Task <GetOrdersResponse> GetOrdersAsync(DateTime modifiedFrom, DateTime modifiedTo, Mark mark = null)
        {
            try
            {
                var frameworkSearchFilterGroups = new List <FrameworkSearchFilterGroup>
                {
                    new FrameworkSearchFilterGroup()
                    {
                        filters = new[] { new FrameworkFilter()
                                          {
                                              field = "updated_At", conditionType = "gt", value = modifiedFrom.ToSoapParameterString()
                                          } }
                    },
                    new FrameworkSearchFilterGroup()
                    {
                        filters = new[] { new FrameworkFilter()
                                          {
                                              field = "updated_At", conditionType = "lt", value = modifiedTo.ToSoapParameterString()
                                          } }
                    },
                };
                if (!string.IsNullOrWhiteSpace(this.Store))
                {
                    frameworkSearchFilterGroups.Add(new FrameworkSearchFilterGroup()
                    {
                        filters = new[] { new FrameworkFilter()
                                          {
                                              field = "store_Id", conditionType = "eq", value = this.Store
                                          } }
                    });
                }

                var filters = new SalesOrderRepositoryV1GetListRequest
                {
                    searchCriteria = new FrameworkSearchCriteria()
                    {
                        currentPage          = 1,
                        currentPageSpecified = true,
                        filterGroups         = frameworkSearchFilterGroups.ToArray(),
                        sortOrders           = new FrameworkSortOrder[] { new FrameworkSortOrder()
                                                                          {
                                                                              direction = "ASC", field = "Id"
                                                                          } },
                        pageSize          = 100,
                        pageSizeSpecified = true,
                    }
                };

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

                var res = new salesOrderRepositoryV1GetListResponse1();

                var privateClient = this._clientFactory.CreateMagentoSalesOrderRepositoryServiceClient();

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

                    privateClient = this._clientFactory.RefreshMagentoSalesOrderRepositoryServiceClient(privateClient);

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

                return(new GetOrdersResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during GetOrdersAsync(modifiedFrom:{modifiedFrom},modifiedTo{modifiedTo})", exc);
            }
        }