Skip Navigation LinksBase4.NET : Quickstarts : Cool Stuff : Discover available Schemas?

Skip Navigation Links.

Discover what Schemas are available and what is in those schemas?

Base4 provides a very simple model for discovering the capabilities of a server. You simply query it like you would for any other query, except you ask for SchemaImpl, TypeImpl and PropertyImpl etc. This example simply queries the server at the end of the provided connection string and prints out information about every schema, type, property, extended property and event handler registered.

 

using System;

using System.Collections.Generic;

using System.Windows.Forms;

using Base4.Storage;

namespace Base4.Storage.Quickstart

{

    static class Program

    {

        /// <summary>

        /// Print out information about what types etc are available on the provided connection

        /// </summary>

        static void PrintAvailableSchemas(string connectionstring)

        {

            //Connect to an arbitrary server

            ItemContext context = new ItemContext(connectionstring);

            //We are not interested in the default schema

            foreach (SchemaImpl schema in context.Find<SchemaImpl>(SchemaImpl.Fields.Name != "Base4.Storage.dll"))

            {

                Console.WriteLine("Found schema: " + schema.Name);

                Console.WriteLine("\tWhich references:");

                foreach (ISchema reference in schema.References)

                {

                    Console.WriteLine("\t\t" + reference.Name);

                }

                Console.WriteLine("\tAnd is referenced by:");

                foreach(ISchema referencedby in schema.ReferencedBy)

                {

                    Console.WriteLine("\t\t" + referencedby.Name);

                }

                Console.WriteLine("\tAnd contains these types:");

                foreach(IType type in schema.ContainedTypes)

                {

                    Console.WriteLine("\t\t" + type.Name);

                    Console.WriteLine("\t\t\tWhich extends:" + type.BaseTypeName);

                    Console.WriteLine("\t\t\tAnd has these properties:");

                    foreach(IProperty property in type.Properties)

                    {

                        Console.WriteLine("\t\t\t\t" + property.Name);

                    }

                    Console.WriteLine("\t\t\tAnd has these extendedProperty:");

                    foreach(IExtendedProperty eproperty in type.ExtendedProperties)

                    {

                        Console.WriteLine("\t\t\t\t" + eproperty.Name);

                    }

                    Console.WriteLine("\t\t\tAnd has these eventhandlers:");

                    foreach(IEventHandler ehandler in type.EventHandlers)

                    {

                        Console.WriteLine("\t\t\t\t" + ehandler.Name);

                    }

                }

            }

        }

    }

}

 

Note: this code has NOT been optimized for performance if you wanted to do that you would use ObjectScope.