using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Collections.Specialized;
using System.Data;
namespace ScirptMultipleUrn
{
    class Program
    {
        static void TreeMember(DependencyTreeNode node, int depth)
        {
            string pad = new String('\t', depth);
            Console.WriteLine(pad + node.Urn);
            if (node.HasChildNodes)
            {
                TreeMember(node.FirstChild, depth + 1);
            }
            DependencyTreeNode next = node.NextSibling;
            if (next != null)
            {
                TreeMember(next, depth);
            }
        }
        static void Main(string[] args)
        {
            Scripter scripter = new Scripter(new Server());
            UrnCollection urns = new UrnCollection();
            urns.Add(new Urn(@"Server[@Name='CANOPUS5']
                /Database[@Name='AdventureWorks']
                /Table[@Name='Customer' and @Schema='Sales']"));
            urns.Add(new Urn(@"Server[@Name='CANOPUS5']
                /Database[@Name='AdventureWorks']
                /Table[@Name='SalesTerritory' and @Schema='Sales']"));
                           
            DependencyTree tree =
                scripter.DiscoverDependencies(urns, DependencyType.Parents);
            DependencyTreeNode n = tree.FirstChild;
            TreeMember(n, 0);
        }
    }
}
