コード例 #1
0
 public AssetSourcesViewModel(AssetViewModel asset) : base(asset.SafeArgument(nameof(asset)).ServiceProvider)
 {
     this.asset = asset;
     UpdateFromSourceCommand = new AnonymousTaskCommand(ServiceProvider, UpdateAssetFromSource);
     updatedHashes           = SourceHashesHelper.GetAllHashes(asset.Asset);
     currentSourceFiles.AddRange(updatedHashes.Keys);
 }
コード例 #2
0
        public async Task UpdateAssetFromSource(LoggerResult logger)
        {
            await asset.UpdateAssetFromSource(logger);

            var oldHashes = new Dictionary <UFile, ObjectId>((Dictionary <UFile, ObjectId>)updatedHashes);
            var newHashes = new Dictionary <UFile, ObjectId>();

            foreach (var file in currentSourceFiles)
            {
                var hash = asset.Session.SourceTracker.GetCurrentHash(file);
                newHashes[file] = hash;
            }
            // Add an operation to update hashes in the SourceHashHelper
            var operation = new AnonymousDirtyingOperation(asset.Dirtiables,
                                                           () =>
            {
                SourceHashesHelper.UpdateHashes(asset.Asset, oldHashes);
                updatedHashes = oldHashes;
                ComputeNeedUpdateFromSource();
            },
                                                           () =>
            {
                SourceHashesHelper.UpdateHashes(asset.Asset, newHashes);
                updatedHashes = newHashes;
                ComputeNeedUpdateFromSource();
            });

            asset.UndoRedoService.PushOperation(operation);

            updatedHashes = newHashes;
            SourceHashesHelper.UpdateHashes(asset.Asset, updatedHashes);

            NeedUpdateFromSource = false;
            asset.Session.SourceTracker?.UpdateAssetStatus(asset);
        }
コード例 #3
0
ファイル: AssetAnalysis.cs プロジェクト: yonglehou/xenko
        public static void Run(AssetItem assetItem, ILogger log, AssetAnalysisParameters parameters)
        {
            if (assetItem == null) throw new ArgumentNullException(nameof(assetItem));
            if (log == null) throw new ArgumentNullException(nameof(log));
            if (parameters == null) throw new ArgumentNullException(nameof(parameters));

            if (assetItem.Package == null)
            {
                throw new InvalidOperationException("AssetItem must belong to an existing package");
            }

            var package = assetItem.Package;

            // Check that there is no duplicate in assets
            if (package.Session != null)
            {
                var packages = package.FindDependencies();

                foreach (var otherPackage in packages)
                {
                    var existingAsset = otherPackage.Assets.Find(assetItem.Id);

                    if (existingAsset != null)
                    {
                        log.Error("Assets [{0}] with id [{1}] from Package [{2}] is already loaded from package [{3}]", existingAsset.FullPath, existingAsset.Id, package.FullPath, existingAsset.Package.FullPath);
                    }
                    else
                    {
                        existingAsset = otherPackage.Assets.Find(assetItem.Location);
                        if (existingAsset != null)
                        {
                            log.Error("Assets [{0}] with location [{1}] from Package [{2}] is already loaded from package [{3}]", existingAsset.FullPath, existingAsset.Location, package.FullPath, existingAsset.Package.FullPath);
                        }
                    }
                }
            }

            var assetReferences = AssetReferenceAnalysis.Visit(assetItem.Asset);

            if (package.Session != null && parameters.IsProcessingAssetReferences)
            {
                UpdateAssetReferences(assetItem, assetReferences, log, parameters);
            }
            // Update paths for asset items

            if (parameters.IsProcessingUPaths)
            {
                // Find where this asset item was previously stored (in a different package for example)
                CommonAnalysis.UpdatePaths(assetItem, assetReferences.Where(link => link.Reference is UPath), parameters);
                // Source hashes are not processed by analysis, we need to manually indicate them to update
                SourceHashesHelper.UpdateUPaths(assetItem.Asset, assetItem.FullPath.GetParent(), parameters.ConvertUPathTo);
            }
        }