Re: Starting App from a netfolder
Posted: Mon Sep 17, 2018 8:22 pm
Yes, you can. HMG has native support for mysql
Are you know sql?
Are you know sql?
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
http://hmgforum.com/
Code: Select all
#include "hmg.ch"
PROCEDURE Main
PUBLIC cPath:='', cLoggedDBF:='logged_user.dbf', cLoggedUserName:='', cLoggedFileName
hb_vfOpen( hb_ProgName(), 16 ) //The solution proposed by PeteWG.
MsgBox('Checking solution: hb_vfOpen( hb_ProgName(), 16 )')
cLoggedFileName := cPath + cLoggedDBF
IF !FILE( cLoggedFileName )
dbcreate( cLoggedFileName, {{"USERNAME","C",50,0}} )
SELECT 333
USE &(cLoggedFileName)
APPEND BLANK
USE
ENDIF
SELECT 333
SET EXCLUSIVE OFF
USE &(cLoggedFileName)
SET EXCLUSIVE ON
cLoggedUserName := Alltrim ( UserName )
IF !FLOCK()
MsgStop('This application is currently used by ' + cLoggedUserName, 'Access denied.')
QUIT
ENDIF
REPLACE UserName WITH GetComputerName()
COMMIT
//Open any DBF, but do not close select 333 until the application is finished.
DEFINE WINDOW Servisa ;
AT 120,120 ;
WIDTH 400 ;
HEIGHT 300 ;
FONTNAME 'ARIAL' FONTSIZE 12;
TITLE "DATA" ;
MAIN ;
ON RELEASE QuitApp()
END WINDOW
Servisa.center
ACTIVATE WINDOW Servisa
RETURN NIL
*********************************************
FUNCTION QuitApp()
//It is not necessary:
//CloseData() //Close all aliases except 333
//SELECT 333
//REPLACE UserName WITH ''
CLOSE DATA
RETURN
*********************************************
FUNCTION CloseData()
Local i
FOR i := 1 TO 999
IF i <> 333
SELECT &i
CLOSE
ENDIF
NEXT i
RETURN
PeteWG wrote: ↑Mon Sep 17, 2018 10:06 am Hi,
probably the most quick (and not dirty, I hope, yet quite strict and inflexible), might be this line of code alone:Put it on top of your Main() procedure and let the OS be responsibleCode: Select all
hb_vfOpen( hb_ProgName(), 16 )
that only one user at a time will be able to run the program.
It's similar to "semaphore" proposition made by Angel, but it doesn't require
a dummy dfb or something. It's kind of a "self-semaphore-ization"
Note: I have not tested it, but see no reason to not works as expected.
Warning: Be sure your users do not used to have a "two-three hours coffee break", leaving the program running!
regards,
Pete
_____________________________________________________________________________
- “Sir, I exist!”
- “However”, replied the Universe, “the fact has not created in me a sense of obligation”.
(Stephen Crane)
Code: Select all
#include "hmg.ch"
PROCEDURE Main
Local fApp
//Attempt #1
//It doesn't work.
//hb_vfOpen( hb_ProgName(), 16 )
//Attempt #2
//It works only after the third application launch.
//fApp := hb_vfOpen( hb_ProgName(), 16 )
//Attempt #3
//It doesn't work.
//DO WHILE !hb_isPointer(hb_vfOpen( hb_ProgName(), 16 ))
//ENDDO
//Attempt #4
//It works on local devices only
maxAttempts:=1000
nAttempt:=0
DO WHILE .T.
nAttempt++
fApp := hb_vfOpen( hb_ProgName(), 16 )
IF hb_isPointer(fApp) .OR. nAttempt == maxAttempts
EXIT
ENDIF
ENDDO
IF !hb_isPointer(fApp)
MsgInfo('An attempt to set the Exclusive mode failed !')
QUIT
ENDIF
DEFINE WINDOW Servisa ;
AT 120,120 ;
WIDTH 400 ;
HEIGHT 300 ;
FONTNAME 'ARIAL' FONTSIZE 12;
TITLE "DATA" ;
MAIN
END WINDOW
Servisa.center
ACTIVATE WINDOW Servisa
RETURN NIL
*********************************************
Hi EDK,
Code: Select all
#include "hmg.ch"
PROCEDURE Main()
LOCAL pKeyHandle
DEFINE WINDOW AppWin ;
AT 120,120 ;
WIDTH 400 ;
HEIGHT 300 ;
TITLE "Semaphorization!" ;
MAIN ;
ON INIT (Iif( GetTheConch( @pKeyHandle ), NIL, ;
( MsgExclamation( "No one runs the program unless he's holding the conch!", "No Pasaran!" ), __Quit() ) ) ) ;
ON RELEASE ( Iif( ! Empty( pKeyHandle ), ;
MsgInfo( Iif( hb_vfClose( pKeyHandle ), "Key file closed! That's neat.", "Hmm! cannot close key file. (why?)" ) + hb_eol() + ;
"Quitting program...", "Exit" ), NIL ) )
END WINDOW
CENTER WINDOW AppWin
ACTIVATE WINDOW AppWin
RETURN
FUNCTION GetTheConch( pHandle )
LOCAL cProgName := hb_ProgName()
LOCAL cKeyFile := hb_FNameName( cProgName ) + ".key"
IF (pHandle := hb_vfOpen( cKeyFile, 0x0500 ) ) == NIL
RETURN (pHandle := hb_vfOpen( cKeyFile, 16 ) ) != NIL
ENDIF
hb_vfClose( pHandle )
RETURN (pHandle := hb_vfOpen( cKeyFile, 16 ) ) != NIL
Hi Pete.PeteWG wrote: ↑Tue Sep 18, 2018 2:53 pm Anyway, below is a worked sample, of how a file locking scheme, resembling a "semaphore-like" mechanism,
could be implemented and used for the purpose that ROBROS asked for.
(...)
Right now I can't test it on network, only locally on my notebook.
You may want to confirm whether it's working or not.
regards,
Pete
That's good! Now, I'm thinking this function could be extended a little, to do a simple program usage logging,I checked your Semaphorization in a network environment and it works great. Thanks.
yes! normally, a decent O/S should release any pending file-locking(s), made by a program that has stopped running.It seems to me that the operating system releases any file locks made by it after the application is finished.