Connect.cs
namespace SyncContacts
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Windows.Forms;
// Based on http://support.microsoft.com/?kbid=302901
[GuidAttribute("06279257-8C10-4581-B307-2D537484DB18"), ProgId("SyncContacts.Connect")]
public class Connect : Object, Extensibility.IDTExtensibility2
{
private CommandBarButton SyncButton;
public Connect()
{
}
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
{
applicationObject = application;
addInInstance = addInInst;
if(connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}
public void OnDisconnection(Extensibility.ext_DisconnectMode disconnectMode, ref System.Array custom)
{
if(disconnectMode != Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
applicationObject = null;
}
public void OnAddInsUpdate(ref System.Array custom)
{
}
public void OnStartupComplete(ref System.Array custom)
{
CommandBars oCommandBars;
CommandBar oStandardBar;
try
{
oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty , null, applicationObject ,null);
}
catch(Exception)
{
object oActiveExplorer;
oActiveExplorer= applicationObject.GetType().InvokeMember("ActiveExplorer",BindingFlags.GetProperty,null,applicationObject,null);
oCommandBars= (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars",BindingFlags.GetProperty,null,oActiveExplorer,null);
}
oStandardBar = oCommandBars["Standard"];
try
{
SyncButton = (CommandBarButton)oStandardBar.Controls["Sync Contacts"];
}
catch(Exception)
{
object omissing = System.Reflection.Missing.Value ;
SyncButton = (CommandBarButton) oStandardBar.Controls.Add(1, omissing , omissing , omissing , omissing);
SyncButton.Caption = "Sync Contacts";
SyncButton.Style = MsoButtonStyle.msoButtonCaption;
}
SyncButton.Tag = "Sync Contacts Button";
SyncButton.OnAction = "!
SyncButton.Visible = true;
SyncButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.SyncButton_Click);
object oName = applicationObject.GetType().InvokeMember("Name",BindingFlags.GetProperty,null,applicationObject,null);
oStandardBar = null;
oCommandBars = null;
}
public void OnBeginShutdown(ref System.Array custom)
{
}
private void SyncButton_Click(CommandBarButton cmdBarbutton,ref bool cancel)
{
Cursor.Current = Cursors.WaitCursor;
SyncContacts sc = new SyncContacts();
try
{
sc.CopyOrUpdateOutlookContactsToBcm(applicationObject);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "SyncContacts");
}
Cursor.Current = Cursors.Default;
}
private object applicationObject;
private object addInInstance;
}
}
0 Comments:
Post a Comment
<< Home