I have a console application in c# that downloads files from a website.
I have created a variable named Filecount that counts the number of files downloaded in that instance.
In SSIS, I have set the StandardOutputVariable in the Execute process task configuration as User::FileCount that should pass through the number of files that it has downloaded.
I want to create an SQL task that will truncate the table if the file count is greater than 0.
However, when I try to evaluate my expression, it always comes back as true however, this should not occur as no counts have been passed through yet meaning it should be evaluated as false.
Can someone explain if I have either written the expression wrong or set the variable incorrectly?
int fileCount = 0;
using (var client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");
var response = await client.GetAsync(siteUrl + "/_api/Web/GetFolderByServerRelativeUrl('XXX')/Files");
response.EnsureSuccessStatusCode();
json = await response.Content.ReadAsStringAsync();
Root deserializedResults = JsonConvert.DeserializeObject<Root>(json);
foreach (Result result in deserializedResults.d.results)
{
if (result.TimeCreated > DateTime.Today.AddDays(-7))
{
DownloadFileViaRestAPI(siteUrl, credentials, "XXX", result.Name, "XXX");
fileCount++;
}
}
}
Console.Write(fileCount);
SSIS Execute Process Task;
StandardOutVariable = User::FileCount
SQL Task expression;
Property: Disable
Expression: Len(Trim(@[User::FileCount])) > 0 ? False : True
tl;dr; What you've described and my implementation work fine so something else is going awry in your situation.
Set up
I built out a simple SSIS package. Execute Package Task -> Script task (to dump variable values to console) -> A Sequence Container that has your disable logic on it => Another script task (to dump to console if the disable works/does not work)
I have your original variable, User::FileCount of type String and added
User::HasFileof type Boolean with an expression ofLen(Trim(@[User::FileCount])) > 0to test your logic.SO_71067359.bat
I created a batch file that will serve as your C# app. When needed, I'll remove line 2 so no output is generated. Contents are
Results
EPT Download File
Execute Package Task. Working directory set to the location of my batch file. Executable is the batch script. StandardOutputVariable is
User::FileCountSCR Echo Back
This is my standard echo back script and I'll add
User::FileCountandUser::HasFile. When the package runs, this will dump the values to the Console output which is something I can copy and paste unlike the pretty Results tab most are familiar withContent in case my blog goes away is
SEQC Simulate Other
This is a sequence container that has your Disable logic directly added to it. Yes, I have the variable but since you have the inversion of the results, I didn't want to sully the test.
Yes it ran
Inside the sequence container is a copy/paste of the SCR Echo Back except I renamed it to "Yes it ran" and specified the only variable is
System::TaskNameIf the task runs, the console will print the name of the task.Test round 1
The output of the batch script will be "1" so we expect to see the Inner task fire. Let's check the console
Test Round 2
Clearing line 2 of the bat file