November 2, 2012

Install a TDS package into your code

Here is a code snippet to install a TDS package into your code:
public void InstallTDSPackage(string path)
{
    bool hasPostAction;
    string historyPath;

    // Use default logger
    ILog log = LogManager.GetLogger("root");
    XmlConfigurator.Configure((XmlElement)ConfigurationManager.GetSection("log4net"));

    using (new SecurityDisabler())
    {
        DiffInstaller installer = new DiffInstaller(UpgradeAction.Upgrade);
        MetadataView view = UpdateHelper.LoadMetadata(path);

        //Get the package entries
        List<ContingencyEntry> entries = installer.InstallPackage(path, InstallMode.Install, log, out hasPostAction, out historyPath);

        installer.ExecutePostInstallationInstructions(path, historyPath, InstallMode.Install, view, log, ref entries);

        UpdateHelper.SaveInstallationMessages(entries, historyPath);
    }
}

No comments:

Post a Comment