Ejemplo n.º 1
0
        public async System.Threading.Tasks.Task CreateOrUpdateLatestLinksAsync(
            HashSet <BlobArtifactModel> blobsToPublish,
            TargetFeedConfig feedConfig,
            int expectedSuffixLength)
        {
            if (string.IsNullOrEmpty(feedConfig.LatestLinkShortUrlPrefix))
            {
                return;
            }

            Logger.LogMessage(MessageImportance.High, "\nThe following aka.ms links for blobs will be created:");
            IEnumerable <AkaMSLink> linksToCreate = blobsToPublish
                                                    .Where(blob => !feedConfig.FilenamesToExclude.Contains(Path.GetFileName(blob.Id)))
                                                    .Select(blob =>
            {
                // Strip away the feed expected suffix (index.json) and append on the
                // blob path.
                string actualTargetUrl = feedConfig.TargetURL.Substring(0,
                                                                        feedConfig.TargetURL.Length - expectedSuffixLength) + blob.Id;

                // The dotnetcli storage account is in a single datacenter in the US and thus download
                // times can be painful elsewhere. The CDN helps with this thefore we point the target
                // of the aka.ms links to the CDN.
                actualTargetUrl = actualTargetUrl.Replace("//dotnetcli.blob.core.windows.net/", "//dotnetcli.azureedge.net/");

                AkaMSLink newLink = new AkaMSLink
                {
                    ShortUrl  = GetLatestShortUrlForBlob(feedConfig, blob, feedConfig.Flatten),
                    TargetUrl = actualTargetUrl
                };
                Logger.LogMessage(MessageImportance.High, $"  {Path.GetFileName(blob.Id)}");

                Logger.LogMessage(MessageImportance.High, $"  aka.ms/{newLink.ShortUrl} -> {newLink.TargetUrl}");

                return(newLink);
            }).ToList();

            await LinkManager.CreateOrUpdateLinksAsync(linksToCreate, AkaMsOwners, AkaMSCreatedBy, AkaMSGroupOwner, true);
        }