protected void Refresh(IConnection connection)
        {
            if (connection == null)
            {
                LoggedIn          = false;
                IsVisible         = false;
                SectionConnection = null;
                if (Repositories != null)
                {
                    Repositories.CollectionChanged -= UpdateRepositoryList;
                }
                Repositories = null;
                settings     = null;

                if (sectionIndex == 0 && ServiceProvider != null)
                {
                    var section = GetSection(TeamExplorerInvitationBase.TeamExplorerInvitationSectionGuid);
                    IsVisible = !(section?.IsVisible ?? true); // only show this when the invitation section is hidden. When in doubt, don't show it.
                    if (section != null)
                    {
                        section.PropertyChanged += (s, p) =>
                        {
                            if (p.PropertyName == "IsVisible")
                            {
                                IsVisible = LoggedIn || !((ITeamExplorerSection)s).IsVisible;
                            }
                        }
                    }
                    ;
                }
            }
            else
            {
                if (connection != SectionConnection)
                {
                    SectionConnection = connection;
                    Repositories      = SectionConnection.Repositories.CreateDerivedCollection(x => x,
                                                                                               orderer: OrderedComparer <ILocalRepositoryModel> .OrderBy(x => x.Name).Compare);
                    Repositories.CollectionChanged += UpdateRepositoryList;
                    Title     = connection.HostAddress.Title;
                    IsVisible = true;
                    LoggedIn  = true;
                    if (ServiceProvider != null)
                    {
                        RefreshRepositories().Forget();
                    }

                    settings   = packageSettings.UIState.GetOrCreateConnectSection(Title);
                    IsExpanded = settings.IsExpanded;
                }
            }
        }
Example #2
0
        protected void Refresh(IConnection connection)
        {
            InitializeInvitationSection();

            ErrorMessage = connection?.ConnectionError?.GetUserFriendlyErrorMessage(ErrorType.LoginFailed);
            IsLoggingIn  = connection?.IsLoggingIn ?? false;
            IsVisible    = connection != null || (invitationSection?.IsVisible == false);

            if (connection == null || !connection.IsLoggedIn)
            {
                if (Repositories != null)
                {
                    Repositories.CollectionChanged -= UpdateRepositoryList;
                }
                Repositories = null;
                settings     = null;

                if (connection?.ConnectionError != null)
                {
                    ShowLogin  = false;
                    ShowLogout = true;
                    ShowRetry  = !(connection.ConnectionError is Octokit.AuthorizationException);
                }
                else
                {
                    ShowLogin  = true;
                    ShowLogout = false;
                    ShowRetry  = false;
                }
            }
            else if (connection != SectionConnection || Repositories == null)
            {
                Repositories?.Dispose();
                Repositories = localRepositories.GetRepositoriesForAddress(connection.HostAddress);
                Repositories.CollectionChanged += UpdateRepositoryList;
                settings   = packageSettings.UIState.GetOrCreateConnectSection(Title);
                ShowLogin  = false;
                ShowLogout = true;
                Title      = connection.HostAddress.Title;
            }

            if (connection != null && TEServiceProvider != null)
            {
                RefreshRepositories().Forget();
            }

            if (SectionConnection != connection)
            {
                if (SectionConnection != null)
                {
                    SectionConnection.PropertyChanged -= ConnectionPropertyChanged;
                }

                SectionConnection = connection;

                if (SectionConnection != null)
                {
                    SectionConnection.PropertyChanged += ConnectionPropertyChanged;
                }
            }
        }