From ea6b8f61fe52c8374769f83c425cc0c67910ca05 Mon Sep 17 00:00:00 2001 From: slace Date: Tue, 16 Feb 2010 05:55:21 +0000 Subject: [PATCH] DO NOT DOWNLOAD, THERE ARE MUCH MORE IMPORTANT THINGS GOING ON TODAY THAN LOOKING AT THIS SOURCE CODE! Modifying the LINQ to Umbraco node data provider to work with the new schema Adding some additional properties to the DocTypeBase class and IDocTypeBase interface [TFS Changeset #64007] --- .../src/umbraco.Linq/Core/DocTypeBase.cs | 4 + .../src/umbraco.Linq/Core/IDocTypeBase.cs | 18 +- .../Core/Node/NodeAssociationTree.cs | 7 +- .../Core/Node/NodeDataProvider.cs | 97 ++------ .../src/umbraco.Linq/Core/Node/NodeTree.cs | 1 - LinqToUmbraco/src/umbraco.Linq/Core/Tree.cs | 25 +- .../Core/umbraco.Linq.Core.csproj | 6 +- umbraco.sln | 1 - umbraco/presentation/web.config | 218 ------------------ 9 files changed, 61 insertions(+), 316 deletions(-) delete mode 100644 umbraco/presentation/web.config diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs b/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs index b10ed2b773..a4d147ba1e 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/DocTypeBase.cs @@ -313,6 +313,8 @@ namespace umbraco.Linq.Core } } + public virtual string CreatorName { get; internal set; } + /// /// ID of the user who last edited the item /// @@ -344,6 +346,8 @@ namespace umbraco.Linq.Core } } + public virtual string WriterName { get; internal set; } + /// /// Raises the property changing event. /// diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/IDocTypeBase.cs b/LinqToUmbraco/src/umbraco.Linq/Core/IDocTypeBase.cs index 8e01b38fdc..786c03edb0 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/IDocTypeBase.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/IDocTypeBase.cs @@ -36,6 +36,11 @@ namespace umbraco.Linq.Core /// The creator ID. int CreatorID { get; } /// + /// Gets the name of the creator. + /// + /// The name of the creator. + string CreatorName { get; } + /// /// Gets the id of the item. /// /// The id. @@ -67,14 +72,6 @@ namespace umbraco.Linq.Core /// The parent node id. int ParentNodeId { get; set; } /// - /// Occurs when a property value changes. - /// - event PropertyChangedEventHandler PropertyChanged; - /// - /// Occurs when a property value is changing. - /// - event PropertyChangingEventHandler PropertyChanging; - /// /// Gets or sets the sort order. /// /// The sort order. @@ -99,5 +96,10 @@ namespace umbraco.Linq.Core /// /// The writer ID. int WriterID { get; } + /// + /// Gets the name of the writer. + /// + /// The name of the writer. + string WriterName { get; } } } diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeAssociationTree.cs b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeAssociationTree.cs index 102c5502ef..30ecdd60cd 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeAssociationTree.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeAssociationTree.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Xml.Linq; namespace umbraco.Linq.Core.Node { @@ -60,7 +58,7 @@ namespace umbraco.Linq.Core.Node var rawNodes = parents .Single() .Elements() - .Where(x => x.HasAttributes) + .Where(x => x.Attribute("isDoc") != null) ; this._nodes = provider.DynamicNodeCreation(rawNodes).Cast(); //drop is back to the type which was asked for } @@ -86,6 +84,9 @@ namespace umbraco.Linq.Core.Node /// The provider. public override UmbracoDataProvider Provider { get; protected set; } + /// + /// Reloads the cache. + /// public override void ReloadCache() { this.LoadNodes(); diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs index cfc86ee2c9..4a4caf06d2 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs @@ -1,12 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Linq.Expressions; using System.IO; using System.Xml.Linq; -using System.Xml.Schema; -using System.Xml; using System.Reflection; using umbraco.presentation; using umbraco.cms.helpers; @@ -18,19 +14,16 @@ namespace umbraco.Linq.Core.Node /// Data Provider for LINQ to umbraco via umbraco ndoes /// /// - /// This class provides a data access model for the umbraco XML cache. - /// It is responsible for the access to the XML and construction of nodes from it. - /// - /// The is capable of reading the XML cache from either the path provided in the umbraco settings or from a specified location on the file system. + /// This class provides a data access model for the umbraco XML cache. + /// It is responsible for the access to the XML and construction of nodes from it. + /// The is capable of reading the XML cache from either the path provided in the umbraco settings or from a specified location on the file system. /// public sealed class NodeDataProvider : UmbracoDataProvider { private object lockObject = new object(); private string _xmlPath; private Dictionary _trees; - private bool _enforceSchemaValidation; private XDocument _xml; - private const string UMBRACO_XSD_PATH = "umbraco.Linq.Core.Node.UmbracoConfig.xsd"; private Dictionary _knownTypes; private bool _tryMemoryCache = false; @@ -43,10 +36,10 @@ namespace umbraco.Linq.Core.Node { if (this._tryMemoryCache) { - var doc = content.Instance.XmlContent; + var doc = UmbracoContext.Current.Server.ContentXml; if (doc != null) { - this._xml = XDocument.Load(new XmlNodeReader(doc)); + this._xml = doc; } else { @@ -57,55 +50,29 @@ namespace umbraco.Linq.Core.Node { this._xml = XDocument.Load(this._xmlPath); } - - if (this._enforceSchemaValidation) - { - XmlSchemaSet schemas = new XmlSchemaSet(); - //read the resorce for the XSD to validate against - schemas.Add("", System.Xml.XmlReader.Create(this.GetType().Assembly.GetManifestResourceStream(UMBRACO_XSD_PATH))); - - //we'll have a list of all validation exceptions to put them to the screen - List exList = new List(); - - //some funky in-line event handler. Lambda loving goodness ;) - this._xml.Validate(schemas, (o, e) => { exList.Add(e.Exception); }); - - if (exList.Count > 0) - { - //dump out the exception list - StringBuilder sb = new StringBuilder(); - sb.AppendLine("The following validation errors occuring with the XML:"); - foreach (var item in exList) - { - sb.AppendLine(" * " + item.Message + " - " + item.StackTrace); - } - throw new XmlSchemaException(sb.ToString()); - } - } } return this._xml; //cache the XML in memory to increase performance and force the disposable pattern } } - private void Init(string xmlPath, bool legacySchema) + /// + /// Initializes the NodeDataProvider, performing validation + /// + /// The XML path. + /// if set to true [new schema mode]. + protected void Init(string xmlPath, bool newSchemaMode) { - if (legacySchema) - { - throw new NotSupportedException("The NodeDataProvider does not support the old XML schema mode. Set \"UseLegacyXmlSchema\" in your umbracoSettings.Config to \"true\" and republish the site"); - } + if (!newSchemaMode) + throw new NotSupportedException(this.Name + " only supports the new XML schema. Change the umbracoSettings.config to implement this and republish"); if (string.IsNullOrEmpty(xmlPath)) - { throw new ArgumentNullException("xmlPath"); - } if (!File.Exists(xmlPath)) - { throw new FileNotFoundException("The XML used by the provider must exist", xmlPath); - } - this._xmlPath = xmlPath; + this._xmlPath = xmlPath; this._trees = new Dictionary(); } @@ -113,7 +80,7 @@ namespace umbraco.Linq.Core.Node /// Initializes a new instance of the class using umbraco settings as XML path /// public NodeDataProvider() - : this(UmbracoContext.Current.Server.MapPath(UmbracoContext.Current.Server.ContentXmlPath), !UmbracoContext.Current.NewSchemaMode) + : this(UmbracoContext.Current.Server.MapPath(UmbracoContext.Current.Server.ContentXmlPath), UmbracoContext.Current.NewSchemaMode) { this._tryMemoryCache = true; } @@ -122,27 +89,13 @@ namespace umbraco.Linq.Core.Node /// Initializes a new instance of the class /// /// The path of the umbraco XML - /// if set to true [legacy schema]. + /// Indicates which Schema mode is used for the XML file /// /// This constructor is ideal for unit testing as it allows for the XML to be located anywhere /// - public NodeDataProvider(string xmlPath, bool legacySchema) - : this(xmlPath, legacySchema, false) + public NodeDataProvider(string xmlPath, bool newSchemaMode) { - } - - /// - /// Initializes a new instance of the class. - /// - /// The XML path. - /// if set to true [legacy schema]. - /// if set to true when the XML document is accessed validation against the umbraco XSD will be done. - /// Thrown when the xmlPath is null - /// Thrown when the xmlPath does not resolve to a physical file - public NodeDataProvider(string xmlPath, bool legacySchema, bool enforceValidation) - { - this.Init(xmlPath, legacySchema); - this._enforceSchemaValidation = enforceValidation; + this.Init(xmlPath, newSchemaMode); } #region IDisposable Members @@ -198,9 +151,7 @@ namespace umbraco.Linq.Core.Node var attr = ReflectionAssistance.GetUmbracoInfoAttribute(typeof(TDocType)); if (!this._trees.ContainsKey(attr)) - { SetupNodeTree(attr); - } return (NodeTree)this._trees[attr]; } @@ -237,14 +188,10 @@ namespace umbraco.Linq.Core.Node var parentXml = this.Xml.Descendants().SingleOrDefault(d => (int)d.Attribute("id") == id); if (!ReflectionAssistance.CompareByAlias(typeof(TDocType), parentXml)) - { throw new DocTypeMissMatchException(parentXml.Name.LocalName, ReflectionAssistance.GetUmbracoInfoAttribute(typeof(TDocType)).Alias); - } if (parentXml == null) //really shouldn't happen! - { throw new ArgumentException("Parent ID \"" + id + "\" cannot be found in the loaded XML. Ensure that the umbracoDataContext is being disposed of once it is no longer needed"); - } var parent = new TDocType(); this.LoadFromXml(parentXml, parent); @@ -337,10 +284,9 @@ namespace umbraco.Linq.Core.Node { return ((UmbracoInfoAttribute)k.GetCustomAttributes(typeof(UmbracoInfoAttribute), true)[0]).Alias; }); + foreach (var type in types) - { this._knownTypes.Add(Casing.SafeAlias(type.Key), type.Value); - } } @@ -380,7 +326,9 @@ namespace umbraco.Linq.Core.Node node.SortOrder = (int)xml.Attribute("sortOrder"); node.UpdateDate = (DateTime)xml.Attribute("updateDate"); node.CreatorID = (int)xml.Attribute("creatorID"); + node.CreatorName = (string)xml.Attribute("creatorName"); node.WriterID = (int)xml.Attribute("writerID"); + node.WriterName = (string)xml.Attribute("writerName"); node.Level = (int)xml.Attribute("level"); node.TemplateId = (int)xml.Attribute("template"); @@ -391,9 +339,8 @@ namespace umbraco.Linq.Core.Node var data = xml.Element(Casing.SafeAlias(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 6a3c066efa..8d4248ce53 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeTree.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeTree.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Xml.Linq; namespace umbraco.Linq.Core.Node diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/Tree.cs b/LinqToUmbraco/src/umbraco.Linq/Core/Tree.cs index 6363dda737..285c42cfee 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Tree.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Tree.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Collections; -using System.ComponentModel; -using System.Linq.Expressions; -using System.Xml.Linq; namespace umbraco.Linq.Core { @@ -12,7 +7,7 @@ namespace umbraco.Linq.Core /// Represents a collection within DataProvider of a DocType /// /// - /// Similar to the implementation of , + /// Similar to the implementation of , /// providing a single collection which represents all instances of the given type within the DataProvider. /// /// Implementers of this type will need to provide a manner of retrieving the TDocType from the DataProvider @@ -69,9 +64,25 @@ namespace umbraco.Linq.Core #endregion + /// + /// Insert an item on submit of the DataContext + /// + /// The item. public abstract void InsertOnSubmit(TDocType item); + /// + /// Insert a collection of items on submit of the DataContext + /// + /// The items. public abstract void InsertAllOnSubmit(IEnumerable items); + /// + /// Deletes an item on submit of the DataContext + /// + /// The itemm. public abstract void DeleteOnSubmit(TDocType itemm); + /// + /// Deletes a collection of items on submit of the DataContext + /// + /// The items. public abstract void DeleteAllOnSubmit(IEnumerable items); } } diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj b/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj index 8ad3cf9f92..8da30d905a 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj +++ b/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj @@ -53,6 +53,9 @@ 3.5 + + 3.5 + 3.0 @@ -90,9 +93,6 @@ - - Node\UmbracoConfig.xsd - diff --git a/umbraco.sln b/umbraco.sln index 4f8196aacc..523bccc6a8 100644 --- a/umbraco.sln +++ b/umbraco.sln @@ -48,7 +48,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config", "config", "{05329D config templates\config\404handlers.config = config templates\config\404handlers.config config templates\config\Dashboard.config = config templates\config\Dashboard.config umbraco\presentation\config\ExamineIndex.config = umbraco\presentation\config\ExamineIndex.config - umbraco\presentation\config\ExamineSettings.config = umbraco\presentation\config\ExamineSettings.config config templates\config\formHandlers.config = config templates\config\formHandlers.config config templates\config\metablogConfig.config = config templates\config\metablogConfig.config config templates\config\restExtensions.config = config templates\config\restExtensions.config diff --git a/umbraco/presentation/web.config b/umbraco/presentation/web.config deleted file mode 100644 index be28a290aa..0000000000 --- a/umbraco/presentation/web.config +++ /dev/null @@ -1,218 +0,0 @@ - - - -
-
- - - -
- -
-
-
-
- - - - -
- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://regexlib.com/WebServices.asmx - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file