Пример #1
0
        public override bool Execute()
        {
            try
            {
                var matcher = new Matcher().AddInclude(Pattern);
                var assets  = new List <ITaskItem>();
                var assetsByRelativePath = new Dictionary <string, List <ITaskItem> >();

                for (var i = 0; i < Candidates.Length; i++)
                {
                    var candidate          = Candidates[i];
                    var candidateMatchPath = GetCandidateMatchPath(candidate);
                    var match = matcher.Match(candidateMatchPath);
                    if (!match.HasMatches)
                    {
                        Log.LogMessage("Rejected asset '{0}' for pattern '{1}'", candidateMatchPath, Pattern);
                        continue;
                    }

                    Log.LogMessage("Accepted asset '{0}' for pattern '{1}' with relative path '{2}'", candidateMatchPath, Pattern, match.Files.Single().Stem);

                    var candidateRelativePath = StaticWebAsset.Normalize(match.Files.Single().Stem);

                    var asset = new StaticWebAsset
                    {
                        Identity               = candidate.GetMetadata("FullPath"),
                        SourceId               = SourceId,
                        SourceType             = StaticWebAsset.SourceTypes.Discovered,
                        ContentRoot            = ContentRoot,
                        BasePath               = BasePath,
                        RelativePath           = candidateRelativePath,
                        AssetMode              = StaticWebAsset.AssetModes.All,
                        CopyToOutputDirectory  = candidate.GetMetadata(nameof(StaticWebAsset.CopyToOutputDirectory)),
                        CopyToPublishDirectory = candidate.GetMetadata(nameof(StaticWebAsset.CopyToPublishDirectory))
                    };

                    asset.ApplyDefaults();
                    asset.Normalize();

                    var assetItem = asset.ToTaskItem();

                    assetItem.SetMetadata("OriginalItemSpec", candidate.ItemSpec);
                    assets.Add(assetItem);

                    UpdateAssetKindIfNecessary(assetsByRelativePath, candidateRelativePath, assetItem);
                    if (Log.HasLoggedErrors)
                    {
                        return(false);
                    }
                }

                DiscoveredStaticWebAssets = assets.ToArray();
            }
            catch (Exception ex)
            {
                Log.LogError(ex.Message);
            }

            return(!Log.HasLoggedErrors);
        }
Пример #2
0
        internal static StaticWebAsset FromProperties(
            string identity,
            string sourceId,
            string sourceType,
            string basePath,
            string relativePath,
            string contentRoot,
            string assetKind,
            string assetMode,
            string assetRole,
            string relatedAsset,
            string assetTraitName,
            string assetTraitValue,
            string copyToOutputDirectory,
            string copyToPublishDirectory,
            string originalItemSpec)
        {
            var result = new StaticWebAsset
            {
                Identity               = identity,
                SourceId               = sourceId,
                SourceType             = sourceType,
                ContentRoot            = contentRoot,
                BasePath               = basePath,
                RelativePath           = relativePath,
                AssetKind              = assetKind,
                AssetMode              = assetMode,
                AssetRole              = assetRole,
                RelatedAsset           = relatedAsset,
                AssetTraitName         = assetTraitName,
                AssetTraitValue        = assetTraitValue,
                CopyToOutputDirectory  = copyToOutputDirectory,
                CopyToPublishDirectory = copyToPublishDirectory,
                OriginalItemSpec       = originalItemSpec
            };

            result.ApplyDefaults();

            result.Normalize();
            result.Validate();

            return(result);
        }