Example #1
0
        private bool ChooseProject()
        {
            // The domain picker is a user control in the Team Foundation OM
            // for selecting a Team Foundation Server and Team Project.

            TeamProjectPicker domainPicker = new TeamProjectPicker();

            if (m_tfs != null)
            {
                domainPicker.SelectedTeamProjectCollection = m_tfs;
            }

            if (domainPicker.ShowDialog() == DialogResult.OK)
            {
                m_teamProject = null;
                m_tfs         = domainPicker.SelectedTeamProjectCollection;

                ProjectInfo[] projects = domainPicker.SelectedProjects;
                if (projects.Length > 0)
                {
                    m_teamProject = projects[0];
                }

                if (IsAzure(m_tfs))
                {
                    ServiceIdentity retrievedIdentity = null;
                    try
                    {
                        IAccessControlService accessControlService = m_tfs.GetService(typeof(IAccessControlService)) as IAccessControlService;
                        retrievedIdentity = accessControlService.ProvisionServiceIdentity();
                    }
                    catch (Exception ex)
                    {
                        string msg = String.Format(CultureInfo.InvariantCulture, Resources.UnableToGetAzureServiceIdentity, ex.Message);
                        TraceManager.TraceError(msg);
                        MessageBox.Show(msg);
                    }

                    if (retrievedIdentity != null)
                    {
                        try
                        {
                            CredentialsCacheManager.StoreCredentials(m_tfs.Uri,
                                                                     retrievedIdentity.IdentityInfo.Name,
                                                                     retrievedIdentity.IdentityInfo.Password,
                                                                     CachedCredentialsType.ServiceIdentity,
                                                                     true);
                        }
                        catch (Exception ex)
                        {
                            string msg = String.Format(CultureInfo.InvariantCulture, Resources.UnableToSaveAzureServiceIdentityLocally, ex.Message);
                            TraceManager.TraceError(msg);
                            MessageBox.Show(msg);
                        }
                    }
                }

                return(true);
            }
            else
            {
                m_teamProject = null;
                return(false);
            }
        }