/// <summary> /// Gets the catalog representing the resource at the specified URL. /// </summary> /// <param name="url">The URL to the ArcGIS Server catalog.</param> /// <param name="username">The username used to access secure services.</param> /// <param name="password">The password used to access secure services.</param> /// <returns> /// Returns the previously created catalog from cache or the newly created catalog. /// </returns> public IArcGISServerCatalog GetCatalog(string url, string username, string password) { Throw.IfArgumentNullOrEmpty(url, "url"); Throw.IfArgumentNullOrEmpty(username, "username"); Throw.IfArgumentNullOrEmpty(password, "password"); IArcGISServerCatalog catalog; if (_cache.Value.TryGetValue(url.ToLower(), out catalog)) { if (!catalog.IsTokenValid()) { catalog.Token = ArcGISServerFactory.CreateToken(url, username, password); foreach (var service in catalog.Services) { service.Token = catalog.Token; } this.CacheServices(catalog); _cache.Value.TryUpdate(url.ToLower(), catalog, catalog); } return(catalog); } else { catalog = factory.CreateCatalog(url, username, password); Throw.If <IArcGISServerCatalog>(catalog, x => x == null, string.Format( "Unable to create catalog from url '{0}'", url)); _cache.Value.TryAdd(url.ToLower(), catalog); this.CacheServices(catalog); return(catalog); } }
/// <summary> /// Gets the service representing the resource at the specified URL. /// </summary> /// <param name="url">The URL to the ArcGIS Server service.</param> /// <param name="username">The username used to access secure services.</param> /// <param name="password">The password used to access secure services.</param> /// <returns> /// Returns the populated service. /// </returns> public IArcGISService GetService(string url, string username, string password) { Throw.IfArgumentNullOrEmpty(url, "url"); Throw.IfArgumentNullOrEmpty(username, "username"); Throw.IfArgumentNullOrEmpty(password, "password"); IArcGISService service; if (_serviceCache.Value.TryGetValue(url.ToLower(), out service)) { if (!service.IsTokenValid()) { service.Token = ArcGISServerFactory.CreateToken(url, username, password); } return(service); } else { service = factory.CreateService(url, username, password); Throw.If <IArcGISService>(service, x => x == null, string.Format( "Unable to create service from url '{0}'", url)); _serviceCache.Value.TryAdd(url.ToLower(), service); return(service); } }