CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Determine logical ExecutionLocation

Last post 05-28-2007, 5:46 PM by als_uk. 15 replies.
Page 1 of 2 (16 items)   1 2 Next >
Sort Posts: Previous Next
  •  11-03-2006, 6:36 AM 8764

    Determine logical ExecutionLocation

        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.
  •  11-03-2006, 9:26 AM 8770 in reply to 8764

    Re: Determine logical ExecutionLocation

    Voilà - C#

     

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

    {

    // Running on server

    }

    else

    {

    // Running on client

    }


    GuyRoch

    Two scoops of raisins in a package of Kellogg's Raisin Bran ♪ ♫ ♪ ♫
  •  11-03-2006, 10:27 AM 8772 in reply to 8770

    Re: Determine logical ExecutionLocation

    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.
  •  11-03-2006, 10:45 AM 8773 in reply to 8772

    Re: Determine logical ExecutionLocation

    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.
  •  11-03-2006, 10:53 AM 8774 in reply to 8773

    Re: Determine logical ExecutionLocation

    There is another way to check.. just can't find it right now.
  •  11-03-2006, 10:55 AM 8775 in reply to 8774

    Re: Determine logical ExecutionLocation

    No worries. I'm going to trawl through Dataportal stuff a bit more, but probably try the changes. Cheers anyway
  •  05-25-2007, 6:44 AM 15004 in reply to 8775

    Re: 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?

     

  •  05-25-2007, 7:29 AM 15005 in reply to 15004

    Re: 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).
  •  05-25-2007, 8:29 AM 15006 in reply to 15004

    Re: Determine logical ExecutionLocation

    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.
  •  05-25-2007, 8:31 AM 15007 in reply to 15005

    Re: Determine logical ExecutionLocation

    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.
  •  05-25-2007, 9:09 AM 15008 in reply to 15007

    Re: 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.


    Rocky
  •  05-25-2007, 9:13 AM 15009 in reply to 15008

    Re: Determine logical ExecutionLocation

    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.
  •  05-28-2007, 4:03 AM 15030 in reply to 15009

    Re: Determine logical ExecutionLocation

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

    Maybe Rocky could add a property anywhere...

  •  05-28-2007, 7:32 AM 15031 in reply to 15030

    Re: 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.
  •  05-28-2007, 4:55 PM 15032 in reply to 15031

    RE: Determine logical ExecutionLocation

    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.




    Rocky
Page 1 of 2 (16 items)   1 2 Next >
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems