private void _InitServers()
        {
            if (_userServicesInfo.ServersInfo == null)
            {
                _userServicesInfo.ServersInfo = new UserServersInfo();
            }

            ServersInfoWrap wrap = new ServersInfoWrap(
                _servicesInfo.ServersInfo,
                _userServicesInfo.ServersInfo);

            var servers = wrap.Servers.ToArray();

            _servers = servers.Select(_ => default(AgsServer)).ToList();
            _taskRunner.For(0, servers.Length, index =>
            {
                var serverInfo = servers[index];

                var server = new AgsServer(
                    serverInfo,
                    Licenser.LicenseAccount);

                _servers[index] = server;
            });
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        public AgsCachedLayer(AgsServer server, MapLayer layer)
            : base(layer)
        {
            Debug.Assert(layer.MapServiceInfo != null);

            LayerType = AgsLayerType.Cached;
            Server = server;

            if (String.IsNullOrEmpty(layer.MapServiceInfo.Url))
                throw new SettingsException((string)App.Current.FindResource("InvalidMapLayerURL"));

            // format REST URL
            string restUrl = FormatRestUrl(layer.MapServiceInfo.Url);
            if (restUrl == null)
                throw new SettingsException((string)App.Current.FindResource("FailedFormatRESTURL"));

            // create ArcGIS layer
            ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer();
            arcGISTiledMapServiceLayer.ID = "map";
            arcGISTiledMapServiceLayer.Url = restUrl;
            arcGISTiledMapServiceLayer.Visible = layer.MapServiceInfo.IsVisible;
            arcGISTiledMapServiceLayer.Opacity = layer.MapServiceInfo.Opacity;
            ArcGISLayer = arcGISTiledMapServiceLayer;

            UpdateTokenIfNeeded();
        }
Esempio n. 3
0
 /// <summary>
 /// Creates AuthenticationException object.
 /// </summary>
 /// <param name="server">The server authentication failed to.</param>
 /// <param name="inner">Exception instance which caused this one
 /// to be thrown.</param>
 /// <returns>AuthenticationException object containing the specified
 /// server name and inner exception.</returns>
 public static AuthenticationException CreateAuthException(
     AgsServer server,
     Exception inner)
 {
     Debug.Assert(server != null);
     return(CreateAuthException(server.Title, inner));
 }
Esempio n. 4
0
        /// <summary>
        /// Creates CommunicationException object.
        /// </summary>
        public static CommunicationException CreateCommException(
            AgsServer server,
            Exception ex)
        {
            Debug.Assert(server != null);

            return(CreateCommException(server.Title, ex));
        }
Esempio n. 5
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        internal MapLayer(MapServiceInfoWrap serviceInfo, AgsServer server, Map map)
        {
            Debug.Assert(serviceInfo != null);

            _id = Guid.NewGuid();
            _serviceInfo = serviceInfo;
            _map = map;
        }
        /// <summary>
        /// Initializes a new instance of the RestRouteService class with
        /// the specified Routing service url, Routing layer name and ArcGIS
        /// server hosting routing service.
        /// </summary>
        /// <param name="serviceUrl">The Routing service url.</param>
        /// <param name="layerName">The name of the Routing layer.</param>
        /// <param name="server">ArcGIS server instance hosting routing service.</param>
        public RestRouteService(
            string serviceUrl,
            string layerName,
            AgsServer server)
        {
            Debug.Assert(server != null);

            _server = server;
            _baseUrl = UriHelper.Concat(serviceUrl, layerName);
            _baseUrl = UriHelper.Concat(_baseUrl, QUERY_OBJ_SOLVE);
            _restService = new RestService();
        }
        /// <summary>
        /// Initializes a new instance of the RestServiceContextProvider class
        /// with the specified REST service url, VRP tool name and ArcGIS server
        /// instance.
        /// </summary>
        /// <param name="serviceUrl">Url of the VRP REST service.</param>
        /// <param name="toolName">VRP service tool name.</param>
        /// <param name="server">ArcGIS server instance the VRP service is located
        /// at.</param>
        public RestServiceContextProvider(
            string serviceUrl,
            string toolName,
            AgsServer server)
        {
            Debug.Assert(!string.IsNullOrEmpty(serviceUrl));
            Debug.Assert(!string.IsNullOrEmpty(toolName));
            Debug.Assert(server != null);

            _baseUrl = UriHelper.Concat(serviceUrl, toolName);
            _server = server;
        }
Esempio n. 8
0
        /// <summary>
        /// Validates server state.
        /// </summary>
        /// <exception cref="ESRI.ArcLogistics.AuthenticationException">
        /// Is thrown if server state is unauthorized.</exception>
        public static void ValidateServerState(AgsServer server)
        {
            Debug.Assert(server != null);

            if (server.State == AgsServerState.Unauthorized)
            {
                // server is not authorized
                throw CreateAuthException(server);
            }
            else if (server.State == AgsServerState.Unavailable)
            {
                // try to reconnect server
                server.Reconnect();
            }
        }
        /// <summary>
        /// Initializes a new instance of the AgsServerConnection class
        /// with the specified authenticator instance, connection parameters
        /// and ArcGIS server to connect to.
        /// </summary>
        /// <param name="authenticator">Authenticator instance to be used
        /// for accessing ArcGIS server.</param>
        /// <param name="parameters">Connection parameters instance.</param>
        /// <param name="server">ArcGIS server instance to connect to.</param>
        public AgsServerConnection(
            IAgsServerAuthenticator authenticator,
            AgsServerConnectionParameters parameters,
            AgsServer server)
        {
            Debug.Assert(authenticator != null);
            Debug.Assert(parameters != null);
            Debug.Assert(server != null);

            _authenticator = authenticator;
            _parameters    = parameters;
            _server        = server;

            this.RequiresHttpAuthentication = _server.RequiresHttpAuthentication;
        }
        /// <summary>
        /// Initializes a new instance of the AgsServerConnection class
        /// with the specified authenticator instance, connection parameters
        /// and ArcGIS server to connect to.
        /// </summary>
        /// <param name="authenticator">Authenticator instance to be used
        /// for accessing ArcGIS server.</param>
        /// <param name="parameters">Connection parameters instance.</param>
        /// <param name="server">ArcGIS server instance to connect to.</param>
        public AgsServerConnection(
            IAgsServerAuthenticator authenticator,
            AgsServerConnectionParameters parameters,
            AgsServer server)
        {
            Debug.Assert(authenticator != null);
            Debug.Assert(parameters != null);
            Debug.Assert(server != null);

            _authenticator = authenticator;
            _parameters = parameters;
            _server = server;

            this.RequiresHttpAuthentication = _server.RequiresHttpAuthentication;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        public static AgsLayer CreateLayer(AgsServer server, MapLayer layer)
        {
            if (layer.MapServiceInfo.Type == null)
                throw new SettingsException((string)App.Current.FindResource("InvalidMapLayerType"));

            AgsLayer agsLayer = null;
            if (layer.MapServiceInfo.Type.Equals(DYNAMIC_SERVICE,
                StringComparison.OrdinalIgnoreCase))
            {
                agsLayer = new AgsDynamicLayer(server, layer);
            }
            else if (layer.MapServiceInfo.Type.Equals(CACHED_SERVICE,
                StringComparison.OrdinalIgnoreCase))
            {
                agsLayer = new AgsCachedLayer(server, layer);
            }
            else
                throw new SettingsException((string)App.Current.FindResource("UnknownMapLayerType"));

            return agsLayer;
        }
Esempio n. 12
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Finds server by name.
        /// </summary>
        public static AgsServer FindServerByName(string name,
                                                 ICollection <AgsServer> servers)
        {
            Debug.Assert(name != null);
            Debug.Assert(servers != null);

            AgsServer res = null;

            foreach (AgsServer server in servers)
            {
                if (server.Name != null &&
                    server.Name.Equals(name,
                                       StringComparison.InvariantCultureIgnoreCase))
                {
                    res = server;
                    break;
                }
            }

            return(res);
        }
Esempio n. 13
0
        private AgsServer _GetCurrentGcServer(GeocodingServiceInfo geocodingServiceInfo)
        {
            AgsServer currentServer = null;

            foreach (AgsServer server in _servers)
            {
                if (server.Name.Equals(geocodingServiceInfo.serverName,
                                       StringComparison.OrdinalIgnoreCase))
                {
                    Debug.Assert(currentServer == null);
                    currentServer = server;
                }
            }

            if (currentServer == null)
            {
                string message = Properties.Resources.ServerNameNotFound;
                throw new SettingsException(message);
            }

            return(currentServer);
        }
Esempio n. 14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="Server">AgsServer.</param>
        /// <param name="ArcGISLayer">Layer, which token must be updated.</param>
        /// <param name="LayerType">Type of the layer.</param>
        public TokenUpdater(AgsServer Server, Layer ArcGISLayer, AgsLayerType LayerType)
        {
            Debug.Assert(Server != null);
            Debug.Assert(ArcGISLayer != null);
            Debug.Assert(LayerType != null);

            _server = Server;
            _arcGISLayer = ArcGISLayer;
            _layerType = LayerType;

            // Set layer token.
            _SetNewToken(Server.LastToken);

            _InitTimer();

            // If server is in authorized state - start timer.
            if (_server.State == AgsServerState.Authorized)
                _RestartTimer();

            // Subscribe to server state changed event.
            _server.StateChanged += new EventHandler(_ServerStateChanged);
        }
Esempio n. 15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="geocodingServiceInfo">Geocoding service info.</param>
        /// <param name="geocodeServer">Geocode server.</param>
        /// <param name="exceptionHandler">Exception handler.</param>
        internal Geocoder(GeocodingServiceInfo geocodingServiceInfo,
            AgsServer geocodeServer, IServiceExceptionHandler exceptionHandler)
        {
            Debug.Assert(exceptionHandler != null);

            _exceptionHandler = exceptionHandler;

            // Init geocoding properties.
            _propMods = new PropertySet();
            _propMods.PropertyArray = new PropertySetProperty[2];

            _propMods.PropertyArray[0] = _CreateProp("WritePercentAlongField", "TRUE");
            _propMods.PropertyArray[1] = _CreateProp("MatchIfScoresTie", "TRUE");

            _geocodingServiceInfo = geocodingServiceInfo;
            if (_geocodingServiceInfo == null)
            {
                throw new SettingsException(Properties.Resources.DefaultGeocodingInfoIsNotSet);
            }

            _geocodingServer = geocodeServer;

            // Create address fields.
            _CreateAddressFields();

            _actualGeocodingInfo = new GeocodingInfo(geocodingServiceInfo);

            _locatorsInfos = new ReadOnlyCollection<LocatorInfo>(
                _actualGeocodingInfo.Locators ?? new LocatorInfo[] { });

            foreach (var locator in _locatorsInfos)
            {
                if (!_locators.ContainsKey(locator.Name))
                {
                    _locators.Add(locator.Name, locator);
                }
            }

            var fields = _geocodingServiceInfo.FieldMappings.FieldMapping.Select(mapping =>
                (AddressPart)Enum.Parse(
                    typeof(AddressPart),
                    mapping.AddressField,
                    true));

            _defaultLocator = new LocatorInfo(
                string.Empty,
                string.Empty,
                true,
                true,
                SublocatorType.Streets,
                fields);

            // Geocoder should be initialized later.
            _inited = false;
        }
Esempio n. 16
0
 /// <summary>
 /// Converts given exception to CommunicationException if it's related
 /// to communication problems.
 /// </summary>
 public static Exception ConvertCommException(AgsServer server,
                                              Exception ex)
 {
     return(IsCommunicationError(ex) ? CreateCommException(server, ex) : ex);
 }
        /// <summary>
        /// Initializes a new instance of the ArcGisServerLoginViewModel class.
        /// </summary>
        /// <param name="server">The server to provide authentication for.</param>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        public ArcGisServerLoginViewModel(
            AgsServer server,
            IMessenger messenger,
            IWorkingStatusController workingStatusController)
        {
            Debug.Assert(server != null);
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);

            _server = server;
            _server.StateChanged += _ServerStateChanged;

            this.LicenseState = server.State;
            this.RegisterHeader(
                AgsServerState.Unauthorized,
                App.Current.GetString("LoginToServerString", _server.Title));

            _messenger = messenger;
            _workingStatusController = workingStatusController;

            var licensePageCommands = new LicensePageCommands()
            {
                CreateAccount = null,
                RecoverCredentials = null,
                UpgradeLicense = null,
            };

            this.LoginState = new LoginStateViewModel(
                licensePageCommands,
                _ExecuteLogin);

            var licenseInfoText = EnumerableEx.Return(ApplyStyle(new FlowDocument(
                new Paragraph()
                {
                    Inlines =
                    {
                        new Run(App.Current.GetString("LoggedToServerString", _server.Title)),
                        new Run(NEW_LINE),
                        new Run(_server.Description)
                    },
                }
            )));

            this.ConnectedState = new ConnectedStateViewModel(
                licensePageCommands,
                licenseInfoText)
            {
                SwitchUserCommand = new DelegateCommand(
                    _ => this.LicenseState = AgsServerState.Unauthorized),
            };

            var connectionFailureInfo = ApplyStyle(new FlowDocument(
                new Paragraph(
                    new Run(App.Current.GetString(
                        "ServerIsUnavailableString",
                        _server.Title)
                    )
                )
            ));

            this.NotConnectedState = new NotConnectedStateViewModel()
            {
                ConnectionFailureInfo = connectionFailureInfo,
            };
        }
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="serviceUrl">Service url.</param>
        /// <param name="layerName">Layer name.</param>
        /// <param name="server">Server.</param>
        internal NetworkDescription(string serviceUrl, string layerName,
            AgsServer server)
        {
            Debug.Assert(serviceUrl != null);

            // Create connection.
            var connection = server.OpenConnection();
            NAServiceClient client = new NAServiceClient(serviceUrl, connection);

            try
            {
                NAServerNetworkDescription desc = client.GetNetworkDescription(layerName);

                NAServerSolverParams solverParams = client.GetSolverParameters(layerName);

                var parameterValues = solverParams.AttributeParameterValues.ToLookup(
                    value => value.AttributeName, StringComparer.OrdinalIgnoreCase);

                // Create attributes.
                foreach (NAServerNetworkAttribute attr in desc.NetworkAttributes)
                {
                    var routingAttributeName = attr.Name;
                    var attributeParameter = parameterValues[attr.Name].FirstOrDefault();
                    if (attributeParameter != null)
                    {
                        routingAttributeName = attributeParameter.AttributeName;
                    }

                    var usageType = _ConvertUsageType(attr.UsageType);

                    var usageParameter =
                        _GetRestrictionUsageParameter(attr.RestrictionUsageParameterName,
                        parameterValues[attr.Name], usageType);

                    var attribute = new NetworkAttribute(attr.Name, routingAttributeName,
                        _ConvertUnits(attr.Units), usageType,
                        _GetAttrParams(attr, parameterValues[attr.Name]), usageParameter);

                    _attributes.Add(attribute);
                }

                // Enabled restriction names.
                _enabledRestrictionNames = solverParams.RestrictionAttributeNames;
                if (_enabledRestrictionNames == null)
                    _enabledRestrictionNames = new string[0];

                // Get impedance attribute name.
                _impedanceAttrName = solverParams.ImpedanceAttributeName;
            }
            finally
            {
                client.Close();
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Initialize map spatial reference and map scalebar units from server
        /// </summary>
        /// <param name="isInitializationInProgress">True if initialization is in progress,
        /// otherwise false..</param>
        private void _GetMapLayerProperties(bool isInitializationInProgress)
        {
            if (_layers.Count > 0)
            {
                // TODO: check spatial references from other layers and remove hardcode
                // Create client
                MapLayer mapLayer = _layers[0];
                _mapServer = ((AgsMapLayer)mapLayer).Server;

                if (_mapServer.State == AgsServerState.Authorized)
                {
                    MapServiceClient mapservice = new MapServiceClient(
                        mapLayer.Url,
                        _mapServer.OpenConnection());

                    // Get map service info
                    ESRI.ArcLogistics.MapService.MapServerInfo serverInfo =
                        mapservice.GetServerInfo(mapservice.GetDefaultMapName());

                    // Get spatial reference ID
                    _spatialReferenceId = serverInfo.SpatialReference.WKID;
                    _scaleBarUnits = _ConvertScalebarUnits(serverInfo.Units);

                    // Now map is initialized.
                    _inited = true;
                }
                else
                {
                    // Subscribe on server state changed in case of Map is not inited
                    if (isInitializationInProgress)
                    {
                        _mapServer.StateChanged += new EventHandler(_Server_StateChanged);
                    }
                }
            }
        }
Esempio n. 20
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="mapInfo">Map information.</param>
        /// <param name="servers">Servers collection.</param>
        /// <param name="exceptionHandler">Exceptions handler.</param>
        internal Map(MapInfoWrap mapInfo,
            ICollection<AgsServer> servers,
            IServiceExceptionHandler exceptionHandler)
        {
            Debug.Assert(mapInfo != null);
            Debug.Assert(exceptionHandler != null);

            _exceptionHandler = exceptionHandler;

            // create layers
            _CreateLayers(mapInfo.Services, servers);

            // set selected basemap layer
            _SetSelectedBaseMap();

            _mapInfo = mapInfo;

            // Set current map server.
            _mapServer = _GetMapServer(_layers);

            // Map should be initialized later.
            _inited = false;
        }
Esempio n. 21
0
 internal AgsMapLayer(MapServiceInfoWrap serviceInfo, AgsServer server, Map map)
     : base(serviceInfo, server, map)
 {
     Server = server;
 }
Esempio n. 22
0
        private void _CreateGeocoder()
        {
            GeocodingServiceInfo currentGeocodingServiceInfo = null;

            for (int index = 0; index < _servicesInfo.GeocodingInfo.GeocodingServiceInfo.Length; index++)
            {
                GeocodingServiceInfo geocodingServiceInfo = _servicesInfo.GeocodingInfo.GeocodingServiceInfo[index];
                if (geocodingServiceInfo.current)
                {
                    if (currentGeocodingServiceInfo != null)
                    {
                        throw new ApplicationException(Properties.Resources.DefaultGeocodingInfoIsNotUnique);
                    }
                    currentGeocodingServiceInfo = geocodingServiceInfo;
                }

                var isStreetsGeocoder = string.Equals(
                    geocodingServiceInfo.type,
                    STREETS_GEOCODER_TYPE,
                    StringComparison.OrdinalIgnoreCase);
                if (isStreetsGeocoder && this.StreetsGeocoder == null)
                {
                    var streetsGeocoderServer = _GetCurrentGcServer(geocodingServiceInfo);
                    var streetsGeocoder       = new Geocoder(geocodingServiceInfo,
                                                             streetsGeocoderServer, _exceptionHandler);
                    this.StreetsGeocoder = streetsGeocoder;
                }
            }

            // Detect that geocoder type is ArcGisGeocoder.
            var isArcGisGeocoder = string.Equals(
                currentGeocodingServiceInfo.type,
                ARCGIS_GEOCODER_TYPE,
                StringComparison.OrdinalIgnoreCase);

            var isWorldGeocoder = string.Equals(
                currentGeocodingServiceInfo.type,
                "WorldGeocoder",
                StringComparison.OrdinalIgnoreCase);

            // If it is arcgis geocoder - create it and use as default.
            if (isArcGisGeocoder)
            {
                AgsServer geocodeServer = _GetCurrentGcServer(currentGeocodingServiceInfo);
                _geocoder = new ArcGiscomGeocoder(currentGeocodingServiceInfo,
                                                  geocodeServer, _exceptionHandler);
                this.StreetsGeocoder = _geocoder;
            }
            else if (isWorldGeocoder)
            {
                var worldGeocoder = WorldGeocoder.CreateWorldGeocoder(
                    currentGeocodingServiceInfo, _exceptionHandler);
                _geocoder            = worldGeocoder;
                this.StreetsGeocoder = worldGeocoder;
            }
            else
            {
                AgsServer geocodeServer = _GetCurrentGcServer(currentGeocodingServiceInfo);
                _geocoder = new Geocoder(currentGeocodingServiceInfo,
                                         geocodeServer, _exceptionHandler);
            }

            if (this.StreetsGeocoder == null)
            {
                this.StreetsGeocoder = _geocoder;
            }
        }