Esempio n. 1
0
 public RecipeExecutor(
     IEventBus eventBus,
     IRecipeStore recipeStore,
     IOptions <RecipeHarvestingOptions> recipeOptions,
     IApplicationLifetime applicationLifetime,
     ShellSettings shellSettings,
     IOrchardHost orchardHost,
     ILogger <RecipeExecutor> logger,
     IStringLocalizer <RecipeExecutor> localizer)
 {
     _orchardHost         = orchardHost;
     _shellSettings       = shellSettings;
     _applicationLifetime = applicationLifetime;
     _eventBus            = eventBus;
     _recipeStore         = recipeStore;
     _recipeOptions       = recipeOptions.Value;
     Logger = logger;
     T      = localizer;
 }
Esempio n. 2
0
 public RecipeExecutor(
     IEventBus eventBus,
     ISession session,
     IEnumerable <IRecipeParser> recipeParsers,
     IOptions <RecipeHarvestingOptions> recipeOptions,
     IOrchardFileSystem fileSystem,
     IApplicationLifetime applicationLifetime,
     ShellSettings shellSettings,
     IOrchardHost orchardHost,
     ILogger <RecipeExecutor> logger,
     IStringLocalizer <RecipeExecutor> localizer)
 {
     _orchardHost         = orchardHost;
     _shellSettings       = shellSettings;
     _applicationLifetime = applicationLifetime;
     _eventBus            = eventBus;
     _session             = session;
     _recipeParsers       = recipeParsers;
     _recipeOptions       = recipeOptions.Value;
     _fileSystem          = fileSystem;
     _logger = logger;
     T       = localizer;
 }
Esempio n. 3
0
 public RecipeExecutor(
     IEventBus eventBus,
     ISession session,
     IEnumerable<IRecipeParser> recipeParsers,
     IOptions<RecipeHarvestingOptions> recipeOptions,
     IOrchardFileSystem fileSystem,
     IApplicationLifetime applicationLifetime,
     ShellSettings shellSettings,
     IOrchardHost orchardHost,
     ILogger<RecipeExecutor> logger,
     IStringLocalizer<RecipeExecutor> localizer)
 {
     _orchardHost = orchardHost;
     _shellSettings = shellSettings;
     _applicationLifetime = applicationLifetime;
     _eventBus = eventBus;
     _session = session;
     _recipeParsers = recipeParsers;
     _recipeOptions = recipeOptions.Value;
     _fileSystem = fileSystem;
     _logger = logger;
     T = localizer;
 }
Esempio n. 4
0
        /// <summary>
        /// Returns a list of recipes for a content path.
        /// </summary>
        /// <param name="path">A path string relative to the content root of the application.</param>
        /// <returns>The list of <see cref="RecipeDescriptor"/> instances.</returns>
        public static Task <IEnumerable <RecipeDescriptor> > HarvestRecipesAsync(string path, RecipeHarvestingOptions options, IHostingEnvironment hostingEnvironment)
        {
            var recipeContainerFileInfo = hostingEnvironment
                                          .ContentRootFileProvider
                                          .GetFileInfo(path);

            var recipeDescriptors = new List <RecipeDescriptor>();

            var matcher = new Matcher(System.StringComparison.OrdinalIgnoreCase);

            matcher.AddInclude("*.recipe.json");

            var matches = matcher
                          .Execute(new DirectoryInfoWrapper(new DirectoryInfo(recipeContainerFileInfo.PhysicalPath)))
                          .Files;

            if (matches.Any())
            {
                var result = matches
                             .Select(match => hostingEnvironment
                                     .ContentRootFileProvider
                                     .GetFileInfo(Path.Combine(path, match.Path))).ToArray();

                recipeDescriptors.AddRange(result.Select(recipeFile =>
                {
                    // TODO: Try to optimize by only reading the required metadata instead of the whole file
                    using (StreamReader file = File.OpenText(recipeFile.PhysicalPath))
                    {
                        using (var reader = new JsonTextReader(file))
                        {
                            var serializer                  = new JsonSerializer();
                            var recipeDescriptor            = serializer.Deserialize <RecipeDescriptor>(reader);
                            recipeDescriptor.RecipeFileInfo = recipeFile;
                            return(recipeDescriptor);
                        }
                    }
                }));
            }

            return(Task.FromResult <IEnumerable <RecipeDescriptor> >(recipeDescriptors));
        }