Exemple #1
0
        private async Task <IList <SonarQubeNotification> > GetNotificationEvents()
        {
            try
            {
                return(await sonarQubeService.GetNotificationEventsAsync(projectKey,
                                                                         lastCheckDate, cancellation.Token));
            }
            catch (Exception ex)
            {
                sonarLintOutput.Write($"Failed to fetch notifications : {ex.Message}");

                return(null);
            }
        }
        private async Task UpdateEventsAsync(bool isFirstRequest = false)
        {
            // Query server even if notifications are disabled, query the server to know
            // if the icon should be shown (so the notifications can be re-enabled).
            if (!sonarQubeService.IsConnected ||
                (!Model.AreNotificationsEnabled && Model.IsIconVisible))
            {
                return;
            }

            try
            {
                var events = await sonarQubeService.GetNotificationEventsAsync(projectKey,
                                                                               lastCheckDate, cancellation.Token);

                if (events == null)
                {
                    // Notifications are not supported on SonarQube
                    logger.WriteLine(Strings.Notifications_NotSupported);
                    Stop();
                    return;
                }

                // First request is only to detect if notifications are enabled on the server.
                // Even if there are notifications, do not show them as it could be easy to miss
                // (this code is executed on solution load, when a lot of things happen in the UI).
                if (!isFirstRequest)
                {
                    if (events.Count > 0)
                    {
                        lastCheckDate = events.Max(ev => ev.Date);
                    }
                    Model.SetNotificationEvents(events);
                }

                Model.IsIconVisible = true;
            }
            catch (Exception ex)
            {
                logger.WriteLine(Strings.Notifications_ERROR_Fetching, ex.Message);
            }
        }