Exemple #1
0
        private IEnumerable<SkinTemplate> GetSkinTemplatesFromDir(VirtualFileBase virtualDirectory)
        {
            string skinConfigPath = string.Format("{0}/{1}/skin.config", RootSkinsVirtualPath, virtualDirectory.Name);

            if(VirtualPathProvider.FileExists(skinConfigPath))
            {
                IEnumerable<SkinTemplate> deserializedTemplates = GetSkinTemplates(VirtualPathProvider, skinConfigPath);
                deserializedTemplates.ForEach(t => t.TemplateFolder = virtualDirectory.Name);
                return deserializedTemplates;
            }
            return new[] {new SkinTemplate {Name = virtualDirectory.Name, TemplateFolder = virtualDirectory.Name}};
        }
        private Node ExpandVirtualNode(VirtualFileBase virtualNode)
        {
            if (!virtualNode.IsDirectory) return new Node(virtualNode.Name, NodeType.File);

            var node = new Node(virtualNode.Name, NodeType.Directory);

            var virtualDirectory = (VirtualDirectory)virtualNode;
            foreach (var child in virtualDirectory.Directories.Cast<VirtualFileBase>().Union(virtualDirectory.Files.Cast<VirtualFileBase>()))
            {
                // Excluding common folders that are unnecessary to process, the easy way. May need to be configurable.
                if (child.Name == ".hg" || child.Name == ".git") continue;

                node.AddChild(ExpandVirtualNode(child));
            }

            return node;
        }
Exemple #3
0
		// ReSharper disable RedundantNameQualifier
		private ContentRegistration RenderViewForRegistration(VirtualFileBase file, Type modelType, ControllerContext cctx, ViewEngineResult result)
        {
			if (file == null)
				throw new ArgumentNullException("file");

			// ReSharper disable once UseObjectOrCollectionInitializer
			var re = new ContentRegistration(map.CreateDefinition(modelType, N2.Web.Url.RemoveAnyExtension(file.Name)));
            re.IsDefined = false;
            re.Context.TouchedPaths.Add(file.VirtualPath);

            using (var sw = new StringWriter())
            {
                var vdd = new ViewDataDictionary();
                cctx.Controller.ViewData = vdd;
                N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, re);

                try
                {
                    logger.DebugFormat("Rendering view {0} for registrations", file.VirtualPath);
                    result.View.Render(new ViewContext(cctx, result.View, vdd, new TempDataDictionary(), sw), sw);
                    logger.DebugFormat("Rendered view {0}, editables = {1}, defined = {2}", file.VirtualPath, re.Definition.Editables.Count, re.IsDefined);
                }
                catch (Exception ex)
                {
                    logger.Error(file.VirtualPath, ex);
                    if (re.IsDefined)
                        throw new Exception(String.Format("Failed to render view {0} for registrations", file.VirtualPath), ex);
                    return null;
                }
                finally
                {
                    N2.Web.Mvc.Html.RegistrationExtensions.SetRegistrationExpression(cctx.HttpContext, null);
                }

                return re.IsDefined ? re : null;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CompassFile" /> class.
 /// </summary>
 /// <param name="file">The file.</param>
 public CompassFile(VirtualFileBase file)
     : base(file.VirtualPath)
 {
 }