/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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(); } }
/// <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); } } } }