Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssetResolver" /> class.
 /// </summary>
 /// <param name="containsAssetWithLocation">The delegate used to check if an asset location is already used.</param>
 /// <param name="containsAssetWithId">The delegate used to check if an asset identifier is already used.</param>
 public AssetResolver(ContainsAssetWithLocationDelegate containsAssetWithLocation, ContainsAssetWithIdDelegate containsAssetWithId)
 {
     existingIds               = new HashSet <Guid>();
     existingLocations         = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
     ContainsAssetWithLocation = containsAssetWithLocation;
     ContainsAssetWithId       = containsAssetWithId;
     containsLocation          = DefaultContainsLocation;
     containsId = DefaultContainsId;
 }
Exemple #2
0
        /// <summary>
        /// Finds a name available for a new asset. This method will try to create a name based on an existing name and will append
        /// "_" + (number++) on every try.
        /// </summary>
        /// <param name="location">The path of the original asset.</param>
        /// <param name="containsAssetWithLocation">The try location.</param>
        /// <param name="newLocation">A new asset location that has the guaranty to be available when adding the assets to a package..</param>
        /// <returns><c>true</c> if this is a new location, false otherwise.</returns>
        /// <exception cref="System.ArgumentNullException">localNames</exception>
        private static bool FindAvailableLocation(UFile location, ContainsAssetWithLocationDelegate containsAssetWithLocation, out UFile newLocation)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            if (containsAssetWithLocation == null)
            {
                throw new ArgumentNullException("containsAssetWithLocation");
            }

            var    pathStr = location.FullPath;
            int    i       = 1;
            string newPath = pathStr;

            while (containsAssetWithLocation(newPath))
            {
                newPath = pathStr + "_" + i;
                i++;
            }

            newLocation = newPath;
            return(i > 1);
        }