Exemplo n.º 1
0
        public ActionResult IndexPost()
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage settings")))
            {
                return(new HttpUnauthorizedResult());
            }

            var viewModel = new WarmupViewModel {
                Settings      = Services.WorkContext.CurrentSite.As <WarmupSettingsPart>(),
                ReportEntries = Enumerable.Empty <ReportEntry>()
            };

            if (TryUpdateModel(viewModel))
            {
                if (!String.IsNullOrEmpty(viewModel.Settings.Urls))
                {
                    using (var urlReader = new StringReader(viewModel.Settings.Urls)) {
                        string relativeUrl;
                        while (null != (relativeUrl = urlReader.ReadLine()))
                        {
                            if (String.IsNullOrWhiteSpace(relativeUrl))
                            {
                                continue;
                            }
                            if (!Uri.IsWellFormedUriString(relativeUrl, UriKind.Relative) || !(relativeUrl.StartsWith("/")))
                            {
                                AddModelError("Urls", T("\"{0}\" is an invalid warmup url.", relativeUrl));
                            }
                        }
                    }
                }
            }

            if (viewModel.Settings.Scheduled)
            {
                if (viewModel.Settings.Delay <= 0)
                {
                    AddModelError("Delay", T("Delay must be greater than zero."));
                }
            }

            if (ModelState.IsValid)
            {
                _warmupUpdater.Generate();
                Services.Notifier.Information(T("Warmup updated successfully."));
            }
            else
            {
                Services.TransactionManager.Cancel();
            }

            return(Index());
        }
        public void Generate()
        {
            if (Force)
            {
                _warmupUpdater.Generate();
            }
            else
            {
                _warmupUpdater.EnsureGenerate();
            }

            Context.Output.WriteLine(T("Generation finished"));
        }
Exemplo n.º 3
0
 public void StampFileShouldBeDeletedToForceAnUpdate()
 {
     _appDataFolder.CreateFile(_warmupFilename, "");
     _warmupUpdater.Generate();
     Assert.That(_appDataFolder.ListFiles(WarmupFolder).Count(), Is.EqualTo(0));
 }