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 Main(string[] args)
        {
            Scripter scripter = new Scripter(new Server());
            UrnCollection urns = new UrnCollection();
            urns.Add(new Urn(@"Server[@Name='CANOPUS5']
                /Database[@Name='pubs']
                /Table[@Name='authors' and @Schema='dbo']"));
            urns.Add(new Urn(@"Server[@Name='CANOPUS5']
                /Database[@Name='pubs']
                /Table[@Name='publishers' and @Schema='dbo']"));
            scripter.Options.FileName=@"AWDep.sql";
            scripter.Options.WithDependencies = true;
            scripter.Options.ToFileOnly=true;          
            scripter.Script(urns);
            

            scripter.Options.FileName = @"AWNoDep.sql";
            scripter.Options.WithDependencies = false;
            scripter.Options.ToFileOnly = true;
            scripter.Script(urns);

            scripter.Options.FileName = @"AW2.sql";
            scripter.FilterCallbackFunction = delegate(Urn urn)
            {
                if (urns.Contains(urn))
                  return false;
                return true;
            };
          
            scripter.Script(urns);

            scripter.FilterCallbackFunction = null;


            scripter.Options.FileName = @"AWCreates.sql";
            DependencyTree tree = scripter.DiscoverDependencies(urns, false);
            DependencyCollection dependency = scripter.WalkDependencies(tree);
            scripter.ScriptWithList(dependency);


            scripter.Options.FileName = @"AWDrops.sql";
            tree = scripter.DiscoverDependencies(urns, false);
            dependency = scripter.WalkDependencies(tree);
            scripter.ScriptWithList(dependency);
        
        }
    }
}
