public virtual async Task <GetOrdersResponse> GetOrdersAsync(IEnumerable <string> ordersIds)
        {
            var ordersIdsAgregated = string.Empty;

            try
            {
                ordersIdsAgregated = string.Join(",", ordersIds);

                filters filters;
                if (string.IsNullOrWhiteSpace(this.Store))
                {
                    filters = new filters {
                        complex_filter = new complexFilter[1]
                    }
                }
                ;
                else
                {
                    filters = new filters {
                        complex_filter = new complexFilter[2]
                    };
                    filters.complex_filter[1] = new complexFilter {
                        key = "store_id", value = new associativeEntity {
                            key = "in", value = this.Store
                        }
                    };
                }

                filters.complex_filter[0] = new complexFilter {
                    key = "increment_id", value = new associativeEntity {
                        key = "in", value = ordersIdsAgregated
                    }
                };

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

                var res = new salesOrderListResponse();

                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.salesOrderListAsync(sessionId.SessionId, filters).ConfigureAwait(false);
                }).ConfigureAwait(false);

                return(new GetOrdersResponse(res));
            }
            catch (Exception exc)
            {
                throw new MagentoSoapException($"An error occured during GetOrdersAsync({ordersIdsAgregated})", exc);
            }
        }
Esempio n. 2
0
		public virtual async Task< GetOrdersResponse > GetOrdersAsync( DateTime modifiedFrom, DateTime modifiedTo, Mark mark = null )
		{
			try
			{
				filters filters;

				if( string.IsNullOrWhiteSpace( this.Store ) )
					filters = new filters { complex_filter = new complexFilter[ 2 ] };
				else
				{
					filters = new filters { complex_filter = new complexFilter[ 3 ] };
					filters.complex_filter[ 2 ] = new complexFilter { key = "store_id", value = new associativeEntity { key = "in", value = this.Store } };
				}

				filters.complex_filter[ 1 ] = new complexFilter { key = "updated_at", value = new associativeEntity { key = "from", value = modifiedFrom.ToSoapParameterString() } };
				filters.complex_filter[ 0 ] = new complexFilter { key = "updated_at", value = new associativeEntity { key = "to", value = modifiedTo.ToSoapParameterString() } };

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

				var res = new salesOrderListResponse();

				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.salesOrderListAsync( sessionId.SessionId, filters ).ConfigureAwait( false );
				} ).ConfigureAwait( false );

				//crutch for magento 1.7 
				res.result = res.result.Where( x => Extensions.ToDateTimeOrDefault( x.updated_at ) >= modifiedFrom && Extensions.ToDateTimeOrDefault( x.updated_at ) <= modifiedTo ).ToArray();

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