public void Fill(Database database, string connectionString)
        {
            ICode code = null;
            try
            {
                if ((database.Options.Ignore.FilterStoreProcedure) || (database.Options.Ignore.FilterView) || (database.Options.Ignore.FilterFunction) || (database.Options.Ignore.FilterTrigger))
                {
                    root.RaiseOnReading(new ProgressEventArgs("Reading Text Objects...", Constants.READING_TEXTOBJECTS));
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        using (SqlCommand command = new SqlCommand(GetSQL(database.Options), conn))
                        {
                            conn.Open();
                            command.CommandTimeout = 0;
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                while (reader.Read())
                                {
                                    code = null;
                                    root.RaiseOnReadingOne(reader["name"]);
                                    string type = reader["Type"].ToString().Trim();
                                    string name = reader["name"].ToString();
                                    string definition = reader["Text"].ToString();
                                    int id = (int)reader["object_id"];
                                    if (type.Equals("V"))
                                        code = (ICode)database.Views.Find(id);

                                    if (type.Equals("TR"))
                                        code = (ICode)database.Find(id);

                                    if (type.Equals("P"))
                                        ((ICode)database.Procedures.Find(id)).Text = GetObjectDefinition(type, name, definition);

                                    if (type.Equals("IF") || type.Equals("FN") || type.Equals("TF"))
                                        code = (ICode)database.Functions.Find(id);

                                    if (code != null)
                                        code.Text = reader["Text"].ToString();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void Fill(Database database, string connectionString, List<MessageLog> messages)
 {
     ISQLServerSchemaBase parent;
     try
     {
         if (database.Options.Ignore.FilterExtendedPropertys)
         {
             using (SqlConnection conn = new SqlConnection(connectionString))
             {
                 using (SqlCommand command = new SqlCommand(GetSQL(), conn))
                 {
                     conn.Open();
                     command.CommandTimeout = 0;
                     using (SqlDataReader reader = command.ExecuteReader())
                     {
                         while (reader.Read())
                         {
                             ExtendedProperty item = new ExtendedProperty(null);
                             if (((byte)reader["Class"]) == 5)
                             {
                                 item.Level0type = "ASSEMBLY";
                                 item.Level0name = reader["AssemblyName"].ToString();
                             }
                             if (((byte)reader["Class"]) == 1)
                             {
                                 string ObjectType = GetTypeDescription(reader["type"].ToString().Trim());
                                 item.Level0type = "SCHEMA";
                                 item.Level0name = reader["Owner"].ToString();
                                 if (!ObjectType.Equals("TRIGGER"))
                                 {
                                     item.Level1name = reader["ObjectName"].ToString();
                                     item.Level1type = ObjectType;
                                 }
                                 else
                                 {
                                     item.Level1type = "TABLE";
                                     item.Level1name = reader["ParentName"].ToString();
                                     item.Level2name = reader["ObjectName"].ToString();
                                     item.Level2type = ObjectType;
                                 }
                             }
                             if (((byte)reader["Class"]) == 6)
                             {
                                 item.Level0type = "SCHEMA";
                                 item.Level0name = reader["OwnerType"].ToString();
                                 item.Level1name = reader["TypeName"].ToString();
                                 item.Level1type = "TYPE";
                             }
                             if (((byte)reader["Class"]) == 7)
                             {
                                 item.Level0type = "SCHEMA";
                                 item.Level0name = reader["Owner"].ToString();
                                 item.Level1type = "TABLE";
                                 item.Level1name = reader["ObjectName"].ToString();
                                 item.Level2type = reader["class_desc"].ToString();
                                 item.Level2name = reader["IndexName"].ToString();
                             }
                             item.Value = reader["Value"].ToString();
                             item.Name = reader["Name"].ToString();
                             parent = ((ISQLServerSchemaBase)database.Find(item.FullName));
                             if (parent != null)
                             {
                                 item.Parent = (ISchemaBase)parent;
                                 parent.ExtendedProperties.Add(item);
                             }
                             else
                                 messages.Add(new MessageLog(item.FullName + " not found in extended properties.", "", MessageLog.LogType.Error));
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         messages.Add(new MessageLog(ex.Message,ex.StackTrace, MessageLog.LogType.Error));
     }
 }
        //private static string GetSQL(SqlOption options)
        //{
        //    string filter = "";
        //    string sql = "";
        //    sql += "SELECT O.type, M.object_id, OBJECT_DEFINITION(M.object_id) AS Text FROM sys.sql_modules M ";
        //    sql += "INNER JOIN sys.objects O ON O.object_id = M.object_id ";
        //    sql += "WHERE ";
        //    if (options.Ignore.FilterStoreProcedure)
        //        filter += "O.type = 'P' OR ";
        //    if (options.Ignore.FilterView)
        //        filter += "O.type = 'V' OR ";
        //    if (options.Ignore.FilterTrigger)
        //        filter += "O.type = 'TR' OR ";
        //    if (options.Ignore.FilterFunction)
        //        filter += "O.type IN ('IF','FN','TF') OR ";
        //    filter = filter.Substring(0, filter.Length - 4);
        //    return sql + filter;
        //}

        public void Fill(Database database, string connectionString)
        {
            ICode code = null;
            try
            {
                if ((database.Options.Ignore.FilterStoreProcedure) || (database.Options.Ignore.FilterView) || (database.Options.Ignore.FilterFunction) || (database.Options.Ignore.FilterTrigger))
                {
                    root.RaiseOnReading(new ProgressEventArgs("Reading Text Objects...", Constants.READING_TEXTOBJECTS));
                    using (SqlConnection conn = new SqlConnection(connectionString))
                    {
                        string filter = "";
                        if (database.Options.Ignore.FilterStoreProcedure)
                            filter += "O.type = 'P' OR ";
                        if (database.Options.Ignore.FilterView)
                            filter += "O.type = 'V' OR ";
                        if (database.Options.Ignore.FilterTrigger)
                            filter += "O.type = 'TR' OR ";
                        if (database.Options.Ignore.FilterFunction)
                            filter += "O.type IN ('IF','FN','TF') OR ";
                        filter = filter.Substring(0, filter.Length - 4);
                        using (SqlCommand command = new SqlCommand(TextObjectSQLCommand.Get(database.Info.Version,filter), conn))
                        {
                            conn.Open();
                            command.CommandTimeout = 0;
                            using (SqlDataReader reader = command.ExecuteReader())
                            {
                                if (database.Info.Version == DatabaseInfo.VersionNumber.SQLServer2000)
                                {
                                    bool end=false;
                                    bool flag = true;
                                    int newid;
                                    end=!reader.Read();
                                    while (!end)
                                    {

                                        flag = true;
                                            string type = reader["Type"].ToString().Trim();
                                            int id = (int)reader["object_id"];
                                            if (type.Equals("V"))
                                                code = (ICode)database.Views.Find(id);

                                            if (type.Equals("TR"))
                                                code = (ICode)database.Find(id);

                                            if (type.Equals("P"))
                                                code = (ICode)database.Procedures.Find(id);

                                            if (type.Equals("IF") || type.Equals("FN") || type.Equals("TF") || type.Equals("AF"))
                                                code = (ICode)database.Functions.Find(id);
                                            //code.Text = reader["Text"].ToString();
                                            //newid = id;
                                            if (code != null)
                                                while (flag && !end)
                                                {  
                                                    newid = (int)reader["object_id"];
                                                    if (newid != id) { flag = false; continue; }                                                   
                                                    code.Text += reader["Text"].ToString();
                                                    end = !reader.Read();                                                    
                                                }
                                            else end = !reader.Read();  
                                    }
                                }
                                else
                                while (reader.Read())
                                {
                                    string type = reader["Type"].ToString().Trim();
                                    int id = (int)reader["object_id"];
                                    if (type.Equals("V"))
                                        code = (ICode)database.Views.Find(id);

                                    if (type.Equals("TR"))
                                        code = (ICode)database.Find(id);

                                    if (type.Equals("P"))
                                        code = (ICode)database.Procedures.Find(id);

                                    if (type.Equals("IF") || type.Equals("FN") || type.Equals("TF") || type.Equals("AF"))
                                        code = (ICode)database.Functions.Find(id);

                                    if (code != null)
                                        
                                        code.Text = reader["Text"].ToString();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }