예제 #1
0
        public virtual Asset CreateDerivedAsset([NotNull] string baseLocation, out Dictionary <Guid, Guid> idRemapping)
        {
            if (baseLocation == null)
            {
                throw new ArgumentNullException(nameof(baseLocation));
            }

            // Make sure we have identifiers for all items
            AssetCollectionItemIdHelper.GenerateMissingItemIds(this);

            // Clone this asset without overrides (as we want all parameters to inherit from base)
            var newAsset = AssetCloner.Clone(this, AssetClonerFlags.GenerateNewIdsForIdentifiableObjects, out idRemapping);

            // Create a new identifier for this asset
            var newId = AssetId.New();

            // Register this new identifier in the remapping dictionary
            idRemapping?.Add((Guid)newAsset.Id, (Guid)newId);

            // Write the new id into the new asset.
            newAsset.Id = newId;

            // Create the base of this asset
            newAsset.Archetype = new AssetReference(Id, baseLocation);
            return(newAsset);
        }
예제 #2
0
        /// <summary>
        /// Generates a runtime hash id from the serialization of this asset.
        /// </summary>
        /// <param name="asset">The asset to get the runtime hash id</param>
        /// <param name="flags">Flags used to control the serialization process</param>
        /// <returns>An object id</returns>
        internal static ObjectId ComputeHash(object asset, AssetClonerFlags flags = AssetClonerFlags.None)
        {
            if (asset == null)
            {
                return(ObjectId.Empty);
            }

            var cloner = new AssetCloner(asset, flags, null);
            var result = cloner.GetHashId();

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Clones the specified asset using asset serialization.
        /// </summary>
        /// <param name="asset">The asset.</param>
        /// <param name="flags">Flags used to control the cloning process</param>
        /// <param name="externalIdentifiable"></param>
        /// <param name="idRemapping">A dictionary containing the remapping of <see cref="IIdentifiable.Id"/> if <see cref="AssetClonerFlags.GenerateNewIdsForIdentifiableObjects"/> has been passed to the cloner.</param>
        /// <returns>A clone of the asset.</returns>
        public static object Clone(object asset, AssetClonerFlags flags, HashSet <IIdentifiable> externalIdentifiable, [NotNull] out Dictionary <Guid, Guid> idRemapping)
        {
            if (asset == null)
            {
                idRemapping = new Dictionary <Guid, Guid>();
                return(null);
            }
            var cloner    = new AssetCloner(asset, flags, externalIdentifiable);
            var newObject = cloner.Clone(out idRemapping);

            return(newObject);
        }
예제 #4
0
 /// <summary>
 /// Computes a stable hash from an asset including all meta informations (ids, overrides).
 /// </summary>
 /// <param name="asset">An object instance</param>
 /// <param name="flags">Flags used to control the serialization process</param>
 /// <returns>a stable hash</returns>
 public static ObjectId Compute(object asset, AssetClonerFlags flags = AssetClonerFlags.None)
 {
     return(AssetCloner.ComputeHash(asset, flags));
 }