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 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(); }
//private string _lastKnownAutodiscoverUrl = ""; public Mailboxes(ClassLogger Logger, ITraceListener TraceListener = null, Auth.CredentialHandler CredentialHandler = null) { _logger = Logger; _credentialHandler = CredentialHandler; _mailboxes = new Dictionary <string, MailboxInfo>(); _traceListener = TraceListener; CreateAutodiscoverService(); }
public Mailboxes(WebCredentials AutodiscoverCredentials, ClassLogger Logger, ITraceListener TraceListener = null) { _logger = Logger; _mailboxes = new Dictionary <string, MailboxInfo>(); _autodiscover = new AutodiscoverService(ExchangeVersion.Exchange2013); // Minimum version we need is 2013 _autodiscover.RedirectionUrlValidationCallback = RedirectionCallback; if (TraceListener != null) { _autodiscover.TraceListener = TraceListener; _autodiscover.TraceFlags = TraceFlags.All; _autodiscover.TraceEnabled = true; } if (!(AutodiscoverCredentials == null)) { _autodiscover.Credentials = AutodiscoverCredentials; } }
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); }