Finding a logged on user

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Finding a logged on user

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:47 pm

by Anonymous >> Tue, 11 Nov 2003 14:55:57 GMT

Hi all,

I'm new to Jade. I have a quick question, and I hope someone can help me out.

I have a Jade application running, that needs to send a message to another machine on our office network when a certain condition presents itself. But firstly, I need to know if they are logged on or not, and if they are to send them a message in a pop up box.

I have managed to do this so far using node.createExternalProcess, and using net send. But I don't like it - its a hack. There must be a Jade way of donig it...surely?! Anyone?!

Thanks
Dave

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Finding a logged on user

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:47 pm

by Kevin >> Tue, 11 Nov 2003 20:39:16 GMT

Dave,

Why don't you use Jade's notifications and then let the system handle the problem.

Have the receiver of the message register for a user notification when he signs on, eg beginNotification(global, Process_Message, Response_Continuous, 0); , and then the sender will just need to do a causeEvent of that type eg global.causeEvent( Process_Message, true, <your message>); and if the appropriate user is signed on, he will receive the event, and process it.

Note :- if you use global as the target object, the event will not occur across schemas. To cause events across schemas use either system or one of your objects which is visible across the required schemas.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Finding a logged on user

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:47 pm

by Brendan Doolan >> Wed, 12 Nov 2003 10:58:56 GMT

Dave,
The Jade feature called Notifications is the way to do this. And easy too. It may pay to ask yourself if you really need to know that a particular user is logged on and tell that user specifically , or do you just want to tell "anyone who may be interested". Very often it is the latter and then it is even simpler.

1. Define the object you are going to do the event on. This object must be visible to both the process causing the event and the interested party. Let's suppose this object is a persistent customer (cust)

2. The interested party (in your case the user you want to show popup box to) then does something like
rcvr.beginNotification(cust, eventNum, Response_Continuous, 0); where rcvr is often a form but can be any object. However, the userNotify or sysNotify event must be defined on the class of the rcvr object. This line needs to be done only once, for example in the load event of a form. Note that the event method is called userNotify (sysNotify) for Window subclasses but is called userNotification (sysNotification) for other classes. This is a necessary quirk due to the fact that a) controls on a form can be cloned and b) Jade does not support different parameters for overloaded methods.

3. When you want to communicate with interested parties, you do a
cust.causeEvent(eventNum, true, <info>);
where <info> can by anything, including null.

Jade will then send a windows message (a notification) to all interested parties ie. only those who called the method in 2 with the appropriate parameters.

The real beauty of this is that that you (the causer of the event) don't need to know who has declared an interest, if they are running etc.

If you do have to send a message to a specific user, often the best way of doing this is to get a reference to that user's Process object. A persistent instance of the process class is created by Jade for each user on the system. Then that user will do step 2 above but use process (the Jade keyword) instead of cust. You then can do step 3 but using the other user's process object instead of cust. Note that you should set an exception handler before step 3 in case the other user has signed off since, in that case, his process object will have been deleted by Jade so your reference will be to an invalid object. You will probably want to pass information via the third parameter (userInfo) in the causeEvent method.

Using the powerful feature of notifications allows you to let Jade do most of the hard work for you.

Brendan


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 9 guests