好的。经过六个小时的试验和测试,我终于开始了我的活动。这是最终代码:
public sealed class SayPassword : NativeActivity
{
[RequiredArgument]
public InArgument<ConnectionInfo> Connection { get; set; }
[RequiredArgument]
public InArgument<String> Password { get; set; }
public InArgument<String> Language { get; set; }
public InArgument<Int32?> Speaker { get; set; }
#region Implementation
private SaySpeech InnerSaySpeech { get; set; }
private Variable<ConnectionInfo> TempConnectionInfo { get; set; }
private Variable<String> TempUtterance { get; set; }
private Variable<String[]> TempParameters { get; set; }
private Variable<String> TempLanguage { get; set; }
private Variable<Int32?> TempSpeaker { get; set; }
#endregion
public SayPassword()
{
TempConnectionInfo = new Variable<ConnectionInfo>();
TempUtterance = new Variable<String>();
TempParameters = new Variable<String[]>();
TempLanguage = new Variable<String>();
TempSpeaker = new Variable<Int32?>();
InnerSaySpeech = new SaySpeech
{
Connection = new InArgument<ConnectionInfo>(TempConnectionInfo),
Utterance = new InArgument<string>(TempUtterance),
Parameters = new InArgument<string[]>(TempParameters),
Language = new InArgument<string>(TempLanguage),
Speaker = new InArgument<int?>(TempSpeaker)
};
}
private String[] GetSentences(String password) {}
private static string GetPlaceholderString(Int32 NumberOfPlaceholders) {}
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
base.CacheMetadata(metadata);
metadata.AddImplementationVariable(TempConnectionInfo);
metadata.AddImplementationVariable(TempUtterance);
metadata.AddImplementationVariable(TempParameters);
metadata.AddImplementationVariable(TempLanguage);
metadata.AddImplementationVariable(TempSpeaker);
metadata.AddImplementationChild(InnerSaySpeech);
}
protected override void Execute(NativeActivityContext context)
{
String[] SpeakablePassword = GetSentences(Password.Get(context));
context.SetValue(TempConnectionInfo, Connection.Get(context));
context.SetValue(TempUtterance, GetPlaceholderString(SpeakablePassword.Length));
context.SetValue(TempParameters, SpeakablePassword);
context.SetValue(TempLanguage, Language.Get(context));
context.SetValue(TempSpeaker, Speaker.Get(context));
context.ScheduleActivity(InnerSaySpeech);
}
}
我需要创建中间变量来映射传入的参数,以便它们可以成功地传递给内部活动。
CacheMetadata中的 Misadventures 文章– 用代码包装内部活动对我帮助很大。工作流框架似乎不是您日常的 c# 代码。我还有很多东西要学。希望这对其他人有用。