private ResourceCollection GetResources(SonosIdentifier identifier)
        {
            if (!identifier.IsDirectory)
            {
                return(new ResourceCollection(identifier));
            }

            var directoryEntries = new ResourceCollection(identifier);

            directoryEntries.AddRange(_fs.Directory.GetDirectories(identifier.Path).Select(ToPhysicalResource <Container>));
            directoryEntries.AddRange(_fs.Directory.GetFiles(identifier.Path, "*.mp3", SearchOption.TopDirectoryOnly).Select(ToPhysicalResource <MusicFile>));
            return(directoryEntries);
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Renders the js for the page
        /// </summary>
        /// <typeparam name = "TModel"></typeparam>
        /// <param name = "htmlHelper"></param>
        /// <param name = "userScriptPaths">Additional scripts supplied by the user</param>
        public static MvcHtmlString RenderJs <TModel>(this HtmlHelper <TModel> htmlHelper, params string[] userScriptPaths)
        {
            var resourceService = ObjectFactory.GetInstance <IResourceService>();
            var builder         = new StringBuilder();

            var pageResources = new ResourceCollection();

            // include the widget scripts for the page
            pageResources.AddRange(htmlHelper.ViewContext.Controller.ViewBag.Js);

            // include the template scripts for the page
            foreach (var script in userScriptPaths)
            {
                pageResources.Load(script, MatchMode.Path);
            }
            // we treat these separately because we don't want the admin js to be mashed or cached
            var adminJs         = htmlHelper.ViewContext.Controller.ViewBag.AdminJs as ResourceCollection;
            var adminScriptTags = resourceService.GetResourcePaths(adminJs, false, false, true).ToTags();
            var pageScriptTags  = resourceService.GetResourcePaths(pageResources).ToTags();

            builder.AppendLine(adminScriptTags);
            builder.AppendLine(pageScriptTags);

            return(new MvcHtmlString(builder.ToString()));
        }
Exemplo n.º 3
0
        public ResourceCollection UserInterfaceCss()
        {
            var css = new ResourceCollection();

            foreach (var plugin in ObjectFactory.Model.GetAllPossible <IEyePatchPlugin>())
            {
                css.AddRange(plugin.Css);
            }
            return(css);
        }
Exemplo n.º 4
0
        public ResourceCollection AdminCss(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.AdminCss != null))
            {
                result.AddRange(widget.AdminCss);
            }
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Renders the css for the page
        /// </summary>
        /// <typeparam name = "TModel"></typeparam>
        /// <param name = "htmlHelper"></param>
        /// <param name = "scripts">Additional scripts supplied by the use</param>
        public static MvcHtmlString RenderCss <TModel>(this HtmlHelper <TModel> htmlHelper, params string[] userScriptPaths)
        {
            var resourceService = ObjectFactory.GetInstance <IResourceService>();

            var css = new ResourceCollection();

            // include the widget scripts for the page
            css.AddRange(htmlHelper.ViewContext.Controller.ViewBag.Css);
            // include the widget scripts for the page
            foreach (var script in userScriptPaths)
            {
                css.Load(script, MatchMode.Path);
            }

            // we treat these separately because we don't want the admin js to be mashed or cached
            var cssTags = resourceService.GetResourcePaths(css).ToTags();

            return(new MvcHtmlString(cssTags));
        }
Exemplo n.º 6
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
            });
        }
        public static ResourceCollection ToResourceCollection(this IEnumerable<IResource> resources)
        {
            var resourceCollection = new ResourceCollection();
            resourceCollection.AddRange(resources);

            return resourceCollection;
        }
Exemplo n.º 8
0
 public void AddResources(params IResource[] resources)
 {
     _resources.AddRange(resources);
 }
        public virtual IResourceCollection TransformResourceCollection(IResourceCollection value)
        {
            IResource[] array = new IResource[value.Count];
            for (int i = 0; i < value.Count; i++)
            {
                array[i] = this.TransformResource(value[i]);
            }

            IResourceCollection target = new ResourceCollection();
            target.AddRange(array);
            return target;
        }