像函数调用一样用脚本任务替换发送邮件任务
Replace Send mail task with Script Task like a function call
我有一个包含 10 多个包的项目。每个包都通过发送邮件任务配置了成功、失败和错误邮件通知。
我可以用脚本任务替换它来发送邮件通知,因为我必须重试多次才能发送邮件通知。
我在我的脚本任务中准备了如下逻辑。
int attempts = 0;
int times =3;
int delayMs =1000;
do
{
try
{
attempts++;
<Actual Code>
//throw new NullReferenceException("Exception Thrown Manually.");
Dts.TaskResult = (int)ScriptResults.Success;
break; // Sucess! Lets exit the loop!
}
catch (Exception e)
{
if (attempts == times)
{
Dts.Events.FireError(-1, "Task Name", "The process tried to send mail notification " + attempts.ToString() + " times but exception caught on the final attempt as well.Hence failed to send Mail notification.Please see the error message - " + e.Message,String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
break; // Failure! Lets exit the loop!
}
Dts.Events.FireError(-1, "Task Name", "Exception caught on attempt " + attempts.ToString() + " - Will retry after delay " + delayMs.ToString() + " MilliSeconds "
//+ e.Message
, String.Empty, 0);
System.Threading.Thread.Sleep(delayMs);
}
} while (true);
我正在为每个包手动将发送邮件任务替换为脚本任务。这很耗时,也可能导致人为错误。
我不确定我是否可以将这个逻辑放在某个地方并尝试从我的所有包中像函数一样调用这个逻辑,比如代码可重用性。
我一直在尝试解决这个问题。
创建一个只发送电子邮件的包。
您通过调用电子邮件包的包中的包参数将信息传递给它。在调用邮件程序的包中处理正文、主题等的构建。
此时您实际上是将电子邮件包视为一个函数。
我有一个包含 10 多个包的项目。每个包都通过发送邮件任务配置了成功、失败和错误邮件通知。 我可以用脚本任务替换它来发送邮件通知,因为我必须重试多次才能发送邮件通知。
我在我的脚本任务中准备了如下逻辑。
int attempts = 0;
int times =3;
int delayMs =1000;
do
{
try
{
attempts++;
<Actual Code>
//throw new NullReferenceException("Exception Thrown Manually.");
Dts.TaskResult = (int)ScriptResults.Success;
break; // Sucess! Lets exit the loop!
}
catch (Exception e)
{
if (attempts == times)
{
Dts.Events.FireError(-1, "Task Name", "The process tried to send mail notification " + attempts.ToString() + " times but exception caught on the final attempt as well.Hence failed to send Mail notification.Please see the error message - " + e.Message,String.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
break; // Failure! Lets exit the loop!
}
Dts.Events.FireError(-1, "Task Name", "Exception caught on attempt " + attempts.ToString() + " - Will retry after delay " + delayMs.ToString() + " MilliSeconds "
//+ e.Message
, String.Empty, 0);
System.Threading.Thread.Sleep(delayMs);
}
} while (true);
我正在为每个包手动将发送邮件任务替换为脚本任务。这很耗时,也可能导致人为错误。 我不确定我是否可以将这个逻辑放在某个地方并尝试从我的所有包中像函数一样调用这个逻辑,比如代码可重用性。
我一直在尝试解决这个问题。
创建一个只发送电子邮件的包。
您通过调用电子邮件包的包中的包参数将信息传递给它。在调用邮件程序的包中处理正文、主题等的构建。
此时您实际上是将电子邮件包视为一个函数。