Snippets: SocksArmor - FilterObjectShowAll

// SOCKSArmor Snippets - SocksArmor.
// Author: Felipe Kellermann <felipek@socksarmor.org>
// Revision: $Revision: 5395 $
// Date: $Date: 2008-01-03 18:05:06 -0200 (Thu, 03 Jan 2008) $
//
// This snippet lists all the server's filter object list, skipping
// internal objects (Object), and outputs a list with the following
// format:
//   Object: <name>, type: <server filter object type>
//    Entry: <entry data>

using System;
using SocksArmor;

class SocksArmorSnippet
{
    static void Main(string[] args)
    {
        // Remote SOCKSArmor server.
        RemoteServer server = new RemoteServer();
        server.Connect("127.0.0.1", 10842, "username", "password");

        // RemoteServer's FilterObject member is a collection of all the
        // filter objects on the server.  An iteration/enumeration over
        // this objects reveals the server's available "filter objects".
        foreach (FilterObject obj in server.FilterObjects) {
            // Objects "Internal" or having the type Object are only for
            // internal purposes and are generally ignored from the user
            // perspective.  Almost all the operations on these types of
            // objects throw exceptions.
            if (obj.Internal == true || obj.FilterObjectType == FilterObjectTypes.Object)
                continue;

            // Outputs basic information about the current filter
            // object, including the name, type, description an a
            // counting of all the entries available.
            Console.WriteLine("Object: {0}, type: {1}", obj, obj.FilterObjectType);
            Console.WriteLine("  Description: {0}", obj.Description);
            Console.WriteLine("  Entry count: {0}", obj.EntryCount);

            // Outputs each object's entry.  An "entry" is just some
            // type of content that either *available* or *reference*
            // within a filter object.
            for (int index = 0; index < obj.EntryCount; index++) {
                FilterObject.EntryData data = obj.GetEntry(index);
                Console.WriteLine("     Entry: {0} ({1})", data.Name, data.Type);
            }
        }

        server.Disconnect();
    }
}