Skip to content
Permalink
Browse files

[Assets] Turned Session.Packages into a readonly collection

  • Loading branch information
xen2 committed Sep 6, 2018
1 parent eb15b2c commit b9e915a49cffb02fdf8b70b5be3db3533ebb5074
@@ -6,19 +6,28 @@
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using NuGet.ProjectModel;
using Xenko.Core;
using Xenko.Core.Diagnostics;

namespace Xenko.Core.Assets
{
public interface IReadOnlyPackageCollection : IReadOnlyCollection<Package>, INotifyCollectionChanged
{
Package Find(Dependency dependency);

Package Find(Guid packageGuid);

Package Find(PackageDependency packageDependency);

Package Find(string name, PackageVersionRange versionRange);
}

/// <summary>
/// A collection of <see cref="Package"/>.
/// </summary>
[DebuggerTypeProxy(typeof(CollectionDebugView))]
[DebuggerDisplay("Count = {Count}")]
[DataContract("PackageCollection")]
public sealed class PackageCollection : ICollection<Package>, INotifyCollectionChanged
public sealed class PackageCollection : ICollection<Package>, INotifyCollectionChanged, IReadOnlyPackageCollection
{
private readonly List<Package> packages;

@@ -148,6 +148,7 @@ public sealed class PackageSession : IDisposable, IAssetFinder
public static readonly Version DefaultVisualStudioVersion = new Version("14.0.23107.0");

private readonly ConstraintProvider constraintProvider = new ConstraintProvider();
private readonly PackageCollection packages;
private readonly PackageCollection packagesCopy;
private readonly object dependenciesLock = new object();
private SolutionProject currentProject;
@@ -172,10 +173,10 @@ public PackageSession()
Projects = new ProjectCollection();
Projects.CollectionChanged += ProjectsCollectionChanged;

Packages = new PackageCollection();
packages = new PackageCollection();
packagesCopy = new PackageCollection();
AssemblyContainer = new AssemblyContainer();
Packages.CollectionChanged += PackagesCollectionChanged;
packages.CollectionChanged += PackagesCollectionChanged;
}

/// <summary>
@@ -192,7 +193,7 @@ public PackageSession(Package package) : this()
/// Gets the packages referenced by the solution.
/// </summary>
/// <value>The packages.</value>
public PackageCollection Packages { get; }
public IReadOnlyPackageCollection Packages => packages;

/// <summary>
/// The projects referenced by the solution.
@@ -306,7 +307,7 @@ public IEnumerable<Package> GetPackagesFromCurrent()

foreach (var dependency in CurrentProject.Dependencies)
{
var loadedPackage = Packages.Find(dependency);
var loadedPackage = packages.Find(dependency);
// In case the package is not found (when working with session not fully loaded/resolved with all deps)
if (loadedPackage == null)
{
@@ -417,7 +418,7 @@ public void AddExistingPackage(Package package, ILogger logger)
}

// Preset the session on the package to allow the session to look for existing asset
Packages.Add(package);
packages.Add(package);

// Run analysis after
var analysis = new PackageAnalysis(package, GetPackageAnalysisParametersForLoad());
@@ -928,7 +929,7 @@ private void RegisterProject(PackageContainer project)
VSSolution.Projects.Add(solutionProject.VSProject);
}

Packages.Add(project.Package);
packages.Add(project.Package);
}

private void UnRegisterProject(PackageContainer project)
@@ -939,7 +940,7 @@ private void UnRegisterProject(PackageContainer project)
}

if (project.Package != null)
Packages.Remove(project.Package);
packages.Remove(project.Package);
if (project is SolutionProject solutionProject)
{
VSSolution.Projects.Remove(solutionProject.VSProject);
@@ -1110,7 +1111,7 @@ private bool TryLoadAssets(PackageSession session, ILogger log, Package package,
// Process store dependencies for upgraders
foreach (var packageDependency in package.Meta.Dependencies)
{
var dependencyPackage = session.Packages.Find(packageDependency);
var dependencyPackage = session.packages.Find(packageDependency);
if (dependencyPackage == null)
{
continue;
@@ -1321,7 +1322,7 @@ private void PreLoadPackageDependencies(ILogger log, SolutionProject project, Pa
// 1. Load store package
foreach (var projectDependency in project.Dependencies)
{
var loadedPackage = Packages.Find(projectDependency);
var loadedPackage = packages.Find(projectDependency);
if (loadedPackage == null)
{
var file = PackageStore.Instance.GetPackageFileName(projectDependency.Name, new PackageVersionRange(new PackageVersion(projectDependency.VersionRange.MinVersion.Version, projectDependency.VersionRange.MinVersion.SpecialVersion)), constraintProvider);

0 comments on commit b9e915a

Please sign in to comment.
You can’t perform that action at this time.