Share via


Implementing a Managed OnMdbShutdown Event Sink

Implementing a Managed OnMdbShutdown Event Sink

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The following samples catch the OnMDBShutDown 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

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 OnMDBShutDown(ByVal bstrMDBGuid As String, ByVal lFlags As Integer) _
                 Implements Interop.Exoledb.IExStoreSystemEvents.OnMDBShutDown

      ' Variables.
      Dim sr As StreamWriter

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

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

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

         ' 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 OnMDBStartUp(ByVal bstrMDBGuid As String, _
                           ByVal bstrMDBName As String, _
                           ByVal lFlags As Integer) _
              Implements Interop.Exoledb.IExStoreSystemEvents.OnMDBStartUp

      ' Implement OnMDBStartUp 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#

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 OnMDBShutDown(string bstrMDBGuid, int lFlags)
      {
         // Variables.
         StreamWriter sr;

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

         try
         {
            sr.WriteLine ("[C# Event Sink]   OnMDBShutdown()");
            sr.WriteLine("MDBGuid: " + bstrMDBGuid);
            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 OnMDBStartUp(string bstrMDBGuid, string bstrMDBName, int lFlags)
      {
         // Implement OnMDBStartUp code here.
      }
   }
}

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

This topic last updated: September 2004

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.