void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            // reset old plan
            scenario.Tours = new List <Tour>();
            foreach (var o in scenario.Orders)
            {
                o.Tour = null;
            }

            var xtour  = XServerClientFactory.CreateXTourClient(Properties.Settings.Default.XUrl);
            var orders = (from o in scenario.Orders
                          select new TransportDepot
            {
                id = orderMap.B2X(o, o.Id),
                transportPoint = new TransportPoint
                {
                    id = orderMap.B2X(o, o.Id),
                    servicePeriod = 0,                // 0sec; unrealistic but okay for this sample
                    location = new Point
                    {
                        point = new PlainPoint
                        {
                            x = o.Longitude,
                            y = o.Latitude
                        }
                    },
                    openingIntervalConstraint = OpeningIntervalConstraint.START_OF_SERVICE,
                },
                deliveryQuantities = new Quantities {
                    wrappedQuantities = new[] { o.Quantity }
                }
            }).ToArray();

            var depots = (from d in scenario.Depots
                          select new XtourService.Depot
            {
                id = depotMap.B2X(d, d.Id),
                location = new Point
                {
                    point = new PlainPoint
                    {
                        y = d.Latitude,
                        x = d.Longitude
                    }
                }
            }).ToArray();

            var allVehicles = (from d in scenario.Depots select d.Fleet).SelectMany(x => x);

            var interval = new Interval
            {
                @from = 0,
                till  = Convert.ToInt32(scenario.OperatingPeriod.TotalSeconds)
            };

            var vehicles = (from v in allVehicles
                            select new XtourService.Vehicle
            {
                id = vehicleMap.B2X(v, v.Id),
                depotIdStart = depotMap.B2X(v.Depot, v.Depot.Id),
                depotIdEnd = depotMap.B2X(v.Depot, v.Depot.Id),
                isPreloaded = false,
                capacities = new Capacities
                {
                    wrappedCapacities = new[] { new Quantities {
                                                    wrappedQuantities =
                                                        new[] { v.Capacity }
                                                } }
                },
                wrappedOperatingIntervals = new[] { interval },
                dimaId = 1,
                dimaIdSpecified = true,
            }).ToArray();

            var fleet = new Fleet {
                wrappedVehicles = vehicles
            };

            var planningParams = new StandardParams
            {
                wrappedDistanceMatrixCalculation = new DistanceMatrixCalculation[] { new DistanceMatrixByRoad
                                                                                     {
                                                                                         dimaId            = 1,
                                                                                         deleteBeforeUsage = true,
                                                                                         deleteAfterUsage  = true,
                                                                                         profileName       = "dimaTruck",
                                                                                     } },
                availableMachineTime          = 15,
                availableMachineTimeSpecified = true
            };

            var xtourJob = xtour.startPlanBasicTours(orders, depots, fleet, planningParams, null,
                                                     new CallerContext
            {
                wrappedProperties = new[] {
                    new CallerContextProperty {
                        key = "CoordFormat", value = "OG_GEODECIMAL"
                    },
                    new CallerContextProperty {
                        key = "TenantId", value = Guid.NewGuid().ToString()
                    }
                }
            });

            bw.ReportProgress(-1, xtourJob);
            var status = xtourJob.status;

            while (status == JobStatus.QUEUING || status == JobStatus.RUNNING)
            {
                if (bw.CancellationPending)
                {
                    xtour.stopJob(xtourJob.id, null);
                    e.Cancel = true;
                    return;
                }

                xtourJob = xtour.watchJob(xtourJob.id, new WatchOptions
                {
                    maximumPollingPeriod          = 250,
                    maximumPollingPeriodSpecified = true,
                    progressUpdatePeriod          = 250,
                    progressUpdatePeriodSpecified = true
                }, null);
                status = xtourJob.status;

                bw.ReportProgress(-1, xtourJob);

                // wait a bit on the client-side to reduce network+server load
                System.Threading.Thread.Sleep(250);
            }

            var result = xtour.fetchPlan(xtourJob.id, null);

            scenario.Tours = new List <Tour>();
            foreach (var c in result.wrappedChains)
            {
                foreach (var wt in c.wrappedTours)
                {
                    var tour = new Tour();

                    List <TourPoint> tps = new List <TourPoint>();
                    foreach (var tp in wt.wrappedTourPoints)
                    {
                        switch (tp.type)
                        {
                        case TourPointType.DEPOT:
                            tps.Add(new TourPoint
                            {
                                Longitude = depotMap.X2B(tp.id).Longitude,
                                Latitude  = depotMap.X2B(tp.id).Latitude
                            });
                            break;

                        case TourPointType.TRANSPORT_POINT:
                            orderMap.X2B(tp.id).Tour = tour;
                            tps.Add(new TourPoint
                            {
                                Longitude = orderMap.X2B(tp.id).Longitude,
                                Latitude  = orderMap.X2B(tp.id).Latitude
                            });
                            break;
                        }
                    }

                    tour.Vehicle    = vehicleMap.X2B(c.vehicleId);
                    tour.TourPoints = tps;
                    scenario.Tours.Add(tour);
                }
            }
        }