Ejemplo n.º 1
0
 public RecipeExecutor(
     IEnumerable <IRecipeEventHandler> recipeEventHandlers,
     IRecipeStore recipeStore,
     IOptions <RecipeHarvestingOptions> recipeOptions,
     IApplicationLifetime applicationLifetime,
     ShellSettings shellSettings,
     IShellHost orchardHost,
     ILogger <RecipeExecutor> logger,
     IStringLocalizer <RecipeExecutor> localizer)
 {
     _orchardHost         = orchardHost;
     _shellSettings       = shellSettings;
     _applicationLifetime = applicationLifetime;
     _recipeEventHandlers = recipeEventHandlers;
     _recipeStore         = recipeStore;
     _recipeOptions       = recipeOptions.Value;
     Logger = logger;
     T      = localizer;
 }
Ejemplo n.º 2
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));
        }
        /// <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 recipeFiles = hostingEnvironment.ContentRootFileProvider.GetDirectoryContents(path)
                              .Where(x => !x.IsDirectory && x.Name.EndsWith(".recipe.json"));

            if (recipeFiles.Any())
            {
                recipeDescriptors.AddRange(recipeFiles.Select(recipeFile =>
                {
                    // TODO: Try to optimize by only reading the required metadata instead of the whole file

                    using (var stream = recipeFile.CreateReadStream())
                    {
                        using (var reader = new StreamReader(stream))
                        {
                            using (var jsonReader = new JsonTextReader(reader))
                            {
                                var serializer                  = new JsonSerializer();
                                var recipeDescriptor            = serializer.Deserialize <RecipeDescriptor>(jsonReader);
                                recipeDescriptor.RecipeFileInfo = recipeFile;
                                return(recipeDescriptor);
                            }
                        }
                    }
                }));
            }

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