private ProjectLocationInformation GetProjectLocation(IHttpRequest request)
        {
            string projectName = request.Headers["Host"].Split('.')[0];

            projectName = projectName.ToLower();

            projectLocationsLock.EnterUpgradeableReadLock();
            try
            {
                if (!projectLocations.ContainsKey(projectName))
                {
                    projectLocationsLock.EnterWriteLock();
                    try
                    {
                        var            service = new ProjectInfoService();
                        ProjectTfsInfo info;
                        try
                        {
                            info = service.GetTfsInfoForProject(projectName);
                        }
                        catch (Exception ex)
                        {
                            if (ex.Message.Contains("Unknown project name"))
                            {
                                return(new ProjectLocationInformation(null, null));
                            }
                            else
                            {
                                throw;
                            }
                        }
                        string tfsServerUrl = info.TfsServerUrl.Contains("/tfs/") ?
                                              info.TfsServerUrl.Substring(0, info.TfsServerUrl.Length - 1).Replace(":443", "") :
                                              info.TfsServerUrl.Substring(0, info.TfsServerUrl.Length - 5);
                        string tfsProjectName = info.ProjectPrefix.Substring(2, info.ProjectPrefix.Length - 3);
                        projectLocations[projectName] = new ProjectLocationInformation(tfsProjectName, tfsServerUrl);
                    }
                    finally
                    {
                        projectLocationsLock.ExitWriteLock();
                    }
                }

                return(projectLocations[projectName]);
            }
            finally
            {
                projectLocationsLock.ExitUpgradeableReadLock();
            }
        }
        private ProjectLocationInformation GetProjectLocation(ICredentials credentials, string projectName)
        {
            projectName = projectName.ToLower();
            if (!projectLocations.ContainsKey(projectName))
            {
                string[] servers = this.server.Split(',');
                foreach (string server in servers)
                {
                    ICredentials credentialsForServer = CredentialsHelper.GetCredentialsForServer(server, credentials);
                    SourceItem[] items = sourceControlService.QueryItems(server, credentialsForServer, Constants.ServerRootPath + projectName, RecursionType.None, VersionSpec.Latest, DeletedState.NonDeleted, ItemType.Folder);

                    if (items != null && items.Length > 0)
                    {
                        string remoteProjectName = items[0].RemoteName.Substring(Constants.ServerRootPath.Length);
                        projectLocations[projectName] = new ProjectLocationInformation(remoteProjectName, server);
                    }
                }
                if (!projectLocations.ContainsKey(projectName))
                {
                    throw new InvalidOperationException("Could not find project '" + projectName + "' in: " + this.server);
                }
            }
            return(projectLocations[projectName]);
        }