using System;
using System.Collections.Generic;
using System.Text;
using smo = Microsoft.SqlServer.Management.Smo;
using System.Reflection;
namespace Using
{
    class Program
    {
        static void PropertyOut(smo.Property property, System.IO.TextWriter textWriter)
        {
            textWriter.WriteLine("Name:\t" +property.Name + ", ");
            textWriter.WriteLine("  Readable:\t" + property.Readable + ", ");
            textWriter.WriteLine("  Retrieved:\t" + property.Retrieved  + ", ");
            textWriter.WriteLine("  Dirty:\t" + property.Dirty + ", ");
            textWriter.WriteLine("  Expensive:\t" + property.Expensive + ", ");
            textWriter.WriteLine("  Writeable:\t" + property.Writable + ", ");
            textWriter.WriteLine("  Value:\t" + property.Value);
          
        }
        static void Main(string[] args)
        {
            smo.Server localhost = new smo.Server("CANOPUS5");
            Console.WriteLine(localhost.Name);
            Console.WriteLine(localhost.InstanceName);
            Console.WriteLine(localhost.Properties.Count);
            smo.SqlPropertyInfo pi =
            localhost.Properties.GetPropertyInfo("InstanceName");
            
            foreach (smo.Property property in localhost.Properties)
            {
                PropertyOut(property, Console.Out);
            }
            smo.Database db = localhost.Databases[0];
            Console.WriteLine("---------------");
            Console.WriteLine(db.CreateDate);
            foreach (smo.Property property in db.Properties)
            {
                PropertyOut(property, Console.Out);
            }
            db.Initialize(true);
            Console.WriteLine("-----Initialized----------");
            int index = 0;
            Type type = db.GetType();
            foreach (smo.Property property in db.Properties)
            {
                index++;
                Console.Write(index + " ");
                PropertyInfo pinfo = type.GetProperty(property.Name);
                Console.WriteLine(" " + property.Name +  " has property: " + (pinfo != null).ToString(), ", ");
                PropertyOut(property, Console.Out);
            }
           // db.ActiveConnections;
           
Console.WriteLine(db.CompatibilityLevel);
Console.WriteLine(db.CreateDate);
Console.WriteLine(db.DataSpaceUsage);
Console.WriteLine(db.DboLogin);
Console.WriteLine(db.DefaultFileGroup);
Console.WriteLine(db.DefaultSchema);
Console.WriteLine(db.ID);
Console.WriteLine(db.IndexSpaceUsage);
Console.WriteLine(db.IsAccessible);
Console.WriteLine(db.IsDbAccessAdmin);
Console.WriteLine(db.IsDbBackupOperator);
Console.WriteLine(db.IsDbDatareader);
Console.WriteLine(db.IsDbDatawriter);
Console.WriteLine(db.IsDbDdlAdmin);
Console.WriteLine(db.IsDbDenyDatareader);
Console.WriteLine(db.IsDbDenyDatawriter);
Console.WriteLine(db.IsDbOwner);
Console.WriteLine(db.IsDbSecurityAdmin);
Console.WriteLine(db.IsFullTextEnabled);
Console.WriteLine(db.IsSystemObject);
Console.WriteLine(db.LastBackupDate);
Console.WriteLine(db.LastLogBackupDate);
Console.WriteLine(db.Owner);
Console.WriteLine(db.PrimaryFilePath);
Console.WriteLine(db.ReplicationOptions);
Console.WriteLine(db.Size);
Console.WriteLine(db.SpaceAvailable);
Console.WriteLine(db.Status);
Console.WriteLine(db.UserName);
Console.WriteLine(db.CaseSensitive);
Console.WriteLine(db.Collation);
Console.WriteLine(db.IsUpdateable);
Console.WriteLine(db.Version);
Console.WriteLine(db.AutoCreateStatisticsEnabled);
Console.WriteLine(db.AutoUpdateStatisticsEnabled);
Console.WriteLine(db.DatabaseGuid);
Console.WriteLine(db.DatabaseSnapshotBaseName);
Console.WriteLine(db.DefaultFullTextCatalog);
/*
            IsDatabaseSnapshot
IsDatabaseSnapshotBase
IsMailHost
IsMirroringEnabled
LogReuseWaitStatus
MirroringFailoverLogSequenceNumber
MirroringID
MirroringPartner
MirroringRole
MirroringRoleSequence
MirroringSafetyLevel
MirroringSafetySequence
MirroringStatus
MirroringWitness
MirroringWitnessStatus
RecoveryForkGuid
 * */
        }
    }
}
