/// <summary>
        /// This will be invoked by the COM server when it has finished
        /// processing the message.
        /// </summary>
        public void VirusScanCompleted()
        {
            Debug.WriteLine("[AntivirusAgent] Callback from the COM service");

            // Restores the state for the thread.
            this.agentAsyncContext.Resume();

            // Release the COM server resources.
            this.virusScanner = null;

            // This allows Exchange to continue processing the message.
            this.agentAsyncContext.Complete();
        }
Exemple #2
0
        /// <summary>
        /// Invoked by Exchange when a message has been submitted.
        /// </summary>
        /// <param name="source">The source of this event.</param>
        /// <param name="args">Arguments for this event.</param>
        void SubmittedMessageHandler(SubmittedMessageEventSource source, QueuedMessageEventArgs args)
        {
            Debug.WriteLine("[AntivirusAgent] Invoking the COM service");

            try
            {
                // Create the virus scanner COM object.
                Guid classGuid     = new Guid("B71FEE9E-25EF-4e50-A1D2-545361C90E88");
                Guid interfaceGuid = new Guid("7578C871-D9B3-455a-8371-A82F7D864D0D");

                object virusScannerObject = UnsafeNativeMethods.CoCreateInstance(
                    classGuid,
                    null,
                    4, // CLSCTX_LOCAL_SERVER,
                    interfaceGuid);

                this.virusScanner = (IComInvoke)virusScannerObject;

                // GetAgentAsyncContext causes Exchange to wait for this agent
                // to invoke the returned callback before continuing to
                // process the current message.
                this.agentAsyncContext = this.GetAgentAsyncContext();

                this.mailItem = args.MailItem;

                // Invoke the virus scanner.
                this.virusScanner.BeginVirusScan((IComCallback)this);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                Debug.WriteLine("[AntivirusAgent] " + ex.ToString());
                if (this.agentAsyncContext != null)
                {
                    this.agentAsyncContext.Complete();
                }
            }

            return;
        }