Ejemplo n.º 1
0
        // <Module packageId="module1" [repository="somerepo"] version="1.1" />
        // install modules from feed.
        public void ExecuteRecipeStep(RecipeContext recipeContext)
        {
            if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            string packageId = null, version = null, repository = null;

            foreach (var attribute in recipeContext.RecipeStep.Step.Attributes())
            {
                if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase))
                {
                    packageId = attribute.Value;
                }
                else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase))
                {
                    version = attribute.Value;
                }
                else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase))
                {
                    repository = attribute.Value;
                }
                else
                {
                    throw new InvalidOperationException(string.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName));
                }
            }

            if (packageId == null)
            {
                throw new InvalidOperationException("PackageId is required in a Module declaration in a recipe file.");
            }

            // download and install module from the orchard feed or a custom feed if repository is specified.
            bool           enforceVersion = version != null;
            bool           installed      = false;
            PackagingEntry packagingEntry = null;

            var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();

            if (repository != null)
            {
                packagingSource = new PackagingSource {
                    FeedTitle = repository, FeedUrl = repository
                };
            }

            if (enforceVersion)
            {
                packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
                                                                          packages => packages.Where(package =>
                                                                                                     package.PackageType.Equals(DefaultExtensionTypes.Module) &&
                                                                                                     package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
                                                                                                     package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            }
            else
            {
                packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
                                                                          packages => packages.Where(package =>
                                                                                                     package.PackageType.Equals(DefaultExtensionTypes.Module) &&
                                                                                                     package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
                                                                                                     package.IsLatestVersion)).FirstOrDefault();
            }

            if (packagingEntry != null)
            {
                if (!ModuleAlreadyInstalled(packagingEntry.PackageId))
                {
                    _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
                }
                installed = true;
            }

            if (!installed)
            {
                throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", packageId));
            }

            recipeContext.Executed = true;
        }
Ejemplo n.º 2
0
 public static string ExtensionId(this PackagingEntry packagingEntry)
 {
     return(ExtensionId(packagingEntry.IsTheme(), packagingEntry.PackageId));
 }
Ejemplo n.º 3
0
 public static bool IsTheme(this PackagingEntry packagingEntry)
 {
     return(IsTheme(packagingEntry.PackageId));
 }
Ejemplo n.º 4
0
 public static string ExtensionFolder(this PackagingEntry packagingEntry)
 {
     return(ExtensionFolder(packagingEntry.IsTheme()));
 }
Ejemplo n.º 5
0
        // <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" />
        // Install themes from feed.
        public override void Execute(RecipeExecutionContext context)
        {
            bool   enable = false, current = false;
            string packageId = null, version = null, repository = null;

            foreach (var attribute in context.RecipeStep.Step.Attributes())
            {
                if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase))
                {
                    enable = Boolean.Parse(attribute.Value);
                }
                else if (String.Equals(attribute.Name.LocalName, "current", StringComparison.OrdinalIgnoreCase))
                {
                    current = Boolean.Parse(attribute.Value);
                }
                else if (String.Equals(attribute.Name.LocalName, "packageId", StringComparison.OrdinalIgnoreCase))
                {
                    packageId = attribute.Value;
                }
                else if (String.Equals(attribute.Name.LocalName, "version", StringComparison.OrdinalIgnoreCase))
                {
                    version = attribute.Value;
                }
                else if (String.Equals(attribute.Name.LocalName, "repository", StringComparison.OrdinalIgnoreCase))
                {
                    repository = attribute.Value;
                }
                else
                {
                    Logger.Warning("Unrecognized attribute '{0}' encountered; skipping.", attribute.Name.LocalName);
                }
            }

            if (packageId == null)
            {
                throw new InvalidOperationException("The PackageId attribute is required on a Theme declaration in a recipe file.");
            }

            // Download and install theme from the orchard feed or a custom feed if repository is specified.
            var            enforceVersion = version != null;
            var            installed      = false;
            PackagingEntry packagingEntry = null;

            var packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();

            if (repository != null)
            {
                packagingSource = new PackagingSource {
                    FeedTitle = repository, FeedUrl = repository
                };
            }

            if (enforceVersion)
            {
                packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
                                                                          packages => packages.Where(package =>
                                                                                                     package.PackageType.Equals(DefaultExtensionTypes.Theme) &&
                                                                                                     package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
                                                                                                     package.Version.Equals(version, StringComparison.OrdinalIgnoreCase))).FirstOrDefault();
            }
            else
            {
                packagingEntry = _packagingSourceManager.GetExtensionList(false, packagingSource,
                                                                          packages => packages.Where(package =>
                                                                                                     package.PackageType.Equals(DefaultExtensionTypes.Theme) &&
                                                                                                     package.Id.Equals(packageId, StringComparison.OrdinalIgnoreCase) &&
                                                                                                     package.IsLatestVersion)).FirstOrDefault();
            }

            if (packagingEntry != null)
            {
                if (!ThemeAlreadyInstalled(packagingEntry.PackageId))
                {
                    Logger.Information("Installing theme package '{0}'.", packagingEntry.PackageId);
                    _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
                }
                if (current)
                {
                    Logger.Information("Enabling theme '{0}'.", packagingEntry.Title);
                    _themeService.EnableThemeFeatures(packagingEntry.Title);
                    Logger.Information("Setting theme '{0}' as the site theme.", packagingEntry.Title);
                    _siteThemeService.SetSiteTheme(packagingEntry.Title);
                }
                else if (enable)
                {
                    Logger.Information("Enabling theme '{0}'.", packagingEntry.Title);
                    _themeService.EnableThemeFeatures(packagingEntry.Title);
                }

                installed = true;
            }

            if (!installed)
            {
                throw new InvalidOperationException(String.Format("Theme '{0}' was not found in the specified location.", packageId));
            }
        }