Пример #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="contentPage"></param>
 /// <param name="metadata"></param>
 public void SaveContentPageMetadata(ContentPage contentPage, ContentPageMetadata metadata)
 {
     var metadataDir = Path.Combine(contentPage.Parent.PhysicalPath, "_IrohaMetadata");
     var metadataPath = Path.Combine(metadataDir, contentPage.Alias + ".xml");
     if (!Directory.Exists(metadataDir))
     {
         Directory.CreateDirectory(metadataDir);
     }
     metadata.Save(metadataPath);
 }
Пример #2
0
        public void UpdateContentPage(ContentPage contentPage)
        {
            // current -> version
            var currentContentPage = GetContentPage(contentPage.Path, contentPage.Parent);
            CreateNewContentPageVersion(currentContentPage);

            // save
            contentPage.SaveBody();
            SaveContentPageMetadata(contentPage, contentPage.Metadata);

            // rebuild _LocalNavItems
            UpdateLocalNavItems(contentPage.Parent, true);
        }
Пример #3
0
        public ContentPageMetadata ReadContentPageMetadata(ContentPage contentPage)
        {
            var metadataDir = Path.Combine(contentPage.Parent.PhysicalPath, "_IrohaMetadata");
            var metadataPath = Path.Combine(metadataDir, contentPage.Alias + ".xml");
            if (File.Exists(metadataPath))
            {
                return ContentPageMetadata.LoadFromFile(metadataPath);
            }

            return new ContentPageMetadata()
                       {
                           Title = contentPage.Alias,
                           CreatedAt = File.GetCreationTime(contentPage.PhysicalPath),
                           ModifiedAt = File.GetLastWriteTime(contentPage.PhysicalPath),
                           CreatedBy = "",
                           ModifiedBy = ""
                       };
        }
Пример #4
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contentPage"></param>
        /// <returns></returns>
        public IEnumerable<DateTime> GetVersions(ContentPage contentPage)
        {
            var versionsDir = Path.Combine(VersionsRootDirectory, contentPage.Path.Trim('/', '\\'));
            if (!Directory.Exists(versionsDir))
            {
                return Enumerable.Empty<DateTime>();
            }

            return Directory.GetFiles(versionsDir, "*.xml")
                .Select(Path.GetFileNameWithoutExtension)
                .Where(x => Regex.IsMatch(x, "^[0-9]+$"))
                .Select(x => DateTime.FromBinary(Int64.Parse(x)))
                .OrderByDescending(x => x);
        }
Пример #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contentPage"></param>
        /// <param name="version"></param>
        /// <returns></returns>
        public ContentPageVersion GetVersion(ContentPage contentPage, Int64 version)
        {
            var versionsDir = Path.Combine(VersionsRootDirectory, contentPage.Path.Trim('/', '\\'));
            var versionFilePath = Path.Combine(versionsDir, version + ".xml");
            if (!File.Exists(versionFilePath))
                return null;

            return ContentPageVersion.LoadFromFile(versionFilePath);
        }
Пример #6
0
        /// <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;
        }
Пример #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contentPage"></param>
        public void CreateNewContentPageVersion(ContentPage contentPage)
        {
            var versionsDir = Path.Combine(VersionsRootDirectory, contentPage.Path.Trim('/', '\\'));
            if (!Directory.Exists(versionsDir))
            {
                Directory.CreateDirectory(versionsDir);
            }

            contentPage.LoadBody();
            var version = new ContentPageVersion() {Metadata = contentPage.Metadata, Content = contentPage.Body};
            version.Save(Path.Combine(versionsDir, contentPage.ModifiedAt.Ticks + ".xml"));
        }