Skip to content

Commit

Permalink
Merge pull request #1097 from GoogleCloudPlatform/quoct/fix_crash
Browse files Browse the repository at this point in the history
Fix crash when Visual Studio Team is opened
  • Loading branch information
meteatamel authored Oct 8, 2019
2 parents c7936a8 + f418f92 commit d9f628f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Section : Model, ITeamExplorerSection

private readonly ISectionViewModel _viewModel;
private IServiceProvider _serviceProvider;
private TeamExplorerUtils _teamExploerServices;
private TeamExplorerUtils _teamExplorerServices;
private bool _isBusy;
private bool _isExpanded = true;
private bool _isVisible = true;
Expand All @@ -51,7 +51,7 @@ public object SectionContent
// When this get_SectionContent is called, Team Explorer is trying to refresh the section content.
// This is the chance to update the section view with new active repo.
Debug.WriteLine($"CsrTeamExplorerSection.SectionContent");
string newActive = _teamExploerServices?.GetActiveRepository();
string newActive = _teamExplorerServices?.GetActiveRepository();
if (string.Compare(newActive, _activeRepo, StringComparison.OrdinalIgnoreCase) != 0)
{
_viewModel.UpdateActiveRepo(newActive);
Expand Down Expand Up @@ -140,12 +140,12 @@ void ITeamExplorerSection.Loaded(object sender, SectionLoadedEventArgs e)
Debug.WriteLine($"CsrTeamExplorerSection.Loaded {sender.GetType().Name} {sender.ToString()}, {e}");
}

void ITeamExplorerSection.Initialize(object sender, SectionInitializeEventArgs e)
async void ITeamExplorerSection.Initialize(object sender, SectionInitializeEventArgs e)
{
Debug.WriteLine($"CsrTeamExplorerSection.Initialize");
_serviceProvider = e.ServiceProvider;
_teamExploerServices = new TeamExplorerUtils(_serviceProvider);
_viewModel.Initialize(_teamExploerServices);
_teamExplorerServices = new TeamExplorerUtils(_serviceProvider);
await _viewModel.InitializeAsync(_teamExplorerServices);
}

void ITeamExplorerSection.Cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.


using System.Threading.Tasks;

namespace GoogleCloudExtension.TeamExplorerExtension
{
/// <summary>
Expand All @@ -28,7 +30,7 @@ public interface ISectionViewModel
/// <summary>
/// Initializes the view model with <paramref name="teamExplorerService"/> input.
/// </summary>
void Initialize(ITeamExplorerUtils teamExplorerService);
Task InitializeAsync(ITeamExplorerUtils teamExplorerService);

/// <summary>
/// Notifies that the current active repository changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,24 @@ public void Refresh()
}
}

void ISectionViewModel.Initialize(ITeamExplorerUtils teamExplorerService)
async Task ISectionViewModel.InitializeAsync(ITeamExplorerUtils teamExplorerService)
{
// When the user switches to TeamExplorer immediately after opening Visual Studio,
// sometimes, GoogleCloudExtensionPackage is not initialized. This is a hack to
// retry until the instance is initialized.
int retryAttempts = 3;
while (retryAttempts > 0 && GoogleCloudExtensionPackage.Instance == null)
{
await Task.Delay(2000);
retryAttempts--;
}

if (GoogleCloudExtensionPackage.Instance == null)
{
teamExplorerService.ShowError(Resources.FailedLoadingCsr);
return;
}

EventsReporterWrapper.ReportEvent(CsrConnectSectionOpenEvent.Create());
Debug.WriteLine("CsrSectionControlViewModel Initialize");

Expand Down
11 changes: 10 additions & 1 deletion GoogleCloudExtension/GoogleCloudExtension/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions GoogleCloudExtension/GoogleCloudExtension/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -2523,4 +2523,7 @@ Delete corrupted file?</value>
<value>Kubernetes Engine Code Lab</value>
<comment>The tooltip of the info link of the kubernetes console link.</comment>
</data>
<data name="FailedLoadingCsr" xml:space="preserve">
<value>Failed to load Cloud Source Repository.</value>
</data>
</root>

0 comments on commit d9f628f

Please sign in to comment.