如何创建在将新项目上载到媒体库时运行的Sitecore管道处理器

eat*_*ode 2 sitecore sitecore-mvc sitecore8

我想构建一个Sitecore管道处理器,它可以在上传媒体项时获取媒体项的ID,并将该ID保存到第三方应用程序使用的现有自定义数据库中.

我一直无法找到任何方法或示例如何做到这一点?

我正在使用Sitecore 8.0 Update 5和我的代码的MVC结构.

jam*_*kam 5

您可以检查uiUpload管道,但不会为编程创建的项目触发,即只有当用户通过CMS界面上传项目时才会触发.

创建一个新的处理器类:

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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在默认保存处理器之后修补:

<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>
Run Code Online (Sandbox Code Playgroud)