Implementing a Managed OnSyncSave Event Sink

Implementing a Managed OnSyncSave 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 OnSyncSave 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 SyncEvents
   Inherits ServicedComponent
   Implements Exoledb.IExStoreSyncEvents

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

   Public Sub OnSyncSave(ByVal pEventInfo As Interop.Exoledb.IExStoreEventInfo, _
                         ByVal bstrURLItem As String, _
                         ByVal lFlags As Integer) _
              Implements Interop.Exoledb.IExStoreSyncEvents.OnSyncSave

      ' Variables.
      Dim sr As StreamWriter
      Dim rec As ADODB.Record
      Dim dispEvtInfo As Exoledb.IExStoreDispEventInfo

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

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

      ' Write the URL of the item to the log.
      sr.WriteLine("URL of item: " + bstrURLItem)

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

      ' Get the record object representing the item.
      dispEvtInfo = CType(pEventInfo, Exoledb.IExStoreDispEventInfo)
      rec = CType(dispEvtInfo.EventRecord, ADODB.Record)

      ' Write the DAV:href property value of the item to the log.
      sr.WriteLine("DAV:displayname value: " & CType(rec.Fields("DAV:displayname").Value, String))

      sr.WriteLine("")

      ' Determine the phase of the OnSyncSave event.
      If (16777216 = (lFlags And ExevtsnkLib.EVT_SINK_FLAGS.EVT_SYNC_BEGIN)) Then

         ' Begin phase of the OnSyncSave event.
         sr.WriteLine("The EVT_SYNC_BEGIN bit is set.")

      ElseIf (33554432 = (lFlags And ExevtsnkLib.EVT_SINK_FLAGS.EVT_SYNC_COMMITTED)) Then

         ' Commit phase of the OnSyncSave event.
         sr.WriteLine("The EVT_SYNC_COMMITTED bit is set.")

      ElseIf (67108864 = (lFlags And ExevtsnkLib.EVT_SINK_FLAGS.EVT_SYNC_ABORTED)) Then

         ' Abort phase of the OnSyncSave event.
         sr.WriteLine("The EVT_SYNC_ABORTED bit is set.")
      End If

      ' Determine the cause of the OnSyncSave event.
      If (8 = (lFlags And ExevtsnkLib.EVT_SINK_FLAGS.EVT_IS_DELIVERED)) Then

         ' A mail item was delivered.
         sr.WriteLine("The EVT_IS_DELIVERED bit is set.")

      ElseIf (256 = (lFlags And ExevtsnkLib.EVT_SINK_FLAGS.EVT_MOVE)) Then

         ' An item was saved because of a move.
         sr.WriteLine("The EVT_MOVE bit is set.")

      ElseIf (512 = (lFlags And ExevtsnkLib.EVT_SINK_FLAGS.EVT_COPY)) Then

         ' An item was saved because of a copy.
         sr.WriteLine("The EVT_COPY bit is set.")
      End If

      sr.WriteLine("")

      Catch ex As Exception

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

      End Try

      ' Clean up.
      sr.Close()
      rec.Close()

   End Sub

   Public Sub OnSyncDelete(ByVal pEventInfo As Interop.Exoledb.IExStoreEventInfo, _
                           ByVal bstrURLItem As String, _
                           ByVal lFlags As Integer) _
              Implements Interop.Exoledb.IExStoreSyncEvents.OnSyncDelete

      ' Implement OnSyncDelete 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 SyncEvents : ServicedComponent, Exoledb.IExStoreSyncEvents
   {
      // Logfile path.
      private const string LOGFILE = "C:\\evtlog.txt";

      public void OnSyncSave(Exoledb.IExStoreEventInfo pEventInfo, string bstrURLItem, int lFlags)
      {
         // Variables.
         StreamWriter sr;
         ADODB.Record rec;
         Exoledb.IExStoreDispEventInfo dispEvtInfo;

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

         try
         {
            sr.WriteLine ("[C# Event Sink]   OnSyncSave()");

            // Write the URL of the item to the log.
            sr.WriteLine("URL of item: " + bstrURLItem);

            // Write the event flag to the log.
            sr.WriteLine("lFlags: " + lFlags);

            // Get the record object representing the item.
            dispEvtInfo = (Exoledb.IExStoreDispEventInfo)pEventInfo;
            rec = (ADODB.Record)dispEvtInfo.EventRecord;

            // Write the DAV:href property value of the item to the log.
            sr.WriteLine("DAV:displayname value: " + rec.Fields["DAV:displayname"].Value);

            sr.WriteLine("");

            // Determine the phase of the OnSyncSave event.
            if(16777216 == (lFlags & (int)ExevtsnkLib.EVT_SINK_FLAGS.EVT_SYNC_BEGIN) )
            {
               // Begin phase of the OnSyncSave event.
               sr.WriteLine("The EVT_SYNC_BEGIN bit is set.");
            }
            else if(33554432 == ( lFlags & (int)ExevtsnkLib.EVT_SINK_FLAGS.EVT_SYNC_COMMITTED) )
            {
               // Commit phase of the OnSyncSave event.
               sr.WriteLine("The EVT_SYNC_COMMITTED bit is set.");
            }
            else if(67108864 == (lFlags & (int)ExevtsnkLib.EVT_SINK_FLAGS.EVT_SYNC_ABORTED))
            {
               // Abort phase of the OnSyncSave event.
               sr.WriteLine("The EVT_SYNC_ABORTED bit is set.");
            }

            // Determine the cause of the OnSyncSave event.
            if( 8 == (lFlags & (int)ExevtsnkLib.EVT_SINK_FLAGS.EVT_IS_DELIVERED))
            {
               // A mail item was delivered.
               sr.WriteLine("The EVT_IS_DELIVERED bit is set.");
            }
            else if(256 == (lFlags & (int)ExevtsnkLib.EVT_SINK_FLAGS.EVT_MOVE))
            {
               // An item was saved because of a move.
               sr.WriteLine("The EVT_MOVE bit is set.");
            }
            else if(512 == (lFlags & (int)ExevtsnkLib.EVT_SINK_FLAGS.EVT_COPY))
            {
               // An item was saved because of a copy.
               sr.WriteLine("The EVT_COPY bit is set.");
            }

            sr.WriteLine("");
         }
         catch(Exception ex)
         {
            // Write exception info to the log.
            sr.WriteLine("Exception message: " + ex.Message);
            sr.WriteLine("");
         }

         // Clean up.
         sr.Close();
      }

      public void OnSyncDelete(Exoledb.IExStoreEventInfo pEventInfo, string bstrURLItem, int lFlags)
      {
	 // Implement OnSyncDelete 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.