Exemplo n.º 1
0
        /// <summary>
        /// Prepare me for running.
        /// </summary>
        private void Prepare()
        {
            var outlookApp = this.Application;

            this.MaybeUpgradeSettings();

            OutlookVersion = (OutlookMajorVersion)Convert.ToInt32(outlookApp.Version.Split('.')[0]);

            StartLogging();

            synchronisationContext  = new SyncContext(outlookApp);
            contactSynchroniser     = new ContactSyncing("CS", synchronisationContext);
            taskSynchroniser        = new TaskSyncing("TS", synchronisationContext);
            appointmentSynchroniser = new AppointmentSyncing("AS", synchronisationContext);
            EmailArchiver           = new EmailArchiving("EM", synchronisationContext.Log);

            var outlookExplorer = outlookApp.ActiveExplorer();

            this.objExplorer              = outlookExplorer;
            outlookExplorer.FolderSwitch -= objExplorer_FolderSwitch;
            outlookExplorer.FolderSwitch += objExplorer_FolderSwitch;

            // TODO: install/remove these event handlers when settings.AutoArchive changes:
            outlookApp.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(this.Application_NewMail);
            outlookApp.ItemSend  += new Outlook.ApplicationEvents_11_ItemSendEventHandler(this.Application_ItemSend);

            ((Outlook.ApplicationEvents_11_Event)Application).Quit += new Outlook.ApplicationEvents_11_QuitEventHandler(ThisAddIn_Quit);

            if (OutlookVersion < OutlookMajorVersion.Outlook2010)
            {
                outlookApp.ItemContextMenuDisplay += new Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(this.Application_ItemContextMenuDisplay);
                var menuBar = outlookExplorer.CommandBars.ActiveMenuBar;
                objSuiteCRMMenuBar2007 = (Office.CommandBarPopup)menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
                if (objSuiteCRMMenuBar2007 != null)
                {
                    ConstructOutlook2007MenuBar();
                }
            }
            else
            {
                //For Outlook version 2010 and greater
                //var app = this.Application;
                //app.FolderContextMenuDisplay += new Outlook.ApplicationEvents_11_FolderContextMenuDisplayEventHander(this.app_FolderContextMenuDisplay);
            }
        }
Exemplo n.º 2
0
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            try
            {
                var outlookApp = this.Application;
                OutlookVersion = (OutlookMajorVersion)Convert.ToInt32(outlookApp.Version.Split('.')[0]);

                this.settings = new clsSettings();
                StartLogging(settings);

                _syncContext        = new SyncContext(outlookApp, settings);
                _contactSyncing     = new ContactSyncing(_syncContext);
                _taskSyncing        = new TaskSyncing(_syncContext);
                _appointmentSyncing = new AppointmentSyncing(_syncContext);

                var outlookExplorer = outlookApp.ActiveExplorer();
                this.objExplorer              = outlookExplorer;
                outlookExplorer.FolderSwitch -= objExplorer_FolderSwitch;
                outlookExplorer.FolderSwitch += objExplorer_FolderSwitch;

                // TODO: install/remove these event handlers when settings.AutoArchive changes:
                outlookApp.NewMailEx += new Outlook.ApplicationEvents_11_NewMailExEventHandler(this.Application_NewMail);
                outlookApp.ItemSend  += new Outlook.ApplicationEvents_11_ItemSendEventHandler(this.Application_ItemSend);

                if (OutlookVersion < OutlookMajorVersion.Outlook2010)
                {
                    outlookApp.ItemContextMenuDisplay += new Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(this.Application_ItemContextMenuDisplay);
                    var menuBar = outlookExplorer.CommandBars.ActiveMenuBar;
                    objSuiteCRMMenuBar2007 = (Office.CommandBarPopup)menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
                    if (objSuiteCRMMenuBar2007 != null)
                    {
                        objSuiteCRMMenuBar2007.Caption = "SuiteCRM";
                        this.btnArvive               = (Office.CommandBarButton) this.objSuiteCRMMenuBar2007.Controls.Add(Office.MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                        this.btnArvive.Style         = Office.MsoButtonStyle.msoButtonIconAndCaption;
                        this.btnArvive.Caption       = "Archive";
                        this.btnArvive.Picture       = RibbonImageHelper.Convert(Resources.SuiteCRM1);
                        this.btnArvive.Click        += new Office._CommandBarButtonEvents_ClickEventHandler(this.cbtnArchive_Click);
                        this.btnArvive.Visible       = true;
                        this.btnArvive.BeginGroup    = true;
                        this.btnArvive.TooltipText   = "Archive selected emails to SuiteCRM";
                        this.btnArvive.Enabled       = true;
                        this.btnSettings             = (Office.CommandBarButton) this.objSuiteCRMMenuBar2007.Controls.Add(Office.MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                        this.btnSettings.Style       = Office.MsoButtonStyle.msoButtonIconAndCaption;
                        this.btnSettings.Caption     = "Settings";
                        this.btnSettings.Click      += new Office._CommandBarButtonEvents_ClickEventHandler(this.cbtnSettings_Click);
                        this.btnSettings.Visible     = true;
                        this.btnSettings.BeginGroup  = true;
                        this.btnSettings.TooltipText = "SuiteCRM Settings";
                        this.btnSettings.Enabled     = true;
                        this.btnSettings.Picture     = RibbonImageHelper.Convert(Resources.Settings);

                        objSuiteCRMMenuBar2007.Visible = true;
                    }
                }
                else
                {
                    //For Outlook version 2010 and greater
                    //var app = this.Application;
                    //app.FolderContextMenuDisplay += new Outlook.ApplicationEvents_11_FolderContextMenuDisplayEventHander(this.app_FolderContextMenuDisplay);
                }

                while (!this.VerifyLicenceKey())
                {
                    /* if licence key does not validate, show the settings form to allow the user to enter
                     * a (new) key, and retry. */
                    this.ShowSettingsForm();
                }

                SuiteCRMAuthenticate();
                new Thread(() => SyncAndAutoArchive()).Start();
            }
            catch (Exception ex)
            {
                log.Error("ThisAddIn.ThisAddIn_Startup", ex);
            }
        }