From 58874238cc6e1054df6a83ddedafd2760c39175d Mon Sep 17 00:00:00 2001 From: slace Date: Thu, 6 Jan 2011 12:09:24 -1100 Subject: [PATCH 1/2] Adding a more detailed exception when parsing fails for LINQ to Umbraco --- .../Core/Node/NodeDataProvider.cs | 30 +++++++++++++++++-- .../Core/umbraco.Linq.Core.csproj | 14 +++++---- components/SQLCE4Umbraco/SqlCE4Umbraco.csproj | 12 +++++--- .../umbraco.editorControls.csproj | 12 +++++--- .../umbraco.macroRenderings.csproj | 12 +++++--- .../umbraco.controls/umbraco.controls.csproj | 12 +++++--- .../umbraco.webservices.csproj | 12 +++++--- .../umbraco.MacroEngines.csproj | 12 +++++--- .../umbraco.MacroEngines.Legacy.csproj | 12 +++++--- umbraco.Test/umbraco.Test.csproj | 12 +++++--- .../umbraco.businesslogic.csproj | 12 +++++--- umbraco/cms/umbraco.cms.csproj | 12 +++++--- umbraco/datalayer/umbraco.datalayer.csproj | 12 +++++--- umbraco/interfaces/umbraco.interfaces.csproj | 12 +++++--- .../presentation/umbraco.presentation.csproj | 12 +++++--- umbraco/providers/umbraco.providers.csproj | 12 +++++--- umbraco/umbraco.Legacy/umbraco.Legacy.csproj | 12 +++++--- 17 files changed, 156 insertions(+), 68 deletions(-) diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs index 5ab8b4edd2..c372c56f95 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs +++ b/LinqToUmbraco/src/umbraco.Linq/Core/Node/NodeDataProvider.cs @@ -352,18 +352,42 @@ namespace umbraco.Linq.Core.Node if (string.IsNullOrEmpty(data)) { //non-mandatory structs which have no value will be null - p.SetValue(node, null, null); + try + { + p.SetValue(node, null, null); + } + catch (FormatException ex) + { + throw new FormatException( + string.Format("Unable to cast '{0}' to the appropriate type ({1}) for node `{2}`. The alias of the property being parsed is {3}. Refer to inner exception for more details", data, p.PropertyType.FullName, node.Id, attr.Alias), ex); + } } else { //non-mandatory structs which do have a value have to be cast based on the type of their Nullable, found from the first (well, only) GenericArgument - p.SetValue(node, Convert.ChangeType(data, p.PropertyType.GetGenericArguments()[0]), null); + try + { + p.SetValue(node, Convert.ChangeType(data, p.PropertyType.GetGenericArguments()[0]), null); + } + catch (FormatException ex) + { + throw new FormatException( + string.Format("Unable to cast '{0}' to the appropriate type ({1}) for node `{2}`. The alias of the property being parsed is {3}. Refer to inner exception for more details", data, p.PropertyType.FullName, node.Id, attr.Alias), ex); + } } } else { // TODO: Address how Convert.ChangeType works in globalisation - p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null); + try + { + p.SetValue(node, Convert.ChangeType(data, p.PropertyType), null); + } + catch (FormatException ex) + { + throw new FormatException( + string.Format("Unable to cast '{0}' to the appropriate type ({1}) for node `{2}`. The alias of the property being parsed is {3}. Refer to inner exception for more details", data, p.PropertyType.FullName, node.Id, attr.Alias), ex); + } } } } diff --git a/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj b/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj index 96e045563b..23653137dd 100644 --- a/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj +++ b/LinqToUmbraco/src/umbraco.Linq/Core/umbraco.Linq.Core.csproj @@ -12,10 +12,14 @@ umbraco.Linq.Core v3.5 512 - SAK - SAK - SAK - SAK + + + + + + + + ..\..\..\..\..\umbraco\presentation\bin @@ -146,4 +150,4 @@ XCOPY "$(TargetPath)" "$(SolutionDir)\umbraco\presentation\bin" /Y - + \ No newline at end of file diff --git a/components/SQLCE4Umbraco/SqlCE4Umbraco.csproj b/components/SQLCE4Umbraco/SqlCE4Umbraco.csproj index 4204302e67..36d304b524 100644 --- a/components/SQLCE4Umbraco/SqlCE4Umbraco.csproj +++ b/components/SQLCE4Umbraco/SqlCE4Umbraco.csproj @@ -12,10 +12,14 @@ SQLCE4Umbraco v4.0 512 - SAK - SAK - SAK - SAK + + + + + + + + true diff --git a/components/editorControls/umbraco.editorControls.csproj b/components/editorControls/umbraco.editorControls.csproj index 4eaa7aa880..cca7713b4a 100644 --- a/components/editorControls/umbraco.editorControls.csproj +++ b/components/editorControls/umbraco.editorControls.csproj @@ -27,10 +27,14 @@ - SAK - SAK - SAK - SAK + + + + + + + + 3.5 true v3.5 diff --git a/components/macroRenderings/umbraco.macroRenderings.csproj b/components/macroRenderings/umbraco.macroRenderings.csproj index 8a2ac33a75..fd38bf3af1 100644 --- a/components/macroRenderings/umbraco.macroRenderings.csproj +++ b/components/macroRenderings/umbraco.macroRenderings.csproj @@ -27,10 +27,14 @@ - SAK - SAK - SAK - SAK + + + + + + + + 3.5 v3.5 publish\ diff --git a/components/umbraco.controls/umbraco.controls.csproj b/components/umbraco.controls/umbraco.controls.csproj index 22c2108413..6a0cb81460 100644 --- a/components/umbraco.controls/umbraco.controls.csproj +++ b/components/umbraco.controls/umbraco.controls.csproj @@ -10,10 +10,14 @@ Properties umbraco.uicontrols controls - SAK - SAK - SAK - SAK + + + + + + + + 3.5 diff --git a/components/umbraco.webservices/umbraco.webservices.csproj b/components/umbraco.webservices/umbraco.webservices.csproj index 45ade52df6..08cfae2b51 100644 --- a/components/umbraco.webservices/umbraco.webservices.csproj +++ b/components/umbraco.webservices/umbraco.webservices.csproj @@ -12,10 +12,14 @@ umbraco.webservices v3.5 512 - SAK - SAK - SAK - SAK + + + + + + + + 3.5 diff --git a/umbraco.MacroEngines.Juno/umbraco.MacroEngines.csproj b/umbraco.MacroEngines.Juno/umbraco.MacroEngines.csproj index 97a46c3337..55c7024c08 100644 --- a/umbraco.MacroEngines.Juno/umbraco.MacroEngines.csproj +++ b/umbraco.MacroEngines.Juno/umbraco.MacroEngines.csproj @@ -12,10 +12,14 @@ umbraco.MacroEngines v4.0 512 - SAK - SAK - SAK - SAK + + + + + + + + true diff --git a/umbraco.MacroEngines/umbraco.MacroEngines.Legacy.csproj b/umbraco.MacroEngines/umbraco.MacroEngines.Legacy.csproj index 75b5b8d5a9..85ec274857 100644 --- a/umbraco.MacroEngines/umbraco.MacroEngines.Legacy.csproj +++ b/umbraco.MacroEngines/umbraco.MacroEngines.Legacy.csproj @@ -12,10 +12,14 @@ umbraco.MacroEngines.Legacy v4.0 512 - SAK - SAK - SAK - SAK + + + + + + + + diff --git a/umbraco.Test/umbraco.Test.csproj b/umbraco.Test/umbraco.Test.csproj index cf66150518..080b28e0ca 100644 --- a/umbraco.Test/umbraco.Test.csproj +++ b/umbraco.Test/umbraco.Test.csproj @@ -13,10 +13,14 @@ v4.0 512 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - SAK - SAK - SAK - SAK + + + + + + + + 3.5 diff --git a/umbraco/businesslogic/umbraco.businesslogic.csproj b/umbraco/businesslogic/umbraco.businesslogic.csproj index 1c600ce937..42a6e40bbc 100644 --- a/umbraco/businesslogic/umbraco.businesslogic.csproj +++ b/umbraco/businesslogic/umbraco.businesslogic.csproj @@ -27,10 +27,14 @@ - SAK - SAK - SAK - SAK + + + + + + + + 3.5 true v3.5 diff --git a/umbraco/cms/umbraco.cms.csproj b/umbraco/cms/umbraco.cms.csproj index 3b311c40f1..a333f50e7c 100644 --- a/umbraco/cms/umbraco.cms.csproj +++ b/umbraco/cms/umbraco.cms.csproj @@ -27,10 +27,14 @@ - SAK - SAK - SAK - SAK + + + + + + + + 3.5 v3.5 publish\ diff --git a/umbraco/datalayer/umbraco.datalayer.csproj b/umbraco/datalayer/umbraco.datalayer.csproj index ff45e08945..7a0e46c82d 100644 --- a/umbraco/datalayer/umbraco.datalayer.csproj +++ b/umbraco/datalayer/umbraco.datalayer.csproj @@ -10,10 +10,14 @@ Properties umbraco.DataLayer umbraco.DataLayer - SAK - SAK - SAK - SAK + + + + + + + + 3.5 diff --git a/umbraco/interfaces/umbraco.interfaces.csproj b/umbraco/interfaces/umbraco.interfaces.csproj index 5b7d914f2c..a31e3b5fcb 100644 --- a/umbraco/interfaces/umbraco.interfaces.csproj +++ b/umbraco/interfaces/umbraco.interfaces.csproj @@ -27,10 +27,14 @@ - SAK - SAK - SAK - SAK + + + + + + + + 3.5 v3.5 publish\ diff --git a/umbraco/presentation/umbraco.presentation.csproj b/umbraco/presentation/umbraco.presentation.csproj index 87a6e2c489..8d1691eb22 100644 --- a/umbraco/presentation/umbraco.presentation.csproj +++ b/umbraco/presentation/umbraco.presentation.csproj @@ -27,10 +27,14 @@ - SAK - SAK - SAK - SAK + + + + + + + + 3.5 v3.5 diff --git a/umbraco/providers/umbraco.providers.csproj b/umbraco/providers/umbraco.providers.csproj index 47ad5c3226..d2bbb15523 100644 --- a/umbraco/providers/umbraco.providers.csproj +++ b/umbraco/providers/umbraco.providers.csproj @@ -10,10 +10,14 @@ Properties umbraco.providers umbraco.providers - SAK - SAK - SAK - SAK + + + + + + + + 3.5 diff --git a/umbraco/umbraco.Legacy/umbraco.Legacy.csproj b/umbraco/umbraco.Legacy/umbraco.Legacy.csproj index 49d92c05d8..f334e8a0f0 100644 --- a/umbraco/umbraco.Legacy/umbraco.Legacy.csproj +++ b/umbraco/umbraco.Legacy/umbraco.Legacy.csproj @@ -12,10 +12,14 @@ umbraco.Legacy umbraco.Legacy v3.5 - SAK - SAK - SAK - SAK + + + + + + + + 3.5 From 48ff65e597c02c503436ac422b503033c1222e62 Mon Sep 17 00:00:00 2001 From: slace Date: Thu, 6 Jan 2011 12:22:34 -1100 Subject: [PATCH 2/2] adding CurrentPage to the .NET macros --- umbraco/presentation/macro.cs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/umbraco/presentation/macro.cs b/umbraco/presentation/macro.cs index c2e063e325..4b1fc37c29 100644 --- a/umbraco/presentation/macro.cs +++ b/umbraco/presentation/macro.cs @@ -1203,7 +1203,9 @@ namespace umbraco return new LiteralControl(string.Format("Unable to create control {0} from assembly {1}", controlName, asm.FullName)); - /// Properties + AddCurrentNodeToControl(control, type); + + // Properties foreach (string propertyAlias in properties.Keys) { PropertyInfo prop = type.GetProperty(propertyAlias); @@ -1268,9 +1270,9 @@ namespace umbraco /// Loads an usercontrol using reflection into the macro object /// /// Filename of the usercontrol - ie. ~wulff.ascx + /// The attributes. + /// The page elements. /// - /// - /// public Control loadUserControl(string fileName, Hashtable attributes, Hashtable pageElements) { Debug.Assert(!string.IsNullOrEmpty(fileName), "fileName cannot be empty"); @@ -1305,6 +1307,8 @@ namespace umbraco return oControl; } + AddCurrentNodeToControl(oControl, type); + foreach (string propertyAlias in properties.Keys) { PropertyInfo prop = type.GetProperty(propertyAlias); @@ -1384,6 +1388,20 @@ namespace umbraco } } + private static void AddCurrentNodeToControl(Control control, Type type) + { + var currentNodeProperty = type.GetProperty("CurrentNode"); + if (currentNodeProperty != null && currentNodeProperty.CanWrite && currentNodeProperty.PropertyType.IsAssignableFrom(typeof(Node))) + { + currentNodeProperty.SetValue(control, Node.GetCurrent(), null); + } + currentNodeProperty = type.GetProperty("currentNode"); + if (currentNodeProperty != null && currentNodeProperty.CanWrite && currentNodeProperty.PropertyType.IsAssignableFrom(typeof(Node))) + { + currentNodeProperty.SetValue(control, Node.GetCurrent(), null); + } + } + private void TraceInfo(string category, string message) { if (HttpContext.Current != null)