///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <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();
            }
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes routine (support reinit).
        /// </summary>
        /// <param name="mapLayer">Layer for creating images.</param>
        public void Init(MapLayer mapLayer)
        {
            Debug.Assert(null != mapLayer);
            Debug.Assert(!_serviceInWorkedState); // only once

            AgsServer server = ((AgsMapLayer)mapLayer).Server;

            ServiceHelper.ValidateServerState(server);

            _mapService = new MapServiceClient(mapLayer.Url, server.OpenConnection());

            _mapInfo        = _mapService.GetServerInfo(_mapService.GetDefaultMapName());
            _mapDescription = _mapInfo.DefaultMapDescription;

            var imgType = new ImageType();

            imgType.ImageFormat     = esriImageFormat.esriImagePNG;
            imgType.ImageReturnType = esriImageReturnType.esriImageReturnMimeData;

            _imgDescription           = new ImageDescription();
            _imgDescription.ImageType = imgType;

            _serviceInWorkedState = true;
        }