/// <summary>
        ///
        /// </summary>
        /// <param name="locationAreaIdentifier"></param>
        /// <param name="accessMappingMoniker"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <String> GetLocationServiceUrlAsync(
            Guid locationAreaIdentifier,
            String accessMappingMoniker         = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ILocationDataProvider locationData = await GetLocationDataAsync(locationAreaIdentifier, cancellationToken).ConfigureAwait(false);

            if (locationData == null)
            {
                return(null);
            }

            AccessMapping accessMapping = await locationData.GetAccessMappingAsync(accessMappingMoniker ?? AccessMappingConstants.PublicAccessMappingMoniker).ConfigureAwait(false);

            if (accessMapping == null)
            {
                accessMapping = await locationData.GetClientAccessMappingAsync().ConfigureAwait(false);
            }

            return(await locationData.LocationForAccessMappingAsync(
                       ServiceInterfaces.LocationService2,
                       LocationServiceConstants.SelfReferenceIdentifier,
                       accessMapping,
                       cancellationToken).ConfigureAwait(false));
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="managedType"></param>
        /// <returns></returns>
        private async Task <Object> GetClientInstanceAsync(
            Type managedType,
            Guid serviceIdentifier,
            CancellationToken cancellationToken,
            VssHttpRequestSettings settings,
            DelegatingHandler[] handlers)
        {
            CheckForDisposed();
            ILocationService locationService = await GetServiceAsync <ILocationService>(cancellationToken).ConfigureAwait(false);

            ILocationDataProvider locationData = await locationService.GetLocationDataAsync(serviceIdentifier, cancellationToken).ConfigureAwait(false);

            if (locationData == null)
            {
                throw new VssServiceException(WebApiResources.ServerDataProviderNotFound(serviceIdentifier));
            }

            String serviceLocationString = await locationData.LocationForCurrentConnectionAsync(
                ServiceInterfaces.LocationService2,
                LocationServiceConstants.SelfReferenceIdentifier,
                cancellationToken).ConfigureAwait(false);

            // This won't ever be null because of compat code in ServerDataProvider
            Uri clientBaseUri = new Uri(serviceLocationString);

            VssHttpClientBase toReturn = null;

            if (settings != null)
            {
                toReturn = (VssHttpClientBase)Activator.CreateInstance(managedType, clientBaseUri, Credentials, settings, handlers);
            }
            else
            {
                toReturn = (VssHttpClientBase)Activator.CreateInstance(managedType, clientBaseUri, m_pipeline, false /* disposeHandler */);
            }

            ApiResourceLocationCollection resourceLocations = await locationData.GetResourceLocationsAsync(cancellationToken).ConfigureAwait(false);

            toReturn.SetResourceLocations(resourceLocations);

            return(toReturn);
        }
 public GpsLocationManager(ILocationDataProvider dataProvider)
     : base(dataProvider)
 {
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="locationAreaIdentifier"></param>
        /// <param name="currentProvider"></param>
        /// <returns></returns>
        private async Task <ILocationDataProvider> ResolveLocationDataAsync(
            Guid locationAreaIdentifier,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ILocationDataProvider locationData   = null;
            ProviderCache         providerLookup = m_providerLookup;

            if (providerLookup == null)
            {
                providerLookup = new ProviderCache();

                // Create and seed the cache with the local url
                String location = await LocalDataProvider.LocationForCurrentConnectionAsync(
                    ServiceInterfaces.LocationService2,
                    LocationServiceConstants.SelfReferenceIdentifier,
                    cancellationToken).ConfigureAwait(false);

                if (location != null)
                {
                    providerLookup.GetOrAdd(location, LocalDataProvider);
                }

                ProviderCache actualProvider = Interlocked.CompareExchange(ref m_providerLookup, providerLookup, null);

                // Did we lose the race? Pick the winner
                if (actualProvider != null)
                {
                    providerLookup = actualProvider;
                }
            }

            if (!providerLookup.TryGetValue(locationAreaIdentifier, out locationData))
            {
                // First, check our current provider (see if a direct pointer is registered)
                String location = await LocalDataProvider.LocationForCurrentConnectionAsync(
                    ServiceInterfaces.LocationService2,
                    locationAreaIdentifier,
                    cancellationToken).ConfigureAwait(false);

                // Next, check and see if we have a root pointer
                if (location == null &&
                    locationAreaIdentifier != LocationServiceConstants.ApplicationIdentifier &&
                    locationAreaIdentifier != LocationServiceConstants.RootIdentifier) // Don't infinitely recurse
                {
                    ILocationDataProvider rootProvider = await ResolveLocationDataAsync(
                        LocationServiceConstants.RootIdentifier,
                        cancellationToken).ConfigureAwait(false);

                    if (rootProvider != null &&
                        !Object.ReferenceEquals(rootProvider, LocalDataProvider))
                    {
                        location = await rootProvider.LocationForCurrentConnectionAsync(
                            ServiceInterfaces.LocationService2,
                            locationAreaIdentifier,
                            cancellationToken).ConfigureAwait(false);
                    }
                }

                if (location != null)
                {
                    // The caller could be asking for a serviceIdentifier which resolves to a URL
                    // for which we already have a cached provider.
                    // This is typical when serviceIdentifier is a ResourceArea guid.
                    if (!providerLookup.TryGetValue(location, out locationData))
                    {
                        locationData = await CreateDataProviderAsync(location, cancellationToken).ConfigureAwait(false);

                        locationData = providerLookup.GetOrAdd(location, locationData);
                    }

                    providerLookup[locationAreaIdentifier] = locationData;
                }
            }

            return(locationData);
        }
 public ILocationDataProvider GetOrAdd(String locationUrl, ILocationDataProvider provider)
 {
     return(m_urlCache.GetOrAdd(NormalizeUrl(locationUrl), provider));
 }
 public Boolean TryGetValue(String locationUrl, out ILocationDataProvider provider)
 {
     return(m_urlCache.TryGetValue(NormalizeUrl(locationUrl), out provider));
 }
 public Boolean TryGetValue(Guid locationAreaIdentfier, out ILocationDataProvider provider)
 {
     return(m_guidCache.TryGetValue(locationAreaIdentfier, out provider));
 }
 public LocationServiceBase(ILocationDataProvider dataProvider)
 {
     this.dataProvider = dataProvider;
 }