diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs b/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs index 5744d0db2f..578aa37477 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs @@ -22,9 +22,9 @@ namespace umbraco.Linq.Core private string _versionId; private int _templateId; private int _parentId; - private int _writerID; + private int writerID; private User _writer; - private int _creatorID; + private int creatorID; private User _creator; private IEnumerable _ancestors; private AssociationTree _children; @@ -38,46 +38,11 @@ namespace umbraco.Linq.Core this.IsDirty = true; } - internal void LoadFromXml(XElement xml) - { - if (xml.Name != "node") - { - throw new ArgumentException("Xml provided is not valid"); - } - - if (!ReflectionAssistance.CompareByAlias(this.GetType(), xml)) - { - throw new DocTypeMissMatchException((string)xml.Attribute("nodeTypeAlias"), ReflectionAssistance.GetumbracoInfoAttribute(this.GetType()).Alias); - } - - this.Id = (int)xml.Attribute("id"); - this.ParentNodeId = (int)xml.Attribute("parentID"); - this.Name = (string)xml.Attribute("nodeName"); - this.Version = (string)xml.Attribute("version"); - this.CreateDate = (DateTime)xml.Attribute("createDate"); - this.SortOrder = (int)xml.Attribute("sortOrder"); - this.UpdateDate = (DateTime)xml.Attribute("updateDate"); - this._creatorID = (int)xml.Attribute("creatorID"); - this._writerID = (int)xml.Attribute("writerID"); - this.Level = (int)xml.Attribute("level"); - this.TemplateId = (int)xml.Attribute("template"); - - var properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttributes(typeof(PropertyAttribute), true).Count() > 0); - foreach (var p in properties) - { - var attr = ReflectionAssistance.GetumbracoInfoAttribute(p); - - var data = xml.Elements("data").Single(x => (string)x.Attribute("alias") == attr.Alias).Value; - if (p.PropertyType == typeof(int) && string.IsNullOrEmpty(data)) - { - data = "-1"; - } - // TODO: Address how Convert.ChangeType works in globalisation - p.SetValue(this, Convert.ChangeType(data, p.PropertyType), null); - } - } - - internal UmbracoDataProvider Provider { get; set; } + /// + /// Gets or sets the provider. + /// + /// The provider. + protected internal UmbracoDataProvider Provider { get; set; } /// /// Gets or sets a value indicating whether this instance has been modified since it was first loaded @@ -98,7 +63,7 @@ namespace umbraco.Linq.Core { return this._Id; } - protected set + protected internal set { if (this._Id != value) { @@ -169,7 +134,7 @@ namespace umbraco.Linq.Core { return this._versionId; } - protected set + protected internal set { if (this._versionId != value) { @@ -232,7 +197,7 @@ namespace umbraco.Linq.Core /// /// The level. [Field] - [UmbracoInfo("level", DisplayName="Level"), DataMember(Name="Level")] + [UmbracoInfo("level", DisplayName = "Level"), DataMember(Name = "Level")] public virtual int Level { get; set; } #endregion @@ -315,9 +280,24 @@ namespace umbraco.Linq.Core } return this._ancestors.Where(a => a is TDocType).Cast().FirstOrDefault(func); - } + } #endregion + /// + /// Gets or sets the creator ID. + /// + /// The creator ID. + public int CreatorID + { + get + { + return creatorID; + } + internal set + { + this.creatorID = value; + } + } /// /// Gets the umbraco user who created the item /// @@ -328,13 +308,27 @@ namespace umbraco.Linq.Core { if (this._creator == null) { - this._creator = new User(this._creatorID); + this._creator = new User(this.CreatorID); } return this._creator; } } + /// + /// ID of the user who last edited the item + /// + public int WriterID + { + get + { + return writerID; + } + internal set + { + this.writerID = value; + } + } /// /// Gets the umbraco user who last edited the instance /// @@ -345,7 +339,7 @@ namespace umbraco.Linq.Core { if (this._writer == null) { - this._writer = new User(this._writerID); + this._writer = new User(this.WriterID); } return this._writer; diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs index 69f7db0914..ed6f4f9f95 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs @@ -237,7 +237,7 @@ namespace umbraco.Linq.Core.Node } var parent = new TDocType(); - parent.LoadFromXml(parentXml); + this.LoadFromXml(parentXml, parent); return parent; } @@ -306,7 +306,7 @@ namespace umbraco.Linq.Core.Node var alias = (string)ancestor.Attribute("nodeTypeAlias"); var t = KnownTypes[alias]; var instaceOfT = (DocTypeBase)Activator.CreateInstance(t); //create an instance of the type and down-cast so we can use it - instaceOfT.LoadFromXml(ancestor); + this.LoadFromXml(ancestor, instaceOfT); instaceOfT.Provider = this; ancestors.Add(instaceOfT); yield return instaceOfT; @@ -357,5 +357,50 @@ namespace umbraco.Linq.Core.Node this._xml = null; this._trees.Clear(); } + + /// + /// Loads from XML. + /// + /// + /// The XML. + /// The node. + public void LoadFromXml(XElement xml, T node) where T : DocTypeBase + { + if (xml.Name != "node") + { + throw new ArgumentException("Xml provided is not valid"); + } + + if (!ReflectionAssistance.CompareByAlias(node.GetType(), xml)) + { + throw new DocTypeMissMatchException((string)xml.Attribute("nodeTypeAlias"), ReflectionAssistance.GetumbracoInfoAttribute(node.GetType()).Alias); + } + + node.Id = (int)xml.Attribute("id"); + node.ParentNodeId = (int)xml.Attribute("parentID"); + node.Name = (string)xml.Attribute("nodeName"); + node.Version = (string)xml.Attribute("version"); + node.CreateDate = (DateTime)xml.Attribute("createDate"); + node.SortOrder = (int)xml.Attribute("sortOrder"); + node.UpdateDate = (DateTime)xml.Attribute("updateDate"); + node.CreatorID = (int)xml.Attribute("creatorID"); + node.WriterID = (int)xml.Attribute("writerID"); + node.Level = (int)xml.Attribute("level"); + node.TemplateId = (int)xml.Attribute("template"); + + var properties = node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttributes(typeof(PropertyAttribute), true).Count() > 0); + foreach (var p in properties) + { + var attr = ReflectionAssistance.GetumbracoInfoAttribute(p); + + var data = xml.Elements("data").Single(x => (string)x.Attribute("alias") == attr.Alias).Value; + if (p.PropertyType == typeof(int) && string.IsNullOrEmpty(data)) + { + data = "-1"; + } + // TODO: Address how Convert.ChangeType works in globalisation + p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null); + } + } } } diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeTree.cs b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeTree.cs index 687edd0fdb..8a0ad5adb8 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeTree.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeTree.cs @@ -74,7 +74,7 @@ namespace umbraco.Linq.Core.Node foreach (XElement n in rawNodes) { var dt = new TDocTypeBase(); - dt.LoadFromXml(n); + this._provider.LoadFromXml(n, dt); dt.IsDirty = false; dt.Provider = this._provider; diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/UmbracoDataContext.cs b/LinqToUmbraco/src/umbraco.Linq/Core/UmbracoDataContext.cs index 605fd7b95c..5b34fea5d7 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/UmbracoDataContext.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/UmbracoDataContext.cs @@ -8,7 +8,7 @@ using umbraco.Linq.Core.Node; namespace umbraco.Linq.Core { /// - /// The umbracoDataContext which handles the interaction with an + /// The umbracoDataContext which handles the interaction with an /// public abstract class UmbracoDataContext : IDisposable { @@ -41,6 +41,9 @@ namespace umbraco.Linq.Core } } + /// + /// Submits the changes within the UmbracoDataContext through the + /// public void SubmitChanges() { this.CheckDisposed(); @@ -51,14 +54,14 @@ namespace umbraco.Linq.Core #region Constructors /// - /// Initializes a new instance of the class, using a data provider with the connection string from the umbraco config + /// Initializes a new instance of the class, using a data provider with the connection string from the umbraco config /// protected UmbracoDataContext() : this(new NodeDataProvider()) { } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The data provider to use within the DataContext. protected UmbracoDataContext(UmbracoDataProvider dataProvider) diff --git a/umbraco/presentation/umbraco/dialogs/treePicker.aspx b/umbraco/presentation/umbraco/dialogs/treePicker.aspx index da0b54f857..c55dd1a64b 100644 --- a/umbraco/presentation/umbraco/dialogs/treePicker.aspx +++ b/umbraco/presentation/umbraco/dialogs/treePicker.aspx @@ -39,7 +39,7 @@ - +