예제 #1
0
        /// <summary>
        /// The unique identifier for the service owner. This property will attempt to return
        /// a cached value, if possible.
        /// </summary>
        public async Task <Guid> GetInstanceTypeAsync(
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (!NeedToConnect(ConnectOptions.None))
            {
                // We've already made a Connect call and have the authoritative service owner ID.
                return(m_serviceOwner);
            }
            else
            {
                ServerMapData serverData = LocationServerMapCache.ReadServerData(m_fullyQualifiedUrl);
                Guid          toReturn   = serverData.ServiceOwner;

                if (Guid.Empty != toReturn)
                {
                    // We do. Return it.
                    return(toReturn);
                }

                // We do not. Make a Connect call and retrieve the service owner ID.
                await EnsureConnectedAsync(ConnectOptions.None, cancellationToken).ConfigureAwait(false);

                return(m_serviceOwner);
            }
        }
예제 #2
0
        public VssServerDataProvider(
            VssConnection connection,
            HttpMessageHandler pipeline,
            String fullyQualifiedUrl)
        {
            m_connection        = connection;
            m_baseUri           = connection.Uri;
            m_fullyQualifiedUrl = fullyQualifiedUrl;
            m_locationClient    = new LocationHttpClient(m_baseUri, pipeline, false);

            // Try to get the guid for this server
            ServerMapData serverData = LocationServerMapCache.ReadServerData(m_fullyQualifiedUrl);

            m_locationDataCacheManager = new LocationCacheManager(serverData.ServerId, serverData.ServiceOwner, m_baseUri);
        }
예제 #3
0
        public async Task ConnectAsync(ConnectOptions connectOptions, CancellationToken cancellationToken = default(CancellationToken))
        {
            // We want to force ourselves to includes services if our location service cache has no access mappings.
            // This means that this is our first time connecting.
            if (!m_locationDataCacheManager.AccessMappings.Any())
            {
                connectOptions |= ConnectOptions.IncludeServices;
            }

            Int32 lastChangeId = m_locationDataCacheManager.GetLastChangeId();

            // If we have -1 then that means we have no disk cache yet or it means that we recently hit an exception trying to reload
            // the the cache from disk (see Exception catch block in EnsureDiskCacheLoaded).
            // Either way, we cannot make a call to the server with -1 and pass None.
            // If we do, the resulting payload (which would have ClientCacheFresh=false but include no ServiceDefinitions)
            // would leave the in-memory cache in an inconsistent state
            if (lastChangeId == -1)
            {
                connectOptions |= ConnectOptions.IncludeServices;
            }

            Boolean includeServices = (connectOptions & ConnectOptions.IncludeServices) == ConnectOptions.IncludeServices;

            // Perform the connection
            ConnectionData connectionData = await GetConnectionDataAsync(connectOptions, lastChangeId, cancellationToken).ConfigureAwait(false);

            LocationServiceData locationServiceData = connectionData.LocationServiceData;

            // If we were previously connected, make sure we cannot connect as a different user.
            if (m_authenticatedIdentity != null)
            {
                if (!IdentityDescriptorComparer.Instance.Equals(m_authenticatedIdentity.Descriptor, connectionData.AuthenticatedUser.Descriptor))
                {
                    throw new VssAuthenticationException(WebApiResources.CannotAuthenticateAsAnotherUser(m_authenticatedIdentity.DisplayName, connectionData.AuthenticatedUser.DisplayName));
                }
            }

            m_authenticatedIdentity = connectionData.AuthenticatedUser;
            m_authorizedIdentity    = connectionData.AuthorizedUser;

            m_instanceId = connectionData.InstanceId;

            if (locationServiceData != null)
            {
                Guid serviceOwner = connectionData.LocationServiceData.ServiceOwner;

                if (Guid.Empty == serviceOwner)
                {
                    serviceOwner = ServiceInstanceTypes.TFSOnPremises;
                }

                m_serviceOwner = serviceOwner;
            }

            // Verify with our locationServerMap cache that we are storing the correct guid
            // for this server.  If we are, this is essentially a no-op.
            Boolean wroteMapping = LocationServerMapCache.EnsureServerMappingExists(m_fullyQualifiedUrl, m_instanceId, m_serviceOwner);

            if (wroteMapping)
            {
                if (includeServices &&
                    (connectionData.LocationServiceData.ServiceDefinitions == null ||
                     connectionData.LocationServiceData.ServiceDefinitions.Count == 0))
                {
                    // This is the rare, rare case where a new server exists at the same url
                    // that an old server used to (guids are different) and both servers had the same
                    // location service last change id.  In that case, Connect would not have
                    // brought down any services. To fix this we need to query the services back
                    // down with -1 as our last change id
                    ConnectionData updatedConnectionData = await GetConnectionDataAsync(ConnectOptions.IncludeServices, -1, cancellationToken).ConfigureAwait(false);

                    locationServiceData = updatedConnectionData.LocationServiceData;
                }

                m_locationDataCacheManager = new LocationCacheManager(m_instanceId, m_serviceOwner, m_baseUri);
            }

            // update the location service cache if we tried to retireve location service data
            m_locationDataCacheManager.WebApplicationRelativeDirectory = connectionData.WebApplicationRelativeDirectory;
            if (locationServiceData != null)
            {
                m_locationDataCacheManager.LoadServicesData(locationServiceData, includeServices);
            }

            // Set the connection data that we have retrieved
            m_validConnectionData |= connectOptions;

            m_connectionMade = true;
        }