Save Event in SnapSections

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Save Event in SnapSections

Post by roteague »

Is there anyway to capture whenever the Save Event gets fired from within a SnapSection?

Thanks,
Robert
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Save Event in SnapSections

Post by John Morris »

You can hook up an order saved handler using basic package capabilities (not snapsection). From your package OnInitialize() routine, you place this code:

Code: Select all

using SoftPro.OrderTracking.Client
using SoftPro.OrderTracking.Package

protected void OnInitialize()
{
  OrderHelper oh = GetService<OrderHelper>();
  oh.RegisterOrderSavedHandler(this.MySaveHandler);
}

private void MySaveHandler(object sender, EventArgs e)
{
  IOrder o = (IOrder)sender;
  //...place your code here...
}
Your save handler will be called on every save of an order.

Don't place this code into a snapsection, as the current version of the OrderHelper does not allow un-registering a handler. If you hook up a handler from a snapsection, it will cause memory leaks.
John Morris
Sr. Software Architect
SoftPro
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Save Event in SnapSections

Post by ckootg »

John Morris wrote:Don't place this code into a snapsection, as the current version of the OrderHelper does not allow un-registering a handler. If you hook up a handler from a snapsection, it will cause memory leaks.
Is this still applicable in version 2.6?
Randy Mellow

Re: Save Event in SnapSections

Post by Randy Mellow »

Yes, v2.6 has not changed this limitation.
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Save Event in SnapSections

Post by ckootg »

Thanks for the information.

I assume that OrderTracking.OrderSaved replaced OrderHelper.RegisterOrderSavedHandler. Is that correct? If not, would it be safe in a snapsection?

Also, could you explain why adding the save event in a package is safe versus adding it to a snapsection isn't? Doesn't a package live as long as the application is open?
Randy Mellow

Re: Save Event in SnapSections

Post by Randy Mellow »

No. OrderTracking.OrderSaved is the event and OrderHelper.RegisterOrderSavedHandler is how you can register your handler for that event. They work in conjunction with each other, the former is not a replacement for the latter.

The reason you can safely register your handler in a package is because the package lives for the lifetime of the application and its resources are reclaimed when the application ends. Snap sections have a shorter lifetime and are potentially created and destroyed multiple times within a single instance of the application. Since your snap section would not be able to unregister the handler when it is destroyed, there will be a memory leak.
ckootg
Posts: 122
Joined: Fri Jan 06, 2012 6:10 pm

Re: Save Event in SnapSections

Post by ckootg »

Got it. Thanks.
chris.brady
Posts: 105
Joined: Wed Oct 17, 2012 4:20 pm

Re: Save Event in SnapSections

Post by chris.brady »

This question has become relevant for me as well, however, I'm unable to find SoftPro.OrderTracking.Package in the Select install folder.

Can you direct me to which DLL I should be using?
Post Reply