private void requestUpdates(EDataCacheType mode, MergeRequestKey?mrk, int[] intervals)
        {
            DataCache dataCache = getDataCache(mode);

            dataCache?.MergeRequestCache?.RequestUpdate(mrk, intervals);
            dataCache?.DiscussionCache?.RequestUpdate(mrk, intervals);
        }
Exemple #2
0
        private SelectionResult trySelectMergeRequest(MergeRequestKey mrk)
        {
            bool isCached(EDataCacheType mode) => getDataCache(mode)?.MergeRequestCache?.GetMergeRequest(mrk) != null;

            // We want to check lists in specific order:
            EDataCacheType[] modes = new EDataCacheType[]
            {
                EDataCacheType.Live,
                EDataCacheType.Recent,
                EDataCacheType.Search
            };

            // Check if requested MR is cached
            if (modes.All(mode => !isCached(mode)))
            {
                return(SelectionResult.NotFound);
            }

            // Try selecting an item which is not hidden by filters
            foreach (EDataCacheType mode in modes)
            {
                if (isCached(mode) && switchTabAndSelectMergeRequest(mode, mrk))
                {
                    return(SelectionResult.Selected);
                }
            }

            // If we are here, requested MR is hidden on each tab where it is cached
            foreach (EDataCacheType mode in modes)
            {
                if (isCached(mode))
                {
                    if (unhideFilteredMergeRequest(mode))
                    {
                        if (switchTabAndSelectMergeRequest(mode, mrk))
                        {
                            return(SelectionResult.Selected);
                        }
                        Debug.Assert(false);
                    }
                    else
                    {
                        break; // don't ask more than once
                    }
                }
            }

            return(SelectionResult.Hidden);
        }
Exemple #3
0
        private void refreshSelectedMergeRequest()
        {
            EDataCacheType      type = getCurrentTabDataCacheType();
            FullMergeRequestKey?fmk  = getListView(type).GetSelectedMergeRequest();

            if (!fmk.HasValue)
            {
                return;
            }

            MergeRequestKey mrk = new MergeRequestKey(fmk.Value.ProjectKey, fmk.Value.MergeRequest.IId);

            requestUpdates(getDataCache(type), mrk, PseudoTimerInterval, () =>
                           addOperationRecord(String.Format("Merge Request !{0} has been refreshed", mrk.IId)));
        }
Exemple #4
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        async private Task searchMergeRequestsAsync(string hostname, SearchQueryCollection queryCollection,
                                                    EDataCacheType mode)
        {
            if (String.IsNullOrWhiteSpace(hostname) || getDataCache(mode) == null)
            {
                return;
            }

            if (Program.Settings.GetAccessToken(hostname) == String.Empty)
            {
                throw new UnknownHostException(hostname);
            }

            await connectSearchDataCacheAsync(queryCollection, mode);
        }
        private MergeRequestListView getListView(EDataCacheType mode)
        {
            switch (mode)
            {
            case EDataCacheType.Live:
                return(listViewLiveMergeRequests);

            case EDataCacheType.Search:
                return(listViewFoundMergeRequests);

            case EDataCacheType.Recent:
                return(listViewRecentMergeRequests);
            }

            Debug.Assert(false);
            return(null);
        }
        private DataCache getDataCache(EDataCacheType mode)
        {
            switch (mode)
            {
            case EDataCacheType.Live:
                return(_liveDataCache);

            case EDataCacheType.Search:
                return(_searchDataCache);

            case EDataCacheType.Recent:
                return(_recentDataCache);
            }

            Debug.Assert(false);
            return(null);
        }
Exemple #7
0
        private bool unhideFilteredMergeRequest(EDataCacheType dataCacheType)
        {
            Trace.TraceInformation("[MainForm] Notify user that MR is hidden");

            if (MessageBox.Show("Merge Request is hidden by filters and cannot be opened. Do you want to reset filters?",
                                "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification) != DialogResult.Yes)
            {
                Trace.TraceInformation("[MainForm] User decided not to reset filters");
                return(false);
            }

            if (dataCacheType == EDataCacheType.Live)
            {
                checkBoxDisplayFilter.Checked = false;
            }
            return(true);
        }
        private DataCacheUpdateRules getDataCacheUpdateRules(EDataCacheType mode)
        {
            switch (mode)
            {
            case EDataCacheType.Recent:
                return(new DataCacheUpdateRules(Program.Settings.AutoUpdatePeriodMs,
                                                Program.Settings.AutoUpdatePeriodMs,
                                                false));

            case EDataCacheType.Search:
                return(new DataCacheUpdateRules(Program.Settings.AutoUpdatePeriodMs, null, false));

            default:
                Debug.Assert(false);
                break;
            }
            return(null);
        }
        private void onMergeRequestEvent(UserEvents.MergeRequestEvent e, EDataCacheType type)
        {
            MergeRequestKey mrk = new MergeRequestKey(
                e.FullMergeRequestKey.ProjectKey, e.FullMergeRequestKey.MergeRequest.IId);

            if (e.AddedToCache || e.Commits)
            {
                requestCommitStorageUpdate(mrk.ProjectKey);
            }

            if (type == EDataCacheType.Live)
            {
                if (e.AddedToCache)
                {
                    // some labels may appear within a small delay after new MR is detected
                    requestUpdates(EDataCacheType.Live, mrk, new[] {
                        Program.Settings.OneShotUpdateOnNewMergeRequestFirstChanceDelayMs,
                        Program.Settings.OneShotUpdateOnNewMergeRequestSecondChanceDelayMs
                    });
                }
                if (e.RemovedFromCache && isReviewedMergeRequest(mrk))
                {
                    cleanupReviewedMergeRequests(new MergeRequestKey[] { mrk });
                }
            }

            updateMergeRequestList(type);

            FullMergeRequestKey?fmk = getListView(type).GetSelectedMergeRequest();

            if (!fmk.HasValue || !fmk.Value.Equals(e.FullMergeRequestKey) || getCurrentTabDataCacheType() != type)
            {
                return;
            }

            if (e.Details || e.Commits || e.Labels)
            {
                // Non-grid Details are updated here and Grid ones are updated in updateMergeRequestList() above
                Trace.TraceInformation("[MainForm] Updating selected Merge Request ({0})",
                                       getDataCacheName(getDataCache(type)));
                onMergeRequestSelectionChanged(type);
            }
        }
Exemple #10
0
        private void unMuteSelectedMergeRequest()
        {
            EDataCacheType type = getCurrentTabDataCacheType();

            getListView(type).UnmuteSelectedMergeRequest();
        }
Exemple #11
0
        private void muteSelectedMergeRequestUntilMonday()
        {
            EDataCacheType type = getCurrentTabDataCacheType();

            getListView(type).MuteSelectedMergeRequestFor(TimeUtils.GetTimeTillMonday());
        }
Exemple #12
0
        async private Task connectSearchDataCacheAsync(SearchQueryCollection queryCollection, EDataCacheType mode)
        {
            DataCache dataCache = getDataCache(mode);
            await dataCache.Disconnect();

            if (_gitLabInstance != null)
            {
                await dataCache.Connect(_gitLabInstance, new DataCacheConnectionContext(queryCollection));
            }
        }
Exemple #13
0
 async private Task searchMergeRequestsSafeAsync(SearchQueryCollection queryCollection, EDataCacheType mode,
                                                 Func <Exception, bool> exceptionHandler = null)
 {
     try
     {
         await searchMergeRequestsAsync(getHostName(), queryCollection, mode);
     }
     catch (Exception ex) // rethrow in case of unexpected exceptions
     {
         enableSearchTabControls();
         if (exceptionHandler == null)
         {
             exceptionHandler = new Func <Exception, bool>((e) => startWorkflowDefaultExceptionHandler(e));
         }
         if (!exceptionHandler(ex))
         {
             throw;
         }
     }
 }
 private bool doesRequireFixedGroupCollection(EDataCacheType mode)
 {
     return(ConfigurationHelper.IsProjectBasedWorkflowSelected(Program.Settings) && mode == EDataCacheType.Live);
 }