public void TestWithPackage() { var inputs = new AssetItemCollection(); var asset = new AssetObjectTest(); var package = new Package(); package.Assets.Add(new AssetItem("0", asset)); for (int i = 0; i < 10; i++) { var newAsset = new AssetObjectTest() { Id = asset.Id, Reference = new AssetReference <AssetObjectTest>(asset.Id, "bad") }; inputs.Add(new AssetItem("0", newAsset)); } // Tries to use existing ids var outputs = new AssetItemCollection(); AssetCollision.Clean(null, inputs, outputs, AssetResolver.FromPackage(package), true); // Make sure we are generating exactly the same number of elements Assert.AreEqual(inputs.Count, outputs.Count); // Make sure that asset has been cloned Assert.AreNotEqual(inputs[0], outputs[0]); // First Id should not change Assert.AreNotEqual(inputs[0].Id, outputs[0].Id); // Make sure that all ids are different var ids = new HashSet <Guid>(outputs.Select(item => item.Id)); Assert.AreEqual(inputs.Count, ids.Count); // Make sure that all locations are different var locations = new HashSet <UFile>(outputs.Select(item => item.Location)); Assert.AreEqual(inputs.Count, locations.Count); // Reference location "bad"should be fixed to "0_1" pointing to the first element foreach (var output in outputs) { // Make sure of none of the locations are using "0" Assert.AreNotEqual("0", output.Location); var assetRef = ((AssetObjectTest)output.Asset).Reference; Assert.AreEqual("0 (2)", assetRef.Location); Assert.AreEqual(outputs[0].Id, assetRef.Id); } }
/// <summary> /// Initializes a new instance of the <see cref="Package"/> class. /// </summary> public Package() { localDependencies = new List<PackageReference>(); temporaryAssets = new AssetItemCollection(); assets = new PackageAssetCollection(this); explicitFolders = new List<UDirectory>(); Bundles = new BundleCollection(this); Meta = new PackageMeta(); TemplateFolders = new List<TemplateFolder>(); Templates = new List<TemplateDescription>(); Profiles = new PackageProfileCollection(); IsDirty = true; }
public void TestSimpleNewGuids() { var inputs = new AssetItemCollection(); var asset = new AssetObjectTest(); for (int i = 0; i < 10; i++) { var newAsset = new AssetObjectTest() { Id = asset.Id, Reference = new AssetReference <AssetObjectTest>(asset.Id, "bad") }; inputs.Add(new AssetItem("0", newAsset)); } // Force to use new ids var outputs = new AssetItemCollection(); AssetCollision.Clean(null, inputs, outputs, new AssetResolver() { AlwaysCreateNewId = true }, true); // Make sure we are generating exactly the same number of elements Assert.AreEqual(inputs.Count, outputs.Count); // Make sure that asset has been cloned Assert.AreNotEqual(inputs[0], outputs[0]); // First Id should not change Assert.AreNotEqual(inputs[0].Id, outputs[0].Id); // Make sure that all ids are different var ids = new HashSet <Guid>(outputs.Select(item => item.Id)); Assert.AreEqual(inputs.Count, ids.Count); // Make sure that all locations are different var locations = new HashSet <UFile>(outputs.Select(item => item.Location)); Assert.AreEqual(inputs.Count, locations.Count); // Reference location "bad"should be fixed to "0" foreach (var output in outputs) { var assetRef = ((AssetObjectTest)output.Asset).Reference; Assert.AreEqual("0", assetRef.Location); Assert.AreEqual(outputs[0].Id, assetRef.Id); } }
public void TestAssetItemCollection() { // Test serialization of asset items. var inputs = new AssetItemCollection(); for (int i = 0; i < 10; i++) { var newAsset = new AssetObjectTest() { Name = "Test" + i }; inputs.Add(new AssetItem("" + i, newAsset)); } var asText = inputs.ToText(); var outputs = AssetItemCollection.FromText(asText); Assert.AreEqual(inputs.Select(item => item.Location), outputs.Select(item => item.Location)); Assert.AreEqual(inputs.Select(item => item.Asset), outputs.Select(item => item.Asset)); }
public void TestSimpleNewGuids() { var inputs = new AssetItemCollection(); var asset = new AssetObjectTest(); for (int i = 0; i < 10; i++) { var newAsset = new AssetObjectTest() { Id = asset.Id, Reference = new AssetReference<AssetObjectTest>(asset.Id, "bad") }; inputs.Add(new AssetItem("0", newAsset)); } // Force to use new ids var outputs = new AssetItemCollection(); AssetCollision.Clean(inputs, outputs, new AssetResolver() { AlwaysCreateNewId = true }, true); // Make sure we are generating exactly the same number of elements Assert.AreEqual(inputs.Count, outputs.Count); // Make sure that asset has been cloned Assert.AreNotEqual(inputs[0], outputs[0]); // First Id should not change Assert.AreNotEqual(inputs[0].Id, outputs[0].Id); // Make sure that all ids are different var ids = new HashSet<Guid>(outputs.Select(item => item.Id)); Assert.AreEqual(inputs.Count, ids.Count); // Make sure that all locations are different var locations = new HashSet<UFile>(outputs.Select(item => item.Location)); Assert.AreEqual(inputs.Count, locations.Count); // Reference location "bad"should be fixed to "0" foreach (var output in outputs) { var assetRef = ((AssetObjectTest)output.Asset).Reference; Assert.AreEqual("0", assetRef.Location); Assert.AreEqual(outputs[0].Id, assetRef.Id); } }
static void Main(string[] args) { SiftComparison(@"C:\temp\2.jpg", @"C:\temp\1.jpg"); try { if (ConfigurationManager.AppSettings["address"] != "") { var proxy = new WebProxy(ConfigurationManager.AppSettings["address"], true); proxy.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["user"], ConfigurationManager.AppSettings["password"]); WebRequest.DefaultWebProxy = proxy; } } catch (Exception ex) { Console.WriteLine("ERROR: Please check proxy settings in KMB_ImageComparison.exe.config"); Console.ReadLine(); Environment.Exit(0); } PictureparkService.InnerChannel.OperationTimeout = new TimeSpan(0, 20, 0); while (true) { Console.WriteLine("Choose option: "); Console.WriteLine("1: Run comparison"); Console.WriteLine("2: Generate configuration-file"); switch (Console.ReadLine()) { //run comparison case "1": #region run comparison LogFile = DateTime.Now.ToString("yyyyMMdd_hhmmss") + "_ImageComparison_Log.txt"; if (CheckConfiguration()) { Log("Started comparison"); Log("Config file ok.."); //get asset fields AssetFields = PictureparkService.GetAssetFields(coreInfo); Log("Creating folder structure if not already existing"); //create temp folder if not already exists string tempPath = Configuration.ResultPath + "\\temp"; if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } //higher PHASH score than 65 or SIFT matching above 100 string matchingFolder = Configuration.ResultPath + "\\01_matching"; if (!Directory.Exists(matchingFolder)) { Directory.CreateDirectory(matchingFolder); } int matchingCount = 0; //neither PHASH score above 65 or SIFT matching above 100 string noMatchingFolder = Configuration.ResultPath + "\\02_not_matching"; if (!Directory.Exists(noMatchingFolder)) { Directory.CreateDirectory(noMatchingFolder); } int notMatchingCount = 0; //create missing images folder if not already exists string missingImgPath = Configuration.ResultPath + "\\03_missing_on_pp"; if (!Directory.Exists(missingImgPath)) { Directory.CreateDirectory(missingImgPath); } int missingImgCount = 0; //create multiple standard images folder if not already exists string multipleStandardImgPath = Configuration.ResultPath + "\\04_multiple_w11_in_pp"; if (!Directory.Exists(multipleStandardImgPath)) { Directory.CreateDirectory(multipleStandardImgPath); } int multipleW11Count = 0; //create missing images folder if not already exists string invalidAssetPath = Configuration.ResultPath + "\\05_invalid_asset_on_pp"; if (!Directory.Exists(invalidAssetPath)) { Directory.CreateDirectory(invalidAssetPath); } int invalidAssetOnPPCount = 0; int siftMatchingCount = 0; //loop images in ImageFolder DirectoryInfo imgDir = new DirectoryInfo(Configuration.ImagePath); using (var client = new WebClient()) { foreach (FileInfo fileToCheck in imgDir.GetFiles()) { coreInfo = LoginPP(PictureparkService); Log("Checking file: " + fileToCheck.Name); //only check jpg files, ignore others if (fileToCheck.Extension.ToLower() == ".jpg") { string strObjId = fileToCheck.Name.Replace(fileToCheck.Extension, ""); int objId; if (int.TryParse(strObjId, out objId)) { List <ComparisonOperation> comparisonOperations = new List <ComparisonOperation>(); StringEqualOperation stringEqualOperation = new StringEqualOperation() { FieldName = "OBJID", EqualString = objId.ToString() }; comparisonOperations.Add(stringEqualOperation); AndOperation searchOperations = new AndOperation() { ComparisonOperations = comparisonOperations.ToArray() }; ExtendedAssetFilter filter = new ExtendedAssetFilter() { AdditionalSelectFields = new string[] { "AssetName", "OBJID", "KeinDownloadOnline", "MP_Copyright" }, SearchOperation = searchOperations }; AssetItemCollection collection = PictureparkService.GetAssets(coreInfo, filter); List <AssetItem> assets = collection.Assets .Where(a => a.FieldValues .Where(fv => fv.FieldId == GetFieldIdByName(AssetFields.ToList(), "AssetName")) .Any(fv => fv.StringValue.Substring(1, 3).ToLower() == "w11")).ToList(); if (assets.Count() > 1) { //more than one w11 exists for this objId Log("More than one w11 exists for this objId"); File.Move(fileToCheck.FullName, multipleStandardImgPath + "\\" + fileToCheck.Name); multipleW11Count++; } else if (assets.Count() == 1) { AssetItem asset = assets[0]; List <AssetSelection> assetSelection = new List <AssetSelection>() { new AssetSelection() { AssetId = asset.AssetId, DerivativeDefinitionId = 7 } }; DownloadOptions downloadOptions = new DownloadOptions() { UserAction = UserAction.DerivativeDownload }; Download download = new Download(); try { download = PictureparkService.Download(coreInfo, assetSelection.ToArray(), downloadOptions); } catch (Exception ex) { File.Move(fileToCheck.FullName, invalidAssetPath + "\\" + fileToCheck.Name); Log("Problem with asset on picturepark"); invalidAssetOnPPCount++; continue; } //download asset into temp directory string downloadFilePath = tempPath + "\\" + download.DownloadFileName; client.DownloadFile(download.URL, downloadFilePath); double phashScore = CompareImages(fileToCheck.FullName, downloadFilePath); Log("PHASH-Score: " + phashScore); int siftScore = 0; // PHASH does not match, check if SIFT finds matches if (phashScore < 0.65) { Log("PHASH-Score too low, checking SIFT Algorithm"); siftScore = SiftComparison(fileToCheck.FullName, downloadFilePath); Log("SIFT-Score: " + siftScore); if (siftScore > 100) { siftMatchingCount++; } } string folder; if (phashScore > 0.65 || siftScore > 100) { Log("Images match!"); folder = matchingFolder; matchingCount++; } else { Log("Images do not match, lower PHASH than 0.65 and lower SIFT match than 100!"); folder = noMatchingFolder; notMatchingCount++; } string fullObjId = "0000000".Substring(0, 7 - objId.ToString().Length) + objId.ToString(); //move pair to folder File.Move(fileToCheck.FullName, folder + "\\" + fullObjId + "_mp.jpg"); File.Move(downloadFilePath, folder + "\\" + fullObjId + "_pp.jpg"); } else { //no asset found with this obj-id Log("No asset found for ObjId: " + objId.ToString()); File.Move(fileToCheck.FullName, missingImgPath + "\\" + fileToCheck.Name); missingImgCount++; } } else { Log("Filename is not an obj-id, skipping"); } } else { Log("No jpg, skipping.."); } } Log("-------------------------"); Log("Image comparison finished"); Log("-------------------------"); Log("Total matches: " + matchingCount); Log("Matches with PHASH: " + matchingCount + siftMatchingCount); Log("Matches with SIFT: " + siftMatchingCount); Log("-------------------------"); Log("Not matching: " + notMatchingCount); Log("-------------------------"); Log("Missing assets in Picturepark: " + missingImgCount); Log("-------------------------"); Log("Multiple W11 in Picturepark: " + multipleW11Count); Log("-------------------------"); Log("Invalid assets in Picturepark: " + invalidAssetOnPPCount); Log("-------------------------"); } } else { Log("Config file invalid, aborting"); } #endregion break; //generate config file case "2": #region generate config file if (File.Exists("Configuration.txt")) { Console.WriteLine("Configuration file already exists, overwrite with new one? (y)"); if (Console.ReadKey().Key.ToString().ToLower() != "y") { Console.WriteLine("Cancel.."); continue; } } Configuration config = new Configuration() { ImagePath = "PATH_TO_IMAGE_FOLDER", ResultPath = "PATH_TO_RESULTS_FOLDER", LogPath = "PATH_TO_LOG_FOLDER", PP_CustomerId = 0, PP_ClientGUID = "PP_CLIENT_GUID", PP_Email = "PP_EMAIL", PP_Password = "******" }; File.WriteAllText("Configuration.txt", JsonConvert.SerializeObject(config, Formatting.Indented)); FileInfo fi = new FileInfo("Configuration.txt"); Console.WriteLine("Configuration file generated: " + fi.FullName); #endregion break; default: Console.WriteLine("Invalid input.."); break; } } }
private static bool GetReviewedAssets(List <string> alreadyCompared) { ////DEBUG //List<ComparisonOperation> orComparisonOperations = new List<ComparisonOperation>(); //foreach (string tmp in tempcheck) //{ // StringEqualOperation asd = new StringEqualOperation() { FieldName = "OBJID", EqualString = "39894" }; // StringEqualOperation asd = new StringEqualOperation() { FieldName = "AssetName", EqualString = tmp }; // orComparisonOperations.Add(asd); //} //OrOperation orOperations = new OrOperation() { ComparisonOperations = orComparisonOperations.ToArray() }; ////DEBUG List <ComparisonOperation> andComparisonOperations = new List <ComparisonOperation>(); foreach (string ignoreAssets in alreadyCompared) { StringNotEqualOperation notEqualOperator = new StringNotEqualOperation() { FieldName = "AssetName", NotEqualString = ignoreAssets }; andComparisonOperations.Add(notEqualOperator); } StringEqualOperation contentApprovedFlag = new StringEqualOperation() { EqualString = "True", FieldName = "InhaltlichKontrolliert" }; andComparisonOperations.Add(contentApprovedFlag); AndOperation andOperations = new AndOperation() { ComparisonOperations = andComparisonOperations.ToArray() }; List <LogicalOperation> logicalOperations = new List <LogicalOperation>(); logicalOperations.Add(andOperations); //logicalOperations.Add(orOperations); AndOperation searchOperations = new AndOperation() { LogicalOperations = logicalOperations.ToArray() }; ExtendedAssetFilter filter = new ExtendedAssetFilter() { AdditionalSelectFields = new string[] { "AssetName", "OBJID", "FreigabeDatum", "InhaltlichKontrolliert" }, SearchOperation = searchOperations }; AssetItemCollection collection = PictureparkService.GetAssets(coreInfo, filter); //get preview assets List <AssetItem> assets = collection.Assets .Where(a => a.FieldValues .Where(fv => fv.FieldId == GetFieldIdByName(AssetFields.ToList(), "AssetName")) .Any(fv => fv.StringValue.Substring(1, 3).ToLower() == "w11")).ToList(); Log(assets.Count + " noch nicht geprüfte Werke"); if (assets.Count != 0) { if (MessageBox.Show(assets.Count + " noch nicht geprüfte Werke vorhanden. Diese jetzt herunterladen und abgleichen?", "", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { //create new archive directory CreateArchiveDirectory(); using (var client = new WebClient()) { foreach (AssetItem asset in assets) { List <AssetSelection> assetSelection = new List <AssetSelection>() { new AssetSelection() { AssetId = asset.AssetId, DerivativeDefinitionId = 7 //todo: check which derivative id to pass here } }; //List<ExtendedDerivative> availableDerivatives = PictureparkService.GetDerivatives(coreInfo, assetSelection.ToArray()).ToList(); DownloadOptions downloadOptions = new DownloadOptions() { UserAction = UserAction.DerivativeDownload }; Download download = PictureparkService.Download(coreInfo, assetSelection.ToArray(), downloadOptions); //download asset into temp directory client.DownloadFile(download.URL, TempFolderPath + "\\" + download.DownloadFileName); Log(download.DownloadFileName + " in temporäres Verzeichnis heruntergeladen"); } // continue with local comparison return(true); } } else { Log("Abgleich abgebrochen durch Benutzer"); } } else { MessageBox.Show("Es gibt keine neu geprüften Werke"); Log("Es gibt keine neu geprüften Werke"); } return(false); }
public void ValidateAssets(bool alwaysGenerateNewAssetId = false) { if (TemporaryAssets.Count == 0) { return; } try { // Make sure we are suspending notifications before updating all assets Assets.SuspendCollectionChanged(); Assets.Clear(); // Get generated output items var outputItems = new AssetItemCollection(); // Create a resolver from the package var resolver = AssetResolver.FromPackage(this); resolver.AlwaysCreateNewId = alwaysGenerateNewAssetId; // Clean assets AssetCollision.Clean(TemporaryAssets, outputItems, resolver, false); // Add them back to the package foreach (var item in outputItems) { Assets.Add(item); } TemporaryAssets.Clear(); } finally { // Restore notification on assets Assets.ResumeCollectionChanged(); } }
public void TestImportModelSimple() { var file = Path.Combine(Environment.CurrentDirectory, @"scenes\goblin.fbx"); // Create a project with an asset reference a raw file var project = new Package { FullPath = Path.Combine(Environment.CurrentDirectory, "ModelAssets", "ModelAssets" + Package.PackageFileExtension) }; using (var session = new PackageSession(project)) { var importSession = new AssetImportSession(session); // ------------------------------------------------------------------ // Step 1: Add files to session // ------------------------------------------------------------------ importSession.AddFile(file, project, UDirectory.Empty); // ------------------------------------------------------------------ // Step 2: Stage assets // ------------------------------------------------------------------ var stageResult = importSession.Stage(); Assert.IsTrue(stageResult); Assert.AreEqual(0, project.Assets.Count); // ------------------------------------------------------------------ // Step 3: Import asset directly // ------------------------------------------------------------------ importSession.Import(); Assert.AreEqual(4, project.Assets.Count); var assetItem = project.Assets.FirstOrDefault(item => item.Asset is EntityAsset); Assert.NotNull(assetItem); EntityAnalysis.UpdateEntityReferences(((EntityAsset)assetItem.Asset).Hierarchy); var assetCollection = new AssetItemCollection(); // Remove directory from the location assetCollection.Add(assetItem); Console.WriteLine(assetCollection.ToText()); //session.Save(); // Create and mount database file system var objDatabase = new ObjectDatabase("/data/db", "index", "/local/db"); var databaseFileProvider = new DatabaseFileProvider(objDatabase); AssetManager.GetFileProvider = () => databaseFileProvider; ((EntityAsset)assetItem.Asset).Hierarchy.Entities[0].Components.RemoveWhere(x => x.Key != TransformComponent.Key); //((EntityAsset)assetItem.Asset).Data.Entities[1].Components.RemoveWhere(x => x.Key != SiliconStudio.Paradox.Engine.TransformComponent.Key); var assetManager = new AssetManager(); assetManager.Save("Entity1", ((EntityAsset)assetItem.Asset).Hierarchy); assetManager = new AssetManager(); var entity = assetManager.Load<Entity>("Entity1"); var entity2 = entity.Clone(); var entityAsset = (EntityAsset)assetItem.Asset; entityAsset.Hierarchy.Entities[0].Components.Add(TransformComponent.Key, new TransformComponent()); var entityAsset2 = (EntityAsset)AssetCloner.Clone(entityAsset); entityAsset2.Hierarchy.Entities[0].Components.Get(TransformComponent.Key).Position = new Vector3(10.0f, 0.0f, 0.0f); AssetMerge.Merge(entityAsset, entityAsset2, null, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1); } }
public void ValidateAssets(bool alwaysGenerateNewAssetId = false) { if (TemporaryAssets.Count == 0) { return; } try { // Make sure we are suspending notifications before updating all assets Assets.SuspendCollectionChanged(); Assets.Clear(); // Get generated output items var outputItems = new AssetItemCollection(); // Create a resolver from the package var resolver = AssetResolver.FromPackage(this); resolver.AlwaysCreateNewId = alwaysGenerateNewAssetId; // Clean assets AssetCollision.Clean(this, TemporaryAssets, outputItems, resolver, true); // Add them back to the package foreach (var item in outputItems) { Assets.Add(item); } // Don't delete SourceCodeAssets as their files are handled by the package upgrader var dirtyAssets = outputItems.Where(o => o.IsDirty && !(o.Asset is SourceCodeAsset)) .Join(TemporaryAssets, o => o.Id, t => t.Id, (o, t) => t) .ToList(); // Dirty assets (except in system package) should be mark as deleted so that are properly saved again later. if (!IsSystem && dirtyAssets.Count > 0) { IsDirty = true; lock (filesToDelete) { filesToDelete.AddRange(dirtyAssets.Select(a => a.FullPath)); } } TemporaryAssets.Clear(); } finally { // Restore notification on assets Assets.ResumeCollectionChanged(); } }
[Test, Ignore] // ignore the test as long as EntityAsset is not created during import anymore public void TestImportModelSimple() { var file = Path.Combine(Environment.CurrentDirectory, @"scenes\goblin.fbx"); // Create a project with an asset reference a raw file var project = new Package { FullPath = Path.Combine(Environment.CurrentDirectory, "ModelAssets", "ModelAssets" + Package.PackageFileExtension) }; using (var session = new PackageSession(project)) { var importSession = new AssetImportSession(session); // ------------------------------------------------------------------ // Step 1: Add files to session // ------------------------------------------------------------------ importSession.AddFile(file, project, UDirectory.Empty); // ------------------------------------------------------------------ // Step 2: Stage assets // ------------------------------------------------------------------ var stageResult = importSession.Stage(); Assert.IsTrue(stageResult); Assert.AreEqual(0, project.Assets.Count); // ------------------------------------------------------------------ // Step 3: Import asset directly // ------------------------------------------------------------------ importSession.Import(); Assert.AreEqual(4, project.Assets.Count); var assetItem = project.Assets.FirstOrDefault(item => item.Asset is EntityAsset); Assert.NotNull(assetItem); EntityAnalysis.UpdateEntityReferences(((EntityAsset)assetItem.Asset).Hierarchy); var assetCollection = new AssetItemCollection(); // Remove directory from the location assetCollection.Add(assetItem); Console.WriteLine(assetCollection.ToText()); //session.Save(); // Create and mount database file system var objDatabase = new ObjectDatabase("/data/db", "index", "/local/db"); var databaseFileProvider = new DatabaseFileProvider(objDatabase); AssetManager.GetFileProvider = () => databaseFileProvider; ((EntityAsset)assetItem.Asset).Hierarchy.Entities[0].Components.RemoveWhere(x => x.Key != TransformComponent.Key); //((EntityAsset)assetItem.Asset).Data.Entities[1].Components.RemoveWhere(x => x.Key != SiliconStudio.Paradox.Engine.TransformComponent.Key); var assetManager = new AssetManager(); assetManager.Save("Entity1", ((EntityAsset)assetItem.Asset).Hierarchy); assetManager = new AssetManager(); var entity = assetManager.Load <Entity>("Entity1"); var entity2 = entity.Clone(); var entityAsset = (EntityAsset)assetItem.Asset; entityAsset.Hierarchy.Entities[0].Components.Add(TransformComponent.Key, new TransformComponent()); var entityAsset2 = (EntityAsset)AssetCloner.Clone(entityAsset); entityAsset2.Hierarchy.Entities[0].Components.Get(TransformComponent.Key).Position = new Vector3(10.0f, 0.0f, 0.0f); AssetMerge.Merge(entityAsset, entityAsset2, null, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1); } }
public void TestWithPackage() { var inputs = new AssetItemCollection(); var asset = new AssetObjectTest(); var package = new Package(); package.Assets.Add(new AssetItem("0", asset)); for (int i = 0; i < 10; i++) { var newAsset = new AssetObjectTest() { Id = asset.Id, Reference = new AssetReference<AssetObjectTest>(asset.Id, "bad") }; inputs.Add(new AssetItem("0", newAsset)); } // Tries to use existing ids var outputs = new AssetItemCollection(); AssetCollision.Clean(inputs, outputs, AssetResolver.FromPackage(package), true); // Make sure we are generating exactly the same number of elements Assert.AreEqual(inputs.Count, outputs.Count); // Make sure that asset has been cloned Assert.AreNotEqual(inputs[0], outputs[0]); // First Id should not change Assert.AreNotEqual(inputs[0].Id, outputs[0].Id); // Make sure that all ids are different var ids = new HashSet<Guid>(outputs.Select(item => item.Id)); Assert.AreEqual(inputs.Count, ids.Count); // Make sure that all locations are different var locations = new HashSet<UFile>(outputs.Select(item => item.Location)); Assert.AreEqual(inputs.Count, locations.Count); // Reference location "bad"should be fixed to "0_1" pointing to the first element foreach (var output in outputs) { // Make sure of none of the locations are using "0" Assert.AreNotEqual("0", output.Location); var assetRef = ((AssetObjectTest)output.Asset).Reference; Assert.AreEqual("0 (2)", assetRef.Location); Assert.AreEqual(outputs[0].Id, assetRef.Id); } }
/// <summary> /// Initializes a new instance of the <see cref="Package"/> class. /// </summary> public Package() { localDependencies = new List<PackageReference>(); temporaryAssets = new AssetItemCollection(); assets = new PackageAssetCollection(this); explicitFolders = new List<UDirectory>(); loadedAssemblies = new List<PackageLoadedAssembly>(); Bundles = new BundleCollection(this); Meta = new PackageMeta(); TemplateFolders = new List<TemplateFolder>(); Templates = new List<TemplateDescription>(); Profiles = new PackageProfileCollection(); IsDirty = true; settings = new Lazy<PackageUserSettings>(() => new PackageUserSettings(this)); SerializedVersion = PackageFileVersion; }