开发者

Is there a NANT task to start/stop COM+ components?

I am automating our deploymnet using CC.n开发者_StackOverflow中文版et and a NANT build script. I have to stop and start our COM+ components during deployment.

Is there a NANT task that does this?


Assuming that the COM+ components are your components (ServicedComponent instances), then you can use the <regsvcs> task to achieve this.

You would have to indicate the assembly that your COM+ components are in, remove the application (using an action with an ActionType of uninstall) and then install it again (you might need two task instances for this).

If your assembly is not the source of the COM+ components/application, then you will need to write your own custom task accessing the COM+ Administration API through COM interop.


I've been struggling with the same problem. Couldn't find any other detailed way than vbs scripts. The solution I came up with is as follows:

I created a C# .Net solution which references NAnt.Core. I created two classes (tasks) which inherit from the Nant Task class. You need three things: 1) Place TaskName attribute on the class

     [TaskName("startupComApplicationTask")]

2) Place a Task attribute on any properties that you want to pass in from Nant

    [TaskAttribute("machineName", Required = true)]

3) Implement the ExecuteTask() Method

The Final outcome was something like this:

[TaskName("startupComApplicationTask")]
public class StartupComApplicationTask: Task
{
    private string _applicationName;
    private string _machineName;

    [TaskAttribute("applicationName", Required = true)]
    public string ApplicationName
    {
        get
        {
            return _applicationName;
        }
        set
        {
            _applicationName = value;
        }
    }

    [TaskAttribute("machineName", Required = true)]
    public string MachineName
    {
        get
        {
            return _machineName;
        }
        set
        {
            _machineName = value;
        }
    }

    protected override void ExecuteTask()
    {
        COMAdminCatalog objAdmin = new COMAdminCatalog();
        objAdmin.Connect(MachineName);

        var objCollection = (COMAdminCatalogCollection)objAdmin.GetCollection("Applications");

        objCollection.Populate();

        foreach (COMAdminCatalogObject objAppNames in objCollection)
        {
            if (objAppNames.Name.Equals(ApplicationName))
            {
                ICatalogCollection objComponents = (ICatalogCollection)objCollection.GetCollection("Components", objAppNames.Key);
                objComponents.Populate();
            }
        }

        objAdmin.StartApplication(ApplicationName);
    }
}

Obviously in order to get this going you need to include a reference to the ComAdmin interop assembly. Which you can find under "COM+ 1.0 Type Library" in your Com references.

Build the project which will create two dlls for you. The interop one and yours. Drop these into your nant folder (in the bin directory).

You can call these from within Nant the following way:

    <startupComApplicationTask machineName="193.132.119.249" applicationName="NantTest" />

Repeat for shutingdown, just call ShutdownApplication instead of StartApplication.

Hope this helps

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜