Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #11564 > unrolled thread

Concurrent user count

Started byKuno Egger <kuno.egger@gmail.com>
First post2018-04-26 11:31 -0700
Last post2018-05-08 09:41 -0700
Articles 6 — 4 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Concurrent user count Kuno Egger <kuno.egger@gmail.com> - 2018-04-26 11:31 -0700
    Re: Concurrent user count dlzc <dlzc1@cox.net> - 2018-04-26 12:00 -0700
    Re: Concurrent user count Martin <Martin@spam.spam> - 2018-04-27 09:12 +0100
    Re: Concurrent user count "Karl-Heinz" <invalid@invalid.invalid> - 2018-04-28 11:17 +0200
      Re: Concurrent user count "Karl-Heinz" <invalid@invalid.invalid> - 2018-05-06 22:27 +0200
    Re: Concurrent user count Kuno Egger <kuno.egger@gmail.com> - 2018-05-08 09:41 -0700

#11564 — Concurrent user count

FromKuno Egger <kuno.egger@gmail.com>
Date2018-04-26 11:31 -0700
SubjectConcurrent user count
Message-ID<8e056dac-ba36-432f-aa2e-8014c2ee0a75@googlegroups.com>
Hello from British Columbia,

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.

Kuno

[toc] | [next] | [standalone]


#11565

Fromdlzc <dlzc1@cox.net>
Date2018-04-26 12:00 -0700
Message-ID<1244c364-0851-4323-bc43-44f08525946c@googlegroups.com>
In reply to#11564
Dear Kuno Egger:

On Thursday, April 26, 2018 at 11:31:43 AM UTC-7, Kuno Egger wrote:
> Hello from British Columbia,
> 
> 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.

Maybe you could trigger the computer handling the actual database, to run this:
https://docs.microsoft.com/en-us/sysinternals/downloads/handle
... and direct its output to a text file that you can parse.

You could also see if you can put an exclusive lock on the DBF, and it will fail if someone else has it locked at all.

David A. Smith

[toc] | [prev] | [next] | [standalone]


#11566

FromMartin <Martin@spam.spam>
Date2018-04-27 09:12 +0100
Message-ID<pbum2a$at4$1@dont-email.me>
In reply to#11564
There are functions within the ACE API, not sure which ones, but we use 
them to find the owners of a lock.

Search on AdsMgGetOpenTables for a list of open files. There will be a 
function somewhere which does what you want.

On 26/04/2018 19:31, Kuno Egger wrote:
> Hello from British Columbia,
> 
> 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.
> 
> Kuno
> 

[toc] | [prev] | [next] | [standalone]


#11569

From"Karl-Heinz" <invalid@invalid.invalid>
Date2018-04-28 11:17 +0200
Message-ID<fkisldFe172U1@mid.individual.net>
In reply to#11564
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 <YourFirstWindow>

SetExclusive(FALSE)
RddSetDefault ( "DBFCDX" )


    _oDBLicense := DbServer { <yourLicenceDbf> }


    IF SELF:AddUser()

      oWin := <YourFirstWindow>{}
      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 

[toc] | [prev] | [next] | [standalone]


#11579

From"Karl-Heinz" <invalid@invalid.invalid>
Date2018-05-06 22:27 +0200
Message-ID<fl96u2Fdbu0U1@mid.individual.net>
In reply to#11569
FWIW,

From Sysinternal there are the commandline tools handle.exe and handle64.exe

https://docs.microsoft.com/en-us/sysinternals/downloads/handle

combined with the RunPiped() function, posted many years ago to the german
newsgroup,  it´s easy to detect if a specific file is opened or not.

But, according the EULA the usage of this  tool is restricted:

EULA.txt

[...]
* transfer the software or this agreement to any third party; or
* use the software for commercial software hosting services.
[...]

-----------------------------

METHOD PshPipe() CLASS DtaDlgTest
LOCAL cBuffer  AS STRING
LOCA dwBufferLen, dwError AS DWORD


    dwBufferLen := 1000


   IF ( dwError := RunPiped ( "C:\bat\handle64.exe
vveigsta.dbf -nobanner -u" , @cBuffer , dwBufferLen ) )  == 0

/*
       if nothing is found cBuffer contains:   "No matching handles found."

        or if the file is opened something like this:

         "DBMax.EXE       pid:1296  type: File      pcwin8\khrauscher  1FC:
D:\Haus28\dbf\VVEIGSTA.DBF"
         "wwwHaus28.DBG   pid:1381  type: File      pcwin8\khrauscher  2E4:
D:\Haus28\dbf\VVEIGSTA.DBF"

*/
            odcmle:Value := cBuffer

     ELSE

                MsgInfo ( "Errorcode: " + NTrim (dwError ) )
     ENDIF

     RETURN SELF

-------------------------------------

FUNCTION RunPiped(cCmdLine AS STRING, cRet REF STRING, nBuffer AS DWORD) AS
DWORD PASCAL
*Return Value:
* 0= Ok
* 1= Error MemAlloc()
* 2= Error CreatePipe()
* 3= SetStdHandle()
* 4= Timeout
* 5= Error CreateProcess()
* 6= Error von Anwendung gemeldet

/*

    Per cCmdLine übergibst du den Befehl inklusive Parameter aber ohne die
    Pipe, die Pipe erhälts du als String in cRet den du per Referenz
    übergibst. Der Parameter nBuffer muss groß genug sein für die Rückgabe
    der Pipe.

*/

LOCAL si          IS _WINSTARTUPINFO
LOCAL pi          IS _WINPROCESS_INFORMATION
LOCAL nRet        AS DWORD
LOCAL nRead       AS DWORD
LOCAL nWait := 0  AS DWORD
LOCAL nTotal AS DWORD
LOCAL nRest AS DWORD
LOCAL nSize AS DWORD
LOCAL nTimeout AS DWORD
LOCAL hWriteOut   AS PTR
LOCAL hWriteErr   AS PTR
LOCAL hReadOut    AS PTR
LOCAL hReadErr    AS PTR
LOCAL dwFlags     AS DWORD
LOCAL dwExit      AS DWORD
LOCAL sa          IS _WINSECURITY_ATTRIBUTES
LOCAL hOldStdOut  AS PTR
LOCAL hOldErr     AS PTR
LOCAL pszBuff     AS BYTE PTR

nSize :=nBuffer
nTimeout :=1500
hOldStdOut := GetStdHandle(STD_OUTPUT_HANDLE)
hOldErr    := GetStdHandle(STD_ERROR_HANDLE)

sa.nLength              := _SIZEOF(_WINSECURITY_ATTRIBUTES)
sa.lpSecurityDescriptor := NULL_PTR
sa.bInheritHandle       := TRUE

    pszBuff := MemAlloc(nSize)
    IF pszBuff==NULL_PTR
        nRet:=1
    ENDIF

    //  Create a pipe between two processes for Output device
    IF CreatePipe( @hReadOut, @hWriteOut, @sa,nSize)
        IF !SetStdHandle(STD_OUTPUT_HANDLE, hWriteOut)
            nRet:=3
        ENDIF
    ELSE
        nRet:=2
    ENDIF


    IF nRet=0
        //  Create a pipe between two processes for Error device
        IF CreatePipe( @hReadErr, @hWriteErr, @sa,0)
           SetStdHandle(STD_ERROR_HANDLE, hWriteErr)
        ELSE
           nRet:=2
           CloseHandle( hWriteOut)
           CloseHandle( hReadOut)
        ENDIF
    ENDIF

    IF nRet=0
        //  Attempt to spawn process with piped handles for StdError
        //  and StdOutput
        MemSet(@si, 0, _SIZEOF(_WINSTARTUPINFO))

        si.cb           := _SIZEOF(_WINSTARTUPINFO)
        si.lpReserved   := NULL_PTR
        si.lpDesktop    := NULL_PTR
        si.lpTitle      := NULL_PTR
        si.dwFlags      := STARTF_USESTDHANDLES
        si.dwX          := 0
        si.dwY          := 0
        si.wShowWindow  := SW_HIDE       // Hide output
        si.cbReserved2  := 0
        si.lpReserved2  := NULL_PTR
        si.hStdOutput   := hWriteOut     // Piped StdOut
        si.hStdError    := hWriteErr     // Piped StdErr

        dwFlags := CREATE_NO_WINDOW

        IF CreateProcess( NULL,  ;
                       PTR(_CAST, cCmdLine), ;
                       NULL,;
                       NULL,;
                       TRUE,;
                       dwFlags,;
                       NULL,;
                       NULL,;
                       @si,;
                       @PI)

            IF GetExitCodeProcess( pi.hProcess, @dwExit)

                DO WHILE dwExit == STILL_ACTIVE
                    nWait++
                    IF (nWait > nTimeout)
                        TerminateProcess(pi.hProcess, 5333)
                        nRet:=4
                        EXIT
                    ENDIF
                    Sleep(1)
                    GetExitCodeProcess( pi.hProcess, @dwExit )
                ENDDO
            ENDIF

            //  Read from piped device (StdOutput of child process)
            IF PeekNamedPipe(hReadOut, pszBuff, nSize, @nRead, @nTotal,
@nRest)
                IF nRead=0     // keine Ausgabe in StdOut
                    //  Read from piped device (StdError of child process)
                    IF PeekNamedPipe(hReadErr, pszBuff, nSize, @nRead,
@nTotal, @nRest)
                        IF nRead>0
                            nRet:=6
                        ENDIF
                    ENDIF
                ENDIF
            ENDIF

            // Close handles and reset old standard handles
            SetStdHandle(STD_INPUT_HANDLE, hOldStdOut)
            SetStdHandle(STD_ERROR_HANDLE, hOldErr)
            CloseHandle(pi.hProcess )
            CloseHandle(pi.hThread )
        ELSE
            nRet:=5

        ENDIF

        // Close handles
        CloseHandle(hReadOut)
        CloseHandle(hReadErr)
        CloseHandle(hWriteOut)
        CloseHandle(hWriteErr)

    ENDIF

    IF nSize > 0
        cRet+= Psz2String(pszBuff)
    ENDIF

    IF pszBuff != NULL_PTR
        MemFree(pszBuff)
    ENDIF

RETURN nRet

--------------
regards
Karl-Heinz 

[toc] | [prev] | [next] | [standalone]


#11582

FromKuno Egger <kuno.egger@gmail.com>
Date2018-05-08 09:41 -0700
Message-ID<65a5ce4f-eb1d-4e3c-bea5-10ac3407e49c@googlegroups.com>
In reply to#11564
Hello David, Martin and especially Karl-Heinz.

Thanks for the great advice and support. Very helpful. 

Cheers

Kuno

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web