public void Process(ScheduledTaskContext context)
 {
     if (context.Task.TaskType == "SwitchTheme")
     {
         _themeService.EnableThemeFeatures("Offline");
         _siteThemeService.SetSiteTheme("Offline");
     }
     else if (context.Task.TaskType == "ResetSite")
     {
         Logger.Information("start reseting site data at {2} utc", context.Task.ScheduledUtc);
         var factory = _sessionFactoryHolder.GetSessionFactory();
         using (var session = factory.OpenSession()){
             var connection = session.Connection;
             var dialect    = Dialect.GetDialect(_sessionFactoryHolder.GetConfiguration().Properties);
             var meta       = dialect.GetDataBaseSchema((DbConnection)connection);
             var tables     = meta.GetTables(null, null, null, null);
             try{
                 foreach (DataRow dr in tables.Rows)
                 {
                     _schemaBuilder.DropTable(dr["TABLE_NAME"].ToString());
                 }
                 ExecuteOutSql("~/Modules/Coevery.SiteReset/Sql/create.sql");
             }
             catch (Exception ex) {
                 Logger.Warning(ex, "reset site error");
             }
         }
     }
 }
Exemple #2
0
        public void Sweep()
        {
            var peddingTaskCount = _repository.Count(x => x.ScheduledUtc > _clock.UtcNow && x.TaskType == "ResetSite" ||
                                                     x.ScheduledUtc > _clock.UtcNow && x.TaskType == "SwitchTheme");

            if (peddingTaskCount == 0)
            {
                _themeService.EnableThemeFeatures("Mooncake");
                _siteThemeService.SetSiteTheme("Mooncake");
                _scheduledTaskManager.CreateTask("SwitchTheme", _clock.UtcNow.AddMinutes(29), null);
                _scheduledTaskManager.CreateTask("ResetSite", _clock.UtcNow.AddMinutes(30), null);
            }
        }
        public ActionResult Preview(string themeId, string returnUrl)
        {
            if (!Services.Authorizer.Authorize(Permissions.ApplyTheme, T("Couldn't preview the current theme")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (_extensionManager.AvailableExtensions()
                .FirstOrDefault(extension => DefaultExtensionTypes.IsTheme(extension.ExtensionType) && extension.Id.Equals(themeId)) == null)
            {
                Services.Notifier.Error(T("Theme {0} was not found", themeId));
            }
            else
            {
                var alreadyEnabledFeatures = GetEnabledFeatures();
                _themeService.EnableThemeFeatures(themeId);
                _previewTheme.SetPreviewTheme(themeId);
                alreadyEnabledFeatures.Except(new[] { themeId });
                TempData[AlreadyEnabledFeatures] = alreadyEnabledFeatures;
            }

            return(this.RedirectLocal(returnUrl, "~/"));
        }
        public void Activate(string themeName)
        {
            var theme = _extensionManager.AvailableExtensions().FirstOrDefault(x => x.Name.Trim().Equals(themeName, StringComparison.OrdinalIgnoreCase));

            if (theme == null)
            {
                Context.Output.WriteLine(T("Could not find theme {0}", themeName));
                return;
            }

            if (!_shellDescriptor.Features.Any(sf => sf.Name == theme.Id))
            {
                Context.Output.WriteLine(T("Enabling theme \"{0}\"...", themeName));
                _themeService.EnableThemeFeatures(theme.Id);
            }

            Context.Output.WriteLine(T("Activating theme \"{0}\"...", themeName));
            _siteThemeService.SetSiteTheme(theme.Id);

            Context.Output.WriteLine(T("Theme \"{0}\" activated", themeName));
        }
        // <Theme packageId="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" />
        // install themes from feed.
        public void ExecuteRecipeStep(RecipeContext recipeContext)
        {
            if (!String.Equals(recipeContext.RecipeStep.Name, "Theme", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            bool   enable = false, current = false;
            string packageId = null, version = null, repository = null;

            foreach (var attribute in recipeContext.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.Error("Unrecognized attribute {0} encountered in step Theme. Skipping.", attribute.Name.LocalName);
                }
            }

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

            // download and install theme 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.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))
                {
                    _packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
                }
                if (current)
                {
                    _themeService.EnableThemeFeatures(packagingEntry.Title);
                    _siteThemeService.SetSiteTheme(packagingEntry.Title);
                }
                else if (enable)
                {
                    _themeService.EnableThemeFeatures(packagingEntry.Title);
                }

                installed = true;
            }

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

            recipeContext.Executed = true;
        }