Ejemplo n.º 1
0
        private static IWorkspaceService GetVisualStudioProjectCache(HostWorkspaceServices workspaceServices)
        {
            var projectCacheService = new ProjectCacheService(workspaceServices.Workspace, ImplicitCacheTimeoutInMS);

            var documentTrackingService = workspaceServices.GetService <IDocumentTrackingService>();

            // Subscribe to events so that we can cache items from the active document's project
            var manager = new ActiveProjectCacheManager(documentTrackingService, projectCacheService);

            // Subscribe to requests to clear the cache
            var workspaceCacheService = workspaceServices.GetService <IWorkspaceCacheService>();

            if (workspaceCacheService != null)
            {
                workspaceCacheService.CacheFlushRequested += (s, e) => manager.Clear();
            }

            // Also clear the cache when the solution is cleared or removed.
            workspaceServices.Workspace.WorkspaceChanged += (s, e) =>
            {
                if (e.Kind == WorkspaceChangeKind.SolutionCleared || e.Kind == WorkspaceChangeKind.SolutionRemoved)
                {
                    manager.Clear();
                }
            };

            return(projectCacheService);
        }
Ejemplo n.º 2
0
            public ActiveProjectCacheManager(IDocumentTrackingService documentTrackingService, ProjectCacheService projectCacheService)
            {
                _projectCacheService = projectCacheService;

                documentTrackingService.ActiveDocumentChanged += UpdateCache;
                UpdateCache(null, documentTrackingService.TryGetActiveDocument());
            }
Ejemplo n.º 3
0
        public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
        {
            if (workspaceServices.Workspace.Kind != WorkspaceKind.Host)
            {
                return(new ProjectCacheService(workspaceServices.Workspace));
            }

            var service = new ProjectCacheService(
                workspaceServices.Workspace,
                ImplicitCacheTimeoutInMS
                );

            // Also clear the cache when the solution is cleared or removed.
            workspaceServices.Workspace.WorkspaceChanged += (s, e) =>
            {
                if (
                    e.Kind == WorkspaceChangeKind.SolutionCleared ||
                    e.Kind == WorkspaceChangeKind.SolutionRemoved
                    )
                {
                    service.ClearImplicitCache();
                }
            };

            return(service);
        }
Ejemplo n.º 4
0
        internal static void ConnectProjectCacheServiceToDocumentTracking(
            HostWorkspaceServices workspaceServices,
            ProjectCacheService projectCacheService
            )
        {
            var documentTrackingService = workspaceServices.GetService <IDocumentTrackingService>();

            // Subscribe to events so that we can cache items from the active document's project
            var manager = new ActiveProjectCacheManager(
                documentTrackingService,
                projectCacheService
                );

            // Subscribe to requests to clear the cache
            var workspaceCacheService = workspaceServices.GetService <IWorkspaceCacheService>();

            if (workspaceCacheService != null)
            {
                workspaceCacheService.CacheFlushRequested += (s, e) => manager.Clear();
            }

            // Also clear the cache when the solution is cleared or removed.
            workspaceServices.Workspace.WorkspaceChanged += (s, e) =>
            {
                if (
                    e.Kind == WorkspaceChangeKind.SolutionCleared ||
                    e.Kind == WorkspaceChangeKind.SolutionRemoved
                    )
                {
                    manager.Clear();
                }
            };
        }
Ejemplo n.º 5
0
            public ImplicitCacheMonitor(ProjectCacheService owner, int backOffTimeSpanInMS) :
                base(AggregateAsynchronousOperationListener.CreateEmptyListener(),
                     backOffTimeSpanInMS,
                     CancellationToken.None)
            {
                _owner = owner;
                _gate  = new SemaphoreSlim(0);

                Start();
            }
Ejemplo n.º 6
0
            public ActiveProjectCacheManager(IDocumentTrackingService documentTrackingService, ProjectCacheService projectCacheService)
            {
                _documentTrackingService = documentTrackingService;
                _projectCacheService     = projectCacheService;

                if (documentTrackingService != null)
                {
                    documentTrackingService.ActiveDocumentChanged += UpdateCache;
                    UpdateCache(null, documentTrackingService.GetActiveDocument());
                }
            }
        private static IWorkspaceService GetMiscProjectCache(HostWorkspaceServices workspaceServices)
        {
            var projectCacheService = new ProjectCacheService(workspaceServices.Workspace, ImplicitCacheTimeoutInMS);

            // Also clear the cache when the solution is cleared or removed.
            workspaceServices.Workspace.WorkspaceChanged += (s, e) =>
            {
                if (e.Kind == WorkspaceChangeKind.SolutionCleared || e.Kind == WorkspaceChangeKind.SolutionRemoved)
                {
                    projectCacheService.ClearImplicitCache();
                }
            };

            return(projectCacheService);
        }
Ejemplo n.º 8
0
 public Cache(ProjectCacheService cacheService, ProjectId key)
 {
     _cacheService = cacheService;
     _key          = key;
 }