Cobol Foro

Cobol Foro (https://www.cobolforo.es/index.php)
-   PowerCOBOL (ActiveX, v4 - v11) (https://www.cobolforo.es/forumdisplay.php?f=9)
-   -   [Componente] Reto (https://www.cobolforo.es/showthread.php?t=1268)

Nitzer 27 de febrero de 2021 18:13

Reto
 
Hola, a ver si alguien es capaz de realizar algo así, os cuento.

Se trata de FileSystemWatcher.

https://www.levelextreme.com/Home/Sh...or=23&ID=38881

Se trata de averiguar cuando algo en la carpeta seleccionada cambia.
Lo quiero implementar para poder detectar en tiempo real si hay un cambio en alguna DLL y que avise al usuario de que tiene que actualizar.

Espero haberme explicado bien :)

Hay bastante información en Internet, pero no se como implementarlo, igual lo mejor es hacer un ocx. A ver si se os ocurre algo :)

Gracias.

Kuk 28 de febrero de 2021 11:09

@Nitzer, mi proposición:
  1. Ejecutar "cmd /c dir >%directorio\del\fichero%" mediante Execute
  2. Leer el fichero y guardar en Working
  3. Las lecturas siguientes, comparar con lo que hay en working

Hacerlo en un Timer, cada minuto o algo así, para no hacer demasiadas I/O

Nitzer 28 de febrero de 2021 15:39

@kuk, esa solución siempre está presente, pero la idea es hacer algo que en otros lenguajes es relativamente sencillo :).
Lo he probado en Visual Basic y funciona perfectamente, hay varios ejemplos en internet.
Pero no se como implementarlo en Cobol.

fastpho 28 de febrero de 2021 16:04

Buenas @Nitzer, estuve leyendo un poco del tema de monitoreo de carpetas es mas facil en otros lenguajes como vb como comentas, pero podrias probar hacer llamadas cada cierto tiempo a la función FindFirstChangeNotificationA de libreria kernel32 que se puede llamar desde pwc ....

https://docs.microsoft.com/en-us/win...enotificationa
Saludos

Nitzer 28 de febrero de 2021 17:50

Pues Fastpho he estado probando, pero no consigo el resultado :(

he incluido este código, según he visto por Internet como usar la Api.
Código COBOL:
  1.      MOVE SPACES TO RUTA
  2.      STRING 'U:\UNICA' X'00' DELIMITED BY SIZE INTO RUTA
  3.     CALL "FindFirstChangeNotificationA" WITH STDCALL USING BY CONTENT RUTA
  4.                                                        BY VALUE POW-FALSE
  5.                                                        BY VALUE 0
  6.                                                        RETURNING RETORNO

fastpho 28 de febrero de 2021 18:35

Nitzer estoy mirando desde el celular ,me parece q el flag 0 esta mal y empezaria por leer una carpeta del disco local para saber si funciona,no se funcionara con disco de red, que valor tes esta retornando ?

Kuk 28 de febrero de 2021 22:32

@Nitzer, el BY VALUE 0 no lo puede ser, como dice @fastpho.

Tienes que elegir uno de los siguientes valores:

Cita:

Citación del post de Microsoft

FILE_NOTIFY_CHANGE_FILE_NAME
0x00000001

Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file name.

FILE_NOTIFY_CHANGE_DIR_NAME
0x00000002

Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory.

FILE_NOTIFY_CHANGE_ATTRIBUTES
0x00000004

Any attribute change in the watched directory or subtree causes a change notification wait operation to return.

FILE_NOTIFY_CHANGE_SIZE
0x00000008

Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.

FILE_NOTIFY_CHANGE_LAST_WRITE
0x00000010

Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.

FILE_NOTIFY_CHANGE_SECURITY
0x00000100

Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.


Nitzer 28 de febrero de 2021 23:13

@Kuk, U: es una carpeta local, le llamo U de Unica :)

Ya vi los valores, pero como le paso el primero por ejemplo 0X0000001 , no tengo ni idea.

fastpho 1 de marzo de 2021 13:44

@Nitzer, los flags son los filtros o eventos que queres monitorear , los valores serian
Código:

FILE_NOTIFY_CHANGE_FILE_NAME = H1 'decimal 1
 FILE_NOTIFY_CHANGE_DIR_NAME = H2 'decimal 2
 FILE_NOTIFY_CHANGE_ATTRIBUTES = H4 'decimal 4
 FILE_NOTIFY_CHANGE_SIZE = H8 'decimal 8
 FILE_NOTIFY_CHANGE_LAST_WRITE = H10 'decimal 16
 FILE_NOTIFY_CHANGE_LAST_ACCESS = H20 ' decimal 32
 FILE_NOTIFY_CHANGE_CREATION = H40  'decimal 64


Kuk 1 de marzo de 2021 14:41

@Nitzer, lo que empieza por 0x es en Hexadecimal. Con lo cual, sería

Código COBOL:
  1. * FILE_NOTIFY_CHANGE_SECURITY = 0x00000100
  2.  01 FILE_NOTIFY_CHANGE_SECURITY PIC S9(9) COMP-5 VALUE H"00000100".


La franja horaria es GMT +2. Ahora son las 16:20.

Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.