コード例 #1
0
        /// <summary>
        /// Genera un script tipo CREATE & DROP para el objeto envuelto
        /// </summary>
        /// <returns>Stringcollection que representa al script</returns>
        protected StringCollection oldScript()
        {
            soCreate = new ScriptingOptions();
            soDrop   = new ScriptingOptions();
            soDrop.IncludeHeaders         = true;
            soDrop.IncludeDatabaseContext = true;
            soDrop.ScriptDrops            = true;
            soDrop.IncludeIfNotExists     = true;
            soCreate.SchemaQualify        = true;
            soCreate.IncludeHeaders       = true;

            StringCollection createScript = obj.Script(soCreate);
            StringCollection dropScript   = obj.Script(soDrop);

            StringCollection script = new StringCollection();


            foreach (String s in dropScript)
            {
                script.Add(s + "\r\nGO\r\n");
            }
            foreach (String s in createScript)
            {
                script.Add(s + "\r\nGO\r\n");
            }

            return(script);
        }
コード例 #2
0
        string RecreateObject(IScriptable scriptableObject, ScriptingOptions sCO)
        {
            StringBuilder sb = new StringBuilder();

            // Generate Drop script
            ScriptingOptions so = new ScriptingOptions();

            so.ScriptDrops        = true;
            so.IncludeIfNotExists = true;

            foreach (string stmt in scriptableObject.Script(so))
            {
                sb.AppendLine(stmt);
            }

            // Add batch separator
            sb.AppendLine("GO");

            // Now generate Crate script and add it to the resulting ScriptCollection
            sCO.ScriptDrops        = false;
            sCO.IncludeIfNotExists = false;

            foreach (string stmt in scriptableObject.Script(sCO))
            {
                sb.AppendLine(stmt);
                if (stmt.Contains("SET ANSI_NULLS") || stmt.Contains("SET QUOTED_IDENTIFIER"))
                {
                    sb.AppendLine("GO");
                }
            }

            //for (int i = 0; i < sc.Count; i++)
            // sb.Append(sc[i]);
            return(sb.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Scripts a <see cref="IScriptable" /> along with provided options.
        /// </summary>
        /// <param name="scriptableObject">Object to script.</param>
        /// <param name="dropOptions">Drop options; null will ommit.</param>
        /// <param name="createOptions">Create options.</param>
        /// <param name="scrubScript">Value indicating whether or not to scrub the script to make it more readable and remove issues that prvent running.</param>
        /// <returns>Scripted object as a string.</returns>
        public static string Script(IScriptable scriptableObject, ScriptingOptions dropOptions, ScriptingOptions createOptions, bool scrubScript)
        {
            new { scriptableObject }.AsArg().Must().NotBeNull();
            new { dropOptions }.AsArg().Must().NotBeNull();
            new { createOptions }.AsArg().Must().NotBeNull();

            StringCollection dropScript = null;

            if (dropOptions != null)
            {
                dropScript = scriptableObject.Script(dropOptions);
                dropScript.Add("GO");
            }

            var createScript = scriptableObject.Script(createOptions);

            createScript.Add("GO");

            if (scrubScript)
            {
                ScrubScript(createScript);
            }

            return(StringCollectionToSingleString(dropScript) + StringCollectionToSingleString(createScript));
        }
コード例 #4
0
        // Scripts an item in right window if it is scriptable
        private void DependenciesTreeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.ScriptTextBox.Clear();
            if (e.Node.Tag == null)
            {
                return;
            }

            // Script an object
            SqlSmoObject o = this.sqlServerSelection.GetSmoObject((Urn)e.Node.Tag);

            ScriptingOptions so = new ScriptingOptions();

            so.DriAll         = true;
            so.Indexes        = true;
            so.IncludeHeaders = true;
            so.Permissions    = true;
            so.PrimaryObject  = true;
            so.SchemaQualify  = true;
            so.Triggers       = true;

            IScriptable scriptableObject = o as IScriptable;

            if (scriptableObject != null)
            {
                StringBuilder sb = new StringBuilder();
                foreach (string s in scriptableObject.Script(so))
                {
                    sb.Append(s);
                    sb.Append(Environment.NewLine);
                }

                this.ScriptTextBox.Text = sb.ToString();
            }
        }
コード例 #5
0
        public void Save()
        {
            if (string.IsNullOrEmpty(FileName))
            {
                throw new ArgumentException("FileName should be initialized.");
            }

            var options = new ScriptingOptions();

            options.FileName          = FileName;
            options.Indexes           = true;
            options.ToFileOnly        = true;
            options.Triggers          = true;
            options.XmlIndexes        = true;
            options.ClusteredIndexes  = true;
            options.DriAllConstraints = true;
            options.DriAllKeys        = true;
            options.DriChecks         = true;
            options.DriPrimaryKey     = true;
            options.DriUniqueKeys     = true;
            options.ScriptSchema      = true;

            ScriptableObject.Script(options);
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: ramnaresh/SMO
        private void scriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.ListView.SelectedItems.Count == 0)
            {
                return;
            }

            object      selectedObject   = this.ListView.SelectedItems[0].Tag;
            IScriptable scriptableObject = selectedObject as IScriptable;

            if (scriptableObject != null)
            {
                StringCollection strings = scriptableObject.Script();
                TextOutputForm   frm     = new TextOutputForm(strings);
                frm.ShowDialog(this);
            }
        }
コード例 #7
0
        private static string GetScriptText(IScriptable scriptable)
        {
            if (scriptable == null)
            {
                return(String.Empty);
            }

            StringBuilder    stringBuilder = new StringBuilder();
            StringCollection batches;

            try
            {
                batches = scriptable.Script();
            }
            catch {
                return(string.Empty);
            }
            foreach (string batch in batches)
            {
                stringBuilder.AppendFormat(@"{0}\r\nGO\r\n", batch);
            }

            return(stringBuilder.ToString());
        }
コード例 #8
0
        string RecreateObject(IScriptable scriptableObject, ScriptingOptions sCO)
        {
            StringBuilder sb = new StringBuilder();

               // Generate Drop script
               ScriptingOptions so = new ScriptingOptions();
               so.ScriptDrops = true;
               so.IncludeIfNotExists = true;

               foreach (string stmt in scriptableObject.Script(so))
               {
            sb.AppendLine(stmt);
               }

               // Add batch separator
               sb.AppendLine("GO");

               // Now generate Crate script and add it to the resulting ScriptCollection
               sCO.ScriptDrops = false;
               sCO.IncludeIfNotExists = false;

               foreach (string stmt in scriptableObject.Script(sCO))
               {
            sb.AppendLine(stmt);
            if (stmt.Contains("SET ANSI_NULLS") || stmt.Contains("SET QUOTED_IDENTIFIER"))
             sb.AppendLine("GO");
               }

               //for (int i = 0; i < sc.Count; i++)
               // sb.Append(sc[i]);
               return sb.ToString();
        }
コード例 #9
0
ファイル: Scripter.cs プロジェクト: jaguire/Claymore
 private static string GetScript(IScriptable item)
 {
     return item.Script().Cast<string>()
                .Aggregate(string.Empty, (current, next) => current + Environment.NewLine + next);
 }
コード例 #10
0
ファイル: SmoBrowser.cs プロジェクト: rcdosado/SMO
        private static string GetScriptText(IScriptable scriptable)
        {
            if (scriptable == null)
            {
                return String.Empty;
            }

            StringBuilder stringBuilder = new StringBuilder();
            StringCollection batches;
            try
            {
                batches = scriptable.Script();
            }
            catch {
                return string.Empty;
            }
            foreach (string batch in batches)
            {
                stringBuilder.AppendFormat(@"{0}\r\nGO\r\n", batch);
            }

            return stringBuilder.ToString();
        }
コード例 #11
0
ファイル: ScriptWriter.cs プロジェクト: Flushot/dbsnap
 /// <summary>
 /// 
 /// </summary>
 /// <param name="scriptable"></param>
 public void WriteDefinition(IScriptable scriptable)
 {
     WriteScript(scriptable.Script(_options));
 }