Example #1
0
        internal static string GetStatus(object context)
        {
            Trigger trigger = context as Trigger;

            if (trigger != null)
            {
                if (!trigger.IsEnabled)
                {
                    return("Disabled");
                }
            }

            ServerDdlTrigger serverDdlTrigger = context as ServerDdlTrigger;

            if (serverDdlTrigger != null)
            {
                if (!serverDdlTrigger.IsEnabled)
                {
                    return("Disabled");
                }
            }

            DatabaseDdlTrigger databaseDdlTrigger = context as DatabaseDdlTrigger;

            if (databaseDdlTrigger != null)
            {
                if (!databaseDdlTrigger.IsEnabled)
                {
                    return("Disabled");
                }
            }

            return(string.Empty);
        }
 internal DatabaseTriggerElement(DatabaseDdlTrigger trigger)
     : base(trigger, trigger)
 {
 }
Example #3
0
        public bool Process(SqlSmoObject[] objects, int start)
        {
            if (objects == null)
            {
                return(AsyncProcessingStatus.CancelProcessing);
            }

            SqlSmoObject[]   sso                = new SqlSmoObject[1];
            StringCollection tableForeignKey    = new StringCollection();
            StringCollection extendedProperties = new StringCollection();
            StringCollection bcpOutputCommands  = new StringCollection();
            StringCollection bcpTargetCommands  = new StringCollection();
            double           step               = ((100 - start) / (double)objects.Count());
            int loopCnt = 0;

            bool oldSQLdb = _smoScriptOpts.TargetServer.Equals(Properties.Resources.ServerType_AzureSQLDatabase);

            List <string> listAssemblyUDF  = new List <string>();
            List <string> listEncryptedUDF = new List <string>();

            List <string> listEncryptedView = new List <string>();

            List <string> listAssemblySP  = new List <string>();
            List <string> listEncryptedSP = new List <string>();

            List <string> listAssemblyDDLT  = new List <string>();
            List <string> listEncryptedDDLT = new List <string>();


            foreach (SqlSmoObject obj in objects)
            {
                loopCnt++;

                _eventArgs.StatusMsg       = CommonFunc.FormatString(Properties.Resources.ScriptingObj, obj.ToString());
                _eventArgs.PercentComplete = (int)(loopCnt * step);
                _updateStatus(_eventArgs);

                sso[0] = obj;
                switch (obj.Urn.Type)
                {
                case "Table":
                    _sdb.ScriptTables(sso, ref tableForeignKey, ref extendedProperties, ref bcpOutputCommands, ref bcpTargetCommands, ref _outputDir);
                    break;

                case "UserDefinedFunction":
                    UserDefinedFunction udf = (UserDefinedFunction)obj;
                    if (udf.IsEncrypted)
                    {
                        if (udf.AssemblyName.Length > 0)
                        {
                            if (oldSQLdb)
                            {
                                listAssemblyUDF.Add(udf.TextBody);
                            }
                            else
                            {
                                _sdb.ScriptUDF(sso);
                            }
                        }
                        else
                        {
                            listEncryptedUDF.Add(udf.ToString());
                        }
                    }
                    else
                    {
                        _sdb.ScriptUDF(sso);
                    }
                    break;

                case "View":
                    View vw = (View)obj;
                    if (vw.IsEncrypted)
                    {
                        listEncryptedView.Add(vw.ToString());
                    }
                    else
                    {
                        _sdb.ScriptViews(sso);
                    }
                    break;

                case "StoredProcedure":
                    StoredProcedure proc = (StoredProcedure)obj;
                    if (proc.IsEncrypted)
                    {
                        if (proc.AssemblyName.Length > 0)
                        {
                            if (oldSQLdb)
                            {
                                listAssemblySP.Add(proc.TextBody);
                            }
                            else
                            {
                                _sdb.ScriptProcedures(sso);
                            }
                        }
                        else
                        {
                            listEncryptedSP.Add(proc.ToString());
                        }
                    }
                    else
                    {
                        _sdb.ScriptProcedures(sso);
                    }
                    break;

                case "DdlTrigger":
                    DatabaseDdlTrigger ddlt = (DatabaseDdlTrigger)obj;
                    if (ddlt.IsEncrypted)
                    {
                        if (ddlt.AssemblyName.Length > 0)
                        {
                            if (oldSQLdb)
                            {
                                listAssemblyDDLT.Add(ddlt.TextBody);
                            }
                            else
                            {
                                _sdb.ScriptTriggers(sso);
                            }
                        }
                        else
                        {
                            listEncryptedDDLT.Add(ddlt.ToString());
                        }
                    }
                    else
                    {
                        _sdb.ScriptTriggers(sso);
                    }
                    break;
                }

                if (AsyncProcessingStatus.CancelProcessing)
                {
                    _eventArgs.StatusMsg       = Properties.Resources.MessageCanceled;
                    _eventArgs.DisplayColor    = Color.DarkCyan;
                    _eventArgs.DisplayText     = CommonFunc.FormatString(Properties.Resources.MessageCanceledProcessing, DateTime.Now.ToString(CultureInfo.CurrentCulture)) + Environment.NewLine;
                    _eventArgs.PercentComplete = 100;
                    _updateStatus(_eventArgs);
                    return(AsyncProcessingStatus.CancelProcessing);
                }
            }

            OutputNotSupported(Properties.Resources.ObjectTypeUDF, listAssemblyUDF);
            OutputIsEncrypted(Properties.Resources.ObjectTypeUDF, listEncryptedUDF);

            OutputIsEncrypted(Properties.Resources.ObjectTypeViews, listEncryptedView);

            OutputNotSupported(Properties.Resources.ObjectTypeStoredProcedures, listAssemblySP);
            OutputIsEncrypted(Properties.Resources.ObjectTypeStoredProcedures, listEncryptedSP);

            OutputNotSupported(Properties.Resources.ObjectTypeTriggers, listAssemblyDDLT);
            OutputIsEncrypted(Properties.Resources.ObjectTypeTriggers, listEncryptedDDLT);

            _eventArgs.StatusMsg = CommonFunc.FormatString(Properties.Resources.ForiegnKeys);
            _updateStatus(_eventArgs);

            // Ok, due to dependency issues, we need to move the foreign key constraints to the end.
            // But there is some small problem in that SQL Server allows for a DBA to have circular dependencies.  So
            // in order to solve this problem, we need to upload the data to the circular dependent tables first
            // with no foreign keys, add foreign key constraints, and then upload the rest of the data.  The
            // reason that the data it not all uploaded before the foreign key constraints is to avoid performance
            // issues with adding foreign key constraints after the fact.

            if (_smoScriptOpts.ScriptForeignKeys == true)
            {
                _sdb.ScriptStringCollection(ref tableForeignKey, Color.Black);
            }

            if (_smoScriptOpts.ScriptExtendedProperties == true)
            {
                _sdb.ScriptStringCollection(ref extendedProperties, Color.Black);
            }

            if (bcpTargetCommands.Count > 0)
            {
                _sdb.ScriptStringCollection(ref bcpTargetCommands, Color.Green);
            }

            if (bcpOutputCommands.Count > 0)
            {
                _sdb.OutputAnalysisLine(Environment.NewLine + Properties.Resources.BCPOutputSummary, Color.Green);
                foreach (string bcpOutputCommand in bcpOutputCommands)
                {
                    _sdb.OutputAnalysisLine(bcpOutputCommand, Color.Green);
                }
            }
            return(AsyncProcessingStatus.CancelProcessing);
        }