Commit Graph

24 Commits

Author SHA1 Message Date
agrath@gmail.com
300c975284 Moved caching of property data type from DynamicNode to a static method in ContentType
Simplified SQL query used for property type lookup
Added cache clearing for propertyType cache when ContentType.ClearCache is called
Improves performance of new razor property lookups - most improvement on large sets
2011-02-17 14:23:20 -13:00
agrath@gmail.com
e7ebcb29bc Broke string properties with new typecasting stuff by returning false instead of true if the typecasting failed (e.g. it was actually a string)
Changed this to a return true

Replaced some API calls via Document & Property (database level, not nodefactory) with a single SQL scalar where I was getting the control type (to determine if "0"/"1" should actually be "true"/"false")
Should perform a lot better now
2011-02-07 14:10:38 -13:00
agrath@gmail.com
e5c3c8869a Upgraded DynamicNode to do some type inferrence from the IProperty type .Value which is a string
Already had support for YesNoType (where the string value is 1 or 0) being converted/parsed to boolean
Added some TryParse calls to int and decimal respecitvely so that if a IProperty.Value is a valid decimal or int it will be returned from DynamicNode.TryGetMember as such
This enables the .Where operator to have the correct type after property retrieval so that some numerical comparisons will work

Added support for >, >=, <, <= and %[mod] to .Where
@Model.Children.Where("catCount > 1")
@Model.Children.Where("catCount % 2 == 0")
2011-02-07 13:12:34 -13:00
agrath@gmail.com
bcf735f4f8 Added support for DynamicLinq in place of Lambda syntax. The short version is you can't use a Lambda with a DynamicNode
e.g. @Model.Children.Where(node=>node.shouldBeVisible)
To solve this, I used the DynamicQueryable class from the Linq samples which has a parser that can take a string then modified the internals a bit so
that if your object is a DynamicObject, an additional expression tree is generated which calls the TryGetMember on it
The end result is that you can now do this [I have Random(this DynamicNodeList nodes, int max) in my bin folder]
@Model.Children.Where("shouldBeVisible").Random(2) => two nodes, randomly picked, from the ones that should be visible
*Only* Where is implemented here currently, I'll add support by OrderBy and ThenBy after I've tested some more complex scenarios.
I need to fix a small issue with my DynamicLoading of extensions - under some scenarios the class doesn't get found and i'm not sure why.
2011-02-06 19:52:05 -13:00
agrath@gmail.com
eba7c9d550 Overloads for DynamicMedia and DynamicNode constructors that take object and string respectively
New DynamicNode .MediaById (because @Model is DynamicNode) to find a media item by id, e.g. if you are using it with @Model.Parameters.imageId
Overloads for MediaById and NodeById that take object and string to match constructors
2011-02-02 15:51:51 -13:00
agrath@gmail.com
799d718881 Refactored my implementation of IEnumerables being returned from .Children etc to return a new type called DynamicNodeList instead of a DynamicNode (singular) containing a nested list.
This makes the code cleaner and also allows for the .Items (underlying initialization data for DynamicNodeList) to be exposed when you have an instance and hide all of the singular properties etc (Url, Name) that are on DynamicNode - they're not applicable for a List.
Rewrote the reflection code for calling methods on DynamicNodeList to allow mix-ins (e.g. external dlls) to have an extension method defined for DynamicNodeList (e.g. Random(nodeCount))
Lambda syntax still doesn't work (e.g. Children.Where(item=>item.shouldBeVisible)) however methods that don't take lamdas (Take, Random[external], Skip, ElementAt, First, etc) work
2011-02-02 11:52:09 -13:00
agrath@gmail.com
83d88e70a5 Fixed an issue with boolean casting in razor file for if shorthand when properties didn't have value 2011-01-31 08:37:44 -13:00
agrath@gmail.com
26bf18766b Fixed a bad check in my patch for booleans that wasn't installation-portable by making it check the DataTypeDefinition instead of ContentTypeId.
Added a cache for the propertyType lookup (within a single DynamicNode instance) in case the razor logic needs to check the same boolean multiple times within a node.
Should improve performance if working with large trees & repeatedly checking a boolean value
2011-01-28 14:36:13 -13:00
agrath@gmail.com
c692b296d7 Added Pascal Case support to DynamicMedia and .Media helper 2011-01-27 21:56:09 -13:00
agrath@gmail.com
a0dd8aa2ab Improves access to media items when working in Razor
Added a new DynamicMedia class that wraps umbraco.cms.businesslogic.media.Media which caches GetProperty calls (while DynamicMedia is instantiated)
Added method to DynamicNode to retrieve a property as DynamicMedia: @Model.Media("catPicture"); or @Model.Media("catPicture").umbracoFile;
Added overload to DynamicNode Media method for shorthand if you only want one property; @Model.Media("catPicture","umbracoFile");
@Model.catPicture will still return the nodeId of the media item because we can't easily check the propertyType (no propertyType on IProperty)
2011-01-27 21:38:06 -13:00
agrath@gmail.com
6382241e4c Special casing in DynamicNode property retrieval for when the property being retrieved is True/False. I'm not sure how comfortable I am with having to go to Document to get the proerty info or the check of the ContentTypeId but the syntactic sugar of being able to go:
if(@Model.shouldBeVisible) {...} where shouldBeVisible is a true/false property on the datatype is pretty nice
2011-01-27 15:29:38 -13:00
agrath@gmail.com
3ab4944e5e If you're dealing with dynamicNode such as using:
var someNode = new umbraco.MacroEngines.DynamicNode(1046) in your template, it instantiates a DynamicNode like you'd expect, but then it doesn't function as a dynamic object
because it wasn't initialised as a dynamic variable [dynamic someNode = new umbraco.MacroEngines.DynamicNode(1046)]

Added a method to DynamicNode called NodeById which returns a new DynamicNode with the ID you pass, so you can call it off @Model
e.g. var item = @Model.NodeById(1046) will still function as a dynamic, even though it was defined as var
2011-01-27 14:49:56 -13:00
agrath@gmail.com
28b48b187a Added DynamicNode constructor that takes an int and passes it to NodeFactory so you can go var @clientNode = new umbraco.MacroEngines.DynamicNode(1560); 2011-01-27 14:22:28 -13:00
agrath@gmail.com
fce7ea48b0 Didn't test the AncestorOrSelf changes on a non-parent node. Changed implementation to call into Func<DynamicNode,bool> to check Level == 1
Also fixed post-build rule on umbraco.MacroEngines which had an incorrect path for copying umbraco.MacroEngines to presentation (allows debug without manual file copy, I think)
2011-01-27 13:07:10 -13:00
agrath@gmail.com
fbf13d8cf7 Fixed support for AncestorOrSelf when in Test mode (the INode passed to the razor script in testing has a null parent)
Added AncestorOrSelf overload which doesn't require a Func<DynamicNode,bool> argument

Both changes modify DynamicNode.Parent so that if there is no parent, it returns itself instead of null, (you can't new DynamicNode(null) as it throws exception)
and then in the AncestorOrSelf checks, the loop makes sure that it won't get stuck by continually returning itself (because this.Parent returns this)
2011-01-27 12:59:34 -13:00
agrath@gmail.com
dca21f9ce1 Added support for Macro Parameters in Razor Macros (@Model.Parameters.AnimalName) where AnimalName is defined on the Macro as a Parameter 2011-01-26 08:28:16 -13:00
agrath@gmail.com
69a1e7000c Added support for calling IEnumerable methods which return IEnumerable (e.g. Skip,Take) rather than single nodes (e.g. First,ElementAt) 2011-01-26 07:35:55 -13:00
agrath@gmail.com
9259dd897f Upgraded DynamicNode to handle IEnumerable better so that you can chain method/property calls through an IEnumerable set like this: @Model.Children.Count() or @Model.Children.ElementAt(2) 2011-01-25 22:24:40 -13:00
starfighter83
7dea3b872f Fixes broken build 2011-01-05 11:45:28 -01:00
slace
d3df402d4a setting the umbraco.config to be ignored and adding a DynamicNode method to do AncestorOrSelf 2010-12-28 00:04:11 -11:00
slace
4ec0aaab24 adding pluralization support for finding children 2010-12-26 18:05:47 -11:00
slace
cbf9a2e7e0 changed the DynamicNode to also handle child types through property accessors as well 2010-12-26 17:50:21 -11:00
slace
0c3f57f537 making the DynamicNode object work more like a Node object without having to rely on reflection 2010-12-25 22:36:12 -11:00
hartvig
dabafcc972 MacroEngine massage
[TFS Changeset #81621]
2010-12-08 07:09:45 +00:00