Code callable from within dataportal or outside

Code callable from within dataportal or outside

Old forum URL: forums.lhotka.net/forums/t/646.aspx


ajj3085 posted on Monday, July 17, 2006

Hi,

I have a situation where I have some code that may be called while dataportal code is already running, or directly from the UI.  I was thinking to check the ExecutionLocation property to determine if I need to go through DataPortal.Fetch or executing the same code but outside of calling DataPortal.

Is this considered an acceptable thing to do?

Thanks
Andy

vargasbo replied on Monday, July 17, 2006

Your quesitons seems a little vague, but if you want to know if your readonlylist or somethign is being execute on the client or server? then yes, ExecutionLocation will give you that.

ajj3085 replied on Monday, July 17, 2006

The static Fetch method for my readonly object is used by both my UI and internally by some other business objects.

So instead of the standard static method, I have this:

        public static PhoneList GetPhoneList( PhoneListLoader loader ) {
            PhoneList result;

            if ( ApplicationContext.ExecutionLocation ==
                ApplicationContext.ExecutionLocations.Client ) {

                result = DataPortal.Fetch<PhoneList>(
                    new LoaderCriteria( loader )
                );
            }
            else {
                result = new PhoneList();
                result.DataPortal_Fetch( new LoaderCriteria( loader ) );
            }

            return result;
        }

RockfordLhotka replied on Monday, July 17, 2006

While I think that will work fine, it shouldn't be necessary.

If DataPortal.Fetch() is called by code that is already running on the server, the data portal will run in "local" mode, meaning it will just make the call right there on the server - basically doing what you are doing, only automatically.

ajj3085 replied on Tuesday, July 18, 2006

Thanks for the tip Rocky; I wasn't sure if it was 'safe' to call DataPortal.method when already in the dataportal (was concerned about the *Context objects.  If its safe though, I'll just remove the check.

Andy

xal replied on Monday, July 17, 2006

Hi Andy!
If you call Dataportal.Fetch the dataportal will figure out that it's already running inside a remote dp and will run accordingly.

Andrés

Copyright (c) Marimer LLC