public void Connect() { oApp = OutlookCalendar.AttachToOutlook(); log.Debug("Setting up Outlook connection."); // Get the NameSpace and Logon information. NameSpace oNS = oApp.GetNamespace("mapi"); //Log on by using a dialog box to choose the profile. //oNS.Logon("", Type.Missing, true, true); //Implicit logon to default profile, with no dialog box //If 1< profile, a dialogue is forced unless implicit login used exchangeConnectionMode = oNS.ExchangeConnectionMode; if (exchangeConnectionMode != OlExchangeConnectionMode.olNoExchange) { log.Info("Exchange server version: " + oNS.ExchangeMailboxServerVersion.ToString()); } //Logon using a specific profile. Can't see a use case for this when using OGsync //If using this logon method, change the profile name to an appropriate value: //HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles //oNS.Logon("YourValidProfile", Type.Missing, false, true); log.Info("Exchange connection mode: " + exchangeConnectionMode.ToString()); currentUserSMTP = GetRecipientEmail(oNS.CurrentUser); currentUserName = oNS.CurrentUser.Name; if (currentUserName == "Unknown") { log.Info("Current username is \"Unknown\""); if (Settings.Instance.AddAttendees) { System.Windows.Forms.MessageBox.Show("It appears you do not have an Email Account configured in Outlook.\r\n" + "You should set one up now (Tools > Email Accounts) to avoid problems syncing meeting attendees.", "No Email Account Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } //Get the accounts configured in Outlook accounts = oNS.Accounts; // Get the Calendar folders useOutlookCalendar = getDefaultCalendar(oNS); if (MainForm.Instance.IsHandleCreated) { //resetting connection, so pick up selected calendar from GUI dropdown //***This might be cross thread, so don't rely on MainForm MainForm.Instance.cbOutlookCalendars.DataSource = new BindingSource(calendarFolders, null); KeyValuePair<String, MAPIFolder> calendar = (KeyValuePair<String, MAPIFolder>)MainForm.Instance.cbOutlookCalendars.SelectedItem; calendar = (KeyValuePair<String, MAPIFolder>)MainForm.Instance.cbOutlookCalendars.SelectedItem; useOutlookCalendar = calendar.Value; } // Done. Log off. oNS.Logoff(); }
public void Connect() { oApp = OutlookCalendar.AttachToOutlook(); log.Debug("Setting up Outlook connection."); // Get the NameSpace and Logon information. NameSpace oNS = oApp.GetNamespace("mapi"); //Implicit logon to default profile, with no dialog box //If 1< profile, a dialogue is forced unless implicit login used exchangeConnectionMode = oNS.ExchangeConnectionMode; if (exchangeConnectionMode != OlExchangeConnectionMode.olNoExchange) { log.Info("Exchange server version: Unknown"); } log.Info("Exchange connection mode: " + exchangeConnectionMode.ToString()); currentUserSMTP = GetRecipientEmail(oNS.CurrentUser); currentUserName = oNS.CurrentUser.Name; if (currentUserName == "Unknown") { log.Info("Current username is \"Unknown\""); if (Settings.Instance.AddAttendees) { System.Windows.Forms.MessageBox.Show("It appears you do not have an Email Account configured in Outlook.\r\n" + "You should set one up now (Tools > Email Accounts) to avoid problems syncing meeting attendees.", "No Email Account Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } // Get the Calendar folders useOutlookCalendar = getDefaultCalendar(oNS); if (MainForm.Instance.IsHandleCreated) { //resetting connection, so pick up selected calendar from GUI dropdown MainForm.Instance.cbOutlookCalendars.DataSource = new BindingSource(calendarFolders, null); KeyValuePair<String, MAPIFolder> calendar = (KeyValuePair<String, MAPIFolder>)MainForm.Instance.cbOutlookCalendars.SelectedItem; calendar = (KeyValuePair<String, MAPIFolder>)MainForm.Instance.cbOutlookCalendars.SelectedItem; useOutlookCalendar = calendar.Value; } // Done. Log off. oNS.Logoff(); }
public void Connect() { OutlookCalendar.AttachToOutlook(ref oApp, openOutlookOnFail: true, withSystemCall: false); log.Debug("Setting up Outlook connection."); // Get the NameSpace and Logon information. NameSpace oNS = null; try { oNS = oApp.GetNamespace("mapi"); //Log on by using a dialog box to choose the profile. //oNS.Logon("", Type.Missing, true, true); //Implicit logon to default profile, with no dialog box //If 1< profile, a dialogue is forced unless implicit login used exchangeConnectionMode = oNS.ExchangeConnectionMode; if (exchangeConnectionMode != OlExchangeConnectionMode.olNoExchange) { log.Info("Exchange server version: " + oNS.ExchangeMailboxServerVersion.ToString()); } //Logon using a specific profile. Can't see a use case for this when using OGsync //If using this logon method, change the profile name to an appropriate value: //HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles //oNS.Logon("YourValidProfile", Type.Missing, false, true); log.Info("Exchange connection mode: " + exchangeConnectionMode.ToString()); Recipient currentUser = null; try { try { currentUser = oNS.CurrentUser; } catch { log.Warn("We seem to have a faux connection to Outlook! Forcing starting it with a system call :-/"); oNS = (NameSpace)OutlookCalendar.ReleaseObject(oNS); Disconnect(); OutlookCalendar.AttachToOutlook(ref oApp, openOutlookOnFail: true, withSystemCall: true); oNS = oApp.GetNamespace("mapi"); currentUser = oNS.CurrentUser; } currentUserSMTP = GetRecipientEmail(currentUser); currentUserName = currentUser.Name; } finally { currentUser = (Recipient)OutlookCalendar.ReleaseObject(currentUser); } if (currentUserName == "Unknown") { log.Info("Current username is \"Unknown\""); if (Settings.Instance.AddAttendees) { System.Windows.Forms.MessageBox.Show("It appears you do not have an Email Account configured in Outlook.\r\n" + "You should set one up now (Tools > Email Accounts) to avoid problems syncing meeting attendees.", "No Email Account Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } //Get the folders configured in Outlook folders = oNS.Folders; // Get the Calendar folders useOutlookCalendar = getCalendarStore(oNS); if (MainForm.Instance.IsHandleCreated) { log.Fine("Resetting connection, so re-selecting calendar from GUI dropdown"); MainForm.Instance.cbOutlookCalendars.SelectedIndexChanged -= MainForm.Instance.cbOutlookCalendar_SelectedIndexChanged; MainForm.Instance.cbOutlookCalendars.DataSource = new BindingSource(calendarFolders, null); //Select the right calendar int c = 0; foreach (KeyValuePair <String, MAPIFolder> calendarFolder in calendarFolders) { if (calendarFolder.Value.EntryID == Settings.Instance.UseOutlookCalendar.Id) { MainForm.Instance.SetControlPropertyThreadSafe(MainForm.Instance.cbOutlookCalendars, "SelectedIndex", c); } c++; } if ((int)MainForm.Instance.GetControlPropertyThreadSafe(MainForm.Instance.cbOutlookCalendars, "SelectedIndex") == -1) { MainForm.Instance.SetControlPropertyThreadSafe(MainForm.Instance.cbOutlookCalendars, "SelectedIndex", 0); } KeyValuePair <String, MAPIFolder> calendar = (KeyValuePair <String, MAPIFolder>)MainForm.Instance.GetControlPropertyThreadSafe(MainForm.Instance.cbOutlookCalendars, "SelectedItem"); useOutlookCalendar = calendar.Value; MainForm.Instance.cbOutlookCalendars.SelectedIndexChanged += MainForm.Instance.cbOutlookCalendar_SelectedIndexChanged; } } finally { // Done. Log off. oNS.Logoff(); oNS = (NameSpace)OutlookCalendar.ReleaseObject(oNS); } }
public void Connect() { if (!OutlookOgcs.Calendar.InstanceConnect) { return; } OutlookOgcs.Calendar.AttachToOutlook(ref oApp, openOutlookOnFail: true, withSystemCall: false); log.Debug("Setting up Outlook connection."); // Get the NameSpace and Logon information. NameSpace oNS = null; try { oNS = oApp.GetNamespace("mapi"); //Implicit logon to default profile, with no dialog box //If 1< profile, a dialogue is forced unless implicit login used exchangeConnectionMode = oNS.ExchangeConnectionMode; if (exchangeConnectionMode != OlExchangeConnectionMode.olNoExchange) { log.Info("Exchange server version: Unknown"); } log.Info("Exchange connection mode: " + exchangeConnectionMode.ToString()); oNS = GetCurrentUser(oNS); if (!Settings.Instance.OutlookGalBlocked && currentUserName == "Unknown") { log.Info("Current username is \"Unknown\""); if (Settings.Instance.AddAttendees) { System.Windows.Forms.OgcsMessageBox.Show("It appears you do not have an Email Account configured in Outlook.\r\n" + "You should set one up now (Tools > Email Accounts) to avoid problems syncing meeting attendees.", "No Email Account Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } log.Debug("Get the folders configured in Outlook"); folders = oNS.Folders; // Get the Calendar folders useOutlookCalendar = getCalendarStore(oNS); if (Forms.Main.Instance.IsHandleCreated) { log.Fine("Resetting connection, so re-selecting calendar from GUI dropdown"); Forms.Main.Instance.cbOutlookCalendars.SelectedIndexChanged -= Forms.Main.Instance.cbOutlookCalendar_SelectedIndexChanged; Forms.Main.Instance.cbOutlookCalendars.DataSource = new BindingSource(calendarFolders, null); //Select the right calendar int c = 0; foreach (KeyValuePair <String, MAPIFolder> calendarFolder in calendarFolders) { if (calendarFolder.Value.EntryID == Settings.Instance.UseOutlookCalendar.Id) { Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedIndex", c); } c++; } if ((int)Forms.Main.Instance.GetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedIndex") == -1) { Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedIndex", 0); } KeyValuePair <String, MAPIFolder> calendar = (KeyValuePair <String, MAPIFolder>)Forms.Main.Instance.GetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedItem"); useOutlookCalendar = calendar.Value; Forms.Main.Instance.cbOutlookCalendars.SelectedIndexChanged += Forms.Main.Instance.cbOutlookCalendar_SelectedIndexChanged; } OutlookOgcs.Calendar.Categories = null; } finally { // Done. Log off. if (oNS != null) { oNS.Logoff(); } oNS = (NameSpace)OutlookOgcs.Calendar.ReleaseObject(oNS); } }
public void Connect() { if (!OutlookOgcs.Calendar.InstanceConnect) { return; } OutlookOgcs.Calendar.AttachToOutlook(ref oApp, openOutlookOnFail: true, withSystemCall: false); log.Debug("Setting up Outlook connection."); // Get the NameSpace and Logon information. NameSpace oNS = null; try { oNS = oApp.GetNamespace("mapi"); //Log on by using a dialog box to choose the profile. //oNS.Logon("", Type.Missing, true, true); //Implicit logon to default profile, with no dialog box //If 1< profile, a dialogue is forced unless implicit login used exchangeConnectionMode = oNS.ExchangeConnectionMode; if (exchangeConnectionMode != OlExchangeConnectionMode.olNoExchange) { log.Info("Exchange server version: " + oNS.ExchangeMailboxServerVersion.ToString()); } //Logon using a specific profile. Can't see a use case for this when using OGsync //If using this logon method, change the profile name to an appropriate value: //HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles //oNS.Logon("YourValidProfile", Type.Missing, false, true); log.Info("Exchange connection mode: " + exchangeConnectionMode.ToString()); oNS = GetCurrentUser(oNS); if (!Settings.Instance.OutlookGalBlocked && currentUserName == "Unknown") { log.Info("Current username is \"Unknown\""); if (Settings.Instance.AddAttendees) { System.Windows.Forms.MessageBox.Show("It appears you do not have an Email Account configured in Outlook.\r\n" + "You should set one up now (Tools > Email Accounts) to avoid problems syncing meeting attendees.", "No Email Account Found", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); } } log.Debug("Get the folders configured in Outlook"); folders = oNS.Folders; // Get the Calendar folders useOutlookCalendar = getCalendarStore(oNS); if (Forms.Main.Instance.IsHandleCreated) { log.Fine("Resetting connection, so re-selecting calendar from GUI dropdown"); Forms.Main.Instance.cbOutlookCalendars.SelectedIndexChanged -= Forms.Main.Instance.cbOutlookCalendar_SelectedIndexChanged; Forms.Main.Instance.cbOutlookCalendars.DataSource = new BindingSource(calendarFolders, null); //Select the right calendar int c = 0; foreach (KeyValuePair <String, MAPIFolder> calendarFolder in calendarFolders) { if (calendarFolder.Value.EntryID == Settings.Instance.UseOutlookCalendar.Id) { Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedIndex", c); } c++; } if ((int)Forms.Main.Instance.GetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedIndex") == -1) { Forms.Main.Instance.SetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedIndex", 0); } KeyValuePair <String, MAPIFolder> calendar = (KeyValuePair <String, MAPIFolder>)Forms.Main.Instance.GetControlPropertyThreadSafe(Forms.Main.Instance.cbOutlookCalendars, "SelectedItem"); useOutlookCalendar = calendar.Value; Forms.Main.Instance.cbOutlookCalendars.SelectedIndexChanged += Forms.Main.Instance.cbOutlookCalendar_SelectedIndexChanged; } OutlookOgcs.Calendar.Categories = new OutlookOgcs.Categories(); Calendar.Categories.Get(oApp, useOutlookCalendar); //Set up event handlers explorerWatcher = new ExplorerWatcher(oApp); } catch (System.Runtime.InteropServices.COMException ex) { if (OGCSexception.GetErrorCode(ex) == "0x84120009") //Cannot complete the operation. You are not connected. [Issue #514, occurs on GetNamespace("mapi")] { log.Warn(ex.Message); throw new ApplicationException("A problem was encountered with your Office install.\r\n" + "Please perform an Office Repair or reinstall Outlook and then try running OGCS again."); } else { throw ex; } } finally { // Done. Log off. if (oNS != null) { oNS.Logoff(); } oNS = (NameSpace)OutlookOgcs.Calendar.ReleaseObject(oNS); } }