Professional Documents
Culture Documents
Version 5.3
Microsoft Windows .NET
March 2005
Copyright © 1994–2005 EMC Corporation.
The PIA integrates seamlessly into Microsoft Visual Studio .NET and supports
design-time features such as statement completion and object browser help. At
runtime, the PIA provides a thin, efficient layer through which .NET code can
access DFC via the Documentum Java–COM Bridge (DJCB).
Behind the scenes, the PIA accesses the Documentum Java-COM Bridge
(DJCB), which accesses the DFC Java classes. This means that DFC remains in
a single source of implementation (in Java), but there are thin, efficient layers
above that implementation, increasing its accessibility (first to COM-based
clients, and second to .NET-based clients).
For a good overview of Primary Interop Assembly basics, visit The Microsoft
Developer Network (MSDN) online to read “Primary Interop Assemblies (PIAs).”
The Select Installation Folder dialog box appears, displaying the default
folder path for installation.
5. (Optional) Specify that Everyone will have access to the PIA, not just you.
6. Click Next.
7. Click Next.
The Installation Complete dialog box appears. The following items are in the
Global Assembly Cache (GAC):
• PIA
• XML documentation file
• Publisher Policy Assembly (PPA)
Private copies of these items are also in the Shared folder, along with an
HTML Help file, Documentum.Interop.DFC.chm.
The PIA installer also promotes the location of the private PIA so that adding
a reference to it in Visual Studio .NET is as straightforward as possible.
You can verify the successful installation of the PIA and the PPA by launching
Windows Explorer and navigating to %WINDIR%\assembly (that is, literally
enter this value in the address bar). You should see:
• Documentum.Interop.DFC
• policy.5.2.Documentum.Interop.DFC
Note: There is a known Microsoft bug in Visual Studio .NET that prevents the
object browser from displaying help for methods from no parameters. Until a fix
is available from Microsoft, you can use the Reflector utility available from
http://www.aisto.com/roeder/dotnet/
You can also view DFC PIA documentation in HTML Help format by double-
clicking the Documentum.Interop.DFC.chm file in the Shared folder. Navigating
through this documentation is similar to navigating through Microsoft’s own
platform documentation
I’ve been using the DFC 5.2 PIA from the Developer Program web site, what do
I do?
Use the new DFC 5.3 PIA.
The following answer provides more details on how to use the PPA to assist
your application development/deployment.
Examples
C# Examples
Overview
The following are simple examples in C# to help familiarize you with the
concepts required for working with the PIA.
Note: These examples are intentionally basic. If you’re already familiar with
DFC, read the Setup section and skim through the remaining examples.
Setup
1. Open Microsoft Visual Studio .NET.
2. Click New Project.
3. From the tree, select Visual C# Projects.
4. Select Windows Application.
5. Enter Sample as the application name and Click OK.
6. From the Project menu, select Add Reference.
7. Select Documentum.Interop.DFC and Click OK.
Figure 6. The form should look like this, but with your user name and password.
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
m_DfClientX = new DfClientX();
if (null == m_DfClientX)
{
// TBD - add error handling here...
}
}
14. Replace the Dispose(bool disposing) method with the following code:
/// <summary>
Marshal.ReleaseComObject(m_DfClientX);
m_DfClientX = null;
}
}
catch(System.Exception err)
{
// TBA - add exception handling here
}
finally
{
base.Dispose( disposing );
}
}
15. Type F5 to compile and run the application to verify that things are set
up properly. The application should start successfully (with empty list
boxes, of course).
16. Exit the application by clicking the Close box in the upper right hand
corner of the form.
Figure 8. The Docbases listbox should fill when you click the Get Docbases button.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
private void GetDocbasesButton_Click(object sender, System.EventArgs e)
{
IDfClient client = null;
IDfDocbaseMap map = null;
try
{
//clear the list box
DocbasesListbox.Items.Clear();
//get a client
client = m_DfClientX.getLocalClient();
if (null != client)
{
//get collection of repositories (throws on failure)
map = client.getDocbaseMap();
Interacting with sessions is a very common task and doing it wrong can create
confusion as well as bugs, so we provide a single set of procedures to call
whenever we need to use a session.
The remaining examples illustrate this pattern. The first example adds the
procedures to Form1.
1. From the Class View tree, select navigate to Form1 and double-click
it.
2. The file, Form1.cs should display in the edit window.
3. Add the code appearing below these instructions to the Form1 class.
4. Type F5 to compile and run the application to verify that things are set
up properly.
The application should behave just as it did when you ran it in the
previous section, since we’ve added procedures, but we haven’t called
them yet.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
/*
Takes a user name, password, and repository name as input arguments and
returns an IDfSessionManager.
Note:
a) Only call this procedure from within a TRY-CATCH-FINALLY
block.
b) In the FINALLY block, call cleanupSession to ensure
try
{
//get a client
client = m_DfClientX.getLocalClient();
if (null != client)
{
//get a session mgr
smgr = client.newSessionManager();
if (null != smgr)
{
//get a login info
loginInfo = m_DfClientX.getLoginInfo();
if (null != loginInfo)
{
//set up the login info
loginInfo.setUser(user);
loginInfo.setPassword(pwd);
//bind session mgr to login info
smgr.setIdentity(docBase, loginInfo);
return smgr;
}
else
{
throw new System.Exception("Couldn't obtain login info.");
}
}
else
{
throw new System.Exception("Couldn't obtain session mgr.");
}
}
else
{
throw new System.Exception("Couldn't obtain client.");
}
}
catch(System.Exception err)
{
throw err;
}
finally
{
if (client != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(client);
client = null;
}
if (loginInfo != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(loginInfo);
loginInfo = null;
}
}
}
/*
Takes an IDfSessionManager manager and repository name as input arguments
and returns an IDfSession.
Note:
a) Only call this procedure from within a TRY-CATCH-FINALLY
block.
b) In the FINALLY block, call cleanupSession(...) to ensure
that the session is properly released.
if (null == smgr)
{
throw new System.Exception("Session not passed.");
}
//set the session
IDfSession session = smgr.getSession(docBase);
if (null == session)
{
throw new System.Exception("Couldn't obtain session.");
}
return session;
}
/*
Takes IDfSessionManager and IDfSession object references and
frees internals, then sets them to Nothing.
Note: This procedure should always be called whenever
setupSession(...) is called.
*/
private void cleanupSession(IDfSessionManager smgr, ref IDfSession session)
{
try
{
if (null != smgr)
{
if (null != session)
{
//clean up session
smgr.release(session);
}
}
}
catch(System.Exception err)
{
// 'This should never really happen
MessageBox.Show("Error: " + err.ToString());
}
finally
{
if (smgr != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(smgr);
smgr = null;
}
if (session != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(session);
session = null;
}
}
}
Also, notice that we use a query to retrieve the list of cabinets from the
repository.
1. From the Class View tree, select navigate to Form1 and double-click it.
2. The file, Form1.cs should display in the edit window.
3. Replace the DocbasesListbox_SelectedIndexChanged code with the
code appearing below these instructions.
4. Type F5 to compile and run the application and then click the Get
DocBases button.
Figure 9. The Cabinets listbox should fill when you select a repository.
5. Exit the application by clicking the Close box in the upper right hand corner
of the form.
private void DocbasesListbox_SelectedIndexChanged(
object sender, System.EventArgs e)
{
if (query != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(query);
query = null;
}
if (rs != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
rs = null;
}
}
}
Unlike the previous example, where we used a Query object to query the
repository for the cabinets, the following example uses getContents(…) to
retrieve the folders within a given cabinet.
Selecting a repository and then a Cabinet should now result in the Folders
listbox populating appropriately.
Figure 10. The Folders listbox should fill when you select a Cabinet.
5. Exit the application by clicking the Close box in the upper right hand corner
of the form.
private void CabinetsListbox_SelectedIndexChanged(object sender, System.EventArgs e)
{
IDfSessionManager smgr = null;
IDfSession session = null;
IDfFolder cab = null;
IDfCollection rs = null;
IDfId objId = null;
IDfSysObject sysObj = null;
//get a session
session = setupSession(smgr,DocbasesListbox.Text);
if (cab != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(cab);
cab = null;
}
if (rs != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
rs = null;
}
if (objId != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(objId);
objId = null;
}
if (sysObj != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(sysObj);
sysObj = null;
}
}
}
However, down the road, we’re also going to want to refresh the documents
listbox when a document is checked in or checked out. So, we put the code for
populating the documents listbox in a procedure called fillDocumentsListbox(
) and we implement a SelectedIndexChanged event handler which calls it.
Figure 11. The Documents listbox should fill when you select a Folder.
5. Exit the application by clicking the Close box in the upper right hand corner
of the form.
DocumentsListbox.Items.Add(
rs.getString("object_name"));
//if the document is checked out, check the checkbox
if (false == rs.getString("r_lock_owner").Equals(""))
{
DocumentsListbox.SetItemChecked(i, true);
}
i++;
}
}
}
else
{
throw new System.Exception(
"Couldn't obtain folder: "
+ "/"
+ CabinetsListbox.Text
+ "/"
+ FoldersListbox.Text);
}
}
catch(System.Exception err)
{
// 'This should never really happen
MessageBox.Show("Error: " + err.ToString());
}
finally
{
cleanupSession(smgr, ref session);
if (folder != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(folder);
folder = null;
}
if (rs != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs);
rs = null;
}
}
}
1. From the Class View tree, select navigate to Form1 and double-click it.
2. The file, Form1.cs should display in the edit window.
3. Replace the DocumentsListbox_SelectedIndexChanged code with the
code appearing below these instructions. Be sure and add the
toggleCheckout (…) procedure to the Form1 class as well.
4. Type F5 to compile and run the application and then click the Get
DocBases button.
Figure 12. A checked item indicates that the document is currently checked out.
5. Exit the application by clicking the Close box in the upper right hand corner
of the form.
private void toggleCheckout(IDfOperation operation)
{
IDfSessionManager smgr = null;
if (sys != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(sys);
sys = null;
}
if (node != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(node);
node = null;
}
if (list != null)
try
{
// If user clicks a document that has a check, we'll
// check it in. Otherwise, we'll check it out.
if (DocumentsListbox.GetItemChecked(
DocumentsListbox.SelectedIndex))
{
operation = m_DfClientX.getCheckinOperation();
}
else
{
operation = m_DfClientX.getCheckoutOperation();
}
if (null != operation)
{
//call toggleCheckout(...) to check out the document
toggleCheckout(operation);
fillDocumentsListbox();
}
else
{
throw new System.Exception("Couldn't obtain operation");
}
}
catch(System.Exception err)
{
// 'This should never really happen
MessageBox.Show("Error: " + err.ToString());
}
finally
{
if (operation != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(operation);
operation = null;
}
}
}
VB.NET Examples
Overview
We’ve provided some of the simplest examples we could think of in VB.NET to
help familiarize you with the concepts required for working with the PIA.
Note: These examples are intentionally quite basic. If you’re already very
familiar with the DFC APIs read the Setup section and then skim through the
remaining examples.
Setup
1. Open Microsoft Visual Studio .NET.
2. Click New Project.
3. From the tree, select Visual Basic Projects.
4. Select Windows Application.
5. Enter Sample as the application name and click OK.
6. From the Project menu, select Add Reference.
7. Select Documentum.Interop.DFC and click OK.
Figure 14. Add Reference dialog box in Visual Studio .NET with Documentum.Interop.DFC selected.
Figure 15. The form should look like this, but with your user name and password.
13. Replace the Visual Studio Form Designer generated New() method with
the following:
Public Sub New()
MyBase.New()
Marshal.ReleaseComObject(m_DfClientX)
m_DfClientX = Nothing
End If
Catch err As System.Exception
'TBA - add exception handling here
Finally
MyBase.Dispose(disposing)
End Try
End Sub
15. Type F5 to compile and run the application to verify that things are set up
properly. The application should start successfully (with empty list boxes,
of course).
16. Exit the application by clicking the Close box in the upper right hand
corner of the form.
1. From the Class View tree, navigate to Form1 and double-click it.
2. The file, Form1.vb should appear in the edit window.
3. Add the code appearing below these instructions to the file before the
End Class statement.
4. Type F5 to compile and run the application and then click the Get
DocBases button.
Figure 17. Docbases listbox should fill when you click the Get Docbases button.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
Private Sub GetDocbasesButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles GetDocbasesButton.Click
Try
'get a client
client = m_DfClientX.getLocalClient
count = map.getDocbaseCount()
'iterate through repositories and populate listbox
Interacting with sessions is a very common task and doing it wrong can create
confusion as well as bugs, so we want to write a single set of procedures that
we can call whenever we need to use a session.
You’ll see that pattern in practice in the remaining examples – for now, let’s
add the procedures to Form1.
1. From the Class View tree, select navigate to Form1 and double-click
it.
The application should behave just as it did when you ran it in the
previous section, since we’ve added procedures, but we haven’t called
them yet.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
'Takes a user name, password, and repository name as input string arguments
'and returns an object of type IDfSessionManager.
'
'Note: a) Notice there's no TRY-CATCH-FINALLY block here. Exceptions must
' be handled at the caller.
'
' b) Call this procedure from within a TRY-CATCH-FINALLY block.
'
' c) In the FINALLY block, call cleanupSession(...) to ensure
' that the session is properly released.
'
Private Function setupSessionMgr( _
ByVal user As String, _
ByVal pwd As String, _
ByVal docBase As String) As IDfSessionManager
Try
'get a client
client = m_DfClientX.getLocalClient
'return session
setupSession = session
End Function
As you review the sample code, examine the way sessions are managed. Notice
that we call our cleanupSession(…) procedure from within a finally block.
Doing so ensures that the session will always be released safely.
Also, notice that we use a query to retrieve the list of cabinets from the
repository.
1. From the Class View tree, select navigate to Form1 and double-click
it.
2. The file, Form1.vb should display in the edit window.
3. Add the code appearing below these instructions to the file before the
End Class statement (immediately after the code we added in the
previous section).
4. Type F5 to compile and run the application and then click the Get
DocBases button.
Figure 18. Cabinets listbox should fill when you select a repository.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
Private Sub DocBasesListbox_SelectedIndexChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
CabinetsListbox.Items.Clear()
FoldersListbox.Items.Clear()
DocumentsListbox.Items.Clear()
Try
'get a query object
query = m_DfClientX.getQuery()
Unlike the previous example, where we used a Query object to query the
repository for the cabinets, the following example uses getContents(…) to
retrieve the folders within a given cabinet.
1. From the Class View tree, select navigate to Form1 and double-click
it.
2. The file, Form1.vb should display in the edit window.
3. Add the code appearing below these instructions to the file before the
End Class statement (immediately after the code we added in the
previous section).
4. Type F5 to compile and run the application and then click the Get
DocBases button.
Selecting a repository and then a Cabinet should now result in the Folders
listbox populating appropriately.
Figure 19. Folders listbox should fill when you select a Cabinet.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
Private Sub CabinetsListBox_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles CabinetsListbox.SelectedIndexChanged
Dim smgr As IDfSessionManager
Dim session As IDfSession
Dim rs As IDfCollection
Dim cab As IDfFolder 'access the cabinet through this interface
FoldersListbox.Items.Clear()
DocumentsListbox.Items.Clear()
Try
'get a session manager (throws on failure)
smgr = setupSessionMgr(UserTextBox.Text, _
PasswordTextBox.Text, _
DocbasesListbox.Text)
Dim i As Integer
i = 0
'iterate list of folders
While (True = rs.next())
Dim strType As String = rs.getString("r_object_type")
Dim res As Int16 = String.Compare(strType, "dm_folder")
If (res = 0) Then
FoldersListbox.Items.Add(rs.getString("object_name"))
End If
i = i + 1
End While
Else
Throw New System.Exception( _
"Couldn't obtain cabinet: " & CabinetsListbox.Text)
End If
Catch err As System.Exception
MsgBox("Error: " & err.ToString)
Finally
cleanupSession(smgr, session)
If (Not Nothing Is rs) Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(rs)
rs = Nothing
End If
If (Not Nothing Is cab) Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(cab)
cab = Nothing
End If
End Try
End Sub
However, down the road, we’re also going to want to refresh the documents
listbox when a document is checked in or checked out. So, we put the code for
populating the documents listbox in a procedure called fillDocumentsListbox(
) and we implement a SelectedIndexChanged event handler which calls it.
1. From the Class View tree, select navigate to Form1 and double-click
it.
2. The file, Form1.vb should display in the edit window.
Figure 20. Documents listbox should fill when you select a Folder.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
Private Sub FoldersListBox_SelectedIndexChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles FoldersListbox.SelectedIndexChanged
fillDocumentsListbox()
End Sub
DocumentsListbox.Items.Clear()
Try
'get a session manager (throws on failure)
smgr = setupSessionMgr(UserTextBox.Text, _
PasswordTextBox.Text, _
DocbasesListbox.Text)
Dim i As Integer
i = 0
'output list of folders
While (True = rs.next())
Dim objType As String = rs.getString("r_object_type")
Dim res As Int16 = String.Compare(objType, "dm_document")
If (res = 0) Then
'add each document name to the listbox
DocumentsListbox.Items.Add(rs.getString("object_name"))
Since this sample doesn’t do anything fancy during either checkin or checkout,
both actions are accomplished through a single procedure named
toggleCheckout(…). As the code comments explain, depending on whether a
checkin or a checkout is required, a different object (that implements
IDfOperation) is passed, and the right methods are fired.
1. From the Class View tree, select navigate to Form1 and double-click
it.
2. The file, Form1.vb should display in the edit window.
3. Add the code appearing below these instructions to the file before the
End Class statement (immediately after the code we added in the
previous section).
4. Type F5 to compile and run the application and then click the Get
DocBases button.
Figure 21. Checked item indicates that the document is currently checked out.
5. Exit the application by clicking the Close box in the upper right hand
corner of the form.
Private Sub DocumentsListbox_SelectedValueChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles DocumentsListbox.SelectedValueChanged
Dim operation As IDfOperation
Try
'If user clicks a document that has a check, we'll
'check it in. Otherwise, we'll check it out.
If (DocumentsListbox.GetItemChecked( _
DocumentsListbox.SelectedIndex)) Then
operation = m_DfClientX.getCheckinOperation()
Else
operation = m_DfClientX.getCheckoutOperation()
End If
sys = session.getObjectByPath(path)