我想知道是否有可用于AWS .NET SDK的SWF工作流程C#示例代码?
AWS论坛帖子:https://forums.aws.amazon.com/thread.jspa?threadID=122216&tstart=0
答案 0 :(得分:5)
作为熟悉SWF的一部分,我最终编写了一个我希望其他人也可以使用的常见案例库。它被称为SimpleWorkflowFramework.NET,可在https://github.com/sdebnath/SimpleWorkflowFramework.NET作为开源使用。它绝对可以使用很多帮助,所以如果你有兴趣,请直接进入! :)
答案 1 :(得分:0)
我开发了一个开源.NET库 - Guflow来编写Amazon SWF。以下是编写视频转码的工作流程的方法:
[WorkflowDescription("1.0")]
public class TranscodeWorkflow : Workflow
{
public TranscodeWorkflow()
{
//DownloadActivity is the startup activity and will be scheduled when workflow is started.
ScheduleActivity<DownloadActivity>().OnFailure(Reschedule);
//After DownloadActivity is completed TranscodeActivity activity will be scheduled.
ScheduleActivity<TranscodeActivity>().AfterActivity<DownloadActivity>()
.WithInput(a => new {InputFile = ParentResult(a).DownloadedFile, Format = "MP4"})
ScheduleActivity<UploadToS3Activity>().AfterActivity<TranscodeActivity>()
.WithInput(a => new {InputFile = ParentResult(a).TranscodedFile});
ScheduleActivity<SendConfirmationActivity>().AfterActivity<UploadToS3Activity>();
}
private static dynamic ParentResult(IActivityItem a) => a.ParentActivity().Result();
}
在上面的示例中,为了清楚起见,我遗漏了任务路由。 以下是创建活动的方法:
[ActivityDescription("1.0")]
public class DownloadActivity : Activity
{
//It supports both sync/async method.
[ActivityMethod]
public async Task<Response> Execute(string input)
{
//simulate downloading of file
await Task.Delay(10);
return new Response() { DownloadedFile = "downloaded path", PollingQueue = PollingQueue.Download};
}
public class Response
{
public string DownloadedFile;
}
}
为清楚起见,我省略了其他活动的例子。由documentation,tutorial和samples支持的Guflow。