Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to know this is the last user?
Message
From
07/01/2012 21:01:36
 
 
To
06/01/2012 17:40:44
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01532350
Message ID:
01532401
Views:
52
Keep it simple, IMO, is the best way. Track the licenses. Lock the vmcontrol.dbf exclusively when doing a backup. Here is what we do in our application class. If the single user crashed rather than logged out, you can run the backup the next time a single user logs in.:
if checkLockout()
    * tell user too bad charlie brown and exit
endif

if not CheckOpenUsers()
   * licenses all used up, too bad again, exit
endif

if oUser.gnControlRecord = 1
  * make sure backup was run properly, if so go ahead, if not, roo bad charlie brown
endif

.......
......

if LogOutLast()
   do some backup
endif 

PROCEDURE CheckOpenUsers


	* -----------------------------------------------------------------------------
	* There should be a free table in the data folder called vmcontrol.
	* That table has the exact number of records as the user has licenses.  Each login
	* locks one record.  Quitting vmanager loses the lock, so no orphaned logins
	*
	* The previous function of CheckLicenseFile made sure correct number of record
	* were in vmcontrol, so if that is not true here, we will have to quit.
	* ---------------------------------------------------------------------------

	LPARAMETERS tLoginName

	IF NOT USED('VMCONTROL')
		USE (oVM.gcDataPath + 'vmcontrol.dbf') SHARED IN 0
	ENDIF

	SELECT vmcontrol


	COUNT FOR NOT DELETED() TO lnC

	* ----------------------------------------------------------------
	* # of records equals what system.dbf reports as # of licenses.
	* So we will try and lock one record.  If all records already locked,
	* then max users logged in.  Quitting automatically releases the
	* record lock, so ghost logins impossible.
	* ---------------------------------------------------------------
	IF lnC = oVM.gnMaxUsers
		SCAN
			IF RLOCK()
				* OK, folks, we do not know the user name yet!
				REPLACE field1 WITH tLoginName
				REPLACE field2 WITH SYS(0)		&& machine/user name
				oUser.gnControlRecord = RECNO()
				RETURN .T.
			ENDIF
		ENDSCAN
	ENDIF

	* ---------------------------------------------------------
	* * only get here if was right number of records for user license,
	* but we could not get a lock because  max people on already.
	* ---------------------------------------------------------
	RETURN .F.

Procedure LogOutLast
	IF NOT USED('VMCONTROL')
		USE (oVM.gcDataPath + 'vmcontrol.dbf') SHARED IN 0
	ENDIF

	SELECT vmcontrol

       * we should be able to lock every record if we are the only ones in the app    
       SCAN for recno() <> ouser.gncontrolrecord
            if not rlock()
                return .f.
            endif
        endscan
 
        return .t.
>in the multiusers environment, I want to set an automatic backup, after the last user logout.
>the trick is every time an user logout, the program will check if there are any other users still using the program.
>the backup will run only if only one user using the program.
>
>how can I do it?
>
>thanks for the help.
>
>regards,
>
>Jerry
Previous
Reply
Map
View

Click here to load this message in the networking platform