示例#1
0
 /// <summary>
 /// When accessing PTV xServer in the cloud, inject the default token
 /// when no user or password is provided through the configuration file.
 /// </summary>
 private static void SetDefaultPtvXServerInternetToken()
 {
     if (XServerUrl.IsXServerInternet(XServerUrl.Complete(Settings.Default.XUrl, "XMap")) && !String.IsNullOrEmpty(DefaultXServerInternetToken.Value) && String.IsNullOrEmpty(Settings.Default.XToken))
     {
         Settings.Default["XToken"] = DefaultXServerInternetToken.Value; // overwrite settings with default access token
     }
 }
        /// <summary>
        /// Factory for the  of the xServer generated client class granting access to the xRoute server.
        /// If xServers are used on an Azure environment, authentication data has to be integrated when
        /// requests are made.
        /// </summary>
        /// <param name="xUrl">The xServer base url. </param>
        /// <returns></returns>
        public static XRouteWSClient CreateXRouteClient(string xUrl)
        {
            string completeXServerUrl = XServerUrl.Complete(xUrl, "XRoute");

            var binding = new BasicHttpBinding
            {
                ReceiveTimeout         = new TimeSpan(0, 0, 30),
                SendTimeout            = new TimeSpan(0, 0, 30),
                OpenTimeout            = new TimeSpan(0, 0, 30),
                CloseTimeout           = new TimeSpan(0, 0, 30),
                MaxReceivedMessageSize = int.MaxValue
            };

            var endpoint = new EndpointAddress(completeXServerUrl);
            var client   = new XRouteWSClient(binding, endpoint);

            if (!XServerUrl.IsXServerInternet(completeXServerUrl))
            {
                return(client);
            }

            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            client.ClientCredentials.SetConfiguredToken();

            return(client);
        }
        /// <summary>
        /// Factory for the  of the xServer generated client class granting access to the xRoute server.
        /// If xServers are used on an Azure environment, authentication data has to be integrated when
        /// requests are made.
        /// </summary>
        /// <param name="xUrl">The xServer base url. </param>
        /// <param name="user"> User name. </param>
        /// <param name="password"> Password. </param>
        /// <returns> xRoute API based on Web Services. </returns>
        public static XRouteWSClient CreateXRouteClient(string xUrl, string user, string password)
        {
            var completeXServerUrl = XServerUrl.Complete(xUrl, "XRoute");

            var binding = new BasicHttpBinding
            {
                ReceiveTimeout         = new TimeSpan(0, 0, 30),
                SendTimeout            = new TimeSpan(0, 0, 30),
                OpenTimeout            = new TimeSpan(0, 0, 30),
                CloseTimeout           = new TimeSpan(0, 0, 30),
                MaxReceivedMessageSize = int.MaxValue
            };

            var endpoint = new EndpointAddress(completeXServerUrl);
            var client   = new XRouteWSClient(binding, endpoint);

            if (!XServerUrl.IsXServerInternet(completeXServerUrl))
            {
                return(client);
            }

            binding.Security.Mode = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
            client.ClientCredentials.UserName.UserName      = user;
            client.ClientCredentials.UserName.Password      = password;

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

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

            return(client);
        }
        private bool ConfigureWPFMap(Map map)
        {
            #region doc:Static Map Control
            // Initialize map control with xMap layers, especially the URL of the xServer.
            // For layers provided on Azure xServers, an xToken has to be taken into consideration. This information is
            // managed in the Usecase base class, which is globally available for the application and all other use cases.

            if (!UseCase.ManagedAuthentication.IsOk)
            {
                return(false);
            }

            // Safe the layer order for realigning.
            var layerOrder = map.Layers.Select(layer => layer.Name).ToList();

            // Remove only layers which are potentially inserted by this method.
            map.Layers.RemoveXMapBaseLayers();
            map.Layers.Remove(map.Layers["Poi"]);
            if (map.Layers["Feature Layer routes"] != null)
            {
                map.Layers.Remove(map.Layers["Feature Layer routes"]);
            }
            map.Layers.InsertXMapBaseLayers(UseCase.ManagedAuthentication.XMapMetaInfo);

            // Feature Layer settings
            featureLayerUseCase = new FeatureLayerUseCase(map)
            {
                ScenarioChanged = (theme, isBegin) =>
                {
                    Cursor = isBegin ? Cursors.AppStarting : Cursors.Arrow;
                    ComboBoxBy(theme).IsEnabled = CheckBoxBy(theme).IsEnabled = !isBegin;
                }
            };

            InitFeatureLayer(featureLayerUseCase.AvailableTrafficIncidents, TrafficIncidentsComboBox, TrafficIncidentsCheckBox);
            InitFeatureLayer(featureLayerUseCase.AvailableTruckAttributes, TruckAttributesComboBox, TruckAttributesCheckBox);
            InitFeatureLayer(featureLayerUseCase.AvailableRestrictionZones, RestrictionZonesComboBox, RestrictionZonesCheckBox);
            InitFeatureLayer(featureLayerUseCase.AvailablePreferredRoutes, PreferredRoutesComboBox, PreferredRoutesCheckBox);
            InitFeatureLayer(featureLayerUseCase.AvailableSpeedPatterns, SpeedPatternsComboBox, SpeedPatternsCheckBox);

            // Triggers the MapProfile use case to change the maps profile.
            ProfileOKButton_OnClick(null, null);

            // add POI layer (if available)
            var url = UseCase.ManagedAuthentication.XMapMetaInfo.Url;
            if (!(XServerUrl.IsDecartaBackend(url) ||
                  XServerUrl.IsXServerInternet(url) && url.Contains("china")))
            {
                #region doc:AdditionalLayerCreation
                map.InsertPoiLayer(UseCase.ManagedAuthentication.XMapMetaInfo, "Poi", "default.points-of-interest", "Points of interest");
                #endregion
            }

            // recreate the old layer order if the set of layers has not changed
            if (map.Layers.All(layer => layerOrder.Contains(layer.Name)))
            {
                var layers = layerOrder
                             .Where(name => map.Layers[name] != null)
                             .Select((name, index) => new { newIndex = index, oldIndex = map.Layers.IndexOf(map.Layers[name]) });

                foreach (var item in layers)
                {
                    map.Layers.Move(item.oldIndex, item.newIndex);
                }
            }

            if (UseCase.ManagedAuthentication.XMapMetaInfo.GetRegion() == Region.eu)
            {
                map.SetMapLocation(new Point(8.4, 49), 10); // Center in Karlsruhe
            }
            else if (UseCase.ManagedAuthentication.XMapMetaInfo.GetRegion() == Region.na)
            {
                map.SetMapLocation(new Point(-74.11, 40.93), 10); // Center in New York
            }
            else if (UseCase.ManagedAuthentication.XMapMetaInfo.GetRegion() == Region.au)
            {
                map.SetMapLocation(new Point(149.16, -35.25), 10); // Center in Canberra
            }
            else
            {
                map.SetMapLocation(new Point(0, 33), 1.8); // Center on equator, meridian
            }
            #endregion
            return(true);
        }