private async Task LoadCurrentProject()
        {
            // Avoid reentrancy.
            if (_loadingProject)
            {
                return;
            }

            try
            {
                try
                {
                    // Start the loading project process.
                    _loadingProject = true;

                    // Try to load the project.
                    _currentProject = await GetProjectForIdAsync(CredentialsStore.Default.CurrentProjectId);
                }
                catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
                {
                    Debug.WriteLine($"Failed to load project: {ex.Message}");

                    _currentProject = null;
                }

                // If we managed to load the project, set the display string for it.
                ProjectDisplayString = _currentProject?.Name;
            }
            finally
            {
                _loadingProject = false;
            }
        }
        /// <summary>
        /// Continue on by showing unconnected or connected view,
        /// after it checks git is installed.
        /// </summary>
        public void OnGitInstallationCheckSuccess()
        {
            ErrorHandlerUtils.HandleExceptionsAsync(() => InitializeGitAsync(_teamExplorerService));

            _accountChangedHandler = (sender, e) => OnAccountChanged();
            CredentialsStore.Default.CurrentAccountChanged += _accountChangedHandler;
            CredentialsStore.Default.Reset += _accountChangedHandler;

            if (CredentialsStore.Default.CurrentAccount == null)
            {
                ShowUnconnectedView();
            }
            else
            {
                Content = _reposContent;
                if (s_currentAccount != CredentialsStore.Default.CurrentAccount?.AccountName)
                {
                    SetGitCredential(_teamExplorerService);
                    // Continue regardless of whether SetGitCredential succeeds or not.

                    _reposViewModel.Refresh();
                    s_currentAccount = CredentialsStore.Default.CurrentAccount?.AccountName;
                }
            }
        }
 private void SwapFilter()
 {
     ShowAdvancedFilter = !ShowAdvancedFilter;
     AdvancedFilterText = ShowAdvancedFilter ? ComposeSimpleFilters() : null;
     SimpleSearchText   = null;
     ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
 }
        private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            switch (e.PropertyName)
            {
            case nameof(SelectedTimeZone):
                OnTimeZoneChanged();
                break;

            case nameof(LogIdsList.SelectedLogId):
                if (LogIdList != null)
                {
                    ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
                }
                break;

            case nameof(ResourceTypeMenuViewModel.SelectedMenuItem):
                LogIdList = null;
                ErrorHandlerUtils.HandleAsyncExceptions(() => RequestLogFiltersWrapperAsync(PopulateLogIds));
                break;

            case nameof(SelectedLogSeverity):
                ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
                break;

            default:
                break;
            }
        }
Beispiel #5
0
        public GceInstanceViewModel(GceSourceRootViewModel owner, Instance instance)
        {
            _owner   = owner;
            Instance = instance;

            ErrorHandlerUtils.HandleExceptionsAsync(UpdateInstanceStateAsync);
        }
 private void OnCurrentAccountChanged(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         SetCaption();
     });
 }
Beispiel #7
0
 private void OnDragOver(object sender, DragEventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         e.Effects = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
     });
 }
        /// <summary>
        /// Detail view is a tree view.
        /// Each item at tree path is an <seealso cref="ObjectNodeTree"/> object.
        /// The tree view displays the <paramref name="node"/> as name : value pair.
        /// User can click at the "value" to show matching log entries.
        ///
        /// This method composes a filter on node value, adds it to existing AdvancedFilterText.
        /// The filter has format of root_node_name.node_name...node_name = "node.value".
        /// Example: jsonPayload.serviceContext.service="frontend"
        /// </summary>
        private void FilterOnTreeNodeValue(ObjectNodeTree node)
        {
            IsAutoReloadChecked = false;

            // Firstly compose a new filter line.
            StringBuilder newFilter = new StringBuilder();

            newFilter.Append($"{node.FilterLabel}=\"{node.FilterValue}\"");
            while ((node = node.Parent).Parent != null)
            {
                if (!string.IsNullOrWhiteSpace(node.FilterLabel))
                {
                    newFilter.Insert(0, $"{node.FilterLabel}.");
                }
            }

            // Append the new filter line to existing filter text.
            // Or to the composed filter if it is currently showing simple filters.
            if (ShowAdvancedFilter)
            {
                newFilter.Insert(0, Environment.NewLine);
                newFilter.Insert(0, AdvancedFilterText);
            }
            else
            {
                newFilter.Insert(0, ComposeSimpleFilters());
            }

            // Show advanced filter.
            AdvancedFilterText = newFilter.ToString();
            ShowAdvancedFilter = true;
            ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
        }
        private async Task InitializeDialogState()
        {
            try
            {
                // Show the loading message while the project is being validated and the
                // data being loaded.
                LoadingProject = true;

                Task <bool> validateTask = ValidateGcpProject();
                PublishDialog.TrackTask(validateTask);

                if (await validateTask)
                {
                    Task <IEnumerable <Instance> > instancesTask = GetAllWindowsInstancesAsync();
                    PublishDialog.TrackTask(instancesTask);
                    Instances = await instancesTask;
                }
            }
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                CanPublish   = false;
                GeneralError = true;
            }
            finally
            {
                LoadingProject = false;
            }
        }
Beispiel #10
0
 private void OnShowOnlyWindowsInstancesChanged(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         _windowsOnlyButton.IsChecked = ActualRoot.ShowOnlyWindowsInstances;
     });
 }
 private void OnPasswordChanged(object sender, RoutedEventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         ViewModel.Password = _password.Password;
     });
 }
Beispiel #12
0
        public void TestIsCriticalException_FalseForAggregateExceptionContainingOnlyNormalException()
        {
            bool result =
                ErrorHandlerUtils.IsCriticalException(new AggregateException(new Exception(), new Exception()));

            Assert.IsFalse(result);
        }
Beispiel #13
0
        public async Task TestHandleExceptionsAsync_PromptsForNormalExceptionAsync()
        {
            var thrownException = new Exception();
            await ErrorHandlerUtils.HandleExceptionsAsync(() => Task.FromException(thrownException));

            _promptUserMock.Verify(p => p.ExceptionPrompt(thrownException), Times.Once);
        }
Beispiel #14
0
        public void TestIsCriticalException_FalseForAggregateExceptionContainingACriticalException()
        {
            bool result = ErrorHandlerUtils.IsCriticalException(
                new AggregateException(new AccessViolationException(), new Exception()));

            Assert.IsTrue(result);
        }
 /// <summary>
 /// Initializes an instance of <seealso cref="LogsViewerViewModel"/> class.
 /// </summary>
 public LogsViewerViewModel()
 {
     _dataSource       = new Lazy <LoggingDataSource>(CreateDataSource);
     RefreshCommand    = new ProtectedCommand(OnRefreshCommand);
     LogItemCollection = new ListCollectionView(_logs);
     LogItemCollection.GroupDescriptions.Add(new PropertyGroupDescription(nameof(LogItem.Date)));
     CancelRequestCommand    = new ProtectedCommand(CancelRequest);
     SimpleTextSearchCommand = new ProtectedCommand(() =>
     {
         EventsReporterWrapper.ReportEvent(LogsViewerSimpleTextSearchEvent.Create());
         ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
     });
     FilterSwitchCommand         = new ProtectedCommand(SwapFilter);
     SubmitAdvancedFilterCommand = new ProtectedCommand(() =>
     {
         EventsReporterWrapper.ReportEvent(LogsViewerAdvancedFilterEvent.Create());
         ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
     });
     AdvancedFilterHelpCommand = new ProtectedCommand(ShowAdvancedFilterHelp);
     DateTimePickerModel       = new DateTimePickerViewModel(
         TimeZoneInfo.Local, DateTime.UtcNow, isDescendingOrder: true);
     DateTimePickerModel.DateTimeFilterChange += (sender, e) => ErrorHandlerUtils.HandleAsyncExceptions(ReloadAsync);
     PropertyChanged     += OnPropertyChanged;
     ResourceTypeSelector = new ResourceTypeMenuViewModel(_dataSource);
     ResourceTypeSelector.PropertyChanged += OnPropertyChanged;
     OnDetailTreeNodeFilterCommand         = new ProtectedCommand <ObjectNodeTree>(FilterOnTreeNodeValue);
     OnAutoReloadCommand = new ProtectedCommand(AutoReload);
 }
Beispiel #16
0
 private void OnReset(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         Debug.WriteLine("Resetting the credentials.");
         ResetCredentials();
     });
 }
 private void OnCredentialsChanged(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleAsyncExceptions(async() =>
     {
         Debug.WriteLine("Resetting the credentials.");
         await ResetCredentialsAsync();
     });
 }
Beispiel #18
0
 private void OnCurrentAccountChanged(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         Debug.WriteLine("Changing account.");
         ResetCredentials();
     });
 }
Beispiel #19
0
 private void OnDataGridSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         var self = (DataGrid)e.Source;
         ViewModel.InvalidateSelectedItems(self.SelectedItems.Cast <GcsRow>());
     });
 }
Beispiel #20
0
        public async Task TestHandleExceptionsAsync_ThrowsCriticalExceptionAsync()
        {
            await Assert.ThrowsExceptionAsync <AccessViolationException>(
                async() => await ErrorHandlerUtils.HandleExceptionsAsync(
                    () => Task.FromException(new AccessViolationException())));

            _promptUserMock.Verify(p => p.ExceptionPrompt(It.IsAny <Exception>()), Times.Never);
        }
Beispiel #21
0
 private void OnItemChanged(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         var itemSource = (ICloudExplorerItemSource)sender;
         _selectionUtils.SelectItem(itemSource.Item);
     });
 }
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void OnDeployCommand(object sender, EventArgs e)
 {
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         var selectedProject = SolutionHelper.CurrentSolution.SelectedProject;
         Debug.WriteLine($"Deploying project: {selectedProject.FullPath}");
         PublishDialogWindow.PromptUser(selectedProject);
     });
 }
        private async void ResetCredentials()
        {
            try
            {
                IsBusy = true;

                // These data sources only depend on the current account, which will not change for now.
                InvalidateAccountDependentDataSources();
                UpdateUserProfile();

                // Load the projects and select the new current project. Preference is given to the current project
                // as known by CredentialsStore. If it is not a valid project then the first project in the list will
                // be used. If no project is found then null will be the value.
                var projects = await LoadProjectListAsync();

                if (projects.Count == 0)
                {
                    UpdateProjects(null);
                    CurrentProject = s_projectPlaceholder;
                }
                else
                {
                    var newCurrentProject =
                        projects.FirstOrDefault(x => x.ProjectId == CredentialsStore.Default.CurrentProjectId) ??
                        projects.FirstOrDefault();

                    // Set the properties in the right order. This is needed because this in turn will
                    // set the properties in the list control in the right order to preserve the current
                    // project.
                    UpdateProjects(projects);
                    CurrentProject = newCurrentProject;
                }

                // Update the data sources as they will depend on the project being selected.
                NotifySourcesOfUpdatedAccountOrProject();
                RefreshSources();

                // Notify of changes of the empty state.
                InvalidateEmptyState();

                // Update the enabled state of the buttons, to match the empty state.
                foreach (var button in Buttons)
                {
                    button.IsEnabled = IsNotEmptyState;
                }
            }
            // Catch all, otherwise it terminates Visual Studio
            catch (Exception ex) when(!ErrorHandlerUtils.IsCriticalException(ex))
            {
                Debug.WriteLine($"Exception at CloudExplorerViewModel.ResetCredentials. {ex}");
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #24
0
        /// <summary>
        /// Load next page of error groups.
        /// </summary>
        public void LoadNextPage()
        {
            if (_nextPageToken == null)
            {
                Debug.WriteLine("_nextPageToken is null, there is no more events group to load");
                return;
            }

            ErrorHandlerUtils.HandleAsyncExceptions(LoadAsync);
        }
Beispiel #25
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private static void OnDeployCommand(object sender, EventArgs e)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     ErrorHandlerUtils.HandleExceptions(() =>
     {
         IParsedDteProject selectedProject = SolutionHelper.CurrentSolution.SelectedProject.ParsedProject;
         Debug.WriteLine($"Deploying project: {selectedProject.FullPath}");
         PublishDialogWindow.PromptUser(selectedProject);
     });
 }
Beispiel #26
0
 /// <summary>
 /// Initializes a new instance of <seealso cref="ErrorReportingDetailViewModel"/> class.
 /// </summary>
 public ErrorReportingDetailViewModel()
 {
     OnGotoSourceCommand = new ProtectedCommand <StackFrame>(
         (frame) => ShowTooltipUtils.ErrorFrameToSourceLine(GroupItem, frame));
     OnBackToOverViewCommand         = new ProtectedCommand(() => ToolWindowCommandUtils.ShowToolWindow <ErrorReportingToolWindow>());
     OnAutoReloadCommand             = new ProtectedCommand(() => ErrorHandlerUtils.HandleAsyncExceptions(UpdateGroupAndEventAsync));
     _datasource                     = new Lazy <StackdriverErrorReportingDataSource>(CreateDataSource);
     CredentialsStore.Default.Reset += (sender, e) => OnCurrentProjectChanged();
     CredentialsStore.Default.CurrentProjectIdChanged += (sender, e) => OnCurrentProjectChanged();
 }
        /// <summary>
        /// Send request to get logs following prior requests.
        /// </summary>
        public void LoadNextPage()
        {
            IsAutoReloadChecked = false;
            if (String.IsNullOrWhiteSpace(_nextPageToken) || String.IsNullOrWhiteSpace(Project))
            {
                return;
            }

            ErrorHandlerUtils.HandleAsyncExceptions(() => LogLoaddingWrapperAsync(async(cancelToken) => await LoadLogsAsync(cancelToken)));
        }
        /// <summary>
        /// When a new view model is created and attached to Window,
        /// invalidate controls and re-load first page of log entries.
        /// </summary>
        public void InvalidateAllProperties()
        {
            if (String.IsNullOrWhiteSpace(CredentialsStore.Default.CurrentAccount?.AccountName) ||
                String.IsNullOrWhiteSpace(CredentialsStore.Default.CurrentProjectId))
            {
                return;
            }

            ErrorHandlerUtils.HandleAsyncExceptions(() => RequestLogFiltersWrapperAsync(PopulateResourceTypes));
        }
 private void OnItemChanged(object sender, EventArgs e)
 {
     ThreadHelper.ThrowIfNotOnUIThread();
     ErrorHandlerUtils.HandleExceptionsAsync(
         async() =>
     {
         var itemSource = (ICloudExplorerItemSource)sender;
         await _selectionUtils.SelectItemAsync(itemSource.Item);
     });
 }
        public AttachDebuggerWindowViewModel(Instance gceInstance, AttachDebuggerWindow dialogWindow)
        {
            OKCommand     = new ProtectedAsyncCommand(() => ExceuteAsync(OnOKCommand), canExecuteCommand: false);
            CancelCommand = new ProtectedCommand(OnCancelCommand, canExecuteCommand: false);

            var context   = new AttachDebuggerContext(gceInstance, dialogWindow);
            var firstStep = SetCredentialStepViewModel.CreateStep(context);

            ErrorHandlerUtils.HandleExceptionsAsync(() => ExceuteAsync(() => GotoStep(firstStep)));
        }