示例#1
0
        public void Update(Models.MediaContent @new, Models.MediaContent old)
        {
            var contentPath = new MediaContentPath(@new);

            if ([email protected](old.FileName, StringComparison.OrdinalIgnoreCase))
            {
                Kooboo.IO.IOUtility.RenameFile(old.PhysicalPath, @new.FileName);
            }
            if (@new.ContentFile != null)
            {
                @new.FileName = @new.ContentFile.FileName;

                @new.UserKey = @new.FileName;
                @new.UUID    = @new.FileName;

                locker.EnterWriteLock();
                try
                {
                    @new.ContentFile.Stream.SaveAs(contentPath.PhysicalPath);
                }
                finally
                {
                    locker.ExitWriteLock();
                }
            }

            SetFilePublished(contentPath.PhysicalPath, @new.Published);
            metadataStorage.SaveMetadata(@new);
        }
示例#2
0
        public void Add(MediaContent content, bool overrided)
        {
            if (content.ContentFile != null)
            {
                content.FileName = content.ContentFile.FileName;

                content.UserKey = content.FileName;
                content.UUID    = content.FileName;

                // if the file already exist and dont need to overrided just return
                if (content.Exist() && !overrided)
                {
                    return;
                }

                var contentPath = new MediaContentPath(content);

                content.VirtualPath = contentPath.VirtualPath;

                locker.EnterWriteLock();

                try
                {
                    content.ContentFile.Stream.SaveAs(contentPath.PhysicalPath);
                }
                finally
                {
                    locker.ExitWriteLock();
                }

                SetFilePublished(contentPath.PhysicalPath, content.Published);

                metadataStorage.SaveMetadata(content);
            }
        }
示例#3
0
        public virtual ActionResult TextFile(string folderName, string fileName, string body)
        {
            var data = new JsonResultData(ModelState);

            data.RunWithTry((resultData) =>
            {
                MediaContent content = new MediaContent(Repository.Name, folderName);
                content.FileName     = fileName;

                var contentPath = new MediaContentPath(content);

                Kooboo.IO.IOUtility.SaveStringToFile(contentPath.PhysicalPath, body);
            });

            return(Json(data));
        }
示例#4
0
        public virtual ActionResult TextFile(string folderName, string fileName)
        {
            MediaContent content = new MediaContent(Repository.Name, folderName);

            content.FileName = fileName;

            var contentPath = new MediaContentPath(content);

            string body = Kooboo.IO.IOUtility.ReadAsString(contentPath.PhysicalPath);

            return(View(new TextFileModel
            {
                Title = fileName,
                Body = body
            }));
        }
示例#5
0
        public void Move(MediaFolder sourceFolder, string oldFileName, MediaFolder targetFolder, string newFileName)
        {
            var oldMediaContent = new MediaContent()
            {
                Repository = sourceFolder.Repository.Name, FolderName = sourceFolder.FullName, UUID = oldFileName, FileName = oldFileName
            };
            var newMediaContent = new MediaContent()
            {
                Repository = targetFolder.Repository.Name, FolderName = targetFolder.FullName, UUID = newFileName, FileName = newFileName
            };

            var oldPath = new MediaContentPath(oldMediaContent);
            var newPath = new MediaContentPath(newMediaContent);

            File.Move(oldPath.PhysicalPath, newPath.PhysicalPath);

            metadataStorage.MoveMetadata(oldMediaContent, newMediaContent);
        }
示例#6
0
        public virtual ActionResult TextFile(string folderName, string fileName, string body)
        {
            var entry = new JsonResultEntry();

            try
            {
                MediaContent content = new MediaContent(Repository.Name, folderName);
                content.FileName = fileName;

                var contentPath = new MediaContentPath(content);

                Kooboo.IO.IOUtility.SaveStringToFile(contentPath.PhysicalPath, body);
                entry.SetSuccess();
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return(Json(entry));
        }
示例#7
0
        /// <summary>
        /// Exists the specified content.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        public static bool Exist(this MediaContent content)
        {
            var contentPath = new MediaContentPath(content);

            return(File.Exists(contentPath.PhysicalPath));
        }