Calling Custom DLL in AC ASCX.CS Pages

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Mon Feb 27, 2012 9:53 am

Hehe

I prefer the days when I get the bear. But then again, don't we all?

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Mon Feb 27, 2012 12:24 pm

Say, I was wondering...

Is there also a way to code the function in the ASCX.CS file that calls the DLL so that it will call the function and move on as soon as it makes the call? It can take a little time for the DLL to communicate with the NetSuite servers (due to their functionality, based on every other integration I've done). I would like it to be able to call the function and then move on so that the little "Processing" window isn't sitting there every time a customer places an order. I guess this would be an asynchornous call, but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month. I was hoing there was a way to do it outside the DLL.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Thu Mar 01, 2012 8:42 am

vashts1980 wrote:but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month.
Who's limit is that? I've never heard of such a thing.

You might try using System.Threading to make the call in a separate thread with a callback method to handle the response. That way your page processing continues at normal speed but you can still process any responses from NetSuite.

Might force you to redesign your code a bit, but in the long run it'll work much smoother.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Thu Mar 01, 2012 11:21 am

vashts1980 wrote:but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month
This is actually a restriction on the system that I'm connecting AbleCommerce with, so unless you're familiar with NetSuite's web services, I'm not surprised you're unfamiliar with it.

Do you have any good resources I could look at for using System.Threading? And where would I implement it? In the ASCX.CS file or in the DLL?

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Thu Mar 01, 2012 11:47 am

Here's the Microsoft explanation on it:
http://msdn.microsoft.com/en-us/library ... hread.aspx

Scroll most of the way to the bottom, there's a code sample that's pretty easy to follow.

Threads are useful but they need to be done a certain way in AC7 installations. Here's a quick example:

Assume you have a 'GO' button on the page and it's purpose is to launch an update process. You don't want the update process to timeout the page because it takes a while to run.

Make sure to have this at the top with your other includes:

Code: Select all

using System.Threading;
This is the example code:

Code: Select all

    protected void MyGoButton_Click(object sender, EventArgs e)
    {
        System.Threading.ThreadPool.QueueUserWorkItem(MyThreadRoutine);
    }

    private static void MyThreadRoutine(object state)
    {
        Store _Store = StoreDataSource.Load(1);
        Token.Instance.InitStoreContext(_Store);
         ... your code continues from here...
     }
Always best to encapsulate your code in the thread routine with a try-catch, that way you can catch problems and log them accordingly. Makes debugging it a lot easier. In fact, I write and debug the code without threading first....just easier that way. Once I've got it the way I want, I split it back up using the above design.

Remember threads in AC7 have to init the store context, otherwise the new thread has no knowledge of the current storefront.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Thu Mar 01, 2012 3:33 pm

Ok, so if I was going to add this onto the checkout page where I'm capturing newly submitting orders, then this code:

Code: Select all

System.Threading.ThreadPool.QueueUserWorkItem(MyThreadRoutine);
Would be added to the existing "CheckedOut()" method, and the code that I've added to that method to do what I need, the additional lines to init the store context, would instead be moved to the new method I've created and referenced in the thread call, which would be "MyThreadRoutine()" in this particular example.

Does that sound like I have it right?

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by AbleMods » Wed Mar 07, 2012 8:30 am

yup
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Wed Mar 07, 2012 10:25 am

Ok...

I did some extra research into threading, and this is what I've come up with. I've noticed that the majority of examples revolve around methods that operate without use of any parameters, but I needed parameters, so I'm thinking this should work based off of what I've found so far:

Code: Select all

int newOrderId = response.OrderId;
Order newOrder = OrderDataSource.Load(newOrderId);
System.Threading.ThreadPool.QueueUserWorkItem( () => PassNewOrder(newOrder, currentUser, GetShippingAddress() ) );

vashts1980
Lieutenant Commander (LCDR)
Lieutenant Commander (LCDR)
Posts: 98
Joined: Fri Apr 29, 2011 2:56 pm

Re: Calling Custom DLL in AC ASCX.CS Pages

Post by vashts1980 » Fri Mar 16, 2012 3:20 pm

Joe, thnks for the insight on this. I have threading implemented and it appears to be working wonderfully.

Post Reply