/// <summary>Execute a single config file.</summary> /// <param name="sessionContext">The session context.</param> /// <param name="configFile">The config file.</param> /// <param name="activity">The activity</param> /// <param name="fileType">The file types</param> /// <param name="measure">If it should measure.</param> /// <param name="fullPathToConfigFiles">The full Path To Config Files.</param> /// <returns>The success.</returns> private static Tuple <bool, int> ExecuteConfigFile(IWebGreaseContext sessionContext, string configFile, ActivityName activity, FileTypes fileType, bool measure, string fullPathToConfigFiles) { var configFileStart = DateTimeOffset.Now; var configFileInfo = new FileInfo(configFile); // Creates the context specific to the configuration file var fileContext = new WebGreaseContext(sessionContext, configFileInfo); var configFileSuccess = true; var fileSets = GetFileSets(fileContext.Configuration, fileType).ToArray(); if (fileSets.Length > 0 || (fileType.HasFlag(FileTypes.Image) && fileContext.Configuration.ImageDirectoriesToHash.Any())) { var configFileContentItem = ContentItem.FromFile(configFileInfo.FullName); configFileSuccess = sessionContext .SectionedActionGroup(fileType.ToString(), SectionIdParts.WebGreaseBuildTask, SectionIdParts.ConfigurationFile) .MakeCachable(configFileContentItem, new { activity, fileContext.Configuration }, activity == ActivityName.Bundle) // Cached action can only be skipped when it is the bundle activity, otherwise don't. .Execute(configFileCacheSection => { fileContext.Configuration.AllLoadedConfigurationFiles.ForEach(configFileCacheSection.AddSourceDependency); var success = true; fileContext.Log.Information("Activity Start: [{0}] for [{1}] on configuration file \"{2}\"".InvariantFormat(activity, fileType, configFile), MessageImportance.High); switch (activity) { case ActivityName.Bundle: // execute the bundle pipeline var bundleActivity = new BundleActivity(fileContext); success &= bundleActivity.Execute(fileSets); break; case ActivityName.Everything: // execute the full pipeline var everythingActivity = new EverythingActivity(fileContext); success &= everythingActivity.Execute(fileSets, fileType); break; } if (success && measure) { var configReportFile = Path.Combine(sessionContext.Configuration.ReportPath, (configFileInfo.Directory != null ? configFileInfo.Directory.Name + "." : string.Empty) + activity.ToString() + "." + fileType + "." + configFileInfo.Name); fileContext.Measure.WriteResults(configReportFile, configFileInfo.FullName, configFileStart); } fileContext.Log.Information("Activity End: [{0}] for [{1}] on configuration file \"{2}\"".InvariantFormat(activity, fileType, configFile), MessageImportance.High); return(success); }); } return(Tuple.Create(configFileSuccess, fileSets.Length)); }
public void MainActivityDebugIntegrationTest() { var testSourceDirectory = Path.Combine(TestDeploymentPaths.TestDirectory, @"WebGrease.Tests\MainActivityTest"); var configurationFile = Path.Combine(testSourceDirectory, @"Input\Integration\Debug\Configuration\sample1.webgrease.config"); var sourceDirectory = Path.Combine(testSourceDirectory, @"Input\Integration\Debug\Content"); var destinationDirectory = Path.Combine(testSourceDirectory, @"Output\Integration\Debug\sc"); var logsDirectory = Path.Combine(testSourceDirectory, @"Output\Integration\Debug\logs"); var webGreaseConfigurationRoot = new WebGreaseConfiguration(new FileInfo(configurationFile), "Debug", sourceDirectory, destinationDirectory, logsDirectory); var context = new WebGreaseContext(webGreaseConfigurationRoot, logInformation: null, logExtendedWarning: null, logError: LogError, logExtendedError: LogExtendedError); var mainActivity = new EverythingActivity(context); var success = mainActivity.Execute(); Assert.IsTrue(success); VerifyStatics(destinationDirectory, logsDirectory); }
/// <summary>The get minify css pivots.</summary> /// <param name="contentItem">The content item.</param> /// <param name="dpiValues">The dpi values.</param> /// <param name="mergedResources">The merged resources.</param> /// <param name="allDpiResources">The all Dpi Resources.</param> /// <returns>The pivots of the css to minify</returns> private static IEnumerable <MinifyCssPivot> GetMinifyCssPivots(ContentItem contentItem, IEnumerable <float> dpiValues, Dictionary <ResourcePivotKey[], IDictionary <string, IDictionary <string, string> > > mergedResources, IDictionary <string, IDictionary <string, string> > allDpiResources) { var contentResourcePivotKeys = contentItem.ResourcePivotKeys ?? new ResourcePivotKey[] { }; var dpiPivots = dpiValues.Select( dpi => { var dpiResolutionName = EverythingActivity.DpiToResolutionName(dpi); IDictionary <string, string> dpiResources = null; if (allDpiResources != null) { allDpiResources.TryGetValue(dpiResolutionName, out dpiResources); } var dpiResourcePivotKey = new ResourcePivotKey(Strings.DpiResourcePivotKey, dpiResolutionName); return(new { dpi, dpiResolutionName, dpiResourcePivotKey, dpiResources }); }); // Make sure we do dpi each before pivot to make it optimal when parallel var pivots = mergedResources.SelectMany( mergedResourceValues => { var mergedResource = mergedResourceValues.Value.Values.ToList(); return(dpiPivots.Select( dpiPivot => { var dpiSpecificMergedResources = mergedResource.ToList(); if (dpiPivot.dpiResources != null) { dpiSpecificMergedResources.Add(dpiPivot.dpiResources); } return new MinifyCssPivot( dpiSpecificMergedResources, contentResourcePivotKeys.Concat(mergedResourceValues.Key).Concat(new[] { dpiPivot.dpiResourcePivotKey }).ToArray(), dpiPivot.dpi); })); }); return(pivots); }