Example #1
0
        public async Task <ShopVisibleOrders> GetOrdersToExportAdvancedAsync(ProcessingOptions processingOptions, AvailableExportTypes exportType, bool returnAddressesOnly, bool includeCustomerTokens, int ordersToReturn, int[] orderStatusOverride, int[] itemStatusOverride, int[] includeSupplierIds, int buyersRemorse = 60)
        {
            var orders = new ShopVisibleOrders();

            includeSupplierIds  = includeSupplierIds ?? new int[0];
            orderStatusOverride = orderStatusOverride ?? new int[0];
            itemStatusOverride  = itemStatusOverride ?? new int[0];
            var requestParameters = processingOptions.ToPipedStrings(exportType, buyersRemorse, includeSupplierIds, returnAddressesOnly, includeCustomerTokens, ordersToReturn, orderStatusOverride, itemStatusOverride);

            await ActionPolicies.GetAsync.Do(async() =>
            {
                var xmlnewOrders = await this._client.GetOrdersToExportAdvancedAsync(
                    this._credentials.ClientName,
                    this._credentials.Guid,
                    requestParameters
                    );

                var newOrders = XmlSerializeHelpers.Deserialize <ShopVisibleOrders>(xmlnewOrders.OuterXml);

                if (newOrders.Response.ResponseHasErrors && newOrders.Response.ResponseCode != "SUCCESS")
                {
                    throw new Exception(
                        string.Format(
                            "Sync Orders. Client: {0}, Parameters: ({1}) ErrorDescription: {2}", this._credentials.ClientName,
                            requestParameters, newOrders.Response.ResponseDescription));
                }

                orders.Orders.AddRange(newOrders.Orders);
            });

            return(orders);
        }
Example #2
0
        public ShopVisibleOrders GetOrders(DateTime startDateUtc, DateTime endDateUtc)
        {
            var orders = new ShopVisibleOrders();

            ActionPolicies.Get.Do(() =>
            {
                var currentStartDate = startDateUtc;

                while (currentStartDate < endDateUtc)
                {
                    var currentEndDate = currentStartDate.AddHours(1);
                    if (currentEndDate > endDateUtc)
                    {
                        currentEndDate = endDateUtc;
                    }

                    var xmlnewOrders = this._client.GetOrdersByDateTimeRange(this._credentials.ClientName, this._credentials.Guid,
                                                                             currentStartDate.ToString(CultureInfo.InvariantCulture),
                                                                             currentEndDate.ToString(CultureInfo.InvariantCulture),
                                                                             "true");
                    var newOrders = XmlSerializeHelpers.Deserialize <ShopVisibleOrders>(xmlnewOrders.OuterXml);

                    if (newOrders.Response.ResponseHasErrors && newOrders.Response.ResponseCode != "SUCCESS")
                    {
                        throw new Exception(
                            string.Format(
                                "Sync Orders. Client: {0}, DateRange: ({1};{2}), IterationDateRange: ({3};{4}), ErrorDescription: {5}", this._credentials.ClientName,
                                startDateUtc, endDateUtc, currentStartDate, currentEndDate, newOrders.Response.ResponseDescription));
                    }

                    orders.Orders.AddRange(newOrders.Orders);

                    currentStartDate = currentEndDate;
                }

                if (this.ConcatModifiedOrders(startDateUtc, endDateUtc))
                {
                    var xmlmodifiedOrders = this._client.GetChangedOrdersByDateRange(this._credentials.ClientName, this._credentials.Guid,
                                                                                     startDateUtc.ToString(CultureInfo.InvariantCulture), endDateUtc.ToString(CultureInfo.InvariantCulture), "true");
                    var modifiedOrders = XmlSerializeHelpers.Deserialize <ShopVisibleOrders>(xmlmodifiedOrders.OuterXml);

                    if (modifiedOrders.Response.ResponseHasErrors && modifiedOrders.Response.ResponseCode != "SUCCESS")
                    {
                        throw new Exception(string.Format(
                                                "Sync Changed Orders. Client: {0}, DateRange: ({1};{2}), ErrorDescription: {3}", this._credentials.ClientName,
                                                startDateUtc, endDateUtc, modifiedOrders.Response.ResponseDescription));
                    }

                    orders.Orders.AddRange(modifiedOrders.Orders);
                }
            });

            return(orders);
        }