public FormMain() { InitializeComponent(); // Create our logger _logger = new ClassLogger("Notifications.log"); _logger.LogAdded += new ClassLogger.LoggerEventHandler(_logger_LogAdded); _traceListener = new ClassTraceListener("Trace.log"); // Increase default connection limit - this is CRUCIAL when supporting multiple subscriptions, as otherwise only 2 connections will work ServicePointManager.DefaultConnectionLimit = 255; _logger.Log("Default connection limit increased to 255"); comboBoxSubscribeTo.SelectedIndex = 0; // Select All Folders buttonUnsubscribe.Enabled = false; checkBoxSelectAll.CheckState = CheckState.Checked; checkBoxSelectAll_CheckedChanged(this, null); _connections = new Dictionary <string, StreamingSubscriptionConnection>(); ReadMailboxes(); _mailboxes = new Mailboxes(_logger, _traceListener); UpdateUriUI(); UpdateAuthUI(); }
public FormMain() { InitializeComponent(); // Create our logger _logger = new ClassLogger("Notifications.log"); _logger.LogAdded += new ClassLogger.LoggerEventHandler(_logger_LogAdded); _traceListener = new ClassTraceListener("Trace.log"); // Increase default connection limit - this is CRUCIAL when supporting multiple subscriptions ServicePointManager.DefaultConnectionLimit = 255; _logger.Log("Default connection limit increased to 255"); comboBoxSubscribeTo.SelectedIndex = 5; // Set to Inbox first of all checkedListBoxEvents.SetItemChecked(0, true); buttonUnsubscribe.Enabled = false; _connections = new Dictionary <string, StreamingSubscriptionConnection>(); ReadMailboxes(); _mailboxes = new Mailboxes(null, _logger, _traceListener); comboBoxExchangeVersion.SelectedIndex = 0; //comboBoxExchangeVersion.Enabled = false; }
public bool AddMailbox(string SMTPAddress) { // Perform autodiscover for the mailbox and store the information if (_mailboxes.ContainsKey(SMTPAddress)) { // We already have autodiscover information for this mailbox, if it is recent enough we don't bother retrieving it again if (_mailboxes[SMTPAddress].IsStale) { _mailboxes.Remove(SMTPAddress); } else { return(true); } } // Retrieve the autodiscover information GetUserSettingsResponse userSettings = null; try { userSettings = GetUserSettings(SMTPAddress); } catch (Exception ex) { _logger.Log(String.Format("Failed to autodiscover for {0}: {1}", SMTPAddress, ex.Message)); return(false); } // Store the autodiscover result, and check that we have what we need for subscriptions MailboxInfo info = new MailboxInfo(SMTPAddress, userSettings); if (!info.HaveSubscriptionInformation) { _logger.Log(String.Format("Autodiscover succeeded, but EWS Url was not returned for {0}", SMTPAddress)); return(false); } // Add the mailbox to our list, and if it will be part of a new group add that to the group list (with this mailbox as the primary mailbox) _mailboxes.Add(info.SMTPAddress, info); return(true); }
private void buttonSubscribe_Click(object sender, EventArgs e) { CreateGroups(); if (ConnectToSubscriptions()) { buttonUnsubscribe.Enabled = true; buttonSubscribe.Enabled = false; _logger.Log("Connected to subscription(s)"); } else { _logger.Log("Failed to create any subscriptions"); } }
public StreamingSubscriptionConnection AddGroupSubscriptions( ref Dictionary <string, StreamingSubscriptionConnection> Connections, ref Dictionary <string, StreamingSubscription> SubscriptionList, EventType[] SubscribeEvents, FolderId[] SubscribeFolders, ClassLogger Logger, int TimeOut = 30) { if (Connections.ContainsKey(_name)) { foreach (StreamingSubscription subscription in Connections[_name].CurrentSubscriptions) { try { subscription.Unsubscribe(); } catch { } } try { if (Connections[_name].IsOpen) { Connections[_name].Close(); } } catch { } Connections.Remove(_name); } StreamingSubscriptionConnection groupConnection = null; try { // Create the subscription to the primary mailbox, then create the subscription connection if (SubscriptionList.ContainsKey(_primaryMailbox)) { SubscriptionList.Remove(_primaryMailbox); } StreamingSubscription subscription = AddSubscription(_primaryMailbox, ref SubscriptionList, SubscribeEvents, SubscribeFolders); groupConnection = new StreamingSubscriptionConnection(subscription.Service, TimeOut); Connections.Add(_name, groupConnection); //SubscribeConnectionEvents(groupConnection); groupConnection.AddSubscription(subscription); Logger.Log($"{_primaryMailbox} (primary mailbox) subscription created in group {_name}"); // Now add any further subscriptions in this group foreach (string sMailbox in _mailboxes) { if (!sMailbox.Equals(_primaryMailbox)) { try { if (SubscriptionList.ContainsKey(sMailbox)) { SubscriptionList.Remove(sMailbox); } subscription = AddSubscription(sMailbox, ref SubscriptionList, SubscribeEvents, SubscribeFolders); groupConnection.AddSubscription(subscription); Logger.Log($"{sMailbox} subscription created in group {_name}"); } catch (Exception ex) { Logger.Log(String.Format("ERROR when subscribing {0} in group {1}: {2}", sMailbox, _name, ex.Message)); } } } } catch (Exception ex) { Logger.Log($"ERROR when creating subscription connection group {_name}: {ex.Message}"); } return(groupConnection); }
public bool AddMailbox(string SMTPAddress, string AutodiscoverURL = "") { // Perform autodiscover for the mailbox and store the information if (_mailboxes.ContainsKey(SMTPAddress)) { // We already have autodiscover information for this mailbox, if it is recent enough we don't bother retrieving it again if (_mailboxes[SMTPAddress].IsStale) { _mailboxes.Remove(SMTPAddress); } else { return(true); } } MailboxInfo info = null; // Retrieve the autodiscover information _logger.Log($"Retrieving user settings for {SMTPAddress}"); GetUserSettingsResponse userSettings = null; if (!String.IsNullOrEmpty(AutodiscoverURL)) { // Use the supplied Autodiscover URL try { _autodiscover.Url = new Uri(AutodiscoverURL); userSettings = _autodiscover.GetUserSettings(SMTPAddress, UserSettingName.InternalEwsUrl, UserSettingName.ExternalEwsUrl, UserSettingName.GroupingInformation); } catch { } } if (userSettings == null) { try { // Try full autodiscover userSettings = GetUserSettings(SMTPAddress); } catch (Exception ex) { _logger.Log(String.Format("Failed to autodiscover for {0}: {1}", SMTPAddress, ex.Message)); return(false); } } // Store the autodiscover result, and check that we have what we need for subscriptions info = new MailboxInfo(SMTPAddress, userSettings); if (!info.HaveSubscriptionInformation) { _logger.Log(String.Format("Autodiscover succeeded, but EWS Url was not returned for {0}", SMTPAddress)); return(false); } // Add the mailbox to our list, and if it will be part of a new group add that to the group list (with this mailbox as the primary mailbox) _mailboxes.Add(info.SMTPAddress, info); return(true); }
private void buttonSubscribe_Click(object sender, EventArgs e) { if (radioButtonAuthOAuth.Checked) { CredentialHandler().AcquireToken(); } CreateGroups(); if (ConnectToSubscriptions()) { buttonUnsubscribe.Enabled = true; buttonSubscribe.Enabled = false; _logger.Log("Connected to subscription(s)"); } else { _logger.Log("Failed to create any subscriptions"); } }