/*
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.Text;
using System.IO;
using System.Xml;
using Everest.Library.Data.Rule;
using Everest.Library.Data;
using Everest.Library.Data.Entity;
using Everest.Library.ExtensionMethod;
using Everest.CmsServices.Web;
namespace Everest.CmsServices.Models{
public partial class aspnet_Applications : IRuleEntity
{
public aspnet_Applications()
{
this.ApplicationId = Guid.NewGuid();
this.CreateDate = DateTime.Now;
}
#region IRuleEntity Members
public IEnumerable<RuleViolation> GetRuleViolations()
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
List<RuleViolation> violations = new List<RuleViolation>();
this.ApplicationName = this.ApplicationName.TryTrim();
this.BaseApplication = this.BaseApplication.TryTrim();
if (StringExtensions.IsNullOrEmptyTrim(this.ApplicationName))
{
violations.Add(new RuleViolation("ApplicationName", this.ApplicationName, string.Format(Resources.FieldIsRequired, "ApplicationName")));
}
if (this.EntityState == System.Data.EntityState.Added && dataContext.IsApplicationExists(this.ApplicationName, this.ApplicationId).Exists())
{
violations.Add(new RuleViolation("ApplicationName", this.ApplicationName, Resources.ApplicationIsAlreadyExists));
}
if (StringExtensions.IsNullOrEmptyTrim(this.BaseApplication) && !this.ApplicationName.Equals(CmsGlobal.RootApplicationName, StringComparison.OrdinalIgnoreCase))
{
violations.Add(new RuleViolation("BaseApplication", this.BaseApplication, string.Format(Resources.FieldIsRequired, "BaseApplication")));
}
if (!StringExtensions.IsNullOrEmptyTrim(this.HostName))
{
string[] hostNames = HostName.Split(',');
foreach (var domain in hostNames)
{
if (dataContext.IsHostNameExists(domain, this.VirtualPath, this.ApplicationId).Exists())
{
violations.Add(new RuleViolation("HostName", HostName, string.Format(Resources.DomainAlreadyUsed, domain)));
}
}
}
return violations;
}
#endregion
#region Serialize
public static aspnet_Applications DeserializeFromNode(XmlNode parentNode)
{
var aspnet_Applications = new aspnet_Applications();
XmlNode applicationNode = parentNode.SelectSingleNode("application");
if (applicationNode != null)
{
aspnet_Applications.ApplicationId = new Guid(applicationNode.Attributes["ApplicationId"].Value);
aspnet_Applications.ApplicationName = applicationNode.Attributes["ApplicationName"].Value;
return aspnet_Applications;
}
return null;
}
public void SerializeAsNode(XmlNode parentNode)
{
var xmlDom = parentNode.OwnerDocument;
//add applicationNode
XmlNode applicationNode = parentNode.OwnerDocument.CreateElement("application");
parentNode.AppendChild(applicationNode);
XmlAttribute applicationIdAtt = xmlDom.CreateAttribute("ApplicationId");
applicationIdAtt.Value = this.ApplicationId.ToString();
applicationNode.Attributes.Append(applicationIdAtt);
XmlAttribute applicationNameAtt = xmlDom.CreateAttribute("ApplicationName");
applicationNameAtt.Value = this.ApplicationName;
applicationNode.Attributes.Append(applicationNameAtt);
}
#endregion
public bool IsRelease
{
get
{
return this.Release.HasValue && this.Release.Value == true;
}
}
public CmsVisitType VisitType
{
get
{
if (string.IsNullOrEmpty(HostName))
{
return CmsVisitType.Normal;
}
if (!string.IsNullOrEmpty(HostName) && !string.IsNullOrEmpty(VirtualPath))
{
return CmsVisitType.HostNVirtual;
}
return CmsVisitType.Host;
}
}
}
}
|