Beispiel #1
0
        public string ScriptObjects(ScriptingArgs args)
        {
            if (args == null || args.Objects == null || args.Objects.Count == 0)
            {
                return(String.Empty);
            }

            FireTaskProgressInfo("Preparing for scripting...");

            scrp.Options              = args.Options;
            scrp.Options.ToFileOnly   = false;
            scrp.Options.AppendToFile = false;
            scrp.Options.FileName     = String.Empty;
            scrp.Server.ConnectionContext.BatchSeparator = "GO";
            StringCollection scr = null;

            _recentErrors = null;

            if (scrp.Options.ContinueScriptingOnError)
            {
                _recentErrors        = new StringBuilder();
                scrp.ScriptingError += new ScriptingErrorEventHandler(scrp_ScriptingError);
            }

            try
            {
                if (scrp.Options.WithDependencies)
                {
                    scrp.DiscoveryProgress += new ProgressReportEventHandler(dWalk_DiscoveryProgress);
                    FireTaskProgressInfo("Discovering dependencies. (Task 1 of 3)");
                    DependencyTree dTree = scrp.DiscoverDependencies(PrepareObjectUrns(args.Objects), DependencyType.Parents);
                    FireTaskProgressInfo("Walking dependencies. (Task 2 of 3)");
                    DependencyCollection dCol = scrp.WalkDependencies(dTree);
                    FireTaskProgressInfo("Scripting objects. (Task 3 of 3)");
                    scr = scrp.ScriptWithList(dCol);
                }
                else
                {
                    FireTaskProgressInfo("Scripting objects. (Task 1 of 1)");
                    scr = scrp.ScriptWithList(PrepareObjectUrns(args.Objects));
                }
            }
            catch (Exception ex)
            {
                if (_cancelRequested)
                {
                    return(String.Empty);
                }
                throw ex;
            }

            string myComment = "/***** Script generated with PragmaSQL Scripter on " + DateTime.Now.ToString() + " ******/";

            string[] result = new string[scr.Count];
            scr.CopyTo(result, 0);

            return(myComment + "\r\n" + String.Join((String.IsNullOrEmpty(args.BatchSeparator) ? "\r\n" : "\r\n" + args.BatchSeparator + "\r\n"), result));
        }