/// <summary>
        /// Calculates a route and displays the calculated polygons in the map.
        /// </summary>
        /// <param name="scenario">Scenario which defines the route to calculate.</param>
        /// <param name="calculateWithFeatureLayer">Option if the currently selected Feature Layer theme should be used.</param>
        private void CalculateRoute(Scenario scenario, bool calculateWithFeatureLayer)
        {
            XRouteWS xRoute = XServerClientFactory.CreateXRouteClient(Settings.Default.XUrl);

            try
            {
                var now       = DateTime.Now;
                var nowString = $"{now.Year}-{now.Month}-{now.Day}T{now.Hour}:{now.Minute}:{now.Second}+00:00";

                var response = xRoute.calculateRoute(new calculateRouteRequest
                {
                    ArrayOfWaypointDesc_1 = scenario.wayPoints.Select(p => new WaypointDesc
                    {
                        wrappedCoords = new[] { new Point {
                                                    point = p
                                                } },
                        linkType    = LinkType.NEXT_SEGMENT,
                        fuzzyRadius = 10000
                    }).ToArray(),

                    ResultListOptions_4 = new ResultListOptions {
                        dynamicInfo = calculateWithFeatureLayer, polygon = true
                    },
                    ArrayOfRoutingOption_2 = new[] { new RoutingOption {
                                                         parameter = RoutingParameter.START_TIME, value = nowString
                                                     } },

                    CallerContext_5 = new CallerContext
                    {
                        wrappedProperties = new[]
                        {
                            new CallerContextProperty {
                                key = "CoordFormat", value = "OG_GEODECIMAL"
                            },
                            new CallerContextProperty {
                                key = "Profile", value = "truckfast"
                            },
                            new CallerContextProperty {
                                key = "ProfileXMLSnippet", value = calculateWithFeatureLayer ? FeatureLayerXElement.ToString() : DeactivatedXElement.ToString()
                            }
                        }
                    }
                });

                map.Dispatcher.BeginInvoke(new Action <Route>(DisplayRouteInMap), response.result);
            }
            catch (EntryPointNotFoundException) { System.Windows.MessageBox.Show(Properties.Resources.ErrorRouteCalculationDefault); }
            catch (System.ServiceModel.FaultException <XRouteException> faultException)
            {
                var s = faultException.Detail.stackElement;
                System.Windows.MessageBox.Show((s.errorKey == null || s.errorKey == "2530") ? Properties.Resources.ErrorRouteCalculationDefault : s.message);
            }
            catch { System.Windows.MessageBox.Show(Properties.Resources.ErrorRouteCalculationDefault); }
        }
Beispiel #2
0
        /// <summary> Triggers the geocoding of the given multi field data. The call is asynchronously i.e. the caller
        /// is not blocked. The result is stored in the <see cref="GeocoderBase.Addresses"/> property. </summary>
        /// <param name="data"> The data to geocode. </param>
        public void LocateMultiField(MultiFieldData data)
        {
            Addresses.Clear();

            if (data.IsEmpty())
            {
                return;
            }

            #region doc:call xlocate
            XLocateWS xLocate = XServerClientFactory.CreateXLocateClient(Properties.Settings.Default.XUrl);

            var address = new Address
            {
                country  = data.Country,
                state    = data.State,
                postCode = data.PostalCode,
                city     = data.City,
                street   = data.Street
            };
            try
            {
                xLocate.BeginfindAddress(new findAddressRequest
                {
                    Address_1       = address,
                    CallerContext_5 = new CallerContext
                    {
                        wrappedProperties = new[] { new CallerContextProperty {
                                                        key = "CoordFormat", value = "PTV_MERCATOR"
                                                    } }
                    },
                }, LocateMultiFieldComplete, xLocate);
            }
            catch (EntryPointNotFoundException)
            {
                errorDelegate.Invoke(Properties.Resources.ErrorGeocodeEndpointNotFound);
            }
            catch (Exception ex)
            {
                errorDelegate.Invoke(ex.Message);
            }
            #endregion
        }
Beispiel #3
0
        /// <summary> Calculates the route between the given way points. </summary>
        private void CalculateRoute()
        {
            switch (wayPoints.Count)
            {
            case 0: Dispatcher.BeginInvoke(new Action <string>(DisplayError), Properties.Resources.ErrorNoWaypointsSet); return;

            case 1: Dispatcher.BeginInvoke(new Action <string>(DisplayError), Properties.Resources.ErrorNoDestWayPoint); return;
            }

            // reset context menu
            ContextMenuService.SetContextMenu(_wpfMap, null);

            #region doc:call xroute
            // build xServer wayPoints array from wayPoints
            var selectedWayPoints = wayPoints.Select(p => new WaypointDesc
            {
                wrappedCoords = new[] { new XrouteService.Point {
                                            point = p
                                        } },
                linkType    = LinkType.NEXT_SEGMENT,
                fuzzyRadius = 10000
            }).ToArray();

            Dispatcher.Invoke(delegate { Mouse.OverrideCursor = Cursors.Wait; });

            XRouteWS xRoute = XServerClientFactory.CreateXRouteClient(Properties.Settings.Default.XUrl);

            try
            {
                xRoute.BegincalculateRoute(new calculateRouteRequest
                {
                    ArrayOfWaypointDesc_1 = selectedWayPoints,
                    ResultListOptions_4   = new ResultListOptions {
                        polygon = true
                    }
                }, Invoke, xRoute);
            }
            catch (EntryPointNotFoundException)
            {
                Dispatcher.BeginInvoke(new Action <string>(DisplayError), Properties.Resources.ErrorRouteEndpointNotFound);
            }
            #endregion //doc:call xroute
        }
        /// <summary> Triggers the suggestion calculation for the given string. The call is synchronously i.e. the
        /// caller is blocked until the server responds. The result is stored in the <see cref="Suggestions"/> property. </summary>
        /// <param name="toLocate"> The string to look up suggestions for. </param>
        public void Suggest(string toLocate)
        {
            if (!string.IsNullOrEmpty(toLocate))
            {
                #region doc:suggest
                XLocateWS xLocate = XServerClientFactory.CreateXLocateClient(Properties.Settings.Default.XUrl);

                var response = xLocate.findSuggestion(new findSuggestionRequest
                {
                    String_1 = toLocate
                });

                Suggestions = response.result.wrappedSuggestionList;
                #endregion
            }
            else
            {
                Suggestions = new Suggestion[] { }
            };
        }
Beispiel #5
0
        // get coordinates matched on the road by some totally random coordinates
        private static IEnumerable <Point> GetMatchedCoordinates(IEnumerable <Point> inputCoords)
        {
            var locations = from c in inputCoords
                            select new Location
            {
                coordinate = new xPoint
                {
                    point = new PlainPoint
                    {
                        x = c.X,
                        y = c.Y
                    }
                }
            };

            var xlocate = XServerClientFactory.CreateXLocateClient(Properties.Settings.Default.XUrl);

            var result = xlocate.findLocations(locations.ToArray(), new SearchOptionBase[] {
                new ReverseSearchOption {
                    param = ReverseSearchParameter.ENGINE_TARGETSIZE, value = "1"
                },
                new ReverseSearchOption {
                    param = ReverseSearchParameter.ENGINE_FILTERMODE, value = "1"
                }
            },
                                               null, null,
                                               new CallerContext {
                wrappedProperties = new[] { new CallerContextProperty {
                                                key = "CoordFormat", value = "OG_GEODECIMAL"
                                            } }
            }
                                               );

            foreach (var ar in result)
            {
                yield return(new Point(ar.wrappedResultList[0].coordinates.point.x, ar.wrappedResultList[0].coordinates.point.y));
            }
        }
        /// <summary>
        /// Sends a route request to xRoute
        /// </summary>
        /// <param name="param">The parameter, must be a request data object</param>
        public void SendRequest(object param)
        {
            // associated data object
            var data = param as RequestData;

            lock (routeClientLock)
            {
                // abort any previous request that might be active
                xroute?.Abort();

                // create xRoute web service client
                xroute = XServerClientFactory.CreateXRouteClient(Demo.Properties.Settings.Default.XUrl);

                // increase message size
                (xroute.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize       = 4 << 20;
                (xroute.Endpoint.Binding as BasicHttpBinding).ReaderQuotas.MaxBytesPerRead = 4 << 20;

                // set timeouts
                xroute.Endpoint.Binding.SendTimeout    = TimeSpan.FromMilliseconds(5000);
                xroute.Endpoint.Binding.ReceiveTimeout = TimeSpan.FromMilliseconds(10000);

                // finally trigger an asynchronous route calculation with the specified request data
                xroute.BegincalculateRoute(data?.RequestWaypoints, null, null,
                                           new Demo.XrouteService.ResultListOptions {
                    polygon = true
                }, new Demo.XrouteService.CallerContext
                {
                    wrappedProperties = new[] {
                        new Demo.XrouteService.CallerContextProperty {
                            key = "CoordFormat", value = "PTV_SMARTUNITS"
                        },
                        new Demo.XrouteService.CallerContextProperty {
                            key = "ResponseGeometry", value = "WKB"
                        }
                    }
                }, RouteCalculated, data);
            }
        }
        /// <summary> Triggers the geocoding of the given string. The call is asynchronously i.e. the caller is not
        /// blocked. The result is stored in the <see cref="GeocoderBase.Addresses"/> property. </summary>
        /// <param name="toLocate"> The string to geocode. </param>
        public void LocateSingleField(string toLocate)
        {
            Addresses.Clear();

            if (string.IsNullOrEmpty(toLocate))
            {
                return;
            }

            #region doc:call xlocate
            XLocateWS xLocate = XServerClientFactory.CreateXLocateClient(Properties.Settings.Default.XUrl);

            try
            {
                xLocate.BeginfindAddressByText(new findAddressByTextRequest
                {
                    String_1        = toLocate,
                    String_2        = Properties.Settings.Default.XUrl.ToUpper().Contains("-CN-N")?  "CHN " : null,// decarta needs Country for OpenLR geocoding
                    CallerContext_6 = new CallerContext
                    {
                        wrappedProperties = new[] { new CallerContextProperty {
                                                        key = "CoordFormat", value = "PTV_MERCATOR"
                                                    } }
                    }
                }, LocateSingleFieldComplete, xLocate);
            }
            catch (EntryPointNotFoundException)
            {
                errorDelegate.Invoke(Properties.Resources.ErrorGeocodeEndpointNotFound);
            }
            catch (Exception ex)
            {
                errorDelegate.Invoke(ex.Message);
            }
            #endregion
        }
        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);
                }
            }
        }