我從果園代幣提供商那裏得到一個頭痛,任何幫助將是一件幸事。 我一直在複製評論標記。果園代幣 - >
目標是發送「問題」內容項目時發送的電子郵件。
這裏是我的內容類型「問題」的解決方案:
public interface ITokenProvider : IEventHandler
{
void Describe(dynamic context);
void Evaluate(dynamic context);
}
public class QuestionTokens : ITokenProvider
{
public QuestionTokens()
{
T = NullLocalizer.Instance;
}
public Localizer T { get; set; }
public void Describe(dynamic context)
{
//presume this is correct
context.For("Content", T("Content Items"), T("Content Items"))
.Token("QuestionText", T("Question Text"), T("Text of the question"))
.Token("QuestionAuthor", T("Question Author"), T("Author of the question"));
//presume this is incorrect? correct for the content type?
context.For("Question", T("Questions"), T("Questions from users"))
.Token("QuestionText", T("Question Text"), T("Text of the question"))
.Token("QuestionAuthor", T("Question Author"), T("Author of the question"));
}
public void Evaluate(dynamic context)
{
Func<IContent, object> questionTextAccessorFromContent = (content) => {
var part = content.As<QuestionPart>();
return part.QuestionText;
};
Func<QuestionPart, object> questionTextAccessor = (part) =>
{
return part.QuestionText;
};
Func<IContent, object> authorAccessorFromContent = (content) => {
var part = content.As<QuestionPart>();
return part.Author;
};
Func<QuestionPart, object> authorAccessor = (part) =>
{
return part.Author;
};
//doesnt work
context.For<IContent>("Content")
.Token("QuestionText", (Func<IContent, object>)
(content => content.As<QuestionPart>().Record.QuestionText))
.Token("QuestionAuthor", (Func<IContent, object>)
(content => content.As<QuestionPart>().Record.Author));
//doesnt work
context.For<IContent>("Question")
.Token("QuestionText", (Func<IContent, object>)
(content => content.As<QuestionPart>().Record.QuestionText))
.Token("QuestionAuthor", (Func<IContent, object>)
(content => content.As<QuestionPart>().Record.Author));
//doesnt work
context.For<QuestionPart>("Question")
.Token("QuestionText", (Func<QuestionPart, object>)
(content => content.Record.QuestionText))
.Token("Author", (Func<QuestionPart, object>)
(content => content.Record.Author)); ;
}
private static string QuestionText(IContent question)
{
var questionPart = question.As<QuestionPart>();
return questionPart.QuestionText;
}
private static string Author(IContent question)
{
var questionPart = question.As<QuestionPart>();
return questionPart.Author;
}
}
這是Action(當問題被出版),它發送一個電子郵件正文: (更新爲測試Medeiros的建議)
<p>A question has been created by: {Content.QuestionAuthor}</p>
<p>A question has been created by: {Content.QuestionAuthor.Text}</p>
<p>A question has been created by: {Content.QuestionAuthor.Value}</p>
<p>A question has been created by: {Question.QuestionAuthor}</p>
<p>A question has been created by: {Question.QuestionAuthor.Text}</p>
<p>A question has been created by: {Question.QuestionAuthor.Value}</p>
<p>Message: {Content.QuestionText}</p>
<p>Message: {Content.QuestionText.Text}</p>
<p>Message: {Content.QuestionText.Value}</p>
<p>Message: {Question.QuestionText}</p>
<p>Message: {Question.QuestionText.Text}</p>
<p>Message: {Question.QuestionText.Value}</p>
所有'我'的標記被替換爲空白文本。其他令牌,如:{Content.ContentType} {User.Email}工作得很好。任何人注意到的任何錯誤或暗示都將非常有用。
謝謝,馬特
沒有運氣無論是價值還是在最後文本。好的提示雖然。我會嘗試更新我的消息。我曾嘗試過像註釋那樣的靜態方法,但它永遠不會到達該代碼塊。所以我想知道它的描述部分是錯的...? – Matthew 2013-04-24 11:52:17