如何创建在新项目上传到媒体库时运行的 Sitecore 管道处理器
How do you create a Sitecore pipeline processor that runs when a new item is upload to the Media Library
我想构建一个 Sitecore 管道处理器,它可以在媒体项目上传时获取其 ID,并将该 ID 保存到第三方应用程序使用的现有自定义数据库中。
我一直无法找到有关如何执行此操作的任何操作方法或示例?
我正在为我的代码使用 Sitecore 8.0 Update 5 和 MVC 结构。
我不记得在将新项目上传到媒体库时会执行任何管道,但您应该能够使用 item:created
事件。
只需检查 args (ItemCreatedEventArgs
) 中的项目是否为媒体项目并执行您的代码。
public void OnItemCreated(object sender, EventArgs args)
{
var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs;
if (createdArgs != null)
{
if (createdArgs.Item != null)
{
...
}
}
}
您可以签入 uiUpload
管道,但不会触发以编程方式创建的项目,即它只会在用户通过 CMS 界面上传项目时触发。
创建新处理器class:
public class ExternalSystemProcessor
{
public void Process(UploadArgs args)
{
foreach (Item file in args.UploadedItems.Where(file => file.Paths.IsMediaItem))
{
// Custom code here
SaveToExternalSystem(file.ID);
}
}
}
然后在默认保存处理器之后修补:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<processors>
<uiUpload>
<processor type="MyProject.Custom.Pipelines.ExternalSystemProcessor, MyProject.Custom" mode="on"
patch:after="*[@type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" />
</uiUpload>
</processors>
</sitecore>
</configuration>
我想构建一个 Sitecore 管道处理器,它可以在媒体项目上传时获取其 ID,并将该 ID 保存到第三方应用程序使用的现有自定义数据库中。
我一直无法找到有关如何执行此操作的任何操作方法或示例?
我正在为我的代码使用 Sitecore 8.0 Update 5 和 MVC 结构。
我不记得在将新项目上传到媒体库时会执行任何管道,但您应该能够使用 item:created
事件。
只需检查 args (ItemCreatedEventArgs
) 中的项目是否为媒体项目并执行您的代码。
public void OnItemCreated(object sender, EventArgs args)
{
var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs;
if (createdArgs != null)
{
if (createdArgs.Item != null)
{
...
}
}
}
您可以签入 uiUpload
管道,但不会触发以编程方式创建的项目,即它只会在用户通过 CMS 界面上传项目时触发。
创建新处理器class:
public class ExternalSystemProcessor
{
public void Process(UploadArgs args)
{
foreach (Item file in args.UploadedItems.Where(file => file.Paths.IsMediaItem))
{
// Custom code here
SaveToExternalSystem(file.ID);
}
}
}
然后在默认保存处理器之后修补:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<processors>
<uiUpload>
<processor type="MyProject.Custom.Pipelines.ExternalSystemProcessor, MyProject.Custom" mode="on"
patch:after="*[@type='Sitecore.Pipelines.Upload.Save, Sitecore.Kernel']" />
</uiUpload>
</processors>
</sitecore>
</configuration>