当作者保存项目的发布限制时,我需要运行代码。
我将如何做到这一点?
答案 0 :(得分:2)
时间限制存储在“__Valid to”和“__Valid from”字段中。附上一个这样的新管道:
<event name="item:saved">
<handler type="Test.ValidTest, Test" method="OnItemSaved" />
</event>
然后测试这些字段是否已更改并执行您的操作:
public class ValidTest
{
private static readonly ID __Validfrom = new ID("{C8F93AFE-BFD4-4E8F-9C61-152559854661}");
private static readonly ID __Validto = new ID("{4C346442-E859-4EFD-89B2-44AEDF467D21}");
public void OnItemSaved(object sender, EventArgs args)
{
Item obj = Event.ExtractParameter(args, 0) as Item;
if (obj == null)
return;
//if (!(obj.TemplateID == YourTemplateId)) //restrict this to a limited set of templates if possible
// return;
try
{
ItemChanges itemChanges = Event.ExtractParameter(args, 1) as ItemChanges;
if (itemChanges != null &&
(itemChanges.FieldChanges.Contains(__Validfrom) || itemChanges.FieldChanges.Contains(__Validto)))
{
//YOUR THING here
Log.Info("Changed!", (object)this);
}
}
catch (Exception ex)
{
Log.Error("failed", ex, (object)this);
}
}
}