Skip to content

Commit

Permalink
Showing error if something fails at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Apr 27, 2019
1 parent 764e267 commit 6629963
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions src/BuildVision/Core/BuildVisionPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public sealed class BuildVisionPane : ToolWindowPane
private IPackageSettingsProvider _packageSettingsProvider;

public JoinableTaskFactory JoinableTaskFactory { get; private set; }
public ControlView View
public FrameworkElement View
{
get => _contentPresenter.Content as ControlView;
get => _contentPresenter.Content as FrameworkElement;
set => _contentPresenter.Content = value;
}

Expand Down Expand Up @@ -74,28 +74,45 @@ public Task<BuildVisionPaneViewModel> GetViewModelAsync()

async Task<BuildVisionPaneViewModel> InitializeAsync(AsyncPackage asyncPackage)
{
await JoinableTaskFactory.SwitchToMainThreadAsync();

_packageSettingsProvider = await asyncPackage.GetServiceAsync(typeof(IPackageSettingsProvider)) as IPackageSettingsProvider;
Assumes.Present(_packageSettingsProvider);
var solutionProvider = await asyncPackage.GetServiceAsync(typeof(ISolutionProvider)) as ISolutionProvider;
Assumes.Present(solutionProvider);
var buildInformationProvider = await asyncPackage.GetServiceAsync(typeof(IBuildInformationProvider)) as IBuildInformationProvider;
Assumes.Present(buildInformationProvider);
var buildService = await asyncPackage.GetServiceAsync(typeof(IBuildService)) as IBuildService;
Assumes.Present(buildService);
var errorNavigationService = await asyncPackage.GetServiceAsync(typeof(IErrorNavigationService)) as IErrorNavigationService;
Assumes.Present(errorNavigationService);
var taskBarInfoService = await asyncPackage.GetServiceAsync(typeof(ITaskBarInfoService)) as ITaskBarInfoService;
Assumes.Present(taskBarInfoService);

var viewModel = new BuildVisionPaneViewModel(buildInformationProvider, _packageSettingsProvider, solutionProvider, buildService, errorNavigationService, taskBarInfoService);

View = CreateControlView();
View.DataContext = viewModel;
viewModel.ShowOptionPage += ViewModel_ShowOptionPage;
_controlCreatedSuccessfully = true;
return viewModel;
try
{
await JoinableTaskFactory.SwitchToMainThreadAsync();

_packageSettingsProvider = await asyncPackage.GetServiceAsync(typeof(IPackageSettingsProvider)) as IPackageSettingsProvider;
Assumes.Present(_packageSettingsProvider);
var solutionProvider = await asyncPackage.GetServiceAsync(typeof(ISolutionProvider)) as ISolutionProvider;
Assumes.Present(solutionProvider);
var buildInformationProvider = await asyncPackage.GetServiceAsync(typeof(IBuildInformationProvider)) as IBuildInformationProvider;
Assumes.Present(buildInformationProvider);
var buildService = await asyncPackage.GetServiceAsync(typeof(IBuildService)) as IBuildService;
Assumes.Present(buildService);
var errorNavigationService = await asyncPackage.GetServiceAsync(typeof(IErrorNavigationService)) as IErrorNavigationService;
Assumes.Present(errorNavigationService);
var taskBarInfoService = await asyncPackage.GetServiceAsync(typeof(ITaskBarInfoService)) as ITaskBarInfoService;
Assumes.Present(taskBarInfoService);

var viewModel = new BuildVisionPaneViewModel(buildInformationProvider, _packageSettingsProvider, solutionProvider, buildService, errorNavigationService, taskBarInfoService);

View = CreateControlView();
View.DataContext = viewModel;
viewModel.ShowOptionPage += ViewModel_ShowOptionPage;
_controlCreatedSuccessfully = true;
return viewModel;
}
catch (Exception e)
{
ShowError(e);
throw;
}
}

void ShowError(Exception e)
{
View = new TextBox
{
Text = e.ToString(),
IsReadOnly = true,
};
}

private void ViewModel_ShowOptionPage(Type obj)
Expand Down

0 comments on commit 6629963

Please sign in to comment.