Implementing a Managed OnMdbStartup Event Sink

Topic Last Modified: 2006-06-12

The following samples catch the OnMDBStartUp Method and write information to a log file. See Store Event Sink Bit Flags and Building Managed Event Sink DLLs for more information.

Visual Basic.NET

Example

Option Explicit On
Option Strict On

' Add project references to the System.EnterpriseServices, ADODB,
' Interop.Exoledb, and SignedExevtsnk .NET components.
Imports System.IO
Imports System.EnterpriseServices
Imports Exoledb = Interop.Exoledb
Imports ExevtsnkLib = SignedExevtsnk
Imports ADODB
Imports System.Reflection

Namespace ExchangeSDK.Snippets.VBNet

Public Class SystemEvents
   Inherits ServicedComponent
   Implements Exoledb.IExStoreSystemEvents

   ' Logfile path.
   Private Const LOGFILE As String = "C:\\evtlog.txt"

   Public Sub OnMDBStartUp(ByVal bstrMDBGuid As String, _
                           ByVal bstrMDBName As String, _
                           ByVal lFlags As Integer) _
              Implements Interop.Exoledb.IExStoreSystemEvents.OnMDBStartUp

      ' Variables.
      Dim sr As StreamWriter

      ' Open the log file, append text to file.
      sr = File.AppendText(LOGFILE)

      Try
         sr.WriteLine("[VB.NET Event Sink]   OnMDBStartUp()")

         ' Write the GUID of MDB shutting down to the log.
         sr.WriteLine("MDB Guid: " + bstrMDBGuid)

         ' Write the name of MDB shutting down to the log.
         sr.WriteLine("MDB name: " + bstrMDBName)

         ' Write the event flag to the log.
         sr.WriteLine("lFlags: " & lFlags)

      Catch ex As Exception

         ' Write exception info to the log.
         sr.WriteLine("Exception message: " & ex.Message)
         sr.WriteLine("")

      End Try

      ' Close the stream writer.
      sr.Close()
   End Sub

   Public Sub OnMDBShutDown(ByVal bstrMDBGuid As String, ByVal lFlags As Integer) _
                 Implements Interop.Exoledb.IExStoreSystemEvents.OnMDBShutDown

    ' Implement OnMDBShutDown code here.

   End Sub

   Public Sub OnTimer(ByVal bstrURLItem As String, ByVal lFlags As Integer) _
                 Implements Interop.Exoledb.IExStoreSystemEvents.OnTimer

      ' Implement OnTimer code here.

   End Sub
End Class

End Namespace

C#

Example

using System;
using System.Reflection;
using System.Diagnostics;
using Exoledb = Interop.Exoledb;
using ADODB;
using System.EnterpriseServices;
using System.IO;

namespace ExchangeSDK.Snippets.CSharp
{
   public class SystemEvents : ServicedComponent, Exoledb.IExStoreSystemEvents
   {
      // Logfile path.
      private const string LOGFILE = "C:\\evtlog.txt";

      public void OnMDBStartUp(string bstrMDBGuid, string bstrMDBName, int lFlags)
      {
         // Variables.
         StreamWriter sr;

         // Open the log file, append text to file.
         sr = File.AppendText(LOGFILE);

         try
         {
            sr.WriteLine ("[C# Event Sink]   OnMDBStartUp()");
            sr.WriteLine("MDBGuid: " + bstrMDBGuid);
            sr.WriteLine("MDBName: " + bstrMDBName);
            sr.WriteLine("lFlags: " + lFlags);
         }
         catch(Exception ex)
         {
            // Write exception info to the log.
            sr.WriteLine("Exception message: " + ex.Message);
        sr.WriteLine("");
         }

         // Close the stream writer.
         sr.Close();
      }

      public void OnTimer(string bstrURLItem, int lFlags)
      {
     // Implement OnTimer code here.
      }

      public void OnMDBShutDown(string bstrMDBGuid, int lFlags)
      {
         // Implement OnMDBShutDown code here.
      }
   }
}