Get All Subtypes of a Type
| February 2006 | |
|
Software Environment
| Feature | Tested on |
| Operating System | Windows 2000 Server SP4 |
| Language | C# |
| Compiler | Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42 |
| Runtime | Microsoft (R) Windows (R) 2005 Framework version 2.0.50727 |
| DFC | 5.2.x,5.3, 5.3 SP1 |
| Content Server | 5.3 |
Abstract
This snippet gets all the direct and indirect subtypes of a particular supertype.
Snippet
using System;
using System.Collections.Generic;
using System.Text;
using Documentum.Interop.DFC;
using System.Runtime.InteropServices;
namespace CodeSnippets
{
class GetAllSubtypes
{
public static void Main(String[] args)
{
GetAllSubtypes gas = new GetAllSubtypes();
gas.PrintAllSubtypes();
}
String username = "dmadmin";
String password = "dmadmin";
String repository = "devprog53sp1";
string superType = "0c017a1280000105";
public void PrintAllSubtypes()
{
IDfQuery queryObj = null;
IDfCollection coll = null;
IDfSession sess = null;
IDfSessionManager sessMgr = null;
IDfClientX clientX = null;
try
{
StringBuilder bldr = new StringBuilder(24);
bldr.Append("select r_type_name from dmi_type_info where ANY r_supertype IN ('");
bldr.Append(superType);
bldr.Append("')");
String strQuery = bldr.ToString();
clientX = new DfClientX();
queryObj = clientX.getQuery();
queryObj.setDQL(strQuery);
sessMgr = CreateSessionManager();
sess = sessMgr.getSession(repository);
coll = queryObj.execute(sess, tagDfQueryTypes.DF_READ_QUERY);
while (coll.next())
{
String type = coll.getString("r_type_name");
Console.WriteLine(type);
}
Console.WriteLine("Finished printing subtypes");
Console.ReadLine();
}
catch (COMException ex)
{
Console.WriteLine("Authentication Failed");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
finally
{
if (coll != null)
{
try { coll.close(); }
catch (COMException cex2) { }
Marshal.ReleaseComObject(coll);
}
if (sess != null)
{
sessMgr.release(sess);
Marshal.ReleaseComObject(sessMgr);
Marshal.ReleaseComObject(sess);
}
if (clientX != null)
{
Marshal.ReleaseComObject(clientX);
}
}
}
private IDfSessionManager CreateSessionManager()
{
IDfClientX clientX = null;
IDfClient localClient = null;
IDfSessionManager sessMgr = null;
IDfLoginInfo li = null;
try
{
clientX = new DfClientXClass();
li = clientX.getLoginInfo();
li.setUser(username);
li.setPassword(password);
localClient = clientX.getLocalClient();
sessMgr = localClient.newSessionManager();
sessMgr.setIdentity(repository, li);
}
catch (COMException ex)
{
Console.WriteLine("Authentication Failed");
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
finally
{
if (clientX != null) Marshal.ReleaseComObject(clientX);
if (localClient != null) Marshal.ReleaseComObject(localClient);
if (li != null) Marshal.ReleaseComObject(li);
}
return sessMgr;
}
}
}
|
 |
|