Using a File Trigger only on new files - VisualCron - Forum

Community forum

beechc
2016-02-19T12:40:47Z
Good morning.

I'm trying to figure out a way to resolve an issue I am having periodically with an existing VC workflow. In a nut shell, I have a file trigger that activates a workflow pushing files to a remote FTP this is great.

What I am trying to do is limit the trigger to only fire when the file activating the process is a file that has not been seen by the VC trigger previously; thus preventing files which have been previously transmitted from being sent again.

For example:
File ABC.txt is submitted and pushed to FTP.
File XYZ.txt is submitted and pushed to FTP.
File ABC.txt is submitted but should not get pushed as ABC.txt has previously triggered the workflow.

Is there a way to manage this through VC? I can easily write a log of the files which have triggered the workflow, but can't figure out how I might reference the list to evaluate whether the workflow should push the file or error out. Alternately s the trigger information accessible in the job database such that it can be referred to and not trigger if the file has been seen in the last 30 days for example?

ErikC
2016-02-22T09:52:23Z
Hi,

I don't know how your programming skills are, but you you can use a liltte code here to do the trick:

You can have a file write task which will write the current datetime and the triggered filename into one line in a file.
Every trigger will append a line with this data.

The next task can be a .NET task with the triggered filename as a parameter. This task looks into the file created in step 1 and looks for the filename from bottom to top. On the 2nd hit (1st hit will be itself) it checkes the written date to the current date and based on the time diff you return a string value, like "trigger OK" and "trigger NOK". Is there is no 2nd match, the result must be "Trigger OK".

The next step should contain a condition which will check the output of the previous task and run the 3rd task or not.

Reards,
Erik
Uses Visualcron since 2006.
ErikC
2016-02-22T10:03:35Z
Reading my own solution I would do it a bit different.

1st task is the .NET task looking for the 1st hit from bottom to top. -> "Tigger OK" or "Tigger NOK"
2nd task has condition if Trigger OK, than white new entry in trigger log file
3rd task uses the same condition and does the copy task.

So only if a trigger may happen, there will be a new line in the trigger log file.

Regards,
Erik
Uses Visualcron since 2006.
ErikC
2016-02-22T10:40:13Z
This can be the .NET task for you:
using System;
using System.IO;
using System.Globalization;

public class Test
{

 public static string CheckTiggerFile(string triggerlogfile, string triggername, int days2trigger)
 {
 	if(!File.Exists(triggerlogfile))
 		return "Trigger OK";
 
 	string[] readText = File.ReadAllLines(triggerlogfile);
  	DateTime date  = new DateTime();
 	for(int a = readText.Length-1 ; a>=0 ; a--)
 	{
 		if(readText­čů░.Trim().Length > 0)
 		{
 			try{
 				date = DateTime.ParseExact(readText­čů░.Split(' ')[0],"d", CultureInfo.InvariantCulture);
 			}
 			catch(FormatException){
 				return ( readText­čů░.Split(' ')[0] + " is not in the correct format.");
 			}
 			
 			string file = readText­čů░.Split(' ')[1];
 			if(triggername == file){
 				if( (DateTime.Today - date).TotalDays > days2trigger)
 					return "Trigger OK";
 				else
 					return "Trigger NOK";
 			}
 		}
 	} 
     return "Trigger OK";
 }
}


Parameters:
triggerlogfile: c:\triggerlog.txt
days2trigger: 30
triggername: {TRIGGER(Active|LastTrigger|File.Result.Name)}

In the file write task use:
{DATEFORMAT(MM/dd/yyyy)} {TRIGGER(Active|LastTrigger|File.Result.Name)}

Regards
Erik.
Uses Visualcron since 2006.
Scroll to Top