Determine logical ExecutionLocation

Determine logical ExecutionLocation

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


als_uk posted on Friday, November 03, 2006

    I've not looked at the dataportal code lately (but should obviously check), but I need to determine whether I'm logically in a server i.e. my method has been called via a DataPortal method.

This is mainly to prevent accidental use of a Database class I have that deals with all connections etc.

guyroch replied on Friday, November 03, 2006

VoilĂ  - C#

 

if (Csla.ApplicationContext.ExecutionLocation == Csla.ApplicationContext.ExecutionLocations.Server)

{

// Running on server

}

else

{

// Running on client

}

ajj3085 replied on Friday, November 03, 2006

Just wanted to point out...

If you're not using remoting or any other data channel (ie, data access runs on the client) then the ExecutionLocation will alawys be Client.

als_uk replied on Friday, November 03, 2006

Sorry, perhaps I'm workding it wrong. ExecutionLocation does indeed say client when using the LocalProxy, and is therefore useless. I've been looking at the DataPortal, and I reckon that an extra property would be required: ApplicationContext.LogicalExecutionLocation. SetContext (in ApplicationContext) would then need to be modified to set LogicalExecutionLocation to Server when SetExecutionLocation is set to Server (to cover the Server hosts).

LogicalExecutionLocation would need setting to server locally prior to Fetch,etc calls (to the proxy object), and then reset after the proxy calls so we're back to Client LocationExecutionLocation.

That's the way I'd see it'd work. Again, probably worded as clearly as mud. I'm going to have a play with it anyway, as I can't see any other work around with the framework in it's existing incarnation.

ajj3085 replied on Friday, November 03, 2006

There is another way to check.. just can't find it right now.

als_uk replied on Friday, November 03, 2006

No worries. I'm going to trawl through Dataportal stuff a bit more, but probably try the changes. Cheers anyway

Vaidal replied on Friday, May 25, 2007

ummmm... I need this.

When I am developing I don't use remoting but I need to know if I am beyond DataPortal... Any ideas?

 

ajj3085 replied on Friday, May 25, 2007

What are you trying to acomplish?  Usually my code assumes that it won't be 'behind' the DP, other methods assume they will be (usually child data access methods).

als_uk replied on Friday, May 25, 2007

Hi,

I'm trying to ensure that certain methods on static helper classes are only called while in the dataportal. This is to ensure everyone else's code is behaving and only doing data access via my data access class. So my helper class would check the logical execution location and ensure it was Server. If not an exception is thrown.

I know what's needed to modify it (not much), just haven't got round to do it as it is a bit of a pain synching our version of csla with the official release.

----- Original Message ----
From: ajj3085 <cslanet@lhotka.net>
To: "als_uk@yahoo.com" <als_uk@yahoo.com>
Sent: Friday, 25 May, 2007 1:30:18 PM
Subject: Re: [CSLA .NET] Determine logical ExecutionLocation

What are you trying to acomplish?  Usually my code assumes that it won't be 'behind' the DP, other methods assume they will be (usually child data access methods).






New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.

RockfordLhotka replied on Friday, May 25, 2007

The basic rule is simple: if you are running in DataPortal_XYZ then you are logically in "server code", otherwise you are not. This only gets complex if your DataPortal_XYZ methods call other properties or methods, otherwise the rule is a simple one.

If you want to create a location flag, you can use ApplicationContext.LocalContext to store such a flag. Just use a null reference check - if the value is null you are on the client, and non-null means on the server. Then in your custom base classes (which everyone should have) override DataPortal_OnDataPortalInvoke and set your flag to a non-null value, and override DataPortal_OnDataPortalInvokeComplete and delete the flag.

als_uk replied on Friday, May 25, 2007

Thanks for the reply. Had thought of using this (and yes we do have a set of custom base classes), just that it seemed a neater solution to have it as part of the ApplicationContext.

----- Original Message ----
From: RockfordLhotka <cslanet@lhotka.net>
To: "als_uk@yahoo.com" <als_uk@yahoo.com>
Sent: Friday, 25 May, 2007 3:10:34 PM
Subject: Re: [CSLA .NET] Determine logical ExecutionLocation

The basic rule is simple: if you are running in DataPortal_XYZ then you are logically in "server code", otherwise you are not. This only gets complex if your DataPortal_XYZ methods call other properties or methods, otherwise the rule is a simple one.

If you want to create a location flag, you can use ApplicationContext.LocalContext to store such a flag. Just use a null reference check - if the value is null you are on the client, and non-null means on the server. Then in your custom base classes (which everyone should have) override DataPortal_OnDataPortalInvoke and set your flag to a non-null value, and override DataPortal_OnDataPortalInvokeComplete and delete the flag.







New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.

Vaidal replied on Monday, May 28, 2007

well... that runs ok... but it will incur some overhead...

Maybe Rocky could add a property anywhere...

als_uk replied on Monday, May 28, 2007

Exactly what I've been wondering from the start :). i.e. ApplicationContext.LogicalExecutionLocation. Still I can always add it to our company's CSLA

----- Original Message ----
From: Vaidal <cslanet@lhotka.net>
To: "als_uk@yahoo.com" <als_uk@yahoo.com>
Sent: Monday, 28 May, 2007 1:06:27 PM
Subject: Re: [CSLA .NET] Determine logical ExecutionLocation

well... that runs ok... but it will incur some overhead...

Maybe Rocky could add a property anywhere...







Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today.

RockfordLhotka replied on Monday, May 28, 2007

Added to the wish list.

 

Rocky

 

From: Alun Jones [mailto:cslanet@lhotka.net]
Sent: Monday, May 28, 2007 7:32 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Determine logical ExecutionLocation

 

Exactly what I've been wondering from the start :). i.e. ApplicationContext.LogicalExecutionLocation. Still I can always add it to our company's CSLA

----- Original Message ----
From: Vaidal <cslanet@lhotka.net>
To: "als_uk@yahoo.com" <als_uk@yahoo.com>
Sent: Monday, 28 May, 2007 1:06:27 PM
Subject: Re: [CSLA .NET] Determine logical ExecutionLocation

well... that runs ok... but it will incur some overhead...

Maybe Rocky could add a property anywhere...



 

 


Yahoo! Mail is the world's favourite email. Don't settle for less, sign up for your free account today.



als_uk replied on Friday, May 25, 2007

Hi,

I know what I need to do to add that to the ApplicationContext, but I'd rather have it in the official release (bit of a pain diff'ing official files to our modified ones!). Just had an email off someone else who is associated with csla, so I'll try and explain to them what is required and - finger crossed - it may get implemented.

----- Original Message ----
From: Vaidal <cslanet@lhotka.net>
To: "als_uk@yahoo.com" <als_uk@yahoo.com>
Sent: Friday, 25 May, 2007 1:06:31 PM
Subject: Re: [CSLA .NET] Determine logical ExecutionLocation

ummmm... I need this.

When I am developing I don't use remoting but I need to know if I am beyond DataPortal... Any ideas?

 







Yahoo! Answers - Got a question? Someone out there knows the answer. Try it now.

als_uk replied on Monday, May 28, 2007

Thanks




New Yahoo! Mail is the ultimate force in competitive emailing. Find out more at the Yahoo! Mail Championships. Plus: play games and win prizes.

Copyright (c) Marimer LLC