views:

1087

answers:

9

In particular, I have to extract all the messages and attachments from Lotus Notes files in the fastest and most reliable way. Another point that may be relevant is that I need to do this from a secondary thread.

Edit

Thanks for the answers - both of which are good. I should provide more background information.

We currently have a WinForms application with a background thread using the Notes COM API.

However it seems to be unstable. (Of course it may be we are doing something wrong.) For example, we have found we have to preinitialize the Notes session on the main thread or else the call to session.CreateDXLExporter() on the background thread throws an exception.

+2  A: 

Take a look at NotesSQL:

http://www.ibm.com/developerworks/lotus/products/notesdomino/notessql/

jasonlaflair
Any idea if this can be used to get items out in a "native" format such as .dxl (without having to produce the XML ourselves)?
Phil Haselden
+2  A: 

If you have a Domino / Lotus Notes client installed on the same machine, you can use COM. Just do a Google search on 'Accessing the Domino Objects through COM' and you'll find the Domino Designer help entry for just about any version of Domino.

You can also access Domino via the C API, but wouldn't recommend it. Very messy. You also still need the Domino / Lotus Notes client installed.

If you do not have Domino / Lotus Notes client installed on the same machine and the Domino server is running http, you could also do it via http. This will not be nearly as fast. You would also probably want some custom http views setup on the Domino server to make your life easier.

Jeff B
+1  A: 

You could create a Domino web service using Java or LotusScript. Then use C# to access the web service.

I've only done this once, to read data out of an Lotus Notes db into a .NET app running on another machine.

Writing and testing simple Web services http://www.ibm.com/developerworks/lotus/library/web-services2/

when i find some time I will write a complete example :-)

Eric Labashosky
+1  A: 

I worked on a Notes plugin for several months a little while back, and yes, the API can be maddening. However, I was able to get it to work so I could access all the Notes information using a C# application (actually, since I was writing a plugin, I had Notes call out to the C# app through a C++ bridge that it registered in a startup .ini file). Certain methods that they document in their API don't actually work though, so a lot of testing is required. Sometimes you have to do some code gymnastics...

Sam Schutte
+2  A: 

An Lotus Notes COM Api Reference can be found here

To get a Notes Session (The starting point) in VB.Net you can use:

Dim oSess As Object = Nothing
oSess = CreateObject("Notes.NotesSession")

I normally program in C#, for operating with COM I prefer VB.Net

It is better to access all COM servers from the same thread, unless you are certain that is will not cause any trouble.

GvS
+1  A: 

Back in the day I would have recommended N2N from Proposion, but that product has gone since Quest acquired Proposion.

That said, Proposion was proof that you can wrap the Notes API in a set of .Net classes safely. You can find some info on that in Bob Balaban's blog.

Peter LaComb Jr.
A: 

I would personally do this native in Notes in either LotusScript or Java. You can do a scheduled agent in Notes much easier than a service in C#.

Martin Murphy
+1  A: 

I really do hate that NotesSession COM object.

You cannot use it in another thread than the thread it was initialized. Threads in .NET are fibers, the real underlying thread may change at any time.

So I suggest using it this way, in a using block :

Imports Domino
Imports System.Threading

Public Class AffinitedSession
    Implements IDisposable

    Private _session As NotesSession
    Public Sub New(ByVal pass As String)
        Thread.BeginThreadAffinity()
        _session = New NotesSession()
        _session.Initialize(pass)
    End Sub

    Public ReadOnly Property NotesSession() As NotesSession
        Get
            Return _session
        End Get
    End Property

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: free other state (managed objects).
            End If

            ' TODO: free your own state (unmanaged objects).
            ' TODO: set large fields to null.
            _session = Nothing
            Thread.EndThreadAffinity()
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

Notice the Thread.BeginThreadAffinity() and the Thread.EndThreadAffinity()

Those are your friends.

Cheers !

Alex Rouillard
Very interesting answer Alex. I will look into this further. Thanks. BTW, I haven't found anything that states that .Net threads are fibres, though I have seen some doco saying that we shouldn't assume .Net threads have a 1-to-1 mapping to unmanaged OS threads.
Phil Haselden
Those are not *real* fibers like Python or Ruby, those are managed threads. That is why the underlying OS thread can change at any time.
Alex Rouillard
A: 

I personally quite like Domino wrapped .NET assembly for COM API. When you develop your C# code you almost can imagine your dreams about a proper Notes IDE became true. But it has some drawbacks like for the version 6.5 (I haven't tried newer) you get your application crashes in many cases when the LotusScript code returns type mismatch for the parameter. But this is due to COM limitations of course.

At the same time the wrapper doesn't allow working with NotesUI classes. However I used reflections from very old Notes COM API examples to call NotesUI classes and it worked. It was handy when I developed an Outlook plug-in that required interaction with Notes client UI. I managed to create a simple wrapper for UI classes too.

Alexey Zimarev