Skip to content
Permalink
Browse files

[Assets] Removed Package.Id

  • Loading branch information
xen2 committed Sep 18, 2018
1 parent 0b5ba02 commit e59316a8d203f8dc97dced255ea631ec99a2cbd5
Showing with 68 additions and 309 deletions.
  1. +9 −14 sources/assets/Xenko.Core.Assets.Tests/TestPackage.cs
  2. +8 −40 sources/assets/Xenko.Core.Assets/Package.cs
  3. +1 −1 sources/assets/Xenko.Core.Assets/PackageAssetCollection.cs
  4. +4 −42 sources/assets/Xenko.Core.Assets/PackageCollection.cs
  5. +0 −87 sources/assets/Xenko.Core.Assets/PackageReference.cs
  6. +10 −11 sources/assets/Xenko.Core.Assets/PackageSession.cs
  7. +0 −44 sources/assets/Xenko.Core.Assets/Serializers/PackageReferenceSerializer.cs
  8. +2 −2 sources/assets/Xenko.Core.Assets/SourceCodeAsset.cs
  9. +1 −1 sources/editor/Xenko.Assets.Presentation/EffectCompilerServerSession.cs
  10. +1 −1 sources/editor/Xenko.Assets.Presentation/Templates/AssetTemplateGenerator.cs
  11. +1 −1 sources/editor/Xenko.Assets.Presentation/Templates/ScriptTemplateGenerator.cs
  12. +0 −14 sources/editor/Xenko.Assets.Presentation/Templates/TemplateSampleGenerator.cs
  13. +2 −12 sources/editor/Xenko.Core.Assets.Editor/ViewModel/PackageViewModel.cs
  14. +7 −7 sources/editor/Xenko.Editor/Build/XenkoShaderImporter.cs
  15. +1 −1 sources/editor/Xenko.GameStudio/GameStudioWindow.xaml.cs
  16. +1 −2 sources/engine/Xenko.Assets/GameSettingsAssetCompiler.cs
  17. +2 −3 sources/engine/Xenko.Assets/Templates/ProjectTemplateGeneratorHelper.cs
  18. +0 −2 sources/engine/Xenko.Engine/Engine/Design/GameSettings.cs
  19. +1 −1 sources/engine/Xenko.Engine/Engine/Game.cs
  20. +2 −2 sources/engine/Xenko.Engine/Rendering/EffectSystem.cs
  21. +7 −7 sources/engine/Xenko.Engine/Shaders.Compiler/RemoteEffectCompilerClient.cs
  22. +8 −13 sources/tools/Xenko.EffectCompilerServer/EffectCompilerServer.cs
  23. +0 −1 sources/tools/Xenko.ProjectGenerator/PackageUnitTestGenerator.cs
@@ -26,7 +26,7 @@ public void TestBasicPackageCreateSaveLoad()

// Force the PackageId to be the same each time we run the test
// Usually the PackageId is unique and generated each time we create a new project
var project = new Package { Id = Guid.Empty, FullPath = testGenerated1 };
var project = new Package { FullPath = testGenerated1 };
project.Profile.AssetFolders.Clear();
project.Profile.AssetFolders.Add(new AssetFolder("."));

@@ -56,7 +56,6 @@ public void TestBasicPackageCreateSaveLoad()
AssertResult(project2Result);
var project2 = project2Result.Session.LocalPackages.FirstOrDefault();
Assert.NotNull(project2);
Assert.Equal(project.Id, project2.Id);
Assert.True(project2.Profile.AssetFolders.Count > 0);
Assert.Equal(project2.Container, project2Result.Session.CurrentProject); // Check that the current package is setup when loading a single package
var sourceFolder = project.Profile.AssetFolders.First().Path;
@@ -69,7 +68,6 @@ public void TestBasicPackageCreateSaveLoad()
var sessionReload = sessionResult.Session;
Assert.Single(sessionReload.LocalPackages);
var reloadPackage = sessionReload.LocalPackages.First();
Assert.Equal(project.Id, reloadPackage.Id);
}

[Fact]
@@ -99,9 +97,7 @@ public void TestPackageLoadingWithAssets()
AssertResult(sessionResult);
var session = sessionResult.Session;

var rootPackageId = new Guid("4102BF96-796D-4800-9983-9C227FAB7BBD");

var project = session.Packages.Find(rootPackageId);
var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackageLoadingWithAssets");
Assert.NotNull(project);
Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded");

@@ -119,14 +115,14 @@ public void TestPackageLoadingWithAssets()

// Save project back to disk on a different location
project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackage2\TestPackage2.xkpkg");
var subPackage = session.Packages.Find(Guid.Parse("281321F0-7664-4523-B1DC-3CFC26F80F77"));
var subPackage = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "SubPackage");
subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackage2\SubPackage\SubPackage.xkpkg");
var result = new LoggerResult();
session.Save(result);

var project2Result = PackageSession.Load(DirectoryTestBase + @"TestPackage2\TestPackage2.xkpkg");
AssertResult(project2Result);
var project2 = project2Result.Session.Packages.Find(rootPackageId);
var project2 = project2Result.Session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2");
Assert.NotNull(project2);
Assert.Equal(3, project2.Assets.Count);
}
@@ -137,15 +133,14 @@ public void TestMovingAssets()
var basePath = Path.Combine(DirectoryTestBase, @"TestPackage");
var projectPath = Path.Combine(basePath, "TestPackageLoadingWithAssets.xkpkg");

var rootPackageId = new Guid("4102BF96-796D-4800-9983-9C227FAB7BBD");
var testAssetId = new AssetId("C2D80EF9-2160-43B2-9FEE-A19A903A0BE0");

// Load the project from the original location
var sessionResult1 = PackageSession.Load(projectPath);
{
AssertResult(sessionResult1);
var session = sessionResult1.Session;
var project = session.Packages.Find(rootPackageId);
var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackageLoadingWithAssets");
Assert.NotNull(project);

Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded");
@@ -159,7 +154,7 @@ public void TestMovingAssets()

// First save a copy of the project to TestPackageMovingAssets1
project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets1\TestPackage2.xkpkg");
var subPackage = session.Packages.Find(Guid.Parse("281321F0-7664-4523-B1DC-3CFC26F80F77"));
var subPackage = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "SubPackage");
subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets1\SubPackage\SubPackage.xkpkg");
var result = new LoggerResult();
session.Save(result);
@@ -170,7 +165,7 @@ public void TestMovingAssets()
{
AssertResult(sessionResult2);
var session = sessionResult2.Session;
var project = session.Packages.Find(rootPackageId);
var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2");
Assert.NotNull(project);
Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded");

@@ -184,7 +179,7 @@ public void TestMovingAssets()

// Save the whole project to a different location
project.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets2\TestPackage2.xkpkg");
var subPackage = session.Packages.Find(Guid.Parse("281321F0-7664-4523-B1DC-3CFC26F80F77"));
var subPackage = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2");
subPackage.FullPath = Path.Combine(DirectoryTestBase, @"TestPackageMovingAssets2\SubPackage\SubPackage.xkpkg");
var result = new LoggerResult();
session.Save(result);
@@ -195,7 +190,7 @@ public void TestMovingAssets()
{
AssertResult(sessionResult3);
var session = sessionResult3.Session;
var project = session.Packages.Find(rootPackageId);
var project = session.Packages.Single(x => x.FullPath.GetFileNameWithoutExtension() == "TestPackage2");
Assert.NotNull(project);
Assert.True(3 == project.Assets.Count, "Invalid number of assets loaded");

@@ -51,21 +51,13 @@ public enum PackageState
[DataContract("Package")]
[NonIdentifiableCollectionItems]
[AssetDescription(PackageFileExtension)]
[DebuggerDisplay("Id: {Id}, Name: {Meta.Name}, Version: {Meta.Version}, Assets [{Assets.Count}]")]
[DebuggerDisplay("Name: {Meta.Name}, Version: {Meta.Version}, Assets [{Assets.Count}]")]
[AssetFormatVersion("Assets", PackageFileVersion, "0.0.0.4")]
[AssetUpgrader("Assets", "0.0.0.4", "3.1.0.0", typeof(MovePackageInsideProject))]
public sealed partial class Package : IIdentifiable, IFileSynchronizable, IAssetFinder
public sealed partial class Package : IFileSynchronizable, IAssetFinder
{
private const string PackageFileVersion = "3.1.0.0";

private Guid id;

// Note: Please keep this code in sync with Asset class
/// <summary>
/// Locks the unique identifier for further changes.
/// </summary>
internal bool IsIdLocked;

private readonly List<UFile> filesToDelete = new List<UFile>();

private PackageSession session;
@@ -90,7 +82,6 @@ public sealed partial class Package : IIdentifiable, IFileSynchronizable, IAsset
/// </summary>
public Package()
{
Id = Guid.NewGuid();
// Initializse package with default versions (same code as in Asset..ctor())
var defaultPackageVersion = AssetRegistry.GetCurrentFormatVersions(GetType());
if (defaultPackageVersion != null)
@@ -104,29 +95,6 @@ public Package()
settings = new Lazy<PackageUserSettings>(() => new PackageUserSettings(this));
}

// Note: Please keep this code in sync with Asset class
/// <summary>
/// Gets or sets the unique identifier of this package.
/// </summary>
/// <value>The identifier.</value>
[DataMember(-10000)]
[NonOverridable]
[Display(Browsable = false)]
public Guid Id
{
get
{
return id;
}
set
{
if (value != id && IsIdLocked)
throw new InvalidOperationException("Cannot change an Asset Object Id once it is locked by a package");

id = value;
}
}

// Note: Please keep this code in sync with Asset class
/// <summary>
/// Gets or sets the version number for this asset, used internally when migrating assets.
@@ -768,7 +736,7 @@ public static PackageContainer LoadProject(ILogger log, string filePath)
var projectPath = filePath;
var packagePath = Path.ChangeExtension(filePath, Package.PackageFileExtension);
var package = LoadRaw(log, packagePath);
return new SolutionProject(package, projectPath);
return new SolutionProject(package, Guid.NewGuid(), projectPath);
}
else
{
@@ -779,7 +747,7 @@ public static PackageContainer LoadProject(ILogger log, string filePath)
var projectPath = Path.ChangeExtension(package.FullPath, ".csproj");
if (File.Exists(projectPath))
{
return new SolutionProject(package, projectPath);
return new SolutionProject(package, Guid.NewGuid(), projectPath);
}
else
{
@@ -1051,7 +1019,7 @@ private void LoadAsset(AssetMigrationContext context, PackageLoadingAssetFile as

bool aliasOccurred;
AttachedYamlAssetMetadata yamlMetadata;
var asset = LoadAsset(context.Log, ref id, assetFullPath, assetPath.ToWindowsPath(), assetContent, out aliasOccurred, out yamlMetadata);
var asset = LoadAsset(context.Log, Meta.Name, assetFullPath, assetPath.ToWindowsPath(), assetContent, out aliasOccurred, out yamlMetadata);

// Create asset item
var assetItem = new AssetItem(assetPath, asset, this)
@@ -1117,7 +1085,7 @@ public void RestoreNugetPackages(ILogger log)
}
}

private static Asset LoadAsset(ILogger log, ref Guid packageId, string assetFullPath, string assetPath, byte[] assetContent, out bool assetDirty, out AttachedYamlAssetMetadata yamlMetadata)
private static Asset LoadAsset(ILogger log, string packageName, string assetFullPath, string assetPath, byte[] assetContent, out bool assetDirty, out AttachedYamlAssetMetadata yamlMetadata)
{
var loadResult = assetContent != null
? AssetFileSerializer.Load<Asset>(new MemoryStream(assetContent), assetFullPath, log)
@@ -1131,7 +1099,7 @@ private static Asset LoadAsset(ILogger log, ref Guid packageId, string assetFull
if (sourceCodeAsset != null)
{
// Use an id generated from the location instead of the default id
sourceCodeAsset.Id = SourceCodeAsset.GenerateIdFromLocation(packageId, assetPath);
sourceCodeAsset.Id = SourceCodeAsset.GenerateIdFromLocation(packageName, assetPath);
}

return loadResult.Asset;
@@ -1149,7 +1117,7 @@ private void LoadAssemblyReferencesForPackage(ILogger log, PackageLoadParameters

// Check if already loaded
// TODO: More advanced cases: unload removed references, etc...
var projectReference = new ProjectReference(Id, project.FullPath, Core.Assets.ProjectType.Library);
var projectReference = new ProjectReference(project.Id, project.FullPath, Core.Assets.ProjectType.Library);
if (LoadedAssemblies.Any(x => x.ProjectReference == projectReference))
return;

@@ -363,7 +363,7 @@ public void CheckCanAdd(AssetItem item)
{
if (otherPackage.Assets.ContainsById(item.Id))
{
throw new ArgumentException("Cannot add the asset [{0}] that is already in different package [{1}] in the current session".ToFormat(item.Id, otherPackage.Id));
throw new ArgumentException("Cannot add the asset [{0}] that is already in different package [{1}] in the current session".ToFormat(item.Id, otherPackage.Meta.Name));
}
}
}
@@ -14,8 +14,6 @@ public interface IReadOnlyPackageCollection : IReadOnlyCollection<Package>, INot
{
Package Find(Dependency dependency);

Package Find(Guid packageGuid);

Package Find(PackageDependency packageDependency);

Package Find(string name, PackageVersionRange versionRange);
@@ -81,16 +79,6 @@ public Package Find(Dependency dependency)
return Find(dependency.Name, new PackageVersionRange(dependency.Version));
}

/// <summary>
/// Finds the specified package by its unique identifier.
/// </summary>
/// <param name="packageGuid">The package unique identifier.</param>
/// <returns>Package.</returns>
public Package Find(Guid packageGuid)
{
return packages.FirstOrDefault(package => package.Id == packageGuid);
}

/// <summary>
/// Finds the a package already in this collection from the specified dependency.
/// </summary>
@@ -119,11 +107,8 @@ public Package Find(string name, PackageVersionRange versionRange)
public void Add(Package item)
{
if (item == null) throw new ArgumentNullException("item");
if (Find(item.Id) == null)
{
packages.Add(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}
packages.Add(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
}

public void Clear()
@@ -133,44 +118,21 @@ public void Clear()
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace, packages, oldPackages));
}

/// <summary>
/// Determines whether this collection contains a package with the specified package unique identifier.
/// </summary>
/// <param name="packageGuid">The package unique identifier.</param>
/// <returns><c>true</c> if this collection contains a package with the specified package unique identifier; otherwise, <c>false</c>.</returns>
public bool ContainsById(Guid packageGuid)
{
return packages.Any(package => package.Id == packageGuid);
}

public bool Contains(Package item)
{
if (item == null) throw new ArgumentNullException("item");
return ContainsById(item.Id);
return packages.Contains(item);
}

public void CopyTo(Package[] array, int arrayIndex)
{
packages.CopyTo(array, arrayIndex);
}

public bool RemoveById(Guid packageGuid)
{
var item = Find(packageGuid);
if (item != null)
{

packages.Remove(item);
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
return true;
}
return false;
}

public bool Remove(Package item)
{
if (item == null) throw new ArgumentNullException("item");
return RemoveById(item.Id);
return packages.Remove(item);
}

private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)

0 comments on commit e59316a

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