/// <summary> /// React on map server state changed. /// </summary> /// <param name="sender">Layer, which server state changed.</param> /// <param name="e">Ignored.</param> private void Server_StateChanged(object sender, EventArgs e) { AgsServer agsServer = (AgsServer)sender; // index for inserting layer int index = 0; foreach (AgsLayer wrap in _agsLayers) { if (map.Layers.Contains(wrap.ArcGISLayer)) { index++; } else { AgsMapLayer agsMapLayer = wrap.MapLayer as AgsMapLayer; if (agsMapLayer != null && agsMapLayer.Server == agsServer && agsServer.State == AgsServerState.Authorized) { wrap.UpdateTokenIfNeeded(); map.Layers.Insert(index, wrap.ArcGISLayer); // Check spatial reference ID is present in Map if (Map.SpatialReferenceID.HasValue) { _SetSpatialReferenceIDToObjectLayersIfNeeded(); } } } } }
/// <summary> /// Constructor. /// </summary> /// <param name="geocodingServiceInfo">Geocoding service info.</param> /// <param name="geocodeServer">Geocode server.</param> /// <param name="exceptionHandler">Exception handler.</param> /// <exception cref="System.ArgumentException">Is thrown in case if geocodingServiceInfo /// or geocodeServer parameters is null.</exception> internal ArcGiscomGeocoder(GeocodingServiceInfo geocodingServiceInfo, AgsServer geocodeServer, IServiceExceptionHandler exceptionHandler) : base(geocodingServiceInfo, geocodeServer, exceptionHandler) { if (geocodingServiceInfo == null) { throw new ArgumentException("geocodingServiceInfo"); } if (geocodeServer == null) { throw new ArgumentException("geocodeServer"); } var list = new List <string>(); // Fill collection with names of exact locators types. foreach (var locator in geocodingServiceInfo.ExactLocators.Locators) { list.Add(locator.Type); } // Local storage is exact locator. list.Add(LOCAL_STORAGE_ADDRESS_TYPE); ExactLocatorsTypesNames = list; }
private void _CreateLayers(ICollection <MapServiceInfoWrap> services, ICollection <AgsServer> servers) { Debug.Assert(servers != null); if (services != null) { foreach (MapServiceInfoWrap service in services) { AgsServer server = ServiceHelper.FindServerByName(service.ServerName, servers); if (server != null) { try { // create map layer AgsMapLayer layer = new AgsMapLayer(service, server, this); _layers.Add(layer); } catch (Exception e) { // skip layer Logger.Warning(e); } } } } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// 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); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// 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(); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// internal MapLayer(MapServiceInfoWrap serviceInfo, AgsServer server, Map map) { Debug.Assert(serviceInfo != null); _id = Guid.NewGuid(); _serviceInfo = serviceInfo; _map = map; }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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> /// React on server state changed /// </summary> private void _Server_StateChanged(object sender, EventArgs e) { AgsServer server = (AgsServer)sender; if (server.State == AgsServerState.Authorized) { _GetMapLayerProperties(false); server.StateChanged -= new EventHandler(_Server_StateChanged); } }
/// <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; }
/// <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> /// Method gets current map server. /// </summary> /// <param name="layers">Collection of map layers.</param> /// <returns>Map server reference, if it is, otherwise - null.</returns> private AgsServer _GetMapServer(List <MapLayer> layers) { AgsServer server = null; // Get server from first layer. if (layers.Count > 0) { server = ((AgsMapLayer)layers[0]).Server; } return(server); }
/// <summary> /// Creates a new instance of the <see cref="FeatureService"/> class with the specified /// url. /// </summary> /// <param name="serviceUrl">The URL of the feature service to be created.</param> /// <param name="server">The reference to the feature services server object.</param> /// <returns>A reference to the feature service object for the specified URL.</returns> /// <exception cref="System.ArgumentNullException"><paramref name="serviceUrl"/> /// argument is a null reference.</exception> public static IFeatureService Create(Uri serviceUrl, AgsServer server) { if (serviceUrl == null) { throw new ArgumentNullException("serviceUrl"); } var requestSender = new FeatureServiceRequestSender(server); var serviceQueryUri = string.Format(SERVICE_QUERY_FORMAT, serviceUrl.AbsoluteUri); var options = new HttpRequestOptions { Method = HttpMethod.Get, UseGZipEncoding = true, }; var request = new ESRI.ArcLogistics.Tracking.TrackingService.Requests.RequestBase(); var query = RestHelper.BuildQueryString(request, Enumerable.Empty <Type>(), true); var info = requestSender.SendRequest <ServiceInfo>(serviceQueryUri, query, options); return(new FeatureService(new Uri(serviceQueryUri), info, requestSender)); }
static async Task Main(string[] args) { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); var _options = new AgsOptions(); builder.GetSection("ArcGisServer").Bind(_options); try { var tokenData = await AgsServer.GenerateToken(_options.Scheme, _options.Host, _options.Port, _options.Instance, _options.Username, _options.Password); Console.WriteLine($"token: {tokenData.token}"); Console.ReadKey(); } catch { //failed to get token the usual way. } }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <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; }
/// <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); }
/// <summary> /// Initializes a new instance of the FeatureServiceRequestSender class. /// </summary> /// <param name="server">The reference to the feature services server object.</param> public FeatureServiceRequestSender(AgsServer server) { Debug.Assert(server != null); _server = server; }
/// <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, }; }
internal AgsMapLayer(MapServiceInfoWrap serviceInfo, AgsServer server, Map map) : base(serviceInfo, server, map) { Server = server; }