コード例 #1
0
        /// <summary>
        /// Uploads multiple files given the globbing patterns provided by the selection properties.
        /// </summary>
        /// <param name="clientFactory"></param>
        /// <param name="deployment"></param>
        /// <param name="selection"></param>
        private async Task <IEnumerable <S3UploadResult> > UploadMultiFileSelection(Func <AmazonS3Client> clientFactory, RunningDeployment deployment, S3MultiFileSelectionProperties selection)
        {
            Guard.NotNull(deployment, "Deployment may not be null");
            Guard.NotNull(selection, "Multi file selection properties may not be null");
            Guard.NotNull(clientFactory, "Client factory must not be null");
            var results = new List <S3UploadResult>();

            var files = new RelativeGlobber((@base, pattern) => fileSystem.EnumerateFilesWithGlob(@base, pattern), deployment.StagingDirectory).EnumerateFilesWithGlob(selection.Pattern).ToList();

            if (!files.Any())
            {
                Log.Info($"The glob pattern '{selection.Pattern}' didn't match any files. Nothing was uploaded to S3.");
                return(results);
            }

            Log.Info($"Glob pattern '{selection.Pattern}' matched {files.Count} files");
            var substitutionPatterns = selection.VariableSubstitutionPatterns?.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0];

            new SubstituteInFilesConvention(fileSystem, fileSubstituter,
                                            _ => substitutionPatterns.Any(),
                                            _ => substitutionPatterns)
            .Install(deployment);

            foreach (var matchedFile in files)
            {
                var request = CreateRequest(matchedFile.FilePath, () => $"{selection.BucketKeyPrefix}{matchedFile.MappedRelativePath}", selection);
                LogPutObjectRequest(matchedFile.FilePath, request);

                results.Add(await HandleUploadRequest(clientFactory(), request, WarnAndIgnoreException));
            }

            return(results);
        }
コード例 #2
0
        public void DropsAllBaseFoldersForOverride()
        {
            var files = new List <string> {
                @"c:\staging\content\nested\deep\first.txt", @"c:\staging\content\nested\deep\deeper\two.txt"
            };
            var matches = new RelativeGlobber((@base, pattern) => files, @"c:\staging").EnumerateFilesWithGlob("content/nested/**/* => bob").ToList();

            Assert.AreEqual(@"bob/deep/first.txt", matches[0].MappedRelativePath);
            Assert.AreEqual(@"bob/deep/deeper/two.txt", matches[1].MappedRelativePath);
        }
コード例 #3
0
        public void CanFlattenUsingOverride()
        {
            var files = new List <string> {
                @"c:\staging\content\first.txt", @"c:\staging\content\nested\two.txt"
            };
            var matches = new RelativeGlobber((@base, pattern) => files, @"c:\staging").EnumerateFilesWithGlob("content/**/* => bob/*").ToList();

            Assert.AreEqual(@"bob/first.txt", matches[0].MappedRelativePath);
            Assert.AreEqual(@"bob/two.txt", matches[1].MappedRelativePath);
        }
コード例 #4
0
        public void HasCorrectRelativePathsForRootGlobAllAndOverride()
        {
            var files = new List <string> {
                @"c:\staging\content\first.txt", @"c:\staging\content\nested\two.txt"
            };
            var matches = new RelativeGlobber((@base, pattern) => files, @"c:\staging").EnumerateFilesWithGlob("**/* => bob").ToList();

            Assert.AreEqual(@"bob/content/first.txt", matches[0].MappedRelativePath);
            Assert.AreEqual(@"bob/content/nested/two.txt", matches[1].MappedRelativePath);
        }
コード例 #5
0
        public void HasCorrectRelativePathsForFolderGlob()
        {
            var files = new List <string> {
                @"c:\staging\content\first.txt", @"c:\staging\content\nested\two.txt"
            };
            var matches = new RelativeGlobber((@base, pattern) => files, @"c:\staging").EnumerateFilesWithGlob("content/**/*").ToList();

            Assert.AreEqual(@"first.txt", matches[0].MappedRelativePath);
            Assert.AreEqual(@"nested/two.txt", matches[1].MappedRelativePath);
        }
コード例 #6
0
        /// <summary>
        /// Uploads multiple files given the globbing patterns provided by the selection properties.
        /// </summary>
        /// <param name="clientFactory"></param>
        /// <param name="deployment"></param>
        /// <param name="selection"></param>
        private async Task <IEnumerable <S3UploadResult> > UploadMultiFileSelection(Func <AmazonS3Client> clientFactory, RunningDeployment deployment, S3MultiFileSelectionProperties selection)
        {
            Guard.NotNull(deployment, "Deployment may not be null");
            Guard.NotNull(selection, "Multi file selection properties may not be null");
            Guard.NotNull(clientFactory, "Client factory must not be null");
            var results = new List <S3UploadResult>();

            var files = new RelativeGlobber((@base, pattern) => fileSystem.EnumerateFilesWithGlob(@base, pattern), deployment.StagingDirectory).EnumerateFilesWithGlob(selection.Pattern).ToList();

            if (!files.Any())
            {
                Log.Info($"The glob pattern '{selection.Pattern}' didn't match any files. Nothing was uploaded to S3.");
                return(results);
            }

            Log.Info($"Glob pattern '{selection.Pattern}' matched {files.Count} files");
            var substitutionPatterns = SplitFilePatternString(selection.VariableSubstitutionPatterns);

            if (substitutionPatterns.Any())
            {
                substituteInFiles.Substitute(deployment.CurrentDirectory, substitutionPatterns);
            }

            var structuredSubstitutionPatterns = SplitFilePatternString(selection.StructuredVariableSubstitutionPatterns);

            if (structuredSubstitutionPatterns.Any())
            {
                structuredConfigVariablesService.ReplaceVariables(deployment.CurrentDirectory, structuredSubstitutionPatterns.ToList());
            }

            foreach (var matchedFile in files)
            {
                var request = CreateRequest(matchedFile.FilePath, $"{selection.BucketKeyPrefix}{matchedFile.MappedRelativePath}", selection);
                LogPutObjectRequest(matchedFile.FilePath, request);

                results.Add(await HandleUploadRequest(clientFactory(), request, WarnAndIgnoreException));
            }

            return(results);
        }