Esempio n. 1
0
        public ViewResult Service(Page epPage, Template epTemplate)
        {
            if (epPage == null || epPage.Id == null)
                throw new ApplicationException("page is not specified");

            if (epTemplate == null || epTemplate.Id == null)
                throw new ApplicationException("template is not specified");

            var adminJs = new ResourceCollection();
            adminJs.Load(Resources.Resources.jQuery);
            adminJs.Load(Url.RouteUrl("AdminPanel", new {pageId = epPage.Id}).ToLowerInvariant(), MatchMode.Path,
                      "text/javascript");

            ViewBag.ContentAreas = epPage.ContentAreas.ToList();
            ViewBag.Page = epPage;
            ViewBag.Template = epTemplate;
            ViewBag.Root = contentManager.Folder.RootFolder;
            ViewBag.Js = contentManager.Page.Js(epPage.Id);
            ViewBag.AdminJs = adminJs;
            ViewBag.Css = contentManager.Page.Css(epPage.Id);

            // add cache dependency so we can do sitewide clears on page change
            contentManager.Page.AddOutputCacheDependency(
                ((HttpApplication) HttpContext.GetService(typeof (HttpApplication))).Context);

            return View(Path.GetFileNameWithoutExtension(epTemplate.ViewPath));
        }
Esempio n. 2
0
 public static ResourceCollection ToResourceCollection(this IEnumerable<Resource> collection)
 {
     var result = new ResourceCollection();
     foreach (var resource in collection)
     {
         result.Add(resource);
     }
     return result;
 }
Esempio n. 3
0
 public ResourceCollection UserInterfaceJs()
 {
     var js = new ResourceCollection();
     foreach (var plugin in ObjectFactory.Model.GetAllPossible<IEyePatchPlugin>())
     {
         js.AddRange(plugin.Js);
     }
     return js;
 }
Esempio n. 4
0
 public ResourceCollection AdminJs(string id)
 {
     var page = Load(id);
     var distinctWidgets =
         page.ContentAreas.SelectMany(w => w.Widgets).GroupBy(w => w.Type).Select(g => g.First().GetInstance());
     var result = new ResourceCollection();
     foreach (var widget in distinctWidgets.Where(w => w.AdminJs != null))
     {
         result.AddRange(widget.AdminJs);
     }
     return result;
 }
Esempio n. 5
0
 public IEnumerable<ResourcePath> GetResourcePaths(ResourceCollection resources)
 {
     return GetResourcePaths(resources, EyePatchApplication.ReleaseMode == ReleaseMode.Production,
                             EyePatchApplication.ReleaseMode == ReleaseMode.Production,
                             EyePatchApplication.ReleaseMode == ReleaseMode.Production);
 }
Esempio n. 6
0
        private ResourcePath ProcessGroup(ResourceCollection set, bool minify, bool cacheRefresh)
        {
            if (!set.Any())
                throw new ApplicationException("Cannot process empty group");

            var firstElement = set.First();
            if (set.Count() == 1 && firstElement.IsExternal)
                return new ResourcePath {ContentType = firstElement.ContentType, Url = firstElement.Url};

            var cacheKey = minify ? set.UnqiueId.ToMinPath() : set.UnqiueId;

            var upgraded = false;
            try
            {
                cacheLock.EnterUpgradeableReadLock();

                var cached = cacheProvider.Get<ResourcePath>(cacheKey);
                if (cached != null && cacheRefresh)
                    return cached;

                cacheLock.EnterWriteLock();
                upgraded = true;

                var priorWrite = cacheProvider.Get<ResourcePath>(cacheKey);
                if (priorWrite != null && cacheRefresh)
                    return priorWrite;

                // regenerate
                var result = new ResourcePath();
                result.ContentType = firstElement.ContentType;
                result.Url = Url.Action("fetch", "resource", new {id = cacheKey});

                // mash
                result.Contents = set.Mash();

                // minify
                if (minify)
                {
                    result.Contents = firstElement.ContentType == "text/javascript"
                                          ? JavaScriptCompressor.Compress(result.Contents)
                                          : CssCompressor.Compress(result.Contents);
                }

                // write backup file
                var physicalFilePath = GetFilePath(set.UnqiueId, minify);

                if (!Directory.Exists(Path.GetDirectoryName(physicalFilePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(physicalFilePath));

                if (File.Exists(physicalFilePath))
                    File.Delete(physicalFilePath);

                File.WriteAllText(physicalFilePath, result.Contents);
                result.FileName = physicalFilePath;

                cacheProvider.Add(cacheKey, result, set.Files());
                return result;
            }
            finally
            {
                if (upgraded)
                    cacheLock.ExitWriteLock();

                cacheLock.ExitUpgradeableReadLock();
            }
        }
Esempio n. 7
0
 private static IEnumerable<ResourceCollection> GroupResources(IEnumerable<Resource> resources)
 {
     var groups = new List<ResourceCollection>();
     foreach (var resource in resources)
     {
         var group = groups.LastOrDefault();
         if (resource.IsExternal || group == null || group.Last().IsExternal)
         {
             group = new ResourceCollection();
             groups.Add(group);
         }
         group.Add(resource);
     }
     return groups;
 }
Esempio n. 8
0
        public IEnumerable<ResourcePath> GetResourcePaths(ResourceCollection resources, bool mash, bool minify,
                                                          bool cache)
        {
            if (!mash)
                return resources.Select(r => ProcessResource(r, minify, cache));

            var groups = GroupResources(resources);

            return groups.Select(set => ProcessGroup(set, minify, cache)).ToList();
        }
Esempio n. 9
0
 public void AddRange(ResourceCollection collection)
 {
     resources.AddRange(collection);
 }
Esempio n. 10
0
        public static WidgetInstance ToViewModel(this Widget pageWidget, ResourceCollection pageJs, ResourceCollection pageCss, IContentManager contentManager,
                                                 Controller controller, string sourceUrl)
        {
            var widget = pageWidget.GetInstance();

            pageJs.AddRange(AdminPanelViewModel.DependentJs);
            pageCss.AddRange(AdminPanelViewModel.DependentCss);

            var remainingJs =
                contentManager.Resources.GetResourcePaths(widget.AdminJs.Except(pageJs).ToResourceCollection()).ToList();

            var remainingCss =
                contentManager.Resources.GetResourcePaths(widget.AdminCss.Except(pageCss).ToResourceCollection()).ToList
                    ();

            string contents;
            using (var sw = new MemoryStream())
            {
                using (var writer = new HtmlTextWriter(new StringWriter()))
                {
                    widget.Render(new WidgetContext(controller.ControllerContext, pageWidget, writer, sourceUrl));
                    contents = writer.InnerWriter.ToString();
                }
            }

            return new WidgetInstance
                       {
                           Id = pageWidget.Id,
                           InitializeFunction = widget.CreateFunction,
                           CssClass = widget.CssClass,
                           Js = remainingJs,
                           Css = remainingCss,
                           Contents = contents
                       };
        }
Esempio n. 11
0
 public void AddRange(ResourceCollection collection)
 {
     resources.AddRange(collection);
 }