Example #1
0
        internal MergeRequestManager(
            DataCacheContext dataCacheContext,
            InternalCacheUpdater cacheUpdater,
            string hostname,
            IHostProperties hostProperties,
            DataCacheConnectionContext context,
            IModificationNotifier modificationNotifier)
        {
            _dataCacheContext     = dataCacheContext;
            _cacheUpdater         = cacheUpdater;
            _modificationNotifier = modificationNotifier;

            _modificationNotifier.MergeRequestModified += onMergeRequestModified;

            if (context.UpdateRules.UpdateMergeRequestsPeriod.HasValue)
            {
                DataCacheConnectionContext updateContext = new DataCacheConnectionContext(
                    new DataCacheCallbacks(null, null), // disable callbacks from updates
                    context.UpdateRules,
                    context.CustomData);

                _updateManager = new UpdateManager(_dataCacheContext, hostname, hostProperties,
                                                   updateContext, _cacheUpdater);
                _updateManager.MergeRequestEvent += onUpdate;
            }
        }
Example #2
0
        private DataCacheInternal createCacheInternal(
            InternalCacheUpdater cacheUpdater,
            string hostname,
            IHostProperties hostProperties,
            User user,
            SearchQueryCollection queryCollection,
            IModificationNotifier modificationNotifier,
            INetworkOperationStatusListener networkOperationStatusListener,
            bool isApprovalStatusSupported)
        {
            MergeRequestManager mergeRequestManager = new MergeRequestManager(
                _cacheContext, cacheUpdater, hostname, hostProperties, queryCollection, networkOperationStatusListener,
                isApprovalStatusSupported);
            DiscussionManager discussionManager = new DiscussionManager(
                _cacheContext, hostname, hostProperties, user, mergeRequestManager,
                modificationNotifier, networkOperationStatusListener);
            TimeTrackingManager timeTrackingManager = new TimeTrackingManager(
                hostname, hostProperties, user, discussionManager, modificationNotifier, networkOperationStatusListener);

            ProjectCache projectCache = null;

            if (_cacheContext.SupportProjectCache)
            {
                IProjectListLoader loader = new ProjectListLoader(hostname, _operator);
                projectCache = new ProjectCache(loader, _cacheContext, hostname);
            }
            UserCache userCache = null;

            if (_cacheContext.SupportUserCache)
            {
                IUserListLoader userListLoader = new UserListLoader(hostname, _operator);
                userCache = new UserCache(userListLoader, _cacheContext, hostname);
            }
            return(new DataCacheInternal(mergeRequestManager, discussionManager, timeTrackingManager, projectCache, userCache));
        }
Example #3
0
        async public Task Connect(GitLabInstance gitLabInstance, DataCacheConnectionContext context)
        {
            reset();

            string          hostname       = gitLabInstance.HostName;
            IHostProperties hostProperties = gitLabInstance.HostProperties;

            _operator = new DataCacheOperator(hostname, hostProperties);

            try
            {
                InternalCacheUpdater    cacheUpdater           = new InternalCacheUpdater(new InternalCache());
                IMergeRequestListLoader mergeRequestListLoader =
                    MergeRequestListLoaderFactory.CreateMergeRequestListLoader(hostname, _operator, context, cacheUpdater);

                Trace.TraceInformation(String.Format("[DataCache] Starting new dataCache at {0}", hostname));

                User currentUser = await new CurrentUserLoader(_operator).Load(hostname);
                await mergeRequestListLoader.Load();

                _internal = createCacheInternal(cacheUpdater, hostname, hostProperties, currentUser, context);

                Trace.TraceInformation(String.Format("[DataCache] Started new dataCache at {0}", hostname));
                Connected?.Invoke(hostname, currentUser);
            }
            catch (BaseLoaderException ex)
            {
                if (ex is BaseLoaderCancelledException)
                {
                    throw new DataCacheConnectionCancelledException();
                }
                throw new DataCacheException(ex.OriginalMessage, ex);
            }
        }
Example #4
0
        internal UpdateManager(
            DataCacheContext dataCacheContext,
            string hostname,
            IHostProperties hostProperties,
            SearchQueryCollection queryCollection,
            InternalCacheUpdater cacheUpdater,
            INetworkOperationStatusListener networkOperationStatusListener,
            bool isApprovalStatusSupported)
        {
            _updateOperator         = new DataCacheOperator(hostname, hostProperties, networkOperationStatusListener);
            _mergeRequestListLoader = new MergeRequestListLoader(
                hostname, _updateOperator, cacheUpdater, null, queryCollection,
                isApprovalStatusSupported);
            _mergeRequestLoader = new MergeRequestLoader(_updateOperator, cacheUpdater,
                                                         dataCacheContext.UpdateRules.UpdateOnlyOpenedMergeRequests, isApprovalStatusSupported);
            _extLogging    = dataCacheContext.UpdateManagerExtendedLogging;
            _tagForLogging = dataCacheContext.TagForLogging;

            _cache = cacheUpdater.Cache;

            _timer = new System.Timers.Timer
            {
                Interval = dataCacheContext.UpdateRules.UpdateMergeRequestsPeriod.Value
            };
            _timer.Elapsed            += onTimer;
            _timer.SynchronizingObject = dataCacheContext.SynchronizeInvoke;
            _timer.Start();
        }
Example #5
0
 public ProjectBasedProjectListLoader(DataCacheOperator op,
                                      InternalCacheUpdater cacheUpdater, DataCacheConnectionContext dataCacheConnectionContext)
     : base(op)
 {
     _cacheUpdater = cacheUpdater;
     _dataCacheConnectionContext = dataCacheConnectionContext;
     Debug.Assert(_dataCacheConnectionContext.CustomData is ProjectBasedContext);
 }
 internal SearchBasedProjectListLoader(string hostname, DataCacheOperator op,
                                       InternalCacheUpdater cacheUpdater, DataCacheConnectionContext dataCacheConnectionContext)
     : base(op)
 {
     _hostname     = hostname;
     _cacheUpdater = cacheUpdater;
     _dataCacheConnectionContext = dataCacheConnectionContext;
     Debug.Assert(_dataCacheConnectionContext.CustomData is SearchBasedContext);
 }
Example #7
0
 internal MergeRequestLoader(DataCacheOperator op, InternalCacheUpdater cacheUpdater, bool updateOnlyOpened,
                             bool isApprovalStatusSupported)
     : base(op)
 {
     _cacheUpdater     = cacheUpdater;
     _versionLoader    = new VersionLoader(op, cacheUpdater);
     _approvalLoader   = isApprovalStatusSupported ? new ApprovalLoader(op, cacheUpdater) : null;
     _updateOnlyOpened = updateOnlyOpened;
 }
Example #8
0
 internal MergeRequestListLoader(string hostname, DataCacheOperator op,
                                 InternalCacheUpdater cacheUpdater, DataCacheCallbacks callbacks,
                                 SearchQueryCollection queryCollection, bool isApprovalStatusSupported)
     : base(op)
 {
     _hostname        = hostname;
     _cacheUpdater    = cacheUpdater;
     _versionLoader   = new VersionLoader(_operator, cacheUpdater);
     _approvalLoader  = isApprovalStatusSupported ? new ApprovalLoader(_operator, cacheUpdater) : null;
     _callbacks       = callbacks;
     _queryCollection = queryCollection;
 }
Example #9
0
        async public Task Connect(GitLabInstance gitLabInstance, DataCacheConnectionContext connectionContext)
        {
            assertNotConnected();

            string          hostname       = gitLabInstance.HostName;
            IHostProperties hostProperties = gitLabInstance.HostProperties;

            _operator = new DataCacheOperator(hostname, hostProperties, gitLabInstance.NetworkOperationStatusListener);
            DataCacheOperator myOperator = _operator;

            _isConnecting = true;
            try
            {
                Connecting?.Invoke(hostname);

                InternalCacheUpdater cacheUpdater = new InternalCacheUpdater(new InternalCache());
                bool isApprovalStatusSupported    = await gitLabInstance.IsApprovalStatusSupported();

                IMergeRequestListLoader mergeRequestListLoader = new MergeRequestListLoader(
                    hostname, _operator, cacheUpdater,
                    _cacheContext.Callbacks, connectionContext.QueryCollection,
                    isApprovalStatusSupported);

                traceInformation(String.Format("Connecting data cache to {0}...", hostname));
                string accessToken = hostProperties.GetAccessToken(hostname);
                await new CurrentUserLoader(_operator).Load(hostname, accessToken);
                User currentUser = GlobalCache.GetAuthenticatedUser(hostname, accessToken);

                await mergeRequestListLoader.Load();

                _internal = createCacheInternal(cacheUpdater, hostname, hostProperties, currentUser,
                                                connectionContext.QueryCollection, gitLabInstance.ModificationNotifier,
                                                gitLabInstance.NetworkOperationStatusListener, isApprovalStatusSupported);

                ConnectionContext = connectionContext;
                traceInformation(String.Format("Data cache connected to {0}", hostname));
                Connected?.Invoke(hostname, currentUser);
            }
            catch (BaseLoaderException ex)
            {
                reset();

                if (ex is BaseLoaderCancelledException)
                {
                    throw new DataCacheConnectionCancelledException();
                }
                throw new DataCacheException(ex.OriginalMessage, ex);
            }
            finally
            {
                _isConnecting = false;
            }
        }
Example #10
0
        private DataCacheInternal createCacheInternal(
            InternalCacheUpdater cacheUpdater,
            string hostname,
            IHostProperties hostProperties,
            User user,
            DataCacheConnectionContext context)
        {
            MergeRequestManager mergeRequestManager = new MergeRequestManager(
                _dataCacheContext, cacheUpdater, hostname, hostProperties, context, _modificationNotifier);
            DiscussionManager discussionManager = new DiscussionManager(
                _dataCacheContext, hostname, hostProperties, user, mergeRequestManager, context, _modificationNotifier);
            TimeTrackingManager timeTrackingManager = new TimeTrackingManager(
                hostname, hostProperties, user, discussionManager, _modificationNotifier);

            IProjectListLoader loader = ProjectListLoaderFactory.CreateProjectListLoader(
                hostname, _operator, context, cacheUpdater);
            ProjectCache projectCache = new ProjectCache(cacheUpdater, loader, _dataCacheContext);

            return(new DataCacheInternal(mergeRequestManager, discussionManager, timeTrackingManager, projectCache));
        }
        internal MergeRequestManager(
            DataCacheContext dataCacheContext,
            InternalCacheUpdater cacheUpdater,
            string hostname,
            IHostProperties hostProperties,
            SearchQueryCollection queryCollection,
            INetworkOperationStatusListener networkOperationStatusListener,
            bool isApprovalStatusSupported)
        {
            _cacheUpdater         = cacheUpdater;
            _listRefreshTimestamp = DateTime.Now;

            if (dataCacheContext.UpdateRules.UpdateMergeRequestsPeriod.HasValue)
            {
                _updateManager = new UpdateManager(dataCacheContext, hostname, hostProperties,
                                                   queryCollection, _cacheUpdater, networkOperationStatusListener,
                                                   isApprovalStatusSupported);
                _updateManager.MergeRequestEvent         += onUpdate;
                _updateManager.MergeRequestListRefreshed += onListRefreshed;
                _updateManager.MergeRequestRefreshed     += onMergeRequestRefreshed;
            }
        }
Example #12
0
        internal UpdateManager(
            DataCacheContext dataCacheContext,
            string hostname,
            IHostProperties hostProperties,
            DataCacheConnectionContext context,
            InternalCacheUpdater cacheUpdater)
        {
            DataCacheOperator updateOperator = new DataCacheOperator(hostname, hostProperties);

            _mergeRequestListLoader = MergeRequestListLoaderFactory.CreateMergeRequestListLoader(
                hostname, updateOperator, context, cacheUpdater);
            _mergeRequestLoader = new MergeRequestLoader(updateOperator, cacheUpdater);

            _cache = cacheUpdater.Cache;

            _timer = new System.Timers.Timer
            {
                Interval = context.UpdateRules.UpdateMergeRequestsPeriod.Value
            };
            _timer.Elapsed            += onTimer;
            _timer.SynchronizingObject = dataCacheContext.SynchronizeInvoke;
            _timer.Start();
        }
Example #13
0
        internal ProjectCache(InternalCacheUpdater cacheUpdater,
                              IProjectListLoader projectListLoader, DataCacheContext context)
        {
            _cacheUpdater      = cacheUpdater;
            _projectListLoader = projectListLoader;
            _context           = context;

            _context.SynchronizeInvoke.BeginInvoke(new Action(
                                                       async() =>
            {
                try
                {
                    await _projectListLoader.Load();
                }
                catch (BaseLoaderException ex)
                {
                    if (ex is BaseLoaderCancelledException)
                    {
                        return;
                    }
                    ExceptionHandlers.Handle("Cannot load list of projects", ex);
                }
            }), null);
        }
Example #14
0
 internal ApprovalLoader(DataCacheOperator op, InternalCacheUpdater cacheUpdater)
     : base(op)
 {
     _cacheUpdater = cacheUpdater;
 }
Example #15
0
 internal VersionLoader(DataCacheOperator op, InternalCacheUpdater cacheUpdater)
     : base(op)
 {
     _cacheUpdater = cacheUpdater;
 }
Example #16
0
 internal MergeRequestLoader(DataCacheOperator op, InternalCacheUpdater cacheUpdater)
     : base(op)
 {
     _cacheUpdater  = cacheUpdater;
     _versionLoader = new VersionLoader(op, cacheUpdater);
 }
Example #17
0
        internal static IMergeRequestListLoader CreateMergeRequestListLoader(string hostname,
                                                                             DataCacheOperator op, DataCacheConnectionContext context, InternalCacheUpdater cache)
        {
            IVersionLoader versionLoader = new VersionLoader(op, cache);

            IMergeRequestListLoader listLoader = null;

            if (context.CustomData is ProjectBasedContext)
            {
                listLoader = new ProjectBasedMergeRequestLoader(
                    op, versionLoader, cache, context);
            }
            else if (context.CustomData is SearchBasedContext)
            {
                listLoader = new SearchBasedMergeRequestLoader(hostname,
                                                               op, versionLoader, cache, context);
            }
            return(listLoader);
        }