Page Index Toggle Pages: [1] 2  Send Topic Send Topic Print Print
Very Hot Topic (More than 25 Replies) Polling a Folder for a Dropped In new file (Read 4227 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Polling a Folder for a Dropped In new file
Oct 25th, 2011 at 8:25pm
Print Post Print Post  
I am trying to monitor a folder for dropped in new file and if so, wants to open it up. The following code does not seem to work.  I want the program to work in the background. Initially I have placed it in the command button. It hangs up with slate empty. Any idea?

Code
Select All
var vFileList1 as String      //Initial Filelist
var vFileList2 as String     // FileList after a new file dropped into the folder
var vPath as String = "c:\Progra~1\ePresc~1\Inbound\201110w4"
var vFileToOpen as String
var vFiles as String
var vDigit as Int
var vStr as String

var vLoop as Int
var n as Int



If svStop = "Continue" then
	{

		svStop = "Stop"
		vLoop = 2
	}
	Else
	{
		svStop = "Continue"
		vLoop = 1

	}
WriteLN ("Value For svStop = " + svStop)
WriteLN ("Value of vLoop = " + @str (vLoop))




//svStop = "Continue"

While vLoop = 1
	{
		vFileList1 = @LocalListdirectory (vPath)
		WriteLN (vFileList1)
		Loiter(15000)
		vFileList2 = @LocalListdirectory (vPath)
		WriteLN (vFileList2)



				//WriteLN ("Files after Downloading Completed: " + vListB)
				VFileToOpen = @DifferenceStringArray(vFileList2, vFileList1)
				WriteLN ("Files to Open: " + vFileToOPen)


		For n = 1 to @CountStringArray (vFileToOpen)
				vFiles = @AccessStringArray (vFileToOpen, n)

				 vDigit = @AsynchShell (vPath + "\" +  vFiles)
				vStr = vStr + @NL ( ) + vFiles
				Next



		If svStop = "Continue" then
			{
				vLoop = 1
			}
			Else if svStop = "Stop" then
			{
				vLoop = 2
			}



	}
 



  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #1 - Oct 25th, 2011 at 9:05pm
Print Post Print Post  
It seems like it is the Loiter command that freezes the WriteLN window and does not let me do anything for the loiter period. What I want is something to work in the background without interrupting what I am doing and it should only open up the file when something new dropped into the folder.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Polling a Folder for a Dropped In new file
Reply #2 - Oct 26th, 2011 at 12:13am
Print Post Print Post  
You might want to look up RunEntryOnInterval. It calls a snippet of code on a set interval. That way you can check every once in while without tying up the rest of Sesame with a tight loop.

Try to write the minimal and fastest code you can for the snippet.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #3 - Oct 26th, 2011 at 12:55am
Print Post Print Post  
Thanks Mark. I will try.
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #4 - Oct 26th, 2011 at 7:39am
Print Post Print Post  
RunEntryOnInterval ( ) works great for folder polling purpose.  Thanks to Mark for the tip. Created two command Buttons, one toggle button that changes the color and Label as per state (Polling ON - Green or Polling OFF - Red) and other with the main code and made it invisible.  The code is activated initially from Form Entry event and later on perpetuated by itself with option to interrupt and restart with toggle button.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Polling a Folder for a Dropped In new file
Reply #5 - Oct 26th, 2011 at 1:21pm
Print Post Print Post  
Glad I could help.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Steve_in_Texas
Senior Member
*****
Offline


No personal text

Posts: 893
Location: San Antonio
Joined: Feb 21st, 2004
Re: Polling a Folder for a Dropped In new file
Reply #6 - Oct 26th, 2011 at 10:21pm
Print Post Print Post  
Sounds like a fun project to build, Bharat. I've been wanting  to build a 'smart' email auto-responder ap in Sesame and was hung up on how to check mail every 30 minutes.

RunEntryOnInterval() should get the job done.

Thanks for the insight Bharat and Mark.
  
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #7 - Oct 27th, 2011 at 1:42am
Print Post Print Post  
Hello Mark and Steve,
RunEntryOnInterval () works well. But there might be a little problem. Once the code is activated, Ecape key does not work and this makes working with any forms almost impossible. This could be a bug or problem with coding. It is good that there is a toggle button to interrupt the code. After interrupting the code, Escape works fine. Please look into it. Thanks.
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Polling a Folder for a Dropped In new file
Reply #8 - Oct 27th, 2011 at 12:49pm
Print Post Print Post  
@Steve: Check out the Email commands on page 551-552 of the Sesame User Guide.

@Bharat: We cannot close a form while there is code running and RunEntryOnInterval counts. Usually, continuous polling functions like this are run from a separate client to avoid interfering with other work.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #9 - Oct 27th, 2011 at 1:52pm
Print Post Print Post  
Hi Erika,
I am running the code from Menu form which never closes. However, when the count code is active, it does not let me close any other forms. In short, ESCAPE key does not work in order to come out of any other forms also. This makes it impossible to work when RunEntryOnInterval ( ) code is active. I cannot understand, why the code of one form should affect all other forms functioning?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Polling a Folder for a Dropped In new file
Reply #10 - Oct 27th, 2011 at 3:11pm
Print Post Print Post  
Bharat_Naik wrote on Oct 27th, 2011 at 1:52pm:
Hi Erika,
I am running the code from Menu form which never closes. However, when the count code is active, it does not let me close any other forms. In short, ESCAPE key does not work in order to come out of any other forms also. This makes it impossible to work when RunEntryOnInterval ( ) code is active.


I'm looking into it.

Quote:
I cannot understand, why the code of one form should affect all other forms functioning?


It is probably because we are being overly protective about not closing the relevant form. If you can give me a general idea about the end-goal functional requirement, I may be able to work out a workaround.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #11 - Oct 27th, 2011 at 3:39pm
Print Post Print Post  
Thanks Mark and Erika for looking into this. I get the feedback for ePrescription as they are accepted or rejected. Sometimes some requests for Refill, etc. This is being dumped in one of the folders in the system. I am trying to continuously poll this folder for new files and open it up as they come for my review and further action. I want this to happen in the background while I work on the other files like preparing patient's visit record, printing reports, checking eligibility, etc.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Polling a Folder for a Dropped In new file
Reply #12 - Oct 27th, 2011 at 4:22pm
Print Post Print Post  
I'd strongly recommend that you follow Erika's advice and build a new application for the purpose of retrieving and mildly processing these "dropped-in" files. You can then have any of your main applications query the new application for any info that needs to be shared.

Run both application in separate clients at the same time. That way you can keep working in the main application while the other is processing. Put a button in the main application that pulls info from the polling application whenever you need the main application to be updated.

The polling application should be little more than a clearing house for the files that are getting dropped-in.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Polling a Folder for a Dropped In new file
Reply #13 - Oct 27th, 2011 at 6:35pm
Print Post Print Post  
Well, I do have an extra client. Most of the coding is done, so making extra application should not be a problem. However, it will be inconvenient but workable until future solution is found. It would be really nice if the same application could have also handled polling. In the future, we are more likely to have applications that will have to negotiate through direct communication through internet that will involve some kind of polling. I cannot resist to ask, will the future release will have RunEntryOnInterval ( )  or some similar command for continuous polling  that would not paralyze the whole application, it is activated on? In other words, polling would not necessitate a dedicated client... if it is possible.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Polling a Folder for a Dropped In new file
Reply #14 - Oct 27th, 2011 at 6:58pm
Print Post Print Post  
Paralyze? Is that an overstatement? So far all you have mentioned is that closing a form doesn't work when you are polling. You should be able to simply stop polling briefly, close whatever form, and then continue polling as needed.

It is unwise (in the sense of good, safe design) to poll I/O (including net) in anything other than an application that can act as a dedicated I/O process.

I am looking into why you are unable to close forms in an application that is running code at an interval. 
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send Topic Send Topic Print Print