public IEnumerable <string> ListFiles(string virtualPath, bool recursive)
 {
     if (!recursive)
     {
         return(_virtualPathProvider.ListFiles(virtualPath));
     }
     return(_virtualPathProvider.ListFiles(virtualPath).Concat(ListFiles(ListDirectories(virtualPath))));
 }
        public override IEnumerable <ExtensionReferenceProbeEntry> ProbeReferences(ExtensionDescriptor descriptor)
        {
            if (Disabled)
            {
                return(Enumerable.Empty <ExtensionReferenceProbeEntry>());
            }

            Logger.Information("Probing references for module '{0}'", descriptor.Id);

            var assemblyPath = GetAssemblyPath(descriptor);

            if (assemblyPath == null)
            {
                return(Enumerable.Empty <ExtensionReferenceProbeEntry>());
            }

            var result = _virtualPathProvider
                         .ListFiles(_virtualPathProvider.GetDirectoryName(assemblyPath))
                         .Where(s => StringComparer.OrdinalIgnoreCase.Equals(Path.GetExtension(s), ".dll"))
                         .Where(s => !StringComparer.OrdinalIgnoreCase.Equals(Path.GetFileNameWithoutExtension(s), descriptor.Id))
                         .Select(path => new ExtensionReferenceProbeEntry {
                Descriptor  = descriptor,
                Loader      = this,
                Name        = Path.GetFileNameWithoutExtension(path),
                VirtualPath = path
            })
                         .ToList();

            Logger.Information("Done probing references for module '{0}'", descriptor.Id);
            return(result);
        }
        private void CompileDirectory(CompilationContext context, string viewDirectory)
        {
            // Prevent processing of the same directories multiple times (sligh performance optimization,
            // as the build manager second call to compile a view is essentially a "no-op".
            if (context.ProcessedDirectories.Contains(viewDirectory))
            {
                return;
            }
            context.ProcessedDirectories.Add(viewDirectory);

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            try
            {
                var firstFile = virtualPathProvider
                                .ListFiles(viewDirectory).FirstOrDefault(f => context.FileExtensionsToCompile.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase)));

                if (firstFile != null)
                {
                    BuildManager.GetCompiledAssembly(firstFile);
                }
            }
            catch (Exception e)
            {
                // Some views might not compile, this is ok and harmless in this
                // context of pre-compiling views.
                Logger.InfoFormat(e, "Compilation of directory '{0}' skipped", viewDirectory);
            }
            stopwatch.Stop();
            Logger.InfoFormat("Directory '{0}' compiled in {1} msec", viewDirectory, stopwatch.ElapsedMilliseconds);
        }
        private static void GetViewDirectories(IVirtualPathProvider vpp, string directory, IEnumerable<string> extensions, ICollection<string> files)
        {
            if (vpp.ListFiles(directory).Where(f => extensions.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase))).Any()) {
                files.Add(directory);
            }

            foreach (var childDirectory in vpp.ListDirectories(directory).OrderBy(d => d, StringComparer.OrdinalIgnoreCase)) {
                GetViewDirectories(vpp, childDirectory, extensions, files);
            }
        }
Exemple #5
0
        private static void GetViewDirectories(IVirtualPathProvider vpp, string directory, IEnumerable <string> extensions, ICollection <string> files)
        {
            if (vpp.ListFiles(directory).Where(f => extensions.Any(e => f.EndsWith(e, StringComparison.OrdinalIgnoreCase))).Any())
            {
                files.Add(directory);
            }

            foreach (var childDirectory in vpp.ListDirectories(directory).OrderBy(d => d, StringComparer.OrdinalIgnoreCase))
            {
                GetViewDirectories(vpp, childDirectory, extensions, files);
            }
        }
Exemple #6
0
        public void Discover(ShapeTableBuilder builder)
        {
            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures    = availableFeatures.Where(FeatureIsEnabled);
            var activeExtensions  = Once(activeFeatures);

            var hits = activeExtensions.SelectMany(extensionDescriptor =>
            {
                var basePath    = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                var virtualPath = Path.Combine(basePath, GetFolder()).Replace(Path.DirectorySeparatorChar, '/');
                var shapes      = _virtualPathProvider.ListFiles(virtualPath)
                                  .Select(Path.GetFileName)
                                  .Where(fileName => string.Equals(Path.GetExtension(fileName), GetFileExtension(), StringComparison.OrdinalIgnoreCase))
                                  .Select(cssFileName => new
                {
                    fileName        = Path.GetFileNameWithoutExtension(cssFileName),
                    fileVirtualPath = Path.Combine(virtualPath, cssFileName).Replace(Path.DirectorySeparatorChar, '/'),
                    shapeType       = GetShapePrefix() + GetAlternateShapeNameFromFileName(cssFileName),
                    extensionDescriptor
                });
                return(shapes);
            });

            foreach (var iter in hits)
            {
                var hit = iter;
                var featureDescriptors = hit.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    builder.Describe(iter.shapeType)
                    .From(new Feature {
                        Descriptor = featureDescriptor
                    })
                    .BoundAs(
                        hit.fileVirtualPath,
                        shapeDescriptor => displayContext =>
                    {
                        var shape  = ((dynamic)displayContext.Value);
                        var output = displayContext.ViewContext.Writer;
                        ResourceDefinition resource            = shape.Resource;
                        string condition                       = shape.Condition;
                        Dictionary <string, string> attributes = shape.TagAttributes;
                        ResourceManager.WriteResource(output, resource, hit.fileVirtualPath, condition, attributes);
                        return(null);
                    });
                }
            }
        }
Exemple #7
0
        public virtual IEnumerable <string> ListFiles(string relativePath, bool deep = false)
        {
            var path = GetVirtualPath(relativePath);

            if (!_vpp.DirectoryExists(path))
            {
                return(Enumerable.Empty <string>());
            }

            var files = _vpp.ListFiles(path).Select(x => x.Substring(_root.Length));

            if (deep)
            {
                return(files.Concat(ListDirectories(path).SelectMany(d => ListFiles(d, true))));
            }

            return(files);
        }
        private string GetTinyMceLanguageIdentifier()
        {
            var currentCulture = CultureInfo.GetCultureInfo(_workContext.CurrentCulture);

            if (currentCulture.Name.Equals(DefaultLanguage, StringComparison.OrdinalIgnoreCase))
            {
                return(currentCulture.Name);
            }


            return(_cacheManager.Get(string.Format(CacheKeyFormat, currentCulture.Name), ctx => {
                ctx.Monitor(_signals.When("culturesChanged"));

                var customLanguage = currentCulture.Name.Replace('-', '_');

                var directoryName = _virtualPathProvider.GetDirectoryName("~/modules/tinymce/scripts/langs/");

                var languageFiles = _virtualPathProvider
                                    .ListFiles(directoryName)
                                    .Select(file => file.Replace(directoryName + "/", ""))
                                    .ToList();

                if (languageFiles.Any(x => x == string.Format("{0}.js", customLanguage)))
                {
                    return customLanguage;
                }

                if (!DefaultLanguage.Equals(currentCulture.TwoLetterISOLanguageName, StringComparison.OrdinalIgnoreCase) &&
                    languageFiles.Any(x => x == string.Format("{0}.js", currentCulture.TwoLetterISOLanguageName)))
                {
                    return currentCulture.TwoLetterISOLanguageName;
                }

                return DefaultLanguage;
            }));
        }
Exemple #9
0
        public void Discover(ShapeTableBuilder builder)
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Start discovering shapes");
            }
            var harvesterInfos = _harvesters.Select(harvester => new { harvester, subPaths = harvester.SubPaths() });

            var availableFeatures = _extensionManager.AvailableFeatures();
            var activeFeatures    = availableFeatures.Where(FeatureIsEnabled);
            var activeExtensions  = Once(activeFeatures);

            var hits = activeExtensions.Select(extensionDescriptor =>
            {
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Start discovering candidate views filenames");
                }
                var pathContexts = harvesterInfos.SelectMany(harvesterInfo => harvesterInfo.subPaths.Select(subPath =>
                {
                    var basePath    = Path.Combine(extensionDescriptor.Location, extensionDescriptor.Id).Replace(Path.DirectorySeparatorChar, '/');
                    var virtualPath = Path.Combine(basePath, subPath).Replace(Path.DirectorySeparatorChar, '/');
                    IReadOnlyList <string> fileNames;

                    if (!_virtualPathProvider.DirectoryExists(virtualPath))
                    {
                        fileNames = new List <string>();
                    }
                    else
                    {
                        fileNames = _virtualPathProvider.ListFiles(virtualPath).Select(Path.GetFileName).ToReadOnlyCollection();
                    }

                    return(new { harvesterInfo.harvester, basePath, subPath, virtualPath, fileNames });
                })).ToList();
                if (_logger.IsEnabled(LogLevel.Information))
                {
                    _logger.LogInformation("Done discovering candidate views filenames");
                }
                var fileContexts = pathContexts.SelectMany(pathContext => _shapeTemplateViewEngines.SelectMany(ve =>
                {
                    var fileNames = ve.DetectTemplateFileNames(pathContext.fileNames);
                    return(fileNames.Select(
                               fileName => new
                    {
                        fileName = Path.GetFileNameWithoutExtension(fileName),
                        fileVirtualPath = Path.Combine(pathContext.virtualPath, fileName).Replace(Path.DirectorySeparatorChar, '/'),
                        pathContext
                    }));
                }));

                var shapeContexts = fileContexts.SelectMany(fileContext =>
                {
                    var harvestShapeInfo = new HarvestShapeInfo
                    {
                        SubPath             = fileContext.pathContext.subPath,
                        FileName            = fileContext.fileName,
                        TemplateVirtualPath = fileContext.fileVirtualPath
                    };
                    var harvestShapeHits = fileContext.pathContext.harvester.HarvestShape(harvestShapeInfo);
                    return(harvestShapeHits.Select(harvestShapeHit => new { harvestShapeInfo, harvestShapeHit, fileContext }));
                });

                return(shapeContexts.Select(shapeContext => new { extensionDescriptor, shapeContext }).ToList());
            }).SelectMany(hits2 => hits2);


            foreach (var iter in hits)
            {
                // templates are always associated with the namesake feature of module or theme
                var hit = iter;
                var featureDescriptors = iter.extensionDescriptor.Features.Where(fd => fd.Id == hit.extensionDescriptor.Id);
                foreach (var featureDescriptor in featureDescriptors)
                {
                    if (_logger.IsEnabled(LogLevel.Debug))
                    {
                        _logger.LogDebug("Binding {0} as shape [{1}] for feature {2}",
                                         hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                                         iter.shapeContext.harvestShapeHit.ShapeType,
                                         featureDescriptor.Id);
                    }
                    builder.Describe(iter.shapeContext.harvestShapeHit.ShapeType)
                    .From(new Feature {
                        Descriptor = featureDescriptor
                    })
                    .BoundAs(
                        hit.shapeContext.harvestShapeInfo.TemplateVirtualPath,
                        shapeDescriptor => displayContext => RenderAsync(shapeDescriptor, displayContext, hit.shapeContext.harvestShapeInfo, hit.shapeContext.harvestShapeHit));
                }
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Done discovering shapes");
            }
        }
        public IEnumerable <string> HarvestReducers(string path)
        {
            var reducerPath = Path.Combine(path, ReactFilePaths.Reducers).Replace(Path.DirectorySeparatorChar, '/');

            return(_virtualPathProvider.DirectoryExists(reducerPath) ? _virtualPathProvider.ListFiles(reducerPath).ToList() : new List <string>());
        }