コード例 #1
0
ファイル: ContentManager.cs プロジェクト: rryu/Iroha
        public ContentPage CreateContentPage(Container parentContainer, String pageAlias)
        {
            if (parentContainer == null) throw new ArgumentNullException("parentContainer");
            if (String.IsNullOrWhiteSpace(pageAlias)) throw new ArgumentException("pageAlias");

            if (Regex.IsMatch(pageAlias, "[*?|:<>\"/\\\\]|[\\p{C}-[ ]]"))
                throw new ArgumentException("ページ名には * ? | \" < > : / \\ および制御文字を含めることはできません");
            if (Regex.IsMatch(pageAlias, "^[.]"))
                throw new ArgumentException("ページ名をドットではじめることはできません。");

            if (!Directory.Exists(parentContainer.PhysicalPath))
                throw new DirectoryNotFoundException(String.Format("パス {0} が見つかりません", parentContainer.PhysicalPath));

            var newContentPagePath = Path.Combine(parentContainer.PhysicalPath, pageAlias) + ".cshtml";
            if (File.Exists(newContentPagePath) || Directory.Exists(newContentPagePath))
                throw new ArgumentException("指定された名前のページまたはコンテナはすでに存在しています");

            File.WriteAllText(newContentPagePath, @"@* Using:Iroha.WebPages *@<!-- Using:Iroha.ComponentEditor -->");

            if (parentContainer.CanWrite)
            {
                var contentPage = GetContentPage(parentContainer.Path + "/" + pageAlias, parentContainer);
                return contentPage;
            }

            throw new UnauthorizedAccessException();
        }
コード例 #2
0
ファイル: PagesController.cs プロジェクト: rryu/Iroha
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var siteRootDir = ConfigurationManager.AppSettings["Iroha.WebPages.SiteRootDirectory"];
            if (siteRootDir.StartsWith("~/"))
                siteRootDir = Server.MapPath(siteRootDir);
            var versionsDir = ConfigurationManager.AppSettings["Iroha.WebPages.VersionsDirectory"];
            if (versionsDir.StartsWith("~/"))
                versionsDir = Server.MapPath(versionsDir);

            _contentManager = new ContentManager(siteRootDir, versionsDir,new WindowsPrincipal(User.Identity as WindowsIdentity));

            _rootContainer = _contentManager.GetContainer("", null);
            _targetContainable = _contentManager.GetContainable(filterContext.RouteData.Values.ContainsKey("pagePath") ? filterContext.RouteData.Values["pagePath"].ToString() : "");

            base.OnActionExecuting(filterContext);
        }
コード例 #3
0
ファイル: ContentManager.cs プロジェクト: rryu/Iroha
        public void UpdateLocalNavItems(Container container, Boolean updateParent)
        {
            var localNavItemsString =
                "@* Automatic Generated *@@RenderPage(\"~/_Shared/Partials/_LocalNavItems.cshtml\", new { ";

            localNavItemsString += "Contents = new Dictionary<String, String>{";
            container = GetContainer(container.Path, null); // reload
            localNavItemsString += String.Join(",",
                Enumerable.Union(
                    container.Contents
                        .OfType<ContentPage>()
                        .Where(x => !x.Alias.StartsWith("_") && (String.Compare(x.Alias, "Default", true) != 0))
                        .Select(x =>
                                String.Format("{{ \"{0}\", \"~{1}\" }}",
                                              Utility.EscapeCSharpString(x.Title), Utility.EscapeCSharpString(Regex.Replace(x.Path, "/Default$", "/", RegexOptions.IgnoreCase)))
                        ),
                    container.Contents
                        .OfType<Container>()
                        .Where(x => !x.Alias.StartsWith("_") && x.Contents.OfType<ContentPage>().Any(x2 => (String.Compare(x2.Alias, "Default", true) == 0)))
                        .Select(x =>
                                String.Format("{{ \"{0}\", \"~{1}\" }}",
                                              Utility.EscapeCSharpString(x.Title), Utility.EscapeCSharpString(Regex.Replace(x.Path, "/Default$", "/", RegexOptions.IgnoreCase)))
                        )
                    )
                );
            if (container.Parent != null)
            {
                localNavItemsString += String.Format("}}, Parent = new {{ Title = \"{0}\", Path = \"{1}\" }}", Utility.EscapeCSharpString(container.Parent.Title), Utility.EscapeCSharpString(container.Parent.Path));
            }
            else
            {
                localNavItemsString += "}, Parent = new { Title = \"\", Path = \"\" }";
            }
            localNavItemsString += String.Format(", Current = new {{ Title = \"{0}\", Path = \"{1}\" }}", Utility.EscapeCSharpString(container.Title), Utility.EscapeCSharpString(container.Path));
            localNavItemsString += "})";

            File.WriteAllText(Path.Combine(container.PhysicalPath, "_LocalNavItems.cshtml"), localNavItemsString, new UTF8Encoding(true));

            if (updateParent && container.Parent != null)
            {
                UpdateLocalNavItems(container.Parent, false);
            }
            if (updateParent && container.Contents.OfType<Container>().Any())
            {
                foreach (var c in container.Contents.OfType<Container>())
                {
                    UpdateLocalNavItems(c, false);
                }
            }
        }
コード例 #4
0
ファイル: ContentManager.cs プロジェクト: rryu/Iroha
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parentContainer"></param>
        /// <returns></returns>
        public ContentPage GetContentPage(String path, Container parentContainer)
        {
            path = path.Trim('/');

            var contentPageFullPath = Path.Combine(SiteRootDirectory, path + ".cshtml");
            if (File.Exists(contentPageFullPath))
            {
                var canRead = false;
                var canWrite = false;

                CheckAccessControl(
                    Directory.GetAccessControl(contentPageFullPath).GetAccessRules(true, true, typeof(SecurityIdentifier)),
                    out canRead, out canWrite);

                var contentPage = new ContentPage()
                           {
                               PhysicalPath = contentPageFullPath,
                               Alias = Path.GetFileName(path),
                               CanRead = canRead,
                               CanWrite = canWrite,
                               Parent = parentContainer
                           };

                if (contentPage.Parent == null)
                {
                    if (path.LastIndexOf('/') > 0)
                    {
                        // 親がルート以外
                        contentPage.Parent = GetContainer(path.Substring(0, path.LastIndexOf('/')), null);
                    }
                    else if (!String.IsNullOrWhiteSpace(path))
                    {
                        // 親がルート
                        contentPage.Parent = GetContainer("", null);
                    }
                }

                // Metadata
                var metadata = ReadContentPageMetadata(contentPage);
                contentPage.Metadata = metadata;

                return contentPage;
            }
            return null;
        }
コード例 #5
0
ファイル: ContentManager.cs プロジェクト: rryu/Iroha
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parentContainer"></param>
        /// <returns></returns>
        public IEnumerable<Container> GetContainers(String path, Container parentContainer)
        {
            path = path.Trim('/');

            var fullPath = Path.Combine(SiteRootDirectory, path);

            if (!Directory.Exists(fullPath))
                return Enumerable.Empty<Container>();

            return Directory.GetDirectories(fullPath)
                            .Where(x => !Regex.IsMatch(Path.GetFileName(x), "^([._]|App_)|^bin$"))
                            .Select(x => GetContainer(x, parentContainer))
                            .Where(x => x != null);
        }
コード例 #6
0
ファイル: ContentManager.cs プロジェクト: rryu/Iroha
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="parentContainer"></param>
        /// <returns></returns>
        public Container GetContainer(String path, Container parentContainer)
        {
            path = path.Trim('/');

            var dirFullPath = Path.Combine(SiteRootDirectory, path);
            if (Directory.Exists(dirFullPath))
            {
                var canRead = false;
                var canWrite = false;

                CheckAccessControl(
                    Directory.GetAccessControl(dirFullPath).GetAccessRules(true, true, typeof (SecurityIdentifier)),
                    out canRead, out canWrite);

                var container = new Container
                           {
                               Parent = parentContainer,
                               Alias = Path.GetFileName(path),
                               PhysicalPath = dirFullPath,
                               CanRead = canRead,
                               CanWrite = canWrite,
                           };

                // 子供のコンテナ
                container.Contents = GetContainers(dirFullPath, container);

                // ページ
                var contentPages = Directory.GetFiles(dirFullPath, "*.cshtml")
                    .Select(Path.GetFileNameWithoutExtension)
                    .Select(x => path + "/" + x)
                    .Select(x => GetContentPage(x, container));

                container.Contents = container.Contents.Union(contentPages);

                if (container.Parent == null)
                {
                    if (path.LastIndexOf('/') > 0)
                    {
                        // 親がルート以外
                        container.Parent = GetContainer(path.Substring(0, path.LastIndexOf('/')), null);
                    }
                    else if (!String.IsNullOrWhiteSpace(path))
                    {
                        // 親がルート
                        container.Parent = GetContainer("", null);
                    }
                }
                return container;
            }
            return null;
        }