I'm working on a solution to create a scheduled task in BizTalk with the taskscheduler adapter. With a C# component I've created the FTPDownload function which returns a stream.
I'm now running into the following problem. I need to get the filename as a mark on the stream, so I can read this in another solution to get the right output filename.
For the solution to read out the filename I make use of the context properties of the BizTalk message and it would be great if I can set the filename back into the context properties when I read the FTP into the stream.
public class FTPReceive : IScheduledTaskStreamProvider
{
private readonly string TASK_COMPONENT_NAME = "ScheduledTask FTPReceive";
public Type GetParameterType()
{
return typeof(FTPReceiveArguments);
}
public Stream GetStream(object args)
{
int retryCounter = 1;
bool isDownloaded = false;
Stream responseStream = null;
FTPReceiveArguments parameter = (FTPReceiveArguments) args;
if (string.IsNullOrWhiteSpace(parameter.Url))
{
throw new ArgumentNullException(TASK_COMPONENT_NAME, "URL is null or Empty");
}
while (!isDownloaded && retryCounter <= parameter.RetryCount)
{
try
{
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(@parameter.Url);
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
ftpRequest.Credentials = new NetworkCredential(parameter.Username, parameter.Password);
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
ftpResponse.Headers.Add("Content-disposition", "inline; filename=fileName.ext");
//ftpResponse.Headers.Add("fileNameTest.xml");
responseStream = ftpResponse.GetResponseStream();
//responseStream.
isDownloaded = true;
}
catch (WebException wex)
{
if ((retryCounter +1) <= parameter.RetryCount)
{
Thread.Sleep(parameter.RetryInterval * 60000);
}
else
{
// Only Log Information to prevent the adapter will be disabled!
}
retryCounter++;
}
catch (Exception ex)
{
// Do nothing, otherwise the adapter will be disabled!
}
}
if (isDownloaded && responseStream != null)
{
return responseStream;
}
return null;
}
}
Unfortunately, the out of the box STA does not have the ability to pass Context values from the provider to the Message.
You can however modify the Adapter to do this by modifying (Non)TransactionalTasks and your provider to return an Object containing both the stream and property bag.
You then write the properties to the created Message.