示例#1
0
        public int UpdateFrom7()
        {
            _cacheFileService.Empty();

            SchemaBuilder.AlterTable("CombinatorSettingsPartRecord",
                                     table =>
            {
                table.DropColumn("CombineCDNResources");
                table.AddColumn <bool>("CombineCdnResources");
            }
                                     );

            return(8);
        }
示例#2
0
        // POST
        protected override DriverResult Editor(CombinatorSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            var formerSettings = new CombinatorSettingsPartRecord();

            formerSettings.CombinationExcludeRegex              = part.CombinationExcludeRegex;
            formerSettings.CombineCdnResources                  = part.CombineCDNResources;
            formerSettings.MinifyResources                      = part.MinifyResources;
            formerSettings.MinificationExcludeRegex             = part.MinificationExcludeRegex;
            formerSettings.EmbedCssImages                       = part.EmbedCssImages;
            formerSettings.EmbeddedImagesMaxSizeKB              = part.EmbeddedImagesMaxSizeKB;
            formerSettings.EmbedCssImagesStylesheetExcludeRegex = part.EmbedCssImagesStylesheetExcludeRegex;
            formerSettings.ResourceSetRegexes                   = part.ResourceSetRegexes;

            updater.TryUpdateModel(part, Prefix, null, null);

            // Not emptying the cache would cause inconsistencies
            if (part.CombinationExcludeRegex != formerSettings.CombinationExcludeRegex ||
                part.CombineCDNResources != formerSettings.CombineCdnResources ||
                part.MinifyResources != formerSettings.MinifyResources ||
                (part.MinifyResources && part.MinificationExcludeRegex != formerSettings.MinificationExcludeRegex) ||
                part.EmbedCssImages != formerSettings.EmbedCssImages ||
                (part.EmbedCssImages && part.EmbeddedImagesMaxSizeKB != formerSettings.EmbeddedImagesMaxSizeKB) ||
                (part.EmbedCssImages && part.EmbedCssImagesStylesheetExcludeRegex != formerSettings.EmbedCssImagesStylesheetExcludeRegex) ||
                (part.ResourceSetRegexes != formerSettings.ResourceSetRegexes))
            {
                _cacheFileService.Empty();
            }

            _combinatorEventHandler.ConfigurationChanged();

            return(Editor(part, shapeHelper));
        }
        //public ActionResult EmptyCache(string returnUrl = "") Without AJAX
        public void EmptyCache()
        {
            if (_orchardServices.Authorizer.Authorize(StandardPermissions.SiteOwner))
            {
                _cacheFileService.Empty();
            }

            // Since we are calling this via AJAX, this is not necessary. But the AJAX implementation is not the best.
            //return this.RedirectLocal(returnUrl); // this necessary, as this is from an extension (Orchard.Mvc.Extensions.ControllerExtensions)
        }
        // POST
        protected override DriverResult Editor(CombinatorSettingsPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            return(ContentShape("Parts_CombinatorSettings_SiteSettings",
                                () =>
            {
                if (updater != null)
                {
                    dynamic formerSettings = new ExpandoObject();
                    formerSettings.CombinationExcludeRegex = part.CombinationExcludeRegex;
                    formerSettings.CombineCdnResources = part.CombineCdnResources;
                    formerSettings.RemoteStorageUrlRegex = part.RemoteStorageUrlRegex;
                    formerSettings.ResourceBaseUrl = part.ResourceBaseUrl;
                    formerSettings.MinifyResources = part.MinifyResources;
                    formerSettings.MinificationExcludeRegex = part.MinificationExcludeRegex;
                    formerSettings.EmbedCssImages = part.EmbedCssImages;
                    formerSettings.EmbeddedImagesMaxSizeKB = part.EmbeddedImagesMaxSizeKB;
                    formerSettings.EmbedCssImagesStylesheetExcludeRegex = part.EmbedCssImagesStylesheetExcludeRegex;
                    formerSettings.GenerateImageSprites = part.GenerateImageSprites;
                    formerSettings.EnableResourceSharing = part.EnableResourceSharing;
                    formerSettings.ResourceSharingExcludeRegex = part.ResourceSharingExcludeRegex;
                    formerSettings.ResourceSetRegexes = part.ResourceSetRegexes;

                    updater.TryUpdateModel(part, Prefix, null, null);


                    if (part.CombinationExcludeRegex != formerSettings.CombinationExcludeRegex ||
                        part.CombineCdnResources != formerSettings.CombineCdnResources ||
                        part.RemoteStorageUrlRegex != formerSettings.RemoteStorageUrlRegex ||
                        part.ResourceBaseUrl != formerSettings.ResourceBaseUrl ||
                        part.MinifyResources != formerSettings.MinifyResources ||
                        (part.MinifyResources && part.MinificationExcludeRegex != formerSettings.MinificationExcludeRegex) ||
                        part.EmbedCssImages != formerSettings.EmbedCssImages ||
                        (part.EmbedCssImages && part.EmbeddedImagesMaxSizeKB != formerSettings.EmbeddedImagesMaxSizeKB) ||
                        (part.EmbedCssImages && part.EmbedCssImagesStylesheetExcludeRegex != formerSettings.EmbedCssImagesStylesheetExcludeRegex) ||
                        part.GenerateImageSprites != formerSettings.GenerateImageSprites ||
                        part.EnableResourceSharing != formerSettings.EnableResourceSharing ||
                        part.ResourceSharingExcludeRegex != formerSettings.ResourceSharingExcludeRegex ||
                        (part.ResourceSetRegexes != formerSettings.ResourceSetRegexes))
                    {
                        var valuesAreValid = true;

                        if (!string.IsNullOrEmpty(part.ResourceBaseUrl))
                        {
                            try
                            {
                                UriHelper.CreateUri(part.ResourceBaseUrl);
                            }
                            catch (UriFormatException ex)
                            {
                                valuesAreValid = false;
                                updater.AddModelError("Combinator.ResourceBaseUrlMalformed", T("The resource base URL you provided is invalid: {0}", ex.Message));
                            }
                        }

                        if (!string.IsNullOrEmpty(part.CombinationExcludeRegex))
                        {
                            if (!TestRegex(part.CombinationExcludeRegex, T("combination exclude regex"), updater))
                            {
                                valuesAreValid = false;
                            }
                        }
                        if (!string.IsNullOrEmpty(part.RemoteStorageUrlRegex))
                        {
                            if (!TestRegex(part.RemoteStorageUrlRegex, T("remote storage pattern regex"), updater))
                            {
                                valuesAreValid = false;
                            }
                        }
                        if (!string.IsNullOrEmpty(part.MinificationExcludeRegex))
                        {
                            if (!TestRegex(part.MinificationExcludeRegex, T("minification exclude regex"), updater))
                            {
                                valuesAreValid = false;
                            }
                        }
                        if (!string.IsNullOrEmpty(part.EmbedCssImagesStylesheetExcludeRegex))
                        {
                            if (!TestRegex(part.EmbedCssImagesStylesheetExcludeRegex, T("embedded css images exclude regex"), updater))
                            {
                                valuesAreValid = false;
                            }
                        }
                        if (!string.IsNullOrEmpty(part.ResourceSharingExcludeRegex))
                        {
                            if (!TestRegex(part.ResourceSharingExcludeRegex, T("resource sharing exclude regex"), updater))
                            {
                                valuesAreValid = false;
                            }
                        }
                        if (!string.IsNullOrEmpty(part.ResourceSetRegexes))
                        {
                            int i = 1;
                            foreach (var regex in part.ResourceSetRegexesEnumerable)
                            {
                                if (!TestRegex(regex, T("resource set regexes #{0}", i.ToString()), updater))
                                {
                                    valuesAreValid = false;
                                }
                                i++;
                            }
                        }

                        if (valuesAreValid)
                        {
                            // Not emptying the cache would cause inconsistencies
                            _cacheFileService.Empty();
                            _notifier.Information(T("Combinator cache emptied."));
                        }
                    }

                    _combinatorEventHandler.ConfigurationChanged();
                }

                return shapeHelper.EditorTemplate(
                    TemplateName: "Parts.CombinatorSettings.SiteSettings",
                    Model: part,
                    Prefix: Prefix);
            })
                   .OnGroup("Combinator"));
        }
示例#5
0
        public void EmptyCache()
        {
            _cacheFileService.Empty();

            Context.Output.WriteLine(T("Combinator cache successfully emptied."));
        }