OnCreating in handler is too late?

Topics: Troubleshooting
Feb 22, 2011 at 3:01 PM

I want to check a propertyvalue of my part with the value in the database before updating the record.
I discovered that OnCreating is too late, at that moment the record data is already persisted in the repository.

Coordinator
Feb 22, 2011 at 7:10 PM

Did you try doing that from the part's driver?

Feb 22, 2011 at 8:51 PM

Not from the driver, no.. in the part handler.. there isn't a difference between OnCreating and OnCreated.. looking at the code in DefaultContentManager.
Anyway it's the wrong place for me to hook in anyway.

I need a OnUpdating with access to the IUpdateModel interface or ModelState.

Perhaps this could be done in the driver and use the repository directly..
I tried to clone the complete object using BinaryFormater and even the DataContractSerializer, but then the Medium trust around the corner again hehe

Anyway i think i want a OnUpdating.

Using the ContentManager Get just returns the same object from the session so it's no use.

Coordinator
Feb 22, 2011 at 9:27 PM

Would this be a case where you're looking for the IContentHandler.UpdateEditor(UpdateEditorContext context) override? If that's the case you'll want to check if the item has your part on it, because content handlers are a broadcast pattern.

 

Feb 23, 2011 at 8:49 AM

I tried that one as well, but it's all to late... now i know why, it's NHibernate working with ISession and a not so logic implimentation.. I did set a breakpoint in the SessionLocator to gain any knowledge of the call stack and call hierarchy, to look under the hood. I did remove that breakpoint quickly hehe. Thru i found out that Repository.Update isn't being used anywhere, it doesn't because Save is enough for NHibernate.

After a night sleep i figure out i was working on a wrong solution.
Scenario: The vehicle webservice has to be called every time a property called licenceplate is changed.. before the part is updated in the database.

Wrong solution: Only call the webservice if the licenceplate number is InValidated (new or changed)
Good solution: Always call my IVehicleService where there is a cache on the licenceplate number as key and the webservice result as a value

A good reason to look at orchardcaching :)

Coordinator
Feb 23, 2011 at 6:31 PM

Let us know how that goes. Do you still need information from us or are you all set for now?

Feb 23, 2011 at 6:40 PM

The cachemanager is easy in use, i suppose it's using asp.net session state? I didn't look in the details, it just works.

All set for now :)

Coordinator
Feb 23, 2011 at 9:34 PM

No, the cache is built on the ASP.NET cache, not on session. Different scopes and lifetimes entirely.