Exemplo n.º 1
0
        public void FileHasherActivityNoPreserveSourceDirectoryTest()
        {
            var sourceDirectory    = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\Input");
            var fileHasherActivity = new FileHasherActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            fileHasherActivity.SourceDirectories.Add(sourceDirectory);
            var destinationDirectory = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\Output\FileHasherActivityNoPreserveSourceDirectory");

            fileHasherActivity.DestinationDirectory = destinationDirectory;
            fileHasherActivity.CreateExtraDirectoryLevelFromHashes    = true;
            fileHasherActivity.ShouldPreserveSourceDirectoryStructure = false;
            fileHasherActivity.BasePrefixToRemoveFromOutputPathInLog  = destinationDirectory;
            fileHasherActivity.LogFileName = Path.Combine(destinationDirectory, "FileHasherActivityPreserveSourceDirectory.log.xml");
            fileHasherActivity.Execute();

            Assert.IsTrue(Directory.Exists(destinationDirectory));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "08")));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "ba")));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "db")));
            Assert.IsTrue(File.Exists(fileHasherActivity.LogFileName));
        }
Exemplo n.º 2
0
        public void FileHasherActivityWithExistingLogTest()
        {
            var sourceDirectory    = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\ExistingLog\Input");
            var fileHasherActivity = new FileHasherActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            fileHasherActivity.SourceDirectories.Add(sourceDirectory);
            var destinationDirectory = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\ExistingLog\Output");

            fileHasherActivity.DestinationDirectory = destinationDirectory;
            fileHasherActivity.CreateExtraDirectoryLevelFromHashes    = true;
            fileHasherActivity.ShouldPreserveSourceDirectoryStructure = false;
            fileHasherActivity.ConfigType = string.Empty;
            fileHasherActivity.BasePrefixToRemoveFromOutputPathInLog = destinationDirectory;
            fileHasherActivity.LogFileName = Path.Combine(sourceDirectory, @"..\statics\css_log.xml");
            fileHasherActivity.Execute();

            Assert.IsTrue(File.Exists(fileHasherActivity.LogFileName));
            var xdoc = XDocument.Load(fileHasherActivity.LogFileName);

            Assert.AreEqual(2, xdoc.Descendants("File").Count());
        }
Exemplo n.º 3
0
        public void FileHasherActivityFilterTest()
        {
            var sourceDirectory    = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\Input");
            var fileHasherActivity = new FileHasherActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            fileHasherActivity.SourceDirectories.Add(sourceDirectory);
            var destinationDirectory = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\Output\FileHasherActivityFilterTest");

            fileHasherActivity.DestinationDirectory = destinationDirectory;
            fileHasherActivity.CreateExtraDirectoryLevelFromHashes    = false;
            fileHasherActivity.ShouldPreserveSourceDirectoryStructure = true;
            fileHasherActivity.BasePrefixToRemoveFromOutputPathInLog  = destinationDirectory;
            fileHasherActivity.LogFileName    = Path.Combine(destinationDirectory, "FileHasherActivityFilterTest.log.xml");
            fileHasherActivity.FileTypeFilter = "*.png";
            fileHasherActivity.Execute();

            Assert.IsTrue(Directory.Exists(destinationDirectory));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "C1")));
            Assert.IsFalse(File.Exists(Path.Combine(destinationDirectory, "C1", "ba4027675b202b7bf6f15085cb3344e3.gif")));
            Assert.IsTrue(File.Exists(Path.Combine(destinationDirectory, "C1", "163af4596ea7d10cadda5233fe6f1282.png")));
            Assert.IsTrue(File.Exists(fileHasherActivity.LogFileName));
        }
Exemplo n.º 4
0
        public void FileHasherActivityPreserveSourceDirectoryTest()
        {
            var sourceDirectory    = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\Input");
            var fileHasherActivity = new FileHasherActivity(new WebGreaseContext(new WebGreaseConfiguration()));

            fileHasherActivity.SourceDirectories.Add(sourceDirectory);
            var destinationDirectory = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\FileHasherActivityTest\Output\FileHasherActivityPreserveSourceDirectory");

            fileHasherActivity.DestinationDirectory = destinationDirectory;
            fileHasherActivity.CreateExtraDirectoryLevelFromHashes    = false;
            fileHasherActivity.ShouldPreserveSourceDirectoryStructure = true;
            fileHasherActivity.BasePrefixToRemoveFromOutputPathInLog  = destinationDirectory;
            fileHasherActivity.LogFileName = Path.Combine(destinationDirectory, "FileHasherActivityPreserveSourceDirectory.log.xml");
            fileHasherActivity.Execute();

            Assert.IsTrue(Directory.Exists(destinationDirectory));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "C1")));
            Assert.IsTrue(File.Exists(Path.Combine(destinationDirectory, "C1", "ba4027675b202b7bf6f15085cb3344e3.gif")));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "C1", "C3")));
            Assert.IsTrue(File.Exists(Path.Combine(destinationDirectory, "C1", "C3", "dbd30b957cfadf9e684dc8ef0ce3f2a8.gif")));
            Assert.IsTrue(Directory.Exists(Path.Combine(destinationDirectory, "C2")));
            Assert.IsTrue(File.Exists(Path.Combine(destinationDirectory, "C2", "083b261ab91fa0d8c12e22d898238840.gif")));
            Assert.IsTrue(File.Exists(fileHasherActivity.LogFileName));
        }
Exemplo n.º 5
0
        private static void ExecuteHashFiles(IWebGreaseContext context)
        {
            var hasher = new FileHasherActivity(context)
            {
                CreateExtraDirectoryLevelFromHashes    = true,
                ShouldPreserveSourceDirectoryStructure = false
            };

            // images
            if (context.Configuration.ImageDirectories.Any())
            {
                hasher.LogFileName          = Path.Combine(context.Configuration.LogsDirectory, Strings.ImagesLogFile);
                hasher.DestinationDirectory = GetOutputFolder(null, context.Configuration.DestinationDirectory);
                foreach (var imageDirectory in context.Configuration.ImageDirectories.Distinct())
                {
                    hasher.SourceDirectories.Add(imageDirectory);
                }

                if (context.Configuration.ImageExtensions != null && context.Configuration.ImageExtensions.Any())
                {
                    hasher.FileTypeFilter = string.Join(new string(Strings.FileFilterSeparator), context.Configuration.ImageExtensions.ToArray());
                }

                hasher.Execute();
                hasher.SourceDirectories.Clear();
            }

            // css
            if (context.Configuration.CssFileSets.Any(file => file.InputSpecs.Any() && !file.Output.IsNullOrWhitespace()))
            {
                hasher.LogFileName = Path.Combine(context.Configuration.LogsDirectory, Strings.CssLogFile);
                foreach (var fileSet in context.Configuration.CssFileSets.Where(file => file.InputSpecs.Any() && !file.Output.IsNullOrWhitespace()))
                {
                    var cssConfig = fileSet.Autonaming.GetNamedConfig(context.Configuration.ConfigType);

                    if (cssConfig.ShouldAutoName)
                    {
                        var outputPath = GetOutputFolder(fileSet.Output, context.Configuration.DestinationDirectory);
                        hasher.DestinationDirectory = string.IsNullOrWhiteSpace(Path.GetExtension(outputPath)) ? outputPath : Path.GetDirectoryName(outputPath);
                        foreach (var inputFolder in
                                 fileSet.InputSpecs
                                 .SelectMany(inputSpec => GetFiles(inputSpec.Path, inputSpec.SearchPattern, inputSpec.SearchOption))
                                 .Select(Path.GetDirectoryName).Distinct())
                        {
                            // add the distinct folders
                            hasher.SourceDirectories.Add(inputFolder);
                        }

                        hasher.FileTypeFilter = Strings.CssFilter;

                        try
                        {
                            hasher.Execute();
                        }
                        catch (Exception ex)
                        {
                            HandleError(ex);
                        }

                        hasher.SourceDirectories.Clear();
                    }
                }
            }

            // js
            if (context.Configuration.JSFileSets.Any(file => file.InputSpecs.Any() && !file.Output.IsNullOrWhitespace()))
            {
                hasher.LogFileName = Path.Combine(context.Configuration.LogsDirectory, Strings.JsLogFile);
                foreach (var fileSet in context.Configuration.JSFileSets.Where(file => file.InputSpecs.Any() && !file.Output.IsNullOrWhitespace()))
                {
                    var jsConfig = fileSet.AutoNaming.GetNamedConfig(context.Configuration.ConfigType);

                    if (jsConfig.ShouldAutoName)
                    {
                        var outputPath = GetOutputFolder(fileSet.Output, context.Configuration.DestinationDirectory);
                        hasher.DestinationDirectory = string.IsNullOrWhiteSpace(Path.GetExtension(outputPath)) ? outputPath : Path.GetDirectoryName(outputPath);
                        hasher.CreateExtraDirectoryLevelFromHashes = true;
                        foreach (var inputFolder in
                                 fileSet.InputSpecs
                                 .SelectMany(inputSpec => GetFiles(inputSpec.Path, inputSpec.SearchPattern, inputSpec.SearchOption))
                                 .Select(Path.GetDirectoryName).Distinct())
                        {
                            // add the distinct folders
                            hasher.SourceDirectories.Add(inputFolder);
                        }
                        hasher.FileTypeFilter = Strings.JsFilter;
                        try
                        {
                            hasher.Execute();
                        }
                        catch (Exception ex)
                        {
                            HandleError(ex);
                        }
                        hasher.SourceDirectories.Clear();
                    }
                }
            }
        }