Results 1 to 19 of 19

Thread: Handling variables and params in a DLL project.

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Handling variables and params in a DLL project.

    I have a class library with loads of classes like User and Customer blah blah blah
    I have 4 params that are common to ALL calls to these objects:
    • Auth Username
    • Auth Password
    • WebServiceURL
    • PDC

    ie:
    Code:
    Dim obj As New User("My New User Name", authUsername, authPassword, url, pdc)
    this however is very irritating and I simplyu want to call this function with the param "My New User Name".

    I created a new shared class, in the project with all my other classes, and used this to store the props I want. Now my code looks like:

    Code:
    WokasDataController.AuthUsername = authUsername
    WokasDataController.AuthPassword = authPassword
    WokasDataController.WebServiceURL = url
    WokasDataController.PDC = pdc
    
    Dim obj As New User("My New User Name)
    The code inside the User class then queries this data from the shared file.
    All good so far.

    Except that in the web world the saved data is available to the entire web app and not just the session that the app is running under. These shared params can therefore get overwritten my another user submitting a request.

    Any ideas on how to get these 4 params into my DLL with passing all 4 to every function calls that makes a call to the backend web service?

    Woof

  2. #2

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    After a few queries ppl I will clear a few points up.
    • Ignore the data I am passing, this can be any data...even data like "Woof". This doesn't have to have anything to do with URL's and users.
    • I mentioned the web, but this code can also be for a Win32 app...so it can't use HTTPContext etc.
    • Yes, I could save to a temp file or something like that, but I simply don't want to as I feel that would be a cheap hack...same goes for a DB.
    • Yes, I can use session for web, I am well aware of that
    • ...and no, I am not being a pain in the arse


    Any ideas would be much appreciated.

    WOka

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Handling variables and params in a DLL project.

    Your class could have a Shared Dictionary that stores instances of the class keyed on user name. The Dictionary is universally accessible but each logged in user will be able to access their own instance of the class by specifying their user name.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    Yea, but wouldn't that require me to pass a value to every call of my classes?
    Code:
    Dim obj As New User("NewUserName", "Some identifierKey")
    If I was gonna do that then I may as well store the props in a class and pass the entire class.

    Hmmmm this is a puzzling issue.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Handling variables and params in a DLL project.

    The point was that the user name was the key. Would that not work? You'd only have one entry per user name wouldn't you?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    Yea, but how does the backend of my project know what the username is to retreive the values from the dictionary?

    Woka

  7. #7

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    Code:
    WokasDataController.Data1 = "Some data 1"
    WokasDataController.Data2 = "Some data 2"
    WokasDataController.Number = 4
    
    Dim obj As New MyClass("Data in constructor")
    I have no knowledge of users here. I have renamed the code so that it is generic.

    Woof

  8. #8

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Handling variables and params in a DLL project.

    Maybe I'm misunderstanding something here. You were talking about having a Shared class and getting the values from it, correct?
    vb Code:
    1. Dim userName As String = "NewUser"
    2.  
    3. WoksDataController.UserData.Add(userName, New WoksDataController(authUsername, authPassword, url, pdc))
    4.  
    5. Dim obj As New User(userName)
    Now in your User class:
    vb Code:
    1. Dim myUserData As WoksDataController = WoksDataController.UserData(Me.userName)
    Now you've got the four values for the current user name inside the User object.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Handling variables and params in a DLL project.

    I didn't see posts #7 and #8 until after posting #9. Maybe my idea won't work in your specific circumstances but you've got the pattern I was seeing anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    lol.
    I can see where you're coming from, but I don't have any info that I am passing that could be used as a key, otherwise I would have probably gone for that method also.

    Definately got me scratching my head...

    Woof

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Handling variables and params in a DLL project.

    No credit for me.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: Handling variables and params in a DLL project.

    The problem you have come accross is that web protocols are stateless. That is, the client and the server are disconnected, and if you want to preserve state accros transactions you will have to store the state, and refer to it using a unique session id everytime you need to recall it.

    How you implement this is of course based on your own needs, but the minimum you will need to do is pass a session id to the server on every request.
    Martin J Wallace (Slaine)

  14. #14

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    This has NOTHING to do with web.
    There are no transactions here.

    Like I said, I am aware of using session, but like stated above...this IS NOT an option I am quite capable of doind this via session, DBs, registry, using a file, passing a class to all functions etc....I can implement those no problems. I just simply don't want to because I see all of them as floored programming. end of

    Plus, all of the above methods require you to pass at least one bit of identifying info to the constructors of my classes...which again, is exactly what I do not want to do.

    If I was gonna pass anything at all, it certainly wouldbt be a session ID, it would be as jmcilhinney suggested and I would pass the class object containing all the props I want...but I will repeat myself again...I don't want to pass anything

    *and breath* lol



    Wooooof

  15. #15

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    ...I'd just like to add...this was possible in VB6

    Well it's almost possible here, by using a shared class, except when calling from a web client the shared class props get set by all web sessions...but is just plain stupid. It should be local to a session, and not global to the app. HUGE floor in .NET that has been around for the last 4 years.


    Woof

  16. #16
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: Handling variables and params in a DLL project.

    I will ignore your rant and mispelling of flaw/flawed.

    When you say a shared class, do you infact mean a class with shared properties?

    Shared Properties are available/common to all instances of the class, regardless of instatiation. Is this is what you are experiencing?

    I am presuming, from your description, that it works fine if the class library is used by a winforms application - but not when used from a web application.

    Is this because the forms app creates a seperate process for each instance, whereas the web application is using a single instance for all users (as it should)?

    I don't see it as a flaw, that is simply how it should work. Either you have a 'shared class', that is accessed by everything in the application or you have a unique instance, that you pass a reference to, to your other classess.

    You can't expect your webserver to last very long if you think it will start a new application pool for every user connected.
    Martin J Wallace (Slaine)

  17. #17

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    Please don't ignore my rant

    What you have said is correct.
    Win32 it does work, Web it doesn't...for the exact reason you mentioned.
    I am well aware of this.
    I am aware of what shared/static functions are...I called it a shared class because that's all it does...it's not an instancable class.

    However...that doesn't mean I have to respect, or even acknowledge, that this can't be done, or the fact it should be possible...it should be possible because I say no, nothing more, nothing less

    I want that kinda functionality...and I think I have found a way to do it.

    This code works fine in Win32, so no chances need to be made here.


    So, my work around:

    When initialising the params I do a check...win32 or web? If win32 then store normally in shared param in class, if web then store in session using HTTPContext. The same goes for when retreiving the data.

    So...hmmmm...how to check it's running under web...hmmmm.
    Code:
    if(System.Web.HTTPContext.Current != null)
    {
       //running in web world
       string myData = System.Web.HTTPContext.Current.Session["MyData"].ToString()
    }
    That would seem to work...will implement that tonight..


    Woof

  18. #18
    Fanatic Member Slaine's Avatar
    Join Date
    Jul 2002
    Posts
    641

    Re: Handling variables and params in a DLL project.

    Hey you cheated!

    You said not to use HTTPContext
    Martin J Wallace (Slaine)

  19. #19

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Re: Handling variables and params in a DLL project.

    The reason I said no HTTPContext or web was the fact every man and his dog would have replied saying: Use the session...

    I would then have had to terminate the being of those ppl.

    JUST using session would not have given me what I wanted.

    In the end, this is a very easy bit of code to implement and will give me exactly what I need to get around MS buggy IIS

    lol

    Wooooof

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width