public DependencySharedProjectsSubscriber(
     [Import(ExportContractNames.Scopes.UnconfiguredProject)] IProjectAsynchronousTasksService tasksService,
     IDependenciesSnapshotProvider dependenciesSnapshotProvider)
     : base(synchronousDisposal: true)
 {
     _tasksService = tasksService;
     _dependenciesSnapshotProvider = dependenciesSnapshotProvider;
 }
Exemplo n.º 2
0
 public DependencySharedProjectsSubscriber(
     IUnconfiguredProjectCommonServices commonServices,
     [Import(ExportContractNames.Scopes.UnconfiguredProject)] IProjectAsynchronousTasksService tasksService,
     IDependenciesSnapshotProvider dependenciesSnapshotProvider)
     : base(synchronousDisposal: true)
 {
     _tasksService = tasksService;
     _dependenciesSnapshotProvider = dependenciesSnapshotProvider;
     _subscriptionLinks            = new List <IDisposable>();
 }
        public ProjectRuleHandler(IAggregateDependenciesSnapshotProvider aggregateSnapshotProvider,
                                  IDependenciesSnapshotProvider snapshotProvider,
                                  IUnconfiguredProjectCommonServices commonServices)
        {
            AggregateSnapshotProvider = aggregateSnapshotProvider;
            SnapshotProvider          = snapshotProvider;
            CommonServices            = commonServices;

            AggregateSnapshotProvider.SnapshotChanged           += OnSnapshotChanged;
            AggregateSnapshotProvider.SnapshotProviderUnloading += OnSnapshotProviderUnloading;

            CommonServices.Project.ProjectUnloading += OnUnconfiguredProjectUnloading;
        }
        public void RegisterSnapshotProvider(IDependenciesSnapshotProvider snapshotProvider)
        {
            if (snapshotProvider == null)
            {
                return;
            }

            lock (_snapshotProviders)
            {
                _snapshotProviders[snapshotProvider.CurrentSnapshot.ProjectPath] = snapshotProvider;
                snapshotProvider.SnapshotRenamed           += OnSnapshotRenamed;
                snapshotProvider.SnapshotChanged           += OnSnapshotChanged;
                snapshotProvider.SnapshotProviderUnloading += OnSnapshotProviderUnloading;
            }

            void OnSnapshotProviderUnloading(object sender, SnapshotProviderUnloadingEventArgs e)
            {
                // Project has unloaded, so remove it from the cache and unregister event handlers
                SnapshotProviderUnloading?.Invoke(this, e);

                lock (_snapshotProviders)
                {
                    _snapshotProviders.Remove(snapshotProvider.CurrentSnapshot.ProjectPath);
                    snapshotProvider.SnapshotRenamed           -= OnSnapshotRenamed;
                    snapshotProvider.SnapshotChanged           -= OnSnapshotChanged;
                    snapshotProvider.SnapshotProviderUnloading -= OnSnapshotProviderUnloading;
                }
            }

            void OnSnapshotRenamed(object sender, ProjectRenamedEventArgs e)
            {
                lock (_snapshotProviders)
                {
                    // Remove and re-add provider with new project path
                    if (!string.IsNullOrEmpty(e.OldFullPath) &&
                        _snapshotProviders.TryGetValue(e.OldFullPath, out IDependenciesSnapshotProvider provider) &&
                        _snapshotProviders.Remove(e.OldFullPath) &&
                        provider != null &&
                        !string.IsNullOrEmpty(e.NewFullPath))
                    {
                        _snapshotProviders[e.NewFullPath] = provider;
                    }
                }
            }

            void OnSnapshotChanged(object sender, SnapshotChangedEventArgs e)
            {
                // Propagate the change event
                SnapshotChanged?.Invoke(this, e);
            }
        }
Exemplo n.º 5
0
        public static IAggregateDependenciesSnapshotProvider Implement(
            IDependenciesSnapshotProvider getSnapshotProvider = null,
            MockBehavior mockBehavior = MockBehavior.Default)
        {
            var mock = new Mock <IAggregateDependenciesSnapshotProvider>(mockBehavior);

            if (getSnapshotProvider != null)
            {
                mock.Setup(x => x.GetSnapshotProvider(It.IsAny <string>()))
                .Returns(getSnapshotProvider);
            }

            return(mock.Object);
        }
Exemplo n.º 6
0
        public void RegisterSnapshotProvider(IDependenciesSnapshotProvider snapshotProvider)
        {
            if (snapshotProvider == null)
            {
                return;
            }

            lock (_snapshotProvidersLock)
            {
                SnapshotProviders[snapshotProvider.ProjectFilePath] = snapshotProvider;
                snapshotProvider.SnapshotRenamed           += OnSnapshotRenamed;
                snapshotProvider.SnapshotChanged           += OnSnapshotChanged;
                snapshotProvider.SnapshotProviderUnloading += OnSnapshotProviderUnloading;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// When a given project context is unloaded, remove it form the cache and unregister event handlers
        /// </summary>
        internal void OnSnapshotProviderUnloading(object sender, SnapshotProviderUnloadingEventArgs e)
        {
            IDependenciesSnapshotProvider snapshotProvider = e.SnapshotProvider;

            if (snapshotProvider == null)
            {
                return;
            }

            SnapshotProviderUnloading?.Invoke(this, e);

            lock (_snapshotProvidersLock)
            {
                SnapshotProviders.TryRemove(snapshotProvider.ProjectFilePath, out IDependenciesSnapshotProvider provider);
                snapshotProvider.SnapshotRenamed           -= OnSnapshotRenamed;
                snapshotProvider.SnapshotChanged           -= OnSnapshotChanged;
                snapshotProvider.SnapshotProviderUnloading -= OnSnapshotProviderUnloading;
            }
        }
        public DependenciesProjectTreeProvider(
            IProjectThreadingService threadingService,
            UnconfiguredProject unconfiguredProject,
            IDependenciesSnapshotProvider dependenciesSnapshotProvider,
            [Import(DependencySubscriptionsHost.DependencySubscriptionsHostContract)]
            ICrossTargetSubscriptionsHost dependenciesHost,
            [Import(ExportContractNames.Scopes.UnconfiguredProject)] IProjectAsynchronousTasksService tasksService)
            : base(threadingService, unconfiguredProject)
        {
            ProjectTreePropertiesProviders = new OrderPrecedenceImportCollection <IProjectTreePropertiesProvider>(
                ImportOrderPrecedenceComparer.PreferenceOrder.PreferredComesLast,
                projectCapabilityCheckProvider: unconfiguredProject);

            ViewProviders = new OrderPrecedenceImportCollection <IDependenciesTreeViewProvider>(
                ImportOrderPrecedenceComparer.PreferenceOrder.PreferredComesFirst,
                projectCapabilityCheckProvider: unconfiguredProject);

            DependenciesSnapshotProvider = dependenciesSnapshotProvider;
            DependenciesHost             = dependenciesHost;
            TasksService = tasksService;

            unconfiguredProject.ProjectUnloading += OnUnconfiguredProjectUnloading;
        }
Exemplo n.º 9
0
        /// <inheritdoc />
        public IDisposable RegisterSnapshotProvider(IDependenciesSnapshotProvider snapshotProvider)
        {
            Requires.NotNull(snapshotProvider, nameof(snapshotProvider));

            var unregister = new DisposableBag();

            lock (_lock)
            {
                snapshotProvider.SnapshotRenamed           += OnSnapshotRenamed;
                snapshotProvider.SnapshotProviderUnloading += OnSnapshotProviderUnloading;

                ITargetBlock <SnapshotChangedEventArgs> actionBlock = DataflowBlockSlim.CreateActionBlock <SnapshotChangedEventArgs>(
                    e => SnapshotChanged?.Invoke(this, e),
                    "AggregateDependenciesSnapshotProviderSource {1}",
                    skipIntermediateInputData: true);

                unregister.Add(
                    snapshotProvider.SnapshotChangedSource.LinkTo(
                        actionBlock,
                        DataflowOption.PropagateCompletion));

                _snapshotProviderByPath = _snapshotProviderByPath.SetItem(snapshotProvider.CurrentSnapshot.ProjectPath, snapshotProvider);
            }

            unregister.Add(new DisposableDelegate(
                               () =>
            {
                lock (_lock)
                {
                    string projectPath                          = snapshotProvider.CurrentSnapshot.ProjectPath;
                    _snapshotProviderByPath                     = _snapshotProviderByPath.Remove(projectPath);
                    snapshotProvider.SnapshotRenamed           -= OnSnapshotRenamed;
                    snapshotProvider.SnapshotProviderUnloading -= OnSnapshotProviderUnloading;
                }
            }));

            return(unregister);

            void OnSnapshotProviderUnloading(object sender, SnapshotProviderUnloadingEventArgs e)
            {
                // Project has unloaded, so remove it from the cache and unregister event handlers
                SnapshotProviderUnloading?.Invoke(this, e);

                unregister.Dispose();
            }

            void OnSnapshotRenamed(object sender, ProjectRenamedEventArgs e)
            {
                if (string.IsNullOrEmpty(e.OldFullPath))
                {
                    return;
                }

                lock (_lock)
                {
                    // Remove and re-add provider with new project path
                    if (_snapshotProviderByPath.TryGetValue(e.OldFullPath, out IDependenciesSnapshotProvider provider))
                    {
                        _snapshotProviderByPath = _snapshotProviderByPath.Remove(e.OldFullPath);

                        if (!string.IsNullOrEmpty(e.NewFullPath))
                        {
                            _snapshotProviderByPath = _snapshotProviderByPath.SetItem(e.NewFullPath, provider);
                        }
                    }
                }
            }
        }
Exemplo n.º 10
0
 public SnapshotProviderUnloadingEventArgs(IDependenciesSnapshotProvider snapshotProvider)
 {
     SnapshotProvider = snapshotProvider;
 }
        protected IDependenciesSnapshot GetSnapshot(string projectPath)
        {
            IDependenciesSnapshotProvider snapshotProvider = AggregateSnapshotProvider.GetSnapshotProvider(projectPath);

            return(snapshotProvider?.CurrentSnapshot);
        }