Is document open

Mehboob Alam (7/21/08 8:41PM)
Bruno LEGAY (7/22/08 12:58AM)
steve simpson (7/22/08 9:55AM)
Matthias Schmidt (7/22/08 1:43PM)
Ortwin Zillgen (7/22/08 3:17PM)
Owen Watson (7/22/08 3:25PM)
Matthias Schmidt (7/22/08 4:33PM)
Owen Watson (7/22/08 5:00PM)


Mehboob Alam (7/21/08 8:41 PM)

Steve,

A change in strategy would be helpful... the "foreign" application
should create the file using a random name (32-char alphanumeric), and
then rename the file once it is finished writing its content.

The final name of this file should be the one your application is
looking for, and the name should fit a specific pattern that you are
looking for, thus you can ignore anything else being created in the
same directory, i.e the random named file.

Hope this helps..

sincerely,

mehboob alam

To make a bad day worse, spend it wishing for the impossible.

--- On Mon, 7/21/08, Steve Campbell <steve@... wrote:

From: Steve Campbell <steve@...

Date: Monday, July 21, 2008, 4:45 PM

We're trying everything...

So far, we're up to this code that we will be testing

tomorrow.

Our next try will be the "Get document size"

function suggestion .

Bruno LEGAY (7/22/08 12:58 AM)

Hi,

I understand your need.

I have seen problems with these things (opening files, files being  

locked, etc...) behave in various ways depending on platform, file  

sharing protocols implementations, etc...

This is a pain to debug and make 100% reliable. 99.99% is not always  

good enough because unhandled errors can stop processing (depending  

on error handling) and loose/miss some critical data.

Your application, has to be bullet proof and the foreign application  

too (and there are some complicated cases wich will happen  

statistically, and you may have problem understanding what happened  

and reproduce it)...

An example :

1.1 foreign application opens file (creates a new file if none  

exists, or append to file if exists - and not locked - write mode)

1.2 foreign application writes to file

1.3 foreign application close file

2.1 your application opens file (read or write mode ?)

2.2 your application reads to file

2.3 your application close file

2.4 your application delete file

Can the foreign application support locked file ? Do you read the  

file after locking it to prevent the foreign application to write the  

file while you are reading it ?

What happens if 1.1 occurs between 2.3 and 2.4 (your delete will fail  

because the file is now locked by foreign application, if you try  

again and succeed, you will miss the new data which was added at the  

end, etc...).

I have seen answer which may be partially valid (you will have to  

make sure the foreign applciation is also bullet prrof), but there is  

a simple "design" solution (that is if you can make the foreign  

application follow a new rule).

In this situation, I would make the foreign application create a  

temporary file with a temporary extension (.tmp), when finished  

writing the file, close it and then rename it (.tmp > .txt).

Then don't append to the file, just create a new one with a unique  

sequential value (tick count in hexa format "data_005A65E6.txt" or  

timestamp "data_20080722_223056.txt").

Your application only reads completed files (.txt) reads them  

sequentailly by sorting them by name.

I know this may not be possible, but it is the easyest approach to  

debug/test...

And if you ever need to write files for another application, this is  

a good approach.

HTH

steve simpson (7/22/08 9:55 AM)

<8c8b66580807220655p24c25fa7y8eb82b5cf49132cc@...

On Tue, Jul 22, 2008 at 1:53 AM, Steve Campbell wrote:

Our next try will be the "Get document size"

function suggestion .

This code has been working fine for 15 years in one of our restaurant
POS

polling packages. The POS system is triggered to output a data file
and we

never know how long that will take. All we know is the name.

       ON ERR CALL("doNothing")

        $Cnt:=0

         $doc:=Open document($Path)

         While (OK=0) & ($Cnt<<10)

               `if it was still open, it
will fail,

                 `on err will catch
that (and do nothing about it),

                  `and OK will
return zero. So just wait a bit and try

again.

             Wait (60)    `pause for a
length of time

             $Cnt:=$Cnt+1    `put in
some sort of logical failure limit

             $doc:=Open document($Path)

          End while

          ON ERR CALL("")

          If (OK=1)

             doWhatever

          end if

--

Steve Simpson

813-264-2706 office

813-478-7381 cell

Matthias Schmidt (7/22/08 1:43 PM)

Am/On Mon, 21 Jul 2008 12:56:11 -0400 schrieb/wrote Steve Campbell:

Hi all,

I'm wondering how 4D 2004.6 can determine if a document is open?

The objective is as follows:

Each one minute time interval a document is being created/overwritten  

by a foreign application.  The overwrite might take a second or two

4D is in a delay process loop and attempts to move the document to  

another folder (for processing) every one minute.

Occasionally 4D's attempt to move the document comes exactly when the  

document is "open" being overwritten/updated.

That causes a system error that the file is open or the folder is full.

Is there any way 4D can test to see if the document is open to avoid  

the system error that requires user intervention.

you could do that with Win32API on windows or with our ADmilon

MacExtrasPlugin.

You can download the plugin with an example database and documentation

from here:

<www.admilon-consulting.de>

cheers,

Matthias

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

Admilon Consulting GmbH

Am Wiesengrund 9a, 90584 Allersberg, Germany

Geschäftsführer: Peter Frank, Matthias Schmidt

Amtsgericht Nürnberg: HRB 21750

Tel.: +49-9174 - 6646 Fax: +49-9174 - 6647

<http://www.admilon-consulting.de>

Ortwin Zillgen (7/22/08 3:17 PM)

In my experiences not all third party apps open files the same way.   

For

example, try checking to see if a BBedit file is open.  Even when it  

is,

I've learned that bbedit opens and closes files even though to you  

they

appear open.  When a save needs to be done it is opened write at  

that time.

exactly

Other apps open and lock files normally.  You might want to try  

opening the

document with write access and trap for errors -45 (locked) or -49  

(file

already opened).  That is if you haven't already done so ...

this is a concept that works

ON ERR CALL("Error_None")

repeat

If (Test path name($myDocPath)=Is a document )

$DokRef:=Open document($myDocPath;"";Read and Write )

If (OK=1)

`you get the file

else

`you don't get the file

end if

end if

wait a while, if you don't get the file

until(yourTimeOut)

ON ERR CALL("")

add some checking like $myDocPath="" and you are done

Regards

Ortwin Zillgen

___________________________________________________

Stadt Land Flu&thorn; * Geographic Informationsystems

<mailto:info@...   <http://dddd.mettre.de?4713>

RSS <feed://dddd.mettre.de/dddd.xml>

RSS <feed://dddd.mettre.de/f/DDDD_Links.xml>

Owen Watson (7/22/08 3:25 PM)

<23b8d990807212025k8874e75u9c4f7f86881a4fa1@...

You didn't say whether it was Windows or Mac. . .

One solution for Windows is to run handle.exe and search for the

filename in the resulting output. I can send sample code.

Perhaps Macs have an equivalent?

Matthias Schmidt (7/22/08 4:33 PM)

Am/On Tue, 22 Jul 2008 03:24:57 -0400 schrieb/wrote Steve Campbell:

I'm on a Mac platform.

you could do that with Win32API on windows or with our ADmilon

MacExtrasPlugin.

You can download the plugin with an example database and documentation

from here:

<www.admilon-consulting.de>

you can use:

Util_FileCheck(pathToFile)-> error;

from our Plugin.

It returns, what the OS would return.

cheers,

Matthias

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

Admilon Consulting GmbH

Am Wiesengrund 9a, 90584 Allersberg, Germany

Geschäftsführer: Peter Frank, Matthias Schmidt

Amtsgericht Nürnberg: HRB 21750

Tel.: +49-9174 - 6646 Fax: +49-9174 - 6647

<http://www.admilon-consulting.de>

Owen Watson (7/22/08 5:00 PM)

<23b8d990807212200n7e8316b6hdacb22754fb27306@...

Don't think you can do it with Win32API but no doubt Jeff will chime
in. . .

2008/7/22 Matthias Schmidt <4D_info@...

you could do that with Win32API on windows or with our ADmilon

Reply to this message

Summary created 7/22/08 at 12:01PM by Intellex Corporation

Comments welcome at: feedback@intellexcorp.com