asked on
using System;
using System.Collections.Generic;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;
using System.Collections;
namespace OutlookGuard
{
public partial class ThisAddIn
{
public bool IsLicensed = true;
public string Licensor = "";
public string ExpireDate = "";
/// <summary>
/// Holds a reference to the Application.Inspectors collection
/// Required to get notifications for NewInspector events.
/// </summary>
private Outlook.Inspectors _inspectors;
/// <summary>
/// A dictionary that holds a reference to the Inspectors handled by the add-in
/// </summary>
private Dictionary<Guid, InspectorWrapper> _wrappedInspectors;
public Dictionary<Guid, int> AttachmentCount;
/// <summary>
/// Startup method is called when the add-in is loaded by Outlook
/// </summary>
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
#region license check
if (Properties.Settings.Default.Licence != "")
{
olicense myLicence = new olicense();
oOutlookUtilities mysender = new oOutlookUtilities();
myLicence.AccountEMail = Convert.ToString(mysender.getSenderAddress()[0]);
myLicence.key = Properties.Settings.Default.Licence;
myLicence.decodeLicense();
if (myLicence.Error != "")
{
MessageBox.Show("There was an error starting OutlookGuard: " + myLicence.Error);
IsLicensed = false;
}
else
{
Licensor = myLicence.UserName;
if (myLicence.warningdays > 370) { ExpireDate = "Perpetual"; }
if (myLicence.warningdays < 370) { ExpireDate = Convert.ToString(myLicence.ExpiresDate).Split(' ')[0]; }
}
myLicence = null;
mysender = null;
}
else
{
MessageBox.Show("This product is unregistered. Please go to the OutlookGuard website to obtain a license key, and enter the key in the settings area.");
}
#endregion
_wrappedInspectors = new Dictionary<Guid, InspectorWrapper>();
AttachmentCount = new Dictionary<Guid, int>();
_inspectors = Globals.ThisAddIn.Application.Inspectors;
_inspectors.NewInspector += new Outlook.InspectorsEvents_NewInspectorEventHandler(WrapInspector);
// Handle also already existing Inspectors
// (e.g. Double clicking a .msg file)
foreach (Outlook.Inspector inspector in _inspectors)
{
WrapInspector(inspector);
}
}
/// <summary>
/// Wraps an Inspector if required and remember it in memory to get events of the wrapped Inspector
/// </summary>
/// <param name="inspector">The Outlook Inspector instance</param>
void WrapInspector(Outlook.Inspector inspector)
{
InspectorWrapper wrapper = InspectorWrapper.GetWrapperFor(inspector);
if (wrapper != null)
{
// register for the closed event
wrapper.Closed += new InspectorWrapperClosedEventHandler(wrapper_Closed);
// remember the inspector in memory
_wrappedInspectors[wrapper.Id] = wrapper;
AttachmentCount[wrapper.Id] = 0;
}
}
/// <summary>
/// Method is called when an inspector has been closed
/// Removes reference from memory
/// </summary>
/// <param name="id">The unique id of the closed inspector</param>
void wrapper_Closed(Guid id)
{
_wrappedInspectors.Remove(id);
AttachmentCount.Remove(id);
}
/// <summary>
/// Shutdown method is called when Outlook is unloading the add-in
/// </summary>
///
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
// do the homework and cleanup
_wrappedInspectors.Clear();
AttachmentCount.Clear();
_inspectors.NewInspector -= new Outlook.InspectorsEvents_NewInspectorEventHandler(WrapInspector);
_inspectors = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
MailItemWrapper.cs
Most development for the Microsoft platform is done utilizing the technologies supported by the.NET framework. Other development is done using Visual Basic for Applications (VBA) for programs like Access, Excel, Word and Outlook, with PowerShell for scripting, or with SQL for large databases.
TRUSTED BY
ASKER
Item.Send += new Outlook.ApplicationEvents_
But send is a method not event, how can I do this?