Cms_Folder.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Models » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » Models » Cms_Folder.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Everest.Library.Data.Entity;
using Everest.Library.ExtensionMethod;
using Everest.Library.Data.Rule;
using Everest.Library.Data;
using Everest.CmsServices.Services;
namespace Everest.CmsServices.Models{

    /// <summary>
    /// 
    /// </summary>
    public partial class Cms_Folder : IRuleEntity
    {
        #region Constructor
        /// <summary>
        /// Initializes a new instance of the <see cref="Cms_Folder"/> class.
        /// </summary>
        public Cms_Folder()
        {
            this.UUID = Guid.NewGuid();
            this.OriginalUUID = this.UUID;
        }
        #endregion

        #region get bases
        //IList<Cms_Folder> baseFolders;
        List<string> baseApplications;
        /// <summary>
        /// Gets all its and inherit folders.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Cms_Folder> GetBaseFoldersRecusive()
        {
            return CachedData.GetAllBase(this.UUID);
            //if (baseFolders == null)
            //{
            //    IList<Cms_Folder> folders = new List<Cms_Folder>();

            //    //add its and its parents  cascading.
            //    folders.Add(this);

            //    this.ParentReference.Load();
            //    Cms_Folder parent = this.Parent;
            //    while (parent != null && parent.CanInherit)
            //    {
            //        //if (parent.FolderType == this.FolderType)
            //        {
            //            folders.Add(parent);
            //            parent.ParentReference.Load();
            //            parent = parent.Parent;
            //        }
            //        //else
            //        //{
            //        //    break;
            //        //}

            //    }

            //    //get all base folders
            //    baseFolders = new List<Cms_Folder>();
            //    foreach (var item in folders)
            //    {
            //        baseFolders.Add(item);

            //        item.BaseReference.Load();
            //        Cms_Folder baseFolder = item.Base;
            //        while (baseFolder != null && !baseFolders.Contains(baseFolder))
            //        {
            //            baseFolders.Add(baseFolder);

            //            baseFolder.BaseReference.Load();
            //            baseFolder = baseFolder.Base;
            //        }
            //    }
            //}
            //return baseFolders;
        }
        ///// <summary>
        ///// Gets the base applications.
        ///// </summary>
        ///// <returns></returns>
        //public IEnumerable<string> GetBaseApplicationsRecusive()
        //{
        //    if (baseApplications == null)
        //    {
        //        IEnumerable<Cms_Folder> baseFolders = GetBaseFoldersRecusive();
        //        baseApplications = new List<string>();
        //        foreach (var item in baseFolders)
        //        {
        //            if (!item.aspnet_ApplicationsReference.IsLoaded)
        //            {
        //                item.aspnet_ApplicationsReference.Load();
        //            }

        //            if (!baseApplications.Contains(item.aspnet_Applications.ApplicationName))
        //            {
        //                baseApplications.Add(item.aspnet_Applications.ApplicationName);
        //            }

        //        }
        //    }
        //    return baseApplications;
        //}
        #endregion

        #region Get Folder file path
        private string ContentFileRelativePath
        {
            get
            {
                return Path.Combine(ContentFileManager.ContentFileDirName, this.FolderPath);
            }
        }
        /// <summary>
        /// Gets the absolute folder path.
        /// </summary>
        /// <returns></returns>
        public string GetAbsoluteFolderContentFilePath(string path)
        {
            if ((Everest.CmsServices.Models.FolderType)FolderType == Everest.CmsServices.Models.FolderType.ContentView)
            {
                return string.Empty;
            }
            string absoluteFolderPath = Path.Combine(CmsGlobal.BaseDirPath, ContentFileRelativePath);
            if (!StringExtensions.IsNullOrEmptyTrim(path))
            {
                absoluteFolderPath = Path.Combine(absoluteFolderPath, path);
            }

            if (!Directory.Exists(absoluteFolderPath) && !File.Exists(absoluteFolderPath))
            {
                Directory.CreateDirectory(absoluteFolderPath);
            }
            return absoluteFolderPath;
        }
        #endregion

        #region Properties
        public Guid? SchemaUUIDReference
        {
            get
            {
                return this.Cms_SchemaReference.EntityKey.GetKeyValue<Guid?>("UUID");
            }
        }
        public Guid? WorkflowUUIDReference
        {
            get
            {
                return this.Cms_WorkflowReference.EntityKey.GetKeyValue<Guid?>("UUID");
            }
        }

        /// <summary>
        /// Gets or sets the condition.
        /// 
        /// ContentView query condition. Using the FolderPath field.
        /// </summary>
        /// <value>The condition.</value>
        public string Condition
        {
            get
            {
                if ((Everest.CmsServices.Models.FolderType)FolderType == Everest.CmsServices.Models.FolderType.ContentView)
                {
                    return this.FolderPath;
                }
                return string.Empty;
            }
            set
            {
                if ((Everest.CmsServices.Models.FolderType)FolderType == Everest.CmsServices.Models.FolderType.ContentView)
                {
                    this.FolderPath = value;
                }
            }
        }
        #endregion

        #region override object
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override bool Equals(object obj)
        {
            if (((Cms_Folder)obj).UUID == this.UUID)
            {
                return true;
            }
            return base.Equals(obj);
        }
        #endregion

        #region IRuleEntity Members

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
            List<RuleViolation> violations = new List<RuleViolation>();

            if (StringExtensions.IsNullOrEmptyTrim(this.FolderName))
            {
                violations.Add(new RuleViolation("FolderName", "FolderName", string.Format(Resources.FieldIsRequired, "FolderName")));
            }
            this.aspnet_ApplicationsReference.Load(this.aspnet_Applications, this.EntityState);
            if (dataContext.IsFolderExists(this.aspnet_Applications.ApplicationName, this.FolderName, this.UUID, this.FolderType).Exists())
            {
                violations.Add(new RuleViolation("FolderName", this.FolderName, Resources.FolderIsAlreadyExists));
            }
            if (((FolderType)FolderType == Everest.CmsServices.Models.FolderType.TextContent) && this.EntityState == System.Data.EntityState.Added && this.Cms_Schema == null)
            {
                violations.Add(new RuleViolation("Schema", "null", string.Format(Resources.FieldIsRequired, "Schema")));
            }
            if (this.OriginalUUID != this.UUID && this.EntityState == System.Data.EntityState.Added)
            {
                if (dataContext.IsFolderExists(this.aspnet_Applications.ApplicationName, this.OriginalUUID).Exists())
                {
                    violations.Add(new RuleViolation("Base", this.OriginalUUID.ToString(), string.Format(Resources.FolderInheritanceAlreadyExists, this.Base.FolderName)));
                }
            }

            return violations;
        }

        #endregion

        #region Serialize

        public static Cms_Folder DeserializeFromNode(XmlNode parentNode)
        {
            var folder = new Cms_Folder();
            XmlNode folderNode = parentNode.SelectSingleNode("folder");
            if (folderNode != null)
            {
                folder.UUID = new Guid(folderNode.Attributes["UUID"].Value);
                folder.FolderName = folderNode.Attributes["FolderName"].Value;
                return folder;
            }
            return null;
        }

        public void SerializeAsNode(XmlNode parentNode)
        {
            var xmlDom = parentNode.OwnerDocument;
            //add folderNode
            XmlNode folderNode = parentNode.OwnerDocument.CreateElement("folder");
            parentNode.AppendChild(folderNode);
            XmlAttribute folderUUIDAtt = xmlDom.CreateAttribute("UUID");
            folderUUIDAtt.Value = this.UUID.ToString();
            folderNode.Attributes.Append(folderUUIDAtt);

            XmlAttribute folderNameAtt = xmlDom.CreateAttribute("FolderName");
            folderNameAtt.Value = this.FolderName;
            folderNode.Attributes.Append(folderNameAtt);
        }
        #endregion
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.