Search code examples
c#lotus-notescom-interoplotus-domino

Determining a notes agent's schedule trigger within C#


I want to get a list of all agents and their schedules from within a C# program.

So far I've got as far as enumerating the agents I'm after. Unfortunately the COM objects don't seem to expose what I'm after:

var Session = new NotesSession();

Session.Initialize();

var Servers = new[] { "westerham01/Aqualisa", "westerham02/Aqualisa" };

foreach (var Server in Servers)
{
    var DbDirectory = Session.GetDbDirectory(Server);

    foreach (var Database in GetFromFirstNext<NotesDatabase>(() => { return DbDirectory.GetFirstDatabase(Domino.DB_TYPES.NOTES_DATABASE); },
                                                            DbDirectory.GetNextDatabase))
    {
        Database.Open();

        if (Database.Agents != null)
        {
            foreach (NotesAgent agent in Database.Agents)
            {
                if (agent.IsEnabled && agent.Trigger == AG_TRIGGER.TRIGGER_SCHEDULED)
                {
                    //?????
                }
            }
        }
    }
}

I have managed to do this within notes, although I found the code so don't quite understand how it's working:

Type AssistInfo
    Version As Integer
    TriggerType As Integer  ' 0 none, 1 schedule, 2 new mail, 3 paste, 4 manual, 5 update, 6 router
    SearchType As Integer  ' 0 none, 1 all, 2 new, 3 new/mod, 4 selected, 5 view, 6 unread, 7 prompt, 8 UI
    IntervalType As Integer  ' 0 none, 1 minutes, 2 days, 3 weeks, 4 months
    Interval As Integer
    Time1 As Variant  ' Start time (ms since midnight)
    Time2 As Variant  ' Long (weekday or day of month) or end time (ms since midnight)
    StartTime As Variant  ' Time/Date
    EndTime As Variant  ' Time/Date
    Flags As Long  ' 1 hidden, 2 no weekends, 4 store highlights, 8 mail/paste, 16 choose server
    Spare(15) As Long
End Type
Type BlockID
    hPool As Long
    Block As Integer
End Type
Declare Function ConvertTIMEDATEToText Lib wAPIModule Alias "ConvertTIMEDATEToText" _
(  Byval zI As Long, Byval zT As Long, Byval T As Long, Byval S As String, Byval nS As Integer, nT As Integer) As Integer
Declare Function ConvertTextToTIMEDATE Lib wAPIModule Alias "ConvertTextToTIMEDATE" _
(  Byval zI As Long, Byval zT As Long, pS As Long, Byval nS As Integer, Byval T As Long) As Integer
Declare Private Function NIFFindDesignNote Lib wAPIModule Alias "NIFFindDesignNote" _
(  Byval hDB As Long, Byval S As String, Byval C As Integer, N As Long) As Integer
Declare Private Function NSFDbOpen Lib wAPIModule Alias "NSFDbOpen" _
(  Byval PathName As String, DbHandle As Long) As Integer
Declare Private Function NSFDbClose Lib wAPIModule Alias "NSFDbClose" _
(  Byval DbHandle As Long) As Integer
Declare Private Function NSFNoteOpen Lib wAPIModule Alias "NSFNoteOpen" _
(  Byval hDB As Long, Byval NoteID As Long, Byval F As Integer, hNT As Long) As Integer
Declare Private Function NSFNoteClose Lib wAPIModule Alias "NSFNoteClose" _
(  Byval hNT As Long) As Integer
Declare Function NSFItemInfo Lib wAPIModule Alias "NSFItemInfo" _
(  Byval hNT As Long, Byval N As String, Byval nN As Integer _
,  iB As BlockID, D As Integer, vB As BlockID, nV As Long) As Integer
Declare Private Function NSFNoteUpdate Lib wAPIModule Alias "NSFNoteUpdate" _
(  Byval hNT As Long, Byval F As Integer) As Integer
Declare Function NSFItemDelete Lib wAPIModule Alias "NSFItemDelete" _
(  Byval hNT As Long, Byval N As String, Byval nN As Integer) As Integer
Declare Private Function OSMemAlloc Lib wAPIModule Alias "OSMemAlloc" _
(  Byval T As Integer, Byval N As Long, hM As Long) As Long
Declare Private Function OSMemFree Lib wAPIModule Alias "OSMemFree" _
(  Byval hM As Long) As Long
Declare Private Function OSLockObject Lib wAPIModule Alias "OSLockObject" _
(  Byval H As Long) As Long
Declare Private Sub OSUnlockObject Lib wAPIModule Alias "OSUnlockObject" _
(  Byval H As Long)
Declare Private Function OSPathNetConstruct Lib wAPIModule Alias "OSPathNetConstruct" _
(  Byval NullPort As Long, Byval Server As String, Byval FIle As String, Byval PathNet As String) As Integer
Declare Private Sub Peek Lib "MSVCRT" Alias "memcpy" _
(  D As Any, Byval P As Long, Byval N As Long)
Declare Private Sub Poke Lib "MSVCRT" Alias "memcpy" _
(  Byval D As Long, D As Any, Byval N As Long)
Declare Private Sub PokeString Lib "MSVCRT" Alias "memcpy" _
(  Byval D As Long, Byval S As String, Byval N As Long)

Sub GetAssistInfo(db As NotesDatabase, agent As String, info As AssistInfo)
    Dim np$
    Dim nt%
    Dim t$
    Dim pt&
    Dim p&
    Dim nv&
    Dim ti$
    Dim dt%
    Dim v&
    np$ = Space(1024)
    OSPathNetConstruct 0, db.Server, db.FilePath, np$

'   Dim nc As NotesNoteCollection
'   Set nc = db.CreateNoteCollection(False)
'   nc.SelectAgents = True
'   Call nc.BuildCollection()
'   Dim nid As String
'   nid = nc.GetFirstNoteId()
'   For i = 1 To Count
'       
'   Next

    Dim hDB As Long
    NSFDbOpen np$, hDB
    If hDB = 0 Then
        Messagebox "Can't open database", 16
        Exit Sub
    End If

    pt& = Instr(agent, "|")
    If pt& = 0 Then ti$ = Trim$(agent) Else ti$ = Trim$(Left$(agent, pt& - 1))

    Dim nID As Long
    NIFFindDesignNote hDB, ti$, NOTE_CLASS_FILTER, nID
    If nID = 0 Then
        'Messagebox "Can't find agent " & ti$, 16
        Exit Sub
    End If

    If Instr(db.GetDocumentByID(Hex$(nID)).~$Flags(0), "f") = 0 Then
        Messagebox ti$ & " is not an agent", 16
        Exit Sub
    End If

    Dim hNT As Long
    NSFNoteOpen hDB, nID, 0, hNT

    Dim iB As BlockID, vB As BlockID
    NSFItemInfo hNT&, "$AssistInfo", 11, iB, dt%, vB, nv&
    If Not vB.hPool = 0 Then
        p& = OSLockObject(vB.hPool) + vB.Block
        Peek info.Version, p& + 2, 2
        Peek info.TriggerType, p& + 4, 2
        Peek info.SearchType, p& + 6, 2
        Peek info.IntervalType, p& + 8, 2
        Peek info.Interval, p& + 10, 2
        Peek v&, p& + 12, 4
        If v& <= 31 Then info.Time1 = v& Else info.Time1 = Cdat(v&/100/60/60/24)
        Peek v&, p& + 16, 4
        If v& <= 31 Then info.Time2 = v& Else info.Time2 = Cdat(v&/100/60/60/24)
        t$ = Space(81)
        ConvertTIMEDATEToText 0, 0, p& + 20, t$, 80, nt%
        If Not nt% = 0 Then info.StartTime = Cdat(Left$(t$, nt%))
        t$ = Space(81)
        ConvertTIMEDATEToText 0, 0, p& + 28, t$, 80, nt%
        If Not nt% = 0 Then info.EndTime = Cdat(Left$(t$, nt%))
        Peek info.Flags, p& + 36, 4
        OSUnlockObject vB.hPool
    End If

    NSFNoteClose hNT
    NSFDbClose hDB
End Sub

Can the below be translated into C#? Is there some other way of accessing an agent's schedule?


Solution

  • The LotusScript code you are looking at is calling the Notes C API. C# can definitely call C routines, so yes that code can be translated. In fact, here's a link to an article showing how to call the Notes C API from C#.