我们可以使用.NET自定义部署?自定义、可以使用、NET

2023-09-05 04:41:41 作者:满身是刺i

我需要定制我的部署因为某些原因,我只能看到一些文章,这是使用Java进行自定义部署。

I need to customize my deployer for some reasons, I can only see some articles which are using java for customizing deployer.

我们可以使用.NET项目定制部署,请分享你的想法,如果可能的一些解决方案。

Can we customize deployer using .NET project, please share your thought and if possible some solution.

推荐答案

答案显然是 NO 。该部署是内容分发一个比较低层次的部分,它的可扩展性点仅适用于Java。

The obvious answer is NO. The Deployer is a rather low-level part of Content Delivery, and its extensibility points are only available to Java.

然而,有很多方法对皮肤这只猫,这一切都取决于你想要达到什么目的。

However, there's many ways to skin this cat, it all depends on what you're trying to achieve.

您可以,例如,创建一个.NET web服务,做您的扩展所有的肉,写一个简单的部署模块(使用Java),调用此WebService,通过所有必需的参数吧。

You could, for instance, create a webservice with .NET that does all the meat of your extension, and write a simple Deployer Module (with Java) that calls this webservice, passing all the required parameters to it.

您可以通过发布到你的.NET方法将传递包的真实位置在哪里部署者在听之前被调用的位置pre-过程中的运输包装。

You could pre-process the Transport package by publishing to a location where your .NET method would be called before passing the package to the real location where the deployer is listening.

如果你preFER后期处理,你可以配置你的部署,以保持成功的交​​易和监控的位置,在部署存储这些(传入的文件夹+\成功)。

In case you prefer post-processing, you could configure your deployer to keep successful transactions and monitor the location where the deployer stores these ("incoming folder" + "\Success").

这真的一切都取决于你想要达到什么目的。推荐方法是使用Java,但如果你不舒服的语言,你可以勇于创新,达到同样的最终结果以最少的Java代码。下面是一个空的模块,它遍历项目被公布,并记录有关对象的信息的一个例子:

It really all depends on what you want to achieve. The recommended way is to use Java, but if you're not comfortable with that language, you can be creative and achieve the same end results with minimal Java coding. Here's an example of an "empty" module that loops through the items being published and logs information about the objects:

import java.util.Iterator;

import com.tridion.configuration.Configuration;
import com.tridion.configuration.ConfigurationException;
import com.tridion.deployer.Module;
import com.tridion.deployer.ProcessingException;
import com.tridion.deployer.Processor;

import com.tridion.transport.transportpackage.Binary;
import com.tridion.transport.transportpackage.BinaryKey;
import com.tridion.transport.transportpackage.Component;
import com.tridion.transport.transportpackage.ComponentKey;
import com.tridion.transport.transportpackage.MetaData;
import com.tridion.transport.transportpackage.MetaDataFile;
import com.tridion.transport.transportpackage.Page;
import com.tridion.transport.transportpackage.PageKey;
import com.tridion.transport.transportpackage.ProcessorInstructions;
import com.tridion.transport.transportpackage.Section;
import com.tridion.transport.transportpackage.TransportPackage;

import org.slf4j.LoggerFactory;
import org.slf4j.Logger;


public class CustomCacheNotificationDeploy extends Module {

    String action = null;
    Logger log = null;
    MetaDataFile pageMeta = null;
    MetaDataFile componentMeta = null;
    MetaDataFile binaryMeta = null;
    public CustomCacheNotificationDeploy(Configuration config, Processor processor)
            throws ConfigurationException {
        super(config, processor);
        log = LoggerFactory.getLogger(getClass());
        // TODO Auto-generated constructor stub
    }

    @SuppressWarnings("deprecation")
    public void process(TransportPackage data) throws ProcessingException{
        ProcessorInstructions instructions = data.getProcessorInstructions();
        action = instructions.getAction();
        MetaData pageMetaInfo = instructions.getMetaData("Pages");
        MetaData componentMetaInfo = instructions.getMetaData("Components");
        MetaData binaryMetaInfo = instructions.getMetaData("Binaries");
        pageMeta = data.getMetaData("Pages", pageMetaInfo.getName());
        componentMeta = data.getMetaData("Components", componentMetaInfo.getName());
        binaryMeta = data.getMetaData("Binaries", binaryMetaInfo.getName());

        log.debug("Action " + action + " started for publication " + instructions.getPublicationId());

        Section section = null;
        Iterator<Section> Sections = instructions.getSections();
        for(; Sections.hasNext(); processSection(section))
        {
            section = Sections.next();
        }

    }

    protected void processSection(Section section)
    {
        log.debug("Processing Section " + section.getName());
        Iterator iterator = section.getFileItems();
        Object item;
        for(; iterator.hasNext(); processItem(item, section))
        {
            item = iterator.next();
        }
        Section subSection;
        for(Iterator i$ = section.getSubSections().iterator(); i$.hasNext(); processSection(subSection))
            subSection = (Section)i$.next();
    }

    protected void processItem(Object obj, Section section)
    {
        if(obj instanceof PageKey)
        {
            log.debug("Object is Page");
            PageKey key = (PageKey) obj;
            Page page = (Page)pageMeta.getMetaData(key);
            log.debug("Page being deployed is " + page.getId() + " with URL " + page.getURLPath());
        }
        if(obj instanceof ComponentKey)
        {
            log.debug("Object is Component");
            ComponentKey key = (ComponentKey) obj;
            Component component = (Component)componentMeta.getMetaData(key);
            log.debug("Component being deployed is " + component.getId());
        }
        if(obj instanceof BinaryKey)
        {
            log.debug("Object is Binary");
            BinaryKey key = (BinaryKey) obj;
            Binary binary = (Binary)binaryMeta.getMetaData(key);
            log.debug("Binary being deployed is " + binary.getId() + " with URL " + binary.getURLPath());
        }
    }
}