Recursive output of the data stock

The following example is intended to illustrate the access to the hierarchically structured data stock.

using System;
using Onion.Client;

class Program
{
  static void Main(string[] args)
  {
    using (var session = new OnionSession("ipc://onion.net/onion/server", "admin", "admin"))
    {
      PrintTree(session.Repository.Root, 0);
    }
  }

  private static void PrintTree(IDataObject item, int level)
  {
    Console.WriteLine("".PadLeft(level * 2) + item.Name);

    foreach (IDataObject child in item.Children)
    {
      PrintTree(child, level + 1);
    }
  }
}

As in the last example, a connection is made to the onion.net Information Server. The property “IOnionSession.Repository” groups all data operations of the onion.net Client API. The root of all data objects can be reached via the property “IDataRepository.Root”.

The recursive method “PrintTree” in our example outputs the identifier of a data object in each case and represents the child elements indented. These are the interfaces used in the example:

public interface IDataRepository
{
    IDataObject Root { get; }
    // ...
}

public interface IDataObject
{
    int Id { get; }
    string Name { get; }
    IDataObjectChildrenCollection Children { get; }
    // ...
} 

The output in a system with quite some data could look as follows:

  Editor
    System
    XHTML-Editor
    Website Base
      XSL Renderengine
        Icons
        Ressourcen
          de
          en
        childrenlistviews
        xmleditor
        Editorfunktionen
      GenericForms
        Icons
        Objektstrukturfenster
        Ressourcen
          de
        XHTML Editor
      Scripts
        Icons
        Ressourcen
          de
          en
      Themes
        Icons
        Ressourcen
          de
          en
      Lokalisierung
        Icons
        Ressourcen
          de
          en
      Lightview
        Icons
        Ressourcen
          de
      Structureabstraction
      Icons
      Objektstrukturfenster