Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Karl-Heinz" Newsgroups: comp.lang.clipper.visual-objects Subject: Re: Concurrent user count Date: Sat, 28 Apr 2018 11:17:23 +0200 Lines: 161 Message-ID: References: <8e056dac-ba36-432f-aa2e-8014c2ee0a75@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="utf-8"; reply-type=original Content-Transfer-Encoding: 8bit X-Trace: individual.net 6Fy1Tc7saNxEC8SYqHHWTwWoOsnf1zbE2eJvZaO7/k7GJW2sg= Cancel-Lock: sha1:5QDNGUzwX/4XgAbNM+HwKBV1FGc= In-Reply-To: <8e056dac-ba36-432f-aa2e-8014c2ee0a75@googlegroups.com> X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Newsreader: Microsoft Windows Live Mail 16.4.3564.1216 X-MimeOLE: Produced By Microsoft MimeOLE V16.4.3564.1216 Xref: csiph.com comp.lang.clipper.visual-objects:11569 Hi Kuno, > Does anyone know of a way to find out how many concurrent users > have opened a DBF file? Even just a way to see if it is more than one > would do the trick. > > Any advice appreciated. What you might do is to implement a "poor man" licencing system. 1. Create a dbf with some fields. Avoid to give the dbf a name like licence.dbf, so a poweruser doesn´t know at first sight what the dbf is good for. 2. Append e.g. 4 records. In that case a maximum of 4 users can use the app at the same time. Also store in one of the fields a encrypted value that must be checked each time the server is opened. So it´s not possible to increase the licence by simply appending one more blank record. Now when you call oApp:Usercount() laterone and the return value is 1 currently only one instance of your app is running. Here´s some code. ---------------------- CLASS MyApp INHERIT App PROTECT _oDBLicense AS DbServer ----------------------- METHOD AddUser() CLASS MyApp LOCAL lAllowed AS LOGIC _oDBLicense:Gotop() DO WHILE ! _oDBLicense:EoF IF _oDBLicense:RLOCK ( _oDBLicense:RECNO ) lAllowed := TRUE EXIT ENDIF _oDBLicense:skip ( 1 ) ENDDO RETURN lAllowed -------------- METHOD Start() CLASS MyApp LOCAL oWin AS SetExclusive(FALSE) RddSetDefault ( "DBFCDX" ) _oDBLicense := DbServer { } IF SELF:AddUser() oWin := {} oWin:Show() ELSE MsgInfo ( "Only a maximum of " + NTrim (( _oDBLicense:RECCOUNT )) + " users may use the application at the same time." , ; "Licence notify" ) SELF:quit() ENDIF RETURN SELF ------------------- METHOD UserCount() CLASS MyApp LOCAL dwLockedRecno, dwCount AS DWORD // Note: The RLockList array contains always one recno only ! dwLockedRecno := _oDBLicense:RLockList[1] dwCount := 1 _oDBLicense:Gotop() DO WHILE ! _oDBLicense:EoF // ignore the dwLockedRecno recno IF _oDBLicense:RECNO != dwLockedRecno // Try to lock the current recno. // if it´s not possible one more user has started the app. IF ! _oDBLicense:RLOCK ( _oDBLicense:RECNO ) dwCount := dwCount + 1 ELSE // don´t forget to unlock() the recno ! _oDBLicense:Unlock ( _oDBLicense:RECNO ) ENDIF ENDIF _oDBLicense:skip ( 1 ) ENDDO RETURN dwCount ------------------- FUNCTION Start() LOCAL oApp AS MyApp __SetAppObject( oApp := MyApp{} ) Send( oApp, #Start ) RETURN NIL -------------------- regards Karl-Heinz