Fixing some problems with LINQ to Umbraco:

- inherited properties not properly managed
- non-mandatory structs are handled
- adding NodeName and Path to the BaseDocType class (obsoleted Name property, but not removed)

[TFS Changeset #76091]
This commit is contained in:
slace
2010-08-22 05:16:12 +00:00
parent 1d45486465
commit b68bf3f627
8 changed files with 516 additions and 426 deletions

View File

@@ -16,7 +16,7 @@ namespace umbraco.Linq.Core
{
#region Internal Storage
private int _Id;
private string _name;
private string _nodeName;
private string _versionId;
private int _templateId;
private int _parentId;
@@ -24,6 +24,7 @@ namespace umbraco.Linq.Core
private User _writer;
private int creatorID;
private User _creator;
private string _path;
private IEnumerable<DocTypeBase> _ancestors;
private AssociationTree<DocTypeBase> _children;
#endregion
@@ -77,22 +78,36 @@ namespace umbraco.Linq.Core
/// </summary>
/// <value>The name.</value>
[Field]
[UmbracoInfo("nodeName", DisplayName = "Name", Mandatory = true), DataMember(Name = "Name")]
[UmbracoInfo("nodeName", DisplayName = "NodeName", Mandatory = true), DataMember(Name = "NodeName")]
public virtual string NodeName
{
get
{
return this._nodeName;
}
set
{
if (this._nodeName != value)
{
this.RaisePropertyChanging();
this._nodeName = value;
this.IsDirty = true;
this.RaisePropertyChanged("NodeName");
}
}
}
[Field]
[Obsolete("Name property is obsolete, use NodeName instead")] //this is because most people expect NodeName not Name as the property
public virtual string Name
{
get
{
return this._name;
return this.NodeName;
}
set
{
if (this._name != value)
{
this.RaisePropertyChanging();
this._name = value;
this.IsDirty = true;
this.RaisePropertyChanged("Name");
}
this.NodeName = value;
}
}
@@ -115,7 +130,7 @@ namespace umbraco.Linq.Core
this.RaisePropertyChanging();
this._templateId = value;
this.IsDirty = true;
this.RaisePropertyChanged("Name");
this.RaisePropertyChanged("Template");
}
}
}
@@ -161,7 +176,7 @@ namespace umbraco.Linq.Core
{
this.RaisePropertyChanging();
this._parentId = value;
this.RaisePropertyChanged("Version");
this.RaisePropertyChanged("ParentId");
}
}
}
@@ -197,6 +212,30 @@ namespace umbraco.Linq.Core
[Field]
[UmbracoInfo("level", DisplayName = "Level"), DataMember(Name = "Level")]
public virtual int Level { get; set; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
[Field]
[UmbracoInfo("path", DisplayName = "Path")]
[DataMember(Name = "Path")]
public virtual string Path
{
get
{
return this._path;
}
set
{
if (this._path != value)
{
this.RaisePropertyChanging();
this._path = value;
this.RaisePropertyChanged("Path");
}
}
}
#endregion
#region Parents and Children

View File

@@ -59,6 +59,12 @@ namespace umbraco.Linq.Core
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
string NodeName { get; set; }
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
[Obsolete("Name property is obsolete, use NodeName instead")] //this is because most people expect NodeName not Name as the property
string Name { get; set; }
/// <summary>
/// Parent if current instance
@@ -101,5 +107,10 @@ namespace umbraco.Linq.Core
/// </summary>
/// <value>The name of the writer.</value>
string WriterName { get; }
/// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
string Path { get; set; }
}
}

View File

@@ -320,7 +320,7 @@ namespace umbraco.Linq.Core.Node
node.Id = (int)xml.Attribute("id");
node.ParentNodeId = (int)xml.Attribute("parentID");
node.Name = (string)xml.Attribute("nodeName");
node.NodeName = (string)xml.Attribute("nodeName");
node.Version = (string)xml.Attribute("version");
node.CreateDate = (DateTime)xml.Attribute("createDate");
node.SortOrder = (int)xml.Attribute("sortOrder");
@@ -337,12 +337,29 @@ namespace umbraco.Linq.Core.Node
{
var attr = ReflectionAssistance.GetUmbracoInfoAttribute(p);
var data = xml.Element(Casing.SafeAliasWithForcingCheck(attr.Alias)).Value;
if (p.PropertyType == typeof(int) && string.IsNullOrEmpty(data))
data = "-1";
//here is where you would put a check if the property exists in the XML
//I'm NOT putting the check in here, as there will be unusual results if the XML doesn't
//contain the property, you'd get nulls when something shouldn't really be null
string data = xml.Element(Casing.SafeAliasWithForcingCheck(attr.Alias)).Value;
// TODO: Address how Convert.ChangeType works in globalisation
p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null);
if (p.PropertyType.IsValueType && typeof(Nullable<>).IsAssignableFrom(p.PropertyType.GetGenericTypeDefinition()))
{
if (string.IsNullOrEmpty(data))
{
//non-mandatory structs which have no value will be null
p.SetValue(node, null, null);
}
else
{
//non-mandatory structs which do have a value have to be cast based on the type of their Nullable<T>, found from the first (well, only) GenericArgument
p.SetValue(node, Convert.ChangeType(data, p.PropertyType.GetGenericArguments()[0]), null);
}
}
else
{
// TODO: Address how Convert.ChangeType works in globalisation
p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null);
}
}
}
}

View File

@@ -146,4 +146,4 @@
<PropertyGroup>
<PostBuildEvent>XCOPY "$(TargetPath)" "$(SolutionDir)\umbraco\presentation\bin" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
</Project>

View File

@@ -9,6 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
SHOCKING.testrunconfig = SHOCKING.testrunconfig
umbraco weekly.build = umbraco weekly.build
umbraco.build = umbraco.build
umbraco3.vsmdi = umbraco3.vsmdi
UMBRACOELISE.testrunconfig = UMBRACOELISE.testrunconfig
UMBRACOHUMMER.testrunconfig = UMBRACOHUMMER.testrunconfig
EndProjectSection
@@ -154,7 +155,7 @@ Global
SccLocalPath13 = umbraco.Test
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = umbraco.vsmdi
CategoryFile = umbraco3.vsmdi
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

View File

@@ -394,7 +394,10 @@ jQuery(function() { refreshDropDowns(); });
propertiesPH.Controls.Add(new LiteralControl("<ul class='genericPropertyList' id=\"t_general_Contents\">"));
foreach (cms.businesslogic.propertytype.PropertyType pt in cType.PropertyTypes)
{
if (pt.ContentTypeId == cType.Id && !inTab.ContainsKey(pt.Id.ToString()))
//This use to be:
//if (pt.ContentTypeId == cType.Id && !inTab.ContainsKey(pt.Id.ToString())
//But seriously, if it's not on a tab the tabId is 0, it's a lot easier to read IMO
if (pt.ContentTypeId == cType.Id && pt.TabId == 0)
{
GenericProperties.GenericPropertyWrapper gpw = new umbraco.controls.GenericProperties.GenericPropertyWrapper();

View File

@@ -11,26 +11,26 @@ using umbraco.IO;
namespace umbraco.presentation.umbraco.dialogs
{
public partial class ExportCode : BasePages.UmbracoEnsuredPage
{
private Dictionary<Guid, Type> dataTypeMapping = new Dictionary<Guid, Type>();
private const string EXPORT_FOLDER = "/exported-doctypes/";
public partial class ExportCode : BasePages.UmbracoEnsuredPage
{
private Dictionary<Guid, Type> dataTypeMapping = new Dictionary<Guid, Type>();
private const string EXPORT_FOLDER = "/exported-doctypes/";
private List<DocumentType> _docTypes;
public List<DocumentType> DocTypes
{
get
{
if (_docTypes == null)
{
_docTypes = DocumentType.GetAllAsList();
}
return _docTypes;
}
}
private List<DocumentType> _docTypes;
public List<DocumentType> DocTypes
{
get
{
if (_docTypes == null)
{
_docTypes = DocumentType.GetAllAsList();
}
return _docTypes;
}
}
#region POCO Template
private readonly static string POCO_TEMPLATE = @"using System;
#region POCO Template
private readonly static string POCO_TEMPLATE = @"using System;
using System.Linq;
using umbraco.Linq.Core;
using System.Collections.Generic;
@@ -38,456 +38,469 @@ using System.Collections.Generic;
namespace {0} {{
public partial class {1}DataContext : UmbracoDataContext{2} {{
#region Partials
partial void OnCreated();
#endregion
partial void OnCreated();
#endregion
public {1}DataContext() : base()
{{
OnCreated();
}}
{{
OnCreated();
}}
public {1}DataContext(UmbracoDataProvider provider) : base(provider)
{{
OnCreated();
}}
public {1}DataContext(UmbracoDataProvider provider) : base(provider)
{{
OnCreated();
}}
{3}
{3}
}}
{4}
{4}
}}";
#endregion
#endregion
#region Abstraction Template
private readonly static string POCO_ABSTRACTION_TEMPLATE = @"using System;
#region Abstraction Template
private readonly static string POCO_ABSTRACTION_TEMPLATE = @"using System;
using System.Linq;
using umbraco.Linq.Core;
using System.Collections.Generic;
namespace {0} {{
public interface I{1}DataContext : IUmbracoDataContext {{
{2}
public partial interface I{1}DataContext : IUmbracoDataContext {{
{2}
}}
{3}
{3}
}}";
#endregion
#endregion
#region Tree Template
private readonly static string TREE_TEMPLATE = @"
public Tree<{0}> {0}s
{{
get
{{
return this.LoadTree<{0}>();
}}
}}";
#endregion
#region Tree Template
private readonly static string TREE_TEMPLATE = @"
public Tree<{0}> {0}s
{{
get
{{
return this.LoadTree<{0}>();
}}
}}";
#endregion
#region Abstraction Tree Template
private readonly static string TREE_ABSTRACTION_TEMPLATE = @"
IEnumerable<I{0}> I{1}DataContext.{0}s
{{
get
{{
return this.LoadTree<{0}>().OfType<I{0}>();
}}
}}";
#endregion
#region Abstraction Tree Template
private readonly static string TREE_ABSTRACTION_TEMPLATE = @"
IEnumerable<I{0}> I{1}DataContext.{0}s
{{
get
{{
return this.LoadTree<{0}>().OfType<I{0}>();
}}
}}";
#endregion
#region Class Template
//0 - Alias
//1 - class name
//2 - interface or string.Empty
//3 - properties
//4 - child relationships
//5 - interface explicit implementation
//6 - description
private readonly static string CLASS_TEMPLATE = @"
/// <summary>
/// {6}
/// </summary>
[UmbracoInfo(""{0}"")]
[System.Runtime.Serialization.DataContractAttribute()]
[DocType()]
public partial class {1} : {7} {2} {{
public {1}() {{
}}
{3}
{4}
{5}
#region Class Template
//0 - Alias
//1 - class name
//2 - interface or string.Empty
//3 - properties
//4 - child relationships
//5 - interface explicit implementation
//6 - description
private readonly static string CLASS_TEMPLATE = @"
/// <summary>
/// {6}
/// </summary>
[UmbracoInfo(""{0}"")]
[System.Runtime.Serialization.DataContractAttribute()]
[DocType()]
public partial class {1} : {7} {2} {{
public {1}() {{
}}
{3}
{4}
{5}
}}";
#endregion
#endregion
#region Interface Template
//0 - Class name
//1 - properties
//2 - child relationshipts
private readonly static string INTERFACE_TEMPLATE = @"
public interface I{0} : I{3} {{
{1}
{2}
#region Interface Template
//0 - Class name
//1 - properties
//2 - child relationshipts
private readonly static string INTERFACE_TEMPLATE = @"
public partial interface I{0} : I{3} {{
{1}
{2}
}}";
#endregion
#endregion
#region Properties Template
private readonly static string PROPERTIES_TEMPLATE = @"
private {0} _{1};
/// <summary>
/// {2}
/// </summary>
[UmbracoInfo(""{3}"", DisplayName = ""{4}"", Mandatory = {5})]
[Property()]
public virtual {0} {1}
{{
get
{{
return this._{1};
}}
set
{{
if ((this._{1} != value))
{{
this.RaisePropertyChanging();
this._{1} = value;
this.RaisePropertyChanged(""{1}"");
}}
}}
}}";
#endregion
#region Properties Template
private readonly static string PROPERTIES_TEMPLATE = @"
private {0} _{1};
/// <summary>
/// {2}
/// </summary>
[UmbracoInfo(""{3}"", DisplayName = ""{4}"", Mandatory = {5})]
[Property()]
[System.Runtime.Serialization.DataMemberAttribute()]
public virtual {0} {1}
{{
get
{{
return this._{1};
}}
set
{{
if ((this._{1} != value))
{{
this.RaisePropertyChanging();
this._{1} = value;
this.RaisePropertyChanged(""{1}"");
}}
}}
}}";
#endregion
#region Child Relationships Template
private readonly static string CHILD_RELATIONS_TEMPLATE = @"
private AssociationTree<{0}> _{0}s;
public AssociationTree<{0}> {0}s
{{
get
{{
if ((this._{0}s == null))
{{
this._{0}s = this.ChildrenOfType<{0}>();
}}
return this._{0}s;
}}
set
{{
this._{0}s = value;
}}
}}";
#endregion
#region Child Relationships Template
private readonly static string CHILD_RELATIONS_TEMPLATE = @"
private AssociationTree<{0}> _{0}s;
public AssociationTree<{0}> {0}s
{{
get
{{
if ((this._{0}s == null))
{{
this._{0}s = this.ChildrenOfType<{0}>();
}}
return this._{0}s;
}}
set
{{
this._{0}s = value;
}}
}}";
#endregion
#region Child Relationship Abstraction Template
private readonly static string CHILD_RELATIONS_ABSTRACTION_TEMPLATE = @"
IEnumerable<I{0}> I{1}.{0}s
{{
get
{{
return this.{0}s.OfType<I{0}>();
}}
}}";
#endregion
#region Child Relationship Abstraction Template
private readonly static string CHILD_RELATIONS_ABSTRACTION_TEMPLATE = @"
IEnumerable<I{0}> I{1}.{0}s
{{
get
{{
return this.{0}s.OfType<I{0}>();
}}
}}";
#endregion
protected void Page_Load(object sender, EventArgs e)
{
btnGenerate.Text = ui.Text("create");
}
protected void Page_Load(object sender, EventArgs e)
{
btnGenerate.Text = ui.Text("create");
}
protected void btnGenerate_Click(object sender, EventArgs e)
{
var includeInterfaces = ddlGenerationMode.SelectedValue == "abs";
protected void btnGenerate_Click(object sender, EventArgs e)
{
var includeInterfaces = ddlGenerationMode.SelectedValue == "abs";
var poco = string.Format(POCO_TEMPLATE,
this.txtNamespace.Text,
this.txtDataContextName.Text,
includeInterfaces ? ", I" + this.txtDataContextName.Text + "DataContext" : string.Empty,
GenerateDataContextCollections(includeInterfaces),
GenerateClasses(includeInterfaces)
);
var poco = string.Format(POCO_TEMPLATE,
this.txtNamespace.Text,
this.txtDataContextName.Text,
includeInterfaces ? ", I" + this.txtDataContextName.Text + "DataContext" : string.Empty,
GenerateDataContextCollections(includeInterfaces),
GenerateClasses(includeInterfaces)
);
// As we save in a new folder under Media, we need to ensure it exists
EnsureExportFolder();
string pocoFile = Path.Combine(IO.SystemDirectories.Media + EXPORT_FOLDER, this.txtDataContextName.Text + ".txt");
// As we save in a new folder under Media, we need to ensure it exists
EnsureExportFolder();
string pocoFile = Path.Combine(IO.SystemDirectories.Media + EXPORT_FOLDER, this.txtDataContextName.Text + ".txt");
using (var writer = new StreamWriter(IO.IOHelper.MapPath(pocoFile)))
{
writer.Write(poco);
}
using (var writer = new StreamWriter(IO.IOHelper.MapPath(pocoFile)))
{
writer.Write(poco);
}
lnkPoco.NavigateUrl = pocoFile;
lnkPoco.NavigateUrl = pocoFile;
pnlButtons.Visible = false;
pane_files.Visible = true;
pnlButtons.Visible = false;
pane_files.Visible = true;
if (includeInterfaces)
{
var abstraction = string.Format(POCO_ABSTRACTION_TEMPLATE,
this.txtNamespace.Text,
this.txtDataContextName.Text,
GenerateDataContextAbstractCollections(),
GenerateClassAbstraction()
);
if (includeInterfaces)
{
var abstraction = string.Format(POCO_ABSTRACTION_TEMPLATE,
this.txtNamespace.Text,
this.txtDataContextName.Text,
GenerateDataContextAbstractCollections(),
GenerateClassAbstraction()
);
string abstractionFile = Path.Combine(IO.SystemDirectories.Media + EXPORT_FOLDER, "I" + this.txtDataContextName.Text + ".txt");
string abstractionFile = Path.Combine(IO.SystemDirectories.Media + EXPORT_FOLDER, "I" + this.txtDataContextName.Text + ".txt");
using (var writer = new StreamWriter(IO.IOHelper.MapPath(abstractionFile)))
{
writer.Write(abstraction);
}
using (var writer = new StreamWriter(IO.IOHelper.MapPath(abstractionFile)))
{
writer.Write(abstraction);
}
lnkAbstractions.NavigateUrl = abstractionFile;
lnkAbstractions.Enabled = true;
}
}
lnkAbstractions.NavigateUrl = abstractionFile;
lnkAbstractions.Enabled = true;
}
}
private string GenerateClassAbstraction()
{
var sb = new StringBuilder();
private string GenerateClassAbstraction()
{
var sb = new StringBuilder();
foreach (var dt in this.DocTypes)
{
var baseType = "DocTypeBase";
if (dt.MasterContentType > 0)
{
var parent = DocTypes.First(d => d.Id == dt.MasterContentType);
baseType = GenerateTypeName(parent.Alias);
}
foreach (var dt in this.DocTypes)
{
var baseType = "DocTypeBase";
if (dt.MasterContentType > 0)
{
var parent = DocTypes.First(d => d.Id == dt.MasterContentType);
baseType = GenerateTypeName(parent.Alias);
}
sb.AppendLine(string.Format(INTERFACE_TEMPLATE,
GenerateTypeName(dt.Alias),
GenerateAbstractProperties(dt),
GenerateAbstractRelations(dt),
baseType
)
);
}
sb.AppendLine(string.Format(INTERFACE_TEMPLATE,
GenerateTypeName(dt.Alias),
GenerateAbstractProperties(dt),
GenerateAbstractRelations(dt),
baseType
)
);
}
return sb.ToString();
}
return sb.ToString();
}
private string GenerateAbstractRelations(DocumentType dt)
{
var sb = new StringBuilder();
private string GenerateAbstractRelations(DocumentType dt)
{
var sb = new StringBuilder();
var children = dt.AllowedChildContentTypeIDs;
foreach (var child in DocTypes.Where(d => children.Contains(d.Id)))
{
sb.AppendLine(string.Format("IEnumerable<I{0}> {0}s {{ get; }}",
GenerateTypeName(child.Alias)
)
);
}
var children = dt.AllowedChildContentTypeIDs;
foreach (var child in DocTypes.Where(d => children.Contains(d.Id)))
{
sb.AppendLine(string.Format("IEnumerable<I{0}> {0}s {{ get; }}",
GenerateTypeName(child.Alias)
)
);
}
return sb.ToString();
}
return sb.ToString();
}
private string GenerateAbstractProperties(DocumentType dt)
{
var sb = new StringBuilder();
private string GenerateAbstractProperties(DocumentType dt)
{
var sb = new StringBuilder();
foreach (var pt in dt.PropertyTypes)
{
sb.AppendLine(string.Format("{0} {1} {{ get; set; }}",
GetDotNetType(pt),
GenerateTypeName(pt.Alias)
)
);
}
foreach (var pt in
dt.getVirtualTabs.Where(x => x.ContentType == dt.Id).SelectMany(x => x.PropertyTypes)
.Concat(dt.PropertyTypes.Where(x => x.ContentTypeId == dt.Id && x.TabId == 0))
)
{
sb.AppendLine(string.Format("{0} {1} {{ get; set; }}",
GetDotNetType(pt),
GenerateTypeName(pt.Alias)
)
);
}
return sb.ToString();
}
return sb.ToString();
}
private string GenerateDataContextAbstractCollections()
{
var sb = new StringBuilder();
foreach (var dt in this.DocTypes)
{
sb.AppendLine(string.Format("IEnumerable<I{0}> {0}s {{ get; }}", GenerateTypeName(dt.Alias)));
}
return sb.ToString();
}
private string GenerateDataContextAbstractCollections()
{
var sb = new StringBuilder();
foreach (var dt in this.DocTypes)
{
sb.AppendLine(string.Format("IEnumerable<I{0}> {0}s {{ get; }}", GenerateTypeName(dt.Alias)));
}
return sb.ToString();
}
private string GenerateClasses(bool includeInterfaces)
{
var sb = new StringBuilder();
private string GenerateClasses(bool includeInterfaces)
{
var sb = new StringBuilder();
foreach (var dt in DocTypes)
{
string className = GenerateTypeName(dt.Alias);
foreach (var dt in DocTypes)
{
string className = GenerateTypeName(dt.Alias);
var baseType = "DocTypeBase";
if (dt.MasterContentType > 0)
{
var parent = DocTypes.First(d => d.Id == dt.MasterContentType);
baseType = GenerateTypeName(parent.Alias);
}
var baseType = "DocTypeBase";
if (dt.MasterContentType > 0)
{
var parent = DocTypes.First(d => d.Id == dt.MasterContentType);
baseType = GenerateTypeName(parent.Alias);
}
sb.Append(string.Format(CLASS_TEMPLATE,
dt.Alias,
className,
includeInterfaces ? ", I" + className : string.Empty,
GenerateProperties(dt),
GenerateChildRelationships(dt),
includeInterfaces ? GenerateAbstractionImplementation(dt) : string.Empty,
FormatForComment(dt.Description),
baseType
)
);
}
sb.Append(string.Format(CLASS_TEMPLATE,
dt.Alias,
className,
includeInterfaces ? ", I" + className : string.Empty,
GenerateProperties(dt),
GenerateChildRelationships(dt),
includeInterfaces ? GenerateAbstractionImplementation(dt) : string.Empty,
FormatForComment(dt.Description),
baseType
)
);
}
return sb.ToString();
}
return sb.ToString();
}
private string GenerateAbstractionImplementation(DocumentType dt)
{
var sb = new StringBuilder();
private string GenerateAbstractionImplementation(DocumentType dt)
{
var sb = new StringBuilder();
var children = dt.AllowedChildContentTypeIDs;
foreach (var child in DocTypes.Where(d => children.Contains(d.Id)))
{
sb.Append(string.Format(CHILD_RELATIONS_ABSTRACTION_TEMPLATE,
GenerateTypeName(child.Alias),
GenerateTypeName(dt.Alias)
)
);
}
return sb.ToString();
}
var children = dt.AllowedChildContentTypeIDs;
foreach (var child in DocTypes.Where(d => children.Contains(d.Id)))
{
sb.Append(string.Format(CHILD_RELATIONS_ABSTRACTION_TEMPLATE,
GenerateTypeName(child.Alias),
GenerateTypeName(dt.Alias)
)
);
}
return sb.ToString();
}
private object GenerateChildRelationships(DocumentType dt)
{
var sb = new StringBuilder();
var children = dt.AllowedChildContentTypeIDs;
foreach (var child in DocTypes.Where(d => children.Contains(d.Id)))
{
sb.Append(string.Format(CHILD_RELATIONS_TEMPLATE,
GenerateTypeName(child.Alias)
)
);
}
return sb.ToString();
}
private object GenerateChildRelationships(DocumentType dt)
{
var sb = new StringBuilder();
var children = dt.AllowedChildContentTypeIDs;
foreach (var child in DocTypes.Where(d => children.Contains(d.Id)))
{
sb.Append(string.Format(CHILD_RELATIONS_TEMPLATE,
GenerateTypeName(child.Alias)
)
);
}
return sb.ToString();
}
private object GenerateProperties(DocumentType dt)
{
var sb = new StringBuilder();
foreach (var pt in dt.PropertyTypes)
{
sb.Append(string.Format(PROPERTIES_TEMPLATE,
GetDotNetType(pt),
GenerateTypeName(pt.Alias),
FormatForComment(pt.Description),
pt.Alias,
pt.Name,
pt.Mandatory.ToString().ToLower()
)
);
}
private object GenerateProperties(DocumentType dt)
{
var sb = new StringBuilder();
foreach (var pt in
dt.getVirtualTabs.Where(x => x.ContentType == dt.Id).SelectMany(x => x.PropertyTypes)
.Concat(dt.PropertyTypes.Where(x => x.ContentTypeId == dt.Id && x.TabId == 0))
)
{
sb.Append(string.Format(PROPERTIES_TEMPLATE,
GetDotNetType(pt),
GenerateTypeName(pt.Alias),
FormatForComment(pt.Description),
pt.Alias,
pt.Name,
pt.Mandatory.ToString().ToLower()
)
);
}
return sb.ToString();
}
return sb.ToString();
}
private string GetDotNetType(PropertyType pt)
{
Guid id = pt.DataTypeDefinition.DataType.Id;
if (!dataTypeMapping.ContainsKey(id))
{
var defaultData = pt.DataTypeDefinition.DataType.Data as DefaultData;
if (defaultData != null) //first lets see if it inherits from DefaultData, pretty much all do
{
switch (defaultData.DatabaseType)
{
case DBTypes.Integer:
dataTypeMapping.Add(id, typeof(int));
break;
case DBTypes.Date:
dataTypeMapping.Add(id, typeof(DateTime));
break;
case DBTypes.Nvarchar:
case DBTypes.Ntext:
dataTypeMapping.Add(id, typeof(string));
break;
default:
dataTypeMapping.Add(id, typeof(object));
break;
}
}
else //hmm so it didn't, lets try something else
{
var dbType = BusinessLogic.Application.SqlHelper.ExecuteScalar<string>(@"SELECT [t0].[dbType] FROM [cmsDataType] AS [t0] WHERE [t0].[controlId] = @p0", BusinessLogic.Application.SqlHelper.CreateParameter("@p0", id));
private string GetDotNetType(PropertyType pt)
{
Guid id = pt.DataTypeDefinition.DataType.Id;
if (!dataTypeMapping.ContainsKey(id))
{
var defaultData = pt.DataTypeDefinition.DataType.Data as DefaultData;
if (defaultData != null) //first lets see if it inherits from DefaultData, pretty much all do
{
switch (defaultData.DatabaseType)
{
case DBTypes.Integer:
dataTypeMapping.Add(id, typeof(int));
break;
case DBTypes.Date:
dataTypeMapping.Add(id, typeof(DateTime));
break;
case DBTypes.Nvarchar:
case DBTypes.Ntext:
dataTypeMapping.Add(id, typeof(string));
break;
default:
dataTypeMapping.Add(id, typeof(object));
break;
}
}
else //hmm so it didn't, lets try something else
{
var dbType = BusinessLogic.Application.SqlHelper.ExecuteScalar<string>(@"SELECT [t0].[dbType] FROM [cmsDataType] AS [t0] WHERE [t0].[controlId] = @p0", BusinessLogic.Application.SqlHelper.CreateParameter("@p0", id));
if (!string.IsNullOrEmpty(dbType)) //can I determine from the DB?
{
switch (dbType.ToUpper())
{
case "INTEGER":
dataTypeMapping.Add(id, typeof(int));
break;
case "DATE":
dataTypeMapping.Add(id, typeof(DateTime));
break;
case "NTEXT":
case "NVARCHAR":
dataTypeMapping.Add(id, typeof(string));
break;
default:
dataTypeMapping.Add(id, typeof(object));
break;
}
}
else
{
//ok, you've got a really freaky data type, so you get an Object back :P
dataTypeMapping.Add(id, typeof(object));
}
}
}
return dataTypeMapping[id].Name;
}
if (!string.IsNullOrEmpty(dbType)) //can I determine from the DB?
{
switch (dbType.ToUpper())
{
case "INTEGER":
dataTypeMapping.Add(id, typeof(int));
break;
case "DATE":
dataTypeMapping.Add(id, typeof(DateTime));
break;
case "NTEXT":
case "NVARCHAR":
dataTypeMapping.Add(id, typeof(string));
break;
default:
dataTypeMapping.Add(id, typeof(object));
break;
}
}
else
{
//ok, you've got a really freaky data type, so you get an Object back :P
dataTypeMapping.Add(id, typeof(object));
}
}
}
//if it's a valueType and it's not a mandatory field we'll make it nullable. And let's be lazy and us something like 'int?' rather than
//the fully layed out version :P
if (!pt.Mandatory && dataTypeMapping[id].IsValueType)
return dataTypeMapping[id].Name + "?";
private string GenerateDataContextCollections(bool includeInterfaces)
{
StringBuilder sb = new StringBuilder();
//here we can use a standard type name
return dataTypeMapping[id].Name;
}
foreach (var dt in DocTypes)
{
string className = GenerateTypeName(dt.Alias);
sb.Append(string.Format(TREE_TEMPLATE,
className
)
);
private string GenerateDataContextCollections(bool includeInterfaces)
{
StringBuilder sb = new StringBuilder();
if (includeInterfaces)
{
sb.AppendLine(string.Format(TREE_ABSTRACTION_TEMPLATE,
className,
txtDataContextName.Text
)
);
}
}
return sb.ToString();
}
foreach (var dt in DocTypes)
{
string className = GenerateTypeName(dt.Alias);
sb.Append(string.Format(TREE_TEMPLATE,
className
)
);
private static string GenerateTypeName(string alias)
{
string s = Casing.SafeAlias(alias);
return s[0].ToString().ToUpper() + s.Substring(1, s.Length - 1);
}
if (includeInterfaces)
{
sb.AppendLine(string.Format(TREE_ABSTRACTION_TEMPLATE,
className,
txtDataContextName.Text
)
);
}
}
return sb.ToString();
}
private static string FormatForComment(string s)
{
if (string.IsNullOrEmpty(s))
{
return s;
}
return s.Replace("\r\n", "\r\n///");
}
private static string GenerateTypeName(string alias)
{
string s = Casing.SafeAlias(alias);
return s[0].ToString().ToUpper() + s.Substring(1, s.Length - 1);
}
private static void EnsureExportFolder()
{
string packagesDirectory = IO.SystemDirectories.Media + EXPORT_FOLDER;
if (!System.IO.Directory.Exists(IOHelper.MapPath(packagesDirectory)))
System.IO.Directory.CreateDirectory(IOHelper.MapPath(packagesDirectory));
}
}
private static string FormatForComment(string s)
{
if (string.IsNullOrEmpty(s))
{
return s;
}
return s.Replace("\r\n", "\r\n///");
}
private static void EnsureExportFolder()
{
string packagesDirectory = IO.SystemDirectories.Media + EXPORT_FOLDER;
if (!System.IO.Directory.Exists(IOHelper.MapPath(packagesDirectory)))
System.IO.Directory.CreateDirectory(IOHelper.MapPath(packagesDirectory));
}
}
}

6
umbraco2.vsmdi Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
<RunConfiguration id="0317effe-25fb-4c40-99c3-8529bdb6b284" name="SHOCKING" storage="shocking.testrunconfig" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</TestList>
</TestLists>