/*
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.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Web.Routing;
using Everest.Library.Data;
using Everest.CmsServices.Services;
using Everest.Library.Versioning;
using Everest.Library.ExtensionMethod;
using Everest.Library.Data.Rule;
using Everest.Library.Data.Entity;
namespace Everest.CmsServices.Models{
public partial class Cms_Page : IXmlSerializable, IVersionable, IRuleEntity
{
#region Delete
/// <summary>
/// Deletes the content template in page.
/// </summary>
/// <param name="context">The context.</param>
public void DeleteContentTemplateInPage(IEverestCmsDataContext context)
{
if (!this.Cms_ContentTemplateInPageHolder.IsLoaded)
{
Cms_ContentTemplateInPageHolder.Load();
}
while (this.Cms_ContentTemplateInPageHolder.Count > 0)
{
context.DeleteObject(this.Cms_ContentTemplateInPageHolder.First());
}
this.Cms_ContentTemplateInPageHolder.Clear();
}
/// <summary>
/// Deletes the specified context.
/// </summary>
/// <param name="context">The context.</param>
public void Delete(IEverestCmsDataContext context)
{
DeleteContentTemplateInPage(context);
context.DeleteObject(this);
}
#endregion
#region partial method
/// <summary>
/// set the lowered page name
/// Called when [page name changed].
/// </summary>
partial void OnPageNameChanged()
{
this.LoweredPageName = this.PageName.ToLower();
}
#endregion
#region Route
/// <summary>
///
/// </summary>
Route routeData;
/// <summary>
/// Gets the route.route generate by Cms_Page
/// </summary>
/// <value>The route.</value>
public Route Route
{
get
{
if (routeData == null)
{
RouteValueDictionary defaults = new RouteValueDictionary();
if (!StringExtensions.IsNullOrEmptyTrim(this.DefaultParams))
{
string[] paramArray = this.DefaultParams.Split('&');
foreach (var item in paramArray)
{
if (!StringExtensions.IsNullOrEmptyTrim(item))
{
string[] nameValue = item.Split('=');
defaults.Add(nameValue[0], nameValue[1]);
}
}
}
routeData = new Route(this.Url, defaults, null);
}
return routeData;
}
}
#endregion
#region Serialize
#region IXmlSerializable Members
public System.Xml.Schema.XmlSchema GetSchema()
{
return null;
}
public void ReadXml(XmlReader reader)
{
XmlDocument xmlDom = new XmlDocument();
xmlDom.Load(reader);
XmlNode pageNode = xmlDom.FirstChild.FirstChild;
this.UUID = new Guid(pageNode.Attributes["PageUUID"].Value);
this.PageName = pageNode.Attributes["PageName"].Value;
//deserialize pag template
this.Cms_PageTemplate = Cms_PageTemplate.DeserializeFromNode(pageNode);
this.Url = pageNode.Attributes["Url"].Value;
this.DefaultParams = pageNode.Attributes["DefaultParams"].Value;
if (pageNode.Attributes["ShowInNavigation"] != null)
{
this.ShowInNavigation = bool.Parse(pageNode.Attributes["ShowInNavigation"].Value);
}
if (pageNode.Attributes["NavigationText"] != null)
{
this.NavigationText = pageNode.Attributes["NavigationText"].Value;
}
if (pageNode.Attributes["NavigationOrder"] != null && !StringExtensions.IsNullOrEmptyTrim(pageNode.Attributes["NavigationOrder"].Value))
{
this.NavigationOrder = int.Parse(pageNode.Attributes["NavigationOrder"].Value);
}
this.Cms_ParentPage = Cms_Page.DeserializeFromNode(pageNode, "parentPage");
if (pageNode.Attributes["ApplicationLevel"] != null)
{
this.ApplicationLevel = int.Parse(pageNode.Attributes["ApplicationLevel"].Value);
}
if (pageNode.Attributes["Allows"] != null)
{
this.Allows = pageNode.Attributes["Allows"].Value;
}
if (pageNode.Attributes["Denies"] != null)
{
this.Denies = pageNode.Attributes["Denies"].Value;
}
#region deserialize Application
this.aspnet_Applications = aspnet_Applications.DeserializeFromNode(pageNode);
#endregion
#region deserialize dataRules
XmlNode dataRulesNode = pageNode.SelectSingleNode("dataRules");
if (dataRulesNode != null)
{
foreach (XmlNode dataRuleNode in dataRulesNode.ChildNodes)
{
Cms_DataRule dataRule = new Cms_DataRule();
this.Cms_DataRule.Add(dataRule);
dataRule.DataName = dataRuleNode.Attributes["DataName"].Value;
int valueType;
if (int.TryParse(dataRuleNode.Attributes["ValueType"].Value, out valueType))
{
dataRule.ValueType = valueType;
}
if (!StringExtensions.IsNullOrEmptyTrim(dataRuleNode.Attributes["FolderUUID"].Value))
{
dataRule.Cms_Folder = CachedData.GetFolder(new Guid(dataRuleNode.Attributes["FolderUUID"].Value));
}
dataRule.ValueRule = dataRuleNode.Attributes["ValueRule"].Value;
dataRule.OrderBy = dataRuleNode.Attributes["OrderBy"].Value;
dataRule.TopCount = dataRuleNode.Attributes["TopCount"].Value;
dataRule.IncludeChildren = dataRuleNode.Attributes["IncludeChildren"].Value.GetNullableBool();
dataRule.DynamicLinkingOrder = int.Parse(dataRuleNode.Attributes["DynamicLinkingOrder"].Value);
dataRule.Order = int.Parse(dataRuleNode.Attributes["Order"].Value);
if (dataRuleNode.Attributes["ReferencingContentId"] != null)
{
dataRule.ReferencingContentId = dataRuleNode.Attributes["ReferencingContentId"].Value;
}
if (dataRuleNode.Attributes["PageIndex"] != null)
{
dataRule.PageIndex = dataRuleNode.Attributes["PageIndex"].Value;
}
if (dataRuleNode.Attributes["PageSize"] != null)
{
dataRule.PageSize = dataRuleNode.Attributes["PageSize"].Value;
}
if (dataRuleNode.Attributes["Caching"] != null)
{
dataRule.Caching = dataRuleNode.Attributes["Caching"].Value;
}
}
}
#endregion
#region deserialize the plugins node
//deserialize the plugins node
XmlNode pluginsNode = pageNode.SelectSingleNode("plugins");
foreach (XmlNode pluginNode in pluginsNode.ChildNodes)
{
Cms_Plugin plugin = new Cms_Plugin();
plugin.PluginId = int.Parse(pluginNode.Attributes["PluginId"].Value);
plugin.PluginName = pluginNode.Attributes["PluginName"].Value;
plugin.PluginType = pluginNode.Attributes["PluginType"].Value;
this.Cms_Plugin.Add(plugin);
}
#endregion
#region deserialize content template in page
//deserialize content template in page
XmlNode contentTemplatesInPageNode = pageNode.SelectSingleNode("contentTemplatesInPage");
foreach (XmlNode contentTemplateInPageNode in contentTemplatesInPageNode.ChildNodes)
{
Cms_ContentTemplateInPageHolder contentTemplateInPage = new Cms_ContentTemplateInPageHolder();
Cms_ContentTemplateInPageHolder.Add(contentTemplateInPage);
contentTemplateInPage.Position = contentTemplateInPageNode.Attributes["Position"].Value;
if (contentTemplateInPageNode.Attributes["ContentTemplateUUID"] != null)
{
contentTemplateInPage.Cms_ContentTemplate = new Cms_ContentTemplate();
contentTemplateInPage.Cms_ContentTemplate.UUID = new Guid(contentTemplateInPageNode.Attributes["ContentTemplateUUID"].Value);
}
else
{
contentTemplateInPage.ComponentValue = contentTemplateInPageNode.Attributes["ComponentValue"].Value;
}
contentTemplateInPage.Order = int.Parse(contentTemplateInPageNode.Attributes["Order"].Value);
XmlNode parameterValuesNode = contentTemplateInPageNode.SelectSingleNode("parameterValues");
foreach (XmlNode parameterValueNode in parameterValuesNode.ChildNodes)
{
Cms_ParameterValues parameterValue = new Cms_ParameterValues();
contentTemplateInPage.Cms_ParameterValues.Add(parameterValue);
parameterValue.Name = parameterValueNode.Attributes["Name"].Value;
parameterValue.DataType = parameterValueNode.Attributes["DataType"].Value;
parameterValue.Value = parameterValueNode.Attributes["Value"].Value;
}
}
#endregion
}
public void WriteXml(XmlWriter writer)
{
XmlDocument xmlDom = new XmlDocument();
XmlNode pageNode = xmlDom.CreateElement("page");
xmlDom.AppendChild(pageNode);
//add pageid
XmlAttribute pageIdAtt = xmlDom.CreateAttribute("PageUUID");
pageIdAtt.Value = this.UUID.ToString();
pageNode.Attributes.Append(pageIdAtt);
//add page name
XmlAttribute pageNameAtt = xmlDom.CreateAttribute("PageName");
pageNameAtt.Value = this.PageName;
pageNode.Attributes.Append(pageNameAtt);
//add page template
this.Cms_PageTemplateReference.Load(this.Cms_PageTemplate, this.EntityState);
if (this.Cms_PageTemplate != null)
{
this.Cms_PageTemplate.SerializeAsNode(pageNode);
}
//add url
XmlAttribute urlAtt = xmlDom.CreateAttribute("Url");
urlAtt.Value = this.Url;
pageNode.Attributes.Append(urlAtt);
//add default parameater
XmlAttribute defaultParamsAtt = xmlDom.CreateAttribute("DefaultParams");
defaultParamsAtt.Value = this.DefaultParams;
pageNode.Attributes.Append(defaultParamsAtt);
//add ShowInNavigation
XmlAttribute showInNavigationAtt = xmlDom.CreateAttribute("ShowInNavigation");
showInNavigationAtt.Value = this.ShowInNavigation.ToString();
pageNode.Attributes.Append(showInNavigationAtt);
// add NavigationText
XmlAttribute navigationTextAtt = xmlDom.CreateAttribute("NavigationText");
navigationTextAtt.Value = this.NavigationText;
pageNode.Attributes.Append(navigationTextAtt);
//add NavigationOrder
if (this.NavigationOrder.HasValue)
{
XmlAttribute navigationOrderAtt = xmlDom.CreateAttribute("NavigationOrder");
navigationOrderAtt.Value = this.NavigationOrder.ToString();
pageNode.Attributes.Append(navigationOrderAtt);
}
//add ApplicationLevel
XmlAttribute applicationLevelAtt = xmlDom.CreateAttribute("ApplicationLevel");
applicationLevelAtt.Value = this.ApplicationLevel.ToString();
pageNode.Attributes.Append(applicationLevelAtt);
// add Denies
XmlAttribute deniesAtt = xmlDom.CreateAttribute("Denies");
deniesAtt.Value = this.Denies;
pageNode.Attributes.Append(deniesAtt);
//add Allows
XmlAttribute allowsAtt = xmlDom.CreateAttribute("Allows");
allowsAtt.Value = this.Allows;
pageNode.Attributes.Append(allowsAtt);
this.Cms_ParentPageReference.Load(this.Cms_ParentPage, this.EntityState);
if (this.Cms_ParentPage != null)
{
this.Cms_ParentPage.SerializeAsNode(pageNode, "parentPage");
}
#region add Application
this.aspnet_ApplicationsReference.Load(this.aspnet_Applications, this.EntityState);
this.aspnet_Applications.SerializeAsNode(pageNode);
#endregion
#region add data rules node
//add data rule
XmlNode dataRulesNode = xmlDom.CreateElement("dataRules");
pageNode.AppendChild(dataRulesNode);
if (!this.Cms_DataRule.IsLoaded)
{
this.Cms_DataRule.Load();
}
foreach (var dataRule in this.Cms_DataRule)
{
XmlNode dataRuleNode = xmlDom.CreateElement("dataRule");
dataRulesNode.AppendChild(dataRuleNode);
//add dataName
XmlAttribute dataNameAtt = xmlDom.CreateAttribute("DataName");
dataNameAtt.Value = dataRule.DataName;
dataRuleNode.Attributes.Append(dataNameAtt);
//add valueType
XmlAttribute valueTypeAtt = xmlDom.CreateAttribute("ValueType");
valueTypeAtt.Value = dataRule.ValueType.ToString();
dataRuleNode.Attributes.Append(valueTypeAtt);
//add folder
XmlAttribute folderIdAtt = xmlDom.CreateAttribute("FolderUUID");
if (dataRule.FolderUUIDFromReference.HasValue)
{
folderIdAtt.Value = dataRule.FolderUUIDFromReference.ToString();
}
dataRuleNode.Attributes.Append(folderIdAtt);
//add value rule
XmlAttribute valueRuleAtt = xmlDom.CreateAttribute("ValueRule");
valueRuleAtt.Value = dataRule.ValueRule;
dataRuleNode.Attributes.Append(valueRuleAtt);
//add order by
XmlAttribute orderByAtt = xmlDom.CreateAttribute("OrderBy");
orderByAtt.Value = dataRule.OrderBy;
dataRuleNode.Attributes.Append(orderByAtt);
//add order
XmlAttribute orderAtt = xmlDom.CreateAttribute("Order");
orderAtt.Value = dataRule.Order.ToString();
dataRuleNode.Attributes.Append(orderAtt);
XmlAttribute topCountAtt = xmlDom.CreateAttribute("TopCount");
topCountAtt.Value = dataRule.TopCount;
dataRuleNode.Attributes.Append(topCountAtt);
XmlAttribute includeChildrenAtt = xmlDom.CreateAttribute("IncludeChildren");
includeChildrenAtt.Value = dataRule.IncludeChildren.ToString();
dataRuleNode.Attributes.Append(includeChildrenAtt);
XmlAttribute dynamicLinkingOrderAtt = xmlDom.CreateAttribute("DynamicLinkingOrder");
dynamicLinkingOrderAtt.Value = dataRule.DynamicLinkingOrder.ToString();
dataRuleNode.Attributes.Append(dynamicLinkingOrderAtt);
XmlAttribute referencingContentIdAtt = xmlDom.CreateAttribute("ReferencingContentId");
referencingContentIdAtt.Value = dataRule.ReferencingContentId;
dataRuleNode.Attributes.Append(referencingContentIdAtt);
XmlAttribute pageIndexAtt = xmlDom.CreateAttribute("PageIndex");
pageIndexAtt.Value = dataRule.PageIndex;
dataRuleNode.Attributes.Append(pageIndexAtt);
XmlAttribute pageSizeAtt = xmlDom.CreateAttribute("PageSize");
pageSizeAtt.Value = dataRule.PageSize;
dataRuleNode.Attributes.Append(pageSizeAtt);
XmlAttribute cachingAtt = xmlDom.CreateAttribute("Caching");
cachingAtt.Value = dataRule.Caching;
dataRuleNode.Attributes.Append(cachingAtt);
}
#endregion
#region add plugins
//add the plugin
XmlNode pluginsNode = xmlDom.CreateElement("plugins");
pageNode.AppendChild(pluginsNode);
foreach (var p in this.Cms_Plugin)
{
XmlNode pluginNode = xmlDom.CreateElement("plugin");
pluginsNode.AppendChild(pluginNode);
XmlAttribute pluginIdAtt = xmlDom.CreateAttribute("PluginId");
pluginIdAtt.Value = p.PluginId.ToString();
pluginNode.Attributes.Append(pluginIdAtt);
XmlAttribute pluginNameAtt = xmlDom.CreateAttribute("PluginName");
pluginNameAtt.Value = p.PluginName;
pluginNode.Attributes.Append(pluginNameAtt);
XmlAttribute pluginTypeAtt = xmlDom.CreateAttribute("PluginType");
pluginTypeAtt.Value = p.PluginType;
pluginNode.Attributes.Append(pluginTypeAtt);
}
#endregion
#region add content template in page
XmlNode contentTemplatesInPageNode = xmlDom.CreateElement("contentTemplatesInPage");
pageNode.AppendChild(contentTemplatesInPageNode);
if (!this.Cms_ContentTemplateInPageHolder.IsLoaded)
{
this.Cms_ContentTemplateInPageHolder.Load();
}
foreach (var contentTemplateInPage in this.Cms_ContentTemplateInPageHolder)
{
XmlNode contentTemplateInPageNode = xmlDom.CreateElement("contentTemplateInPage");
contentTemplatesInPageNode.AppendChild(contentTemplateInPageNode);
//add position
XmlAttribute positionAtt = xmlDom.CreateAttribute("Position");
positionAtt.Value = contentTemplateInPage.Position;
contentTemplateInPageNode.Attributes.Append(positionAtt);
//add content template
//if the ComponentValue is not null ,mean that the content template is a plugin template.
//else that is a CMS content template.
if (!StringExtensions.IsNullOrEmptyTrim(contentTemplateInPage.ComponentValue))
{
XmlAttribute ComponentValueAtt = xmlDom.CreateAttribute("ComponentValue");
ComponentValueAtt.Value = contentTemplateInPage.ComponentValue;
contentTemplateInPageNode.Attributes.Append(ComponentValueAtt);
}
else
{
XmlAttribute contentTemplateIdAtt = xmlDom.CreateAttribute("ContentTemplateUUID");
contentTemplateIdAtt.Value = contentTemplateInPage.ContentTemplateUUIDFromReference.ToString();
contentTemplateInPageNode.Attributes.Append(contentTemplateIdAtt);
}
//add order
XmlAttribute contentTemplateOrderAtt = xmlDom.CreateAttribute("Order");
contentTemplateOrderAtt.Value = contentTemplateInPage.Order.ToString();
contentTemplateInPageNode.Attributes.Append(contentTemplateOrderAtt);
#region add parameterValues
//add paramter values
XmlNode parameterValuesNode = xmlDom.CreateElement("parameterValues");
contentTemplateInPageNode.AppendChild(parameterValuesNode);
if (!contentTemplateInPage.Cms_ParameterValues.IsLoaded)
{
contentTemplateInPage.Cms_ParameterValues.Load();
}
foreach (var parameterValue in contentTemplateInPage.Cms_ParameterValues)
{
XmlNode parameterValueNode = xmlDom.CreateElement("parameterValue");
parameterValuesNode.AppendChild(parameterValueNode);
XmlAttribute parameterNameAtt = xmlDom.CreateAttribute("Name");
parameterNameAtt.Value = parameterValue.Name;
parameterValueNode.Attributes.Append(parameterNameAtt);
XmlAttribute parameterDataTypeAtt = xmlDom.CreateAttribute("DataType");
parameterDataTypeAtt.Value = parameterValue.DataType;
parameterValueNode.Attributes.Append(parameterDataTypeAtt);
XmlAttribute parameterValueAtt = xmlDom.CreateAttribute("Value");
parameterValueAtt.Value = parameterValue.Value;
parameterValueNode.Attributes.Append(parameterValueAtt);
}
#endregion
}
#endregion
xmlDom.WriteTo(writer);
}
#endregion
public static Cms_Page DeserializeFromNode(XmlNode parentNode, string nodeName)
{
var page = new Cms_Page();
XmlNode pageNode = parentNode.SelectSingleNode(nodeName);
if (pageNode != null)
{
page.UUID = new Guid(pageNode.Attributes["UUID"].Value);
page.PageName = pageNode.Attributes["Name"].Value;
return page;
}
return null;
}
public void SerializeAsNode(XmlNode parentNode, string nodeName)
{
var xmlDom = parentNode.OwnerDocument;
//add page node
XmlNode pageNode = parentNode.OwnerDocument.CreateElement(nodeName);
parentNode.AppendChild(pageNode);
XmlAttribute pageUUIDAtt = xmlDom.CreateAttribute("UUID");
pageUUIDAtt.Value = this.UUID.ToString();
pageNode.Attributes.Append(pageUUIDAtt);
XmlAttribute pageNameAtt = xmlDom.CreateAttribute("Name");
pageNameAtt.Value = this.PageName;
pageNode.Attributes.Append(pageNameAtt);
}
#endregion
#region IVersionable Members
/// <summary>
/// Gets the name of the snapshot form.
/// </summary>
/// <value>The name of the snapshot form.</value>
public string FormSchemaName
{
get { return "Page"; }
}
public void OnRevert(IVersionItem workingItem, IVersionItem toBeRevertedItem)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
var page = dataContext.QueryPage(this.UUID).First();
page.PageName = this.PageName;
//restor page template must to query the page template instance.
page.Cms_PageTemplate = dataContext.QueryPageTemplate(this.Cms_PageTemplate.UUID).FirstOrDefault();
page.Url = this.Url;
page.DefaultParams = this.DefaultParams;
page.ShowInNavigation = this.ShowInNavigation;
if (this.Cms_ParentPage != null)
{
page.Cms_ParentPage = dataContext.QueryPage(this.Cms_ParentPage.UUID).FirstOrDefault();
}
//restore data rule
//the Data Rule is deserilized from the history
// //can not use the DataRule.Copy
page.ClearDataRule(dataContext);
foreach (var dataRule in this.Cms_DataRule)
{
Cms_DataRule newDataRule = new Cms_DataRule();
newDataRule.DataName = dataRule.DataName;
if (dataRule.Cms_Folder != null)
{
newDataRule.Cms_Folder = dataContext.QueryFolder(dataRule.Cms_Folder.UUID).First();
}
newDataRule.ValueRule = dataRule.ValueRule;
newDataRule.ValueType = dataRule.ValueType;
newDataRule.Order = dataRule.Order;
newDataRule.OrderBy = dataRule.OrderBy;
newDataRule.TopCount = dataRule.TopCount;
newDataRule.IncludeChildren = dataRule.IncludeChildren;
newDataRule.DynamicLinkingOrder = dataRule.DynamicLinkingOrder;
newDataRule.ReferencingContentId = dataRule.ReferencingContentId;
newDataRule.PageIndex = dataRule.PageIndex;
newDataRule.PageSize = dataRule.PageSize;
newDataRule.Caching = dataRule.Caching;
page.Cms_DataRule.Add(newDataRule);
}
//restore plugins
page.ClearPlugins(dataContext);
foreach (var plugin in this.Cms_Plugin)
{
Cms_Plugin newPlugin = new Cms_Plugin();
newPlugin.PluginName = plugin.PluginName;
newPlugin.PluginType = plugin.PluginType;
page.Cms_Plugin.Add(newPlugin);
}
//resotre content template and parameterValues
page.ClearContentTemplateInPage(dataContext);
foreach (var contentTemplateInPage in this.Cms_ContentTemplateInPageHolder)
{
Cms_ContentTemplateInPageHolder newContentTemplateInHolder = new Cms_ContentTemplateInPageHolder();
page.Cms_ContentTemplateInPageHolder.Add(newContentTemplateInHolder);
newContentTemplateInHolder.Position = contentTemplateInPage.Position;
newContentTemplateInHolder.Order = contentTemplateInPage.Order;
newContentTemplateInHolder.ComponentValue = contentTemplateInPage.ComponentValue;
if (contentTemplateInPage.Cms_ContentTemplate != null)
{
newContentTemplateInHolder.Cms_ContentTemplate = dataContext.QueryContentTemplate(contentTemplateInPage.Cms_ContentTemplate.UUID).FirstOrDefault();
}
foreach (var parameterValue in contentTemplateInPage.Cms_ParameterValues)
{
Cms_ParameterValues newParameterValue = new Cms_ParameterValues();
newParameterValue.Name = parameterValue.Name;
newParameterValue.DataType = parameterValue.DataType;
newParameterValue.Value = parameterValue.Value;
newContentTemplateInHolder.Cms_ParameterValues.Add(newParameterValue);
}
}
dataContext.SaveChanges();
}
#endregion
#region clear children
/// <summary>
/// Clears the data rule.
/// </summary>
/// <param name="dataContext">The data context.</param>
internal void ClearDataRule(IEverestCmsDataContext dataContext)
{
if (this.EntityState == System.Data.EntityState.Added)
{
return;
}
if (!this.Cms_DataRule.IsLoaded)
{
this.Cms_DataRule.Load();
}
Cms_DataRule dataRule = null;
do
{
dataRule = Cms_DataRule.FirstOrDefault();
if (dataRule != null)
{
dataContext.DeleteObject(dataRule);
}
} while (dataRule != null);
}
/// <summary>
/// Clears the plugins.
/// </summary>
/// <param name="dataContext">The data context.</param>
internal void ClearPlugins(IEverestCmsDataContext dataContext)
{
if (this.EntityState == System.Data.EntityState.Added)
{
return;
}
if (!this.Cms_Plugin.IsLoaded)
{
this.Cms_Plugin.Load();
}
Cms_Plugin plugin = null;
do
{
plugin = this.Cms_Plugin.FirstOrDefault();
if (plugin != null)
{
dataContext.DeleteObject(plugin);
}
} while (plugin != null);
}
/// <summary>
/// Clears the content template in page.
/// </summary>
/// <param name="dataContext">The data context.</param>
internal void ClearContentTemplateInPage(IEverestCmsDataContext dataContext)
{
if (!this.Cms_ContentTemplateInPageHolder.IsLoaded)
{
this.Cms_ContentTemplateInPageHolder.Load();
}
Cms_ContentTemplateInPageHolder contentTemplateInPage = null;
do
{
contentTemplateInPage = this.Cms_ContentTemplateInPageHolder.FirstOrDefault();
if (contentTemplateInPage != null)
{
dataContext.DeleteObject(contentTemplateInPage);
}
} while (contentTemplateInPage != null);
}
#endregion
#region Copy New
public Cms_Page CopyNew()
{
Cms_Page page = new Cms_Page();
page.UUID = Guid.NewGuid();
page.PageName = this.PageName;
this.Cms_PageTemplateReference.Load(this.Cms_PageTemplate, this.EntityState);
page.Cms_PageTemplate = this.Cms_PageTemplate;
this.Cms_ParentPageReference.Load(this.Cms_ParentPage, this.EntityState);
page.Cms_ParentPage = this.Cms_ParentPage;
page.Url = this.Url;
page.DefaultParams = this.DefaultParams;
page.ShowInNavigation = this.ShowInNavigation;
page.NavigationText = this.NavigationText;
page.NavigationOrder = this.NavigationOrder;
page.Allows = this.Allows;
page.Denies = this.Denies;
//copy the data rule
if (this.Cms_DataRule.IsLoaded == false)
{
this.Cms_DataRule.Load();
}
foreach (var dataRule in this.Cms_DataRule)
{
Cms_DataRule newDataRule = dataRule.Copy();
page.Cms_DataRule.Add(newDataRule);
}
//copy the plugins
if (!this.Cms_Plugin.IsLoaded)
{
this.Cms_Plugin.Load();
}
foreach (var plugin in this.Cms_Plugin)
{
Cms_Plugin newPlugin = new Cms_Plugin();
newPlugin.PluginName = plugin.PluginName;
newPlugin.PluginType = plugin.PluginType;
page.Cms_Plugin.Add(newPlugin);
}
//copy the content template in page holder.
if (!this.Cms_ContentTemplateInPageHolder.IsLoaded)
{
this.Cms_ContentTemplateInPageHolder.Load();
}
foreach (var contentTemplateInPage in this.Cms_ContentTemplateInPageHolder)
{
Cms_ContentTemplateInPageHolder newContentTemplateInHolder = new Cms_ContentTemplateInPageHolder();
page.Cms_ContentTemplateInPageHolder.Add(newContentTemplateInHolder);
newContentTemplateInHolder.Position = contentTemplateInPage.Position;
newContentTemplateInHolder.Order = contentTemplateInPage.Order;
newContentTemplateInHolder.ComponentType = contentTemplateInPage.ComponentType;
newContentTemplateInHolder.ComponentValue = contentTemplateInPage.ComponentValue;
//if the ComponentValue is not null ,mean that the content template is a plugin template.
//else that is a CMS content template.
if (StringExtensions.IsNullOrEmptyTrim(contentTemplateInPage.ComponentValue))
{
contentTemplateInPage.Cms_ContentTemplateReference.Load();
newContentTemplateInHolder.Cms_ContentTemplate = contentTemplateInPage.Cms_ContentTemplate;
}
//load the parameter value.
contentTemplateInPage.Cms_ParameterValues.Load();
foreach (var parameterValue in contentTemplateInPage.Cms_ParameterValues)
{
Cms_ParameterValues newParameterValue = new Cms_ParameterValues();
newParameterValue.Name = parameterValue.Name;
newParameterValue.DataType = parameterValue.DataType;
newParameterValue.Value = parameterValue.Value;
newContentTemplateInHolder.Cms_ParameterValues.Add(newParameterValue);
}
}
return page;
}
#endregion
#region IRuleEntity Members
public IEnumerable<RuleViolation> GetRuleViolations()
{
var dataContext = EverestCmsEntities.GetDataContext();
List<RuleViolation> list = new List<RuleViolation>();
var rootDirectories = Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory).GetDirectories();
if (rootDirectories.Where(d => d.Name.Equals(PageName, StringComparison.InvariantCultureIgnoreCase)).Count() != 0)
{
list.Add(new RuleViolation("PageName", this.PageName, string.Format(Resources.PageNameInvalid, PageName)));
return list;
}
this.aspnet_ApplicationsReference.Load(this.aspnet_Applications, this.EntityState);
Guid? parentPageUUID = null;
if (Cms_ParentPage != null)
{
parentPageUUID = Cms_ParentPage.UUID;
}
if (dataContext.IsPageExists(this.aspnet_Applications.ApplicationName, this.LoweredPageName, this.UUID, parentPageUUID).Exists())
{
if (this.Base == null)
{
list.Add(new RuleViolation("PageName", this.PageName, Resources.PageAlreadyExists));
}
}
return list;
}
#endregion
#region Navigation
public bool IsTop
{
get
{
return this.Cms_ParentPageReference.EntityKey.GetKeyValue<Guid?>("UUID") == null;
}
}
public string LinkText
{
get
{
if (!StringExtensions.IsNullOrEmptyTrim(this.NavigationText))
{
return this.NavigationText;
}
return this.PageName;
}
}
#endregion
#region VirtualPath
public string VirtualPath
{
get
{
return CachedData.GetPageVirtualPath(this.UUID);
}
}
#endregion
}
}
|