/// <summary> /// Handles the talk status changed event /// </summary> private void TeamspeakService_TalkStatusChanged(object sender, TS3.Data.TalkStatusEventArgs e) { var speechNotification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.Speech); var existingNotification = this.Notifications.FirstOrDefault(notification => notification.Equals(speechNotification)); switch (e.Status) { case TS3.Data.Enums.TalkStatus.TalkStarted: // Add to our collection of speaking users if it's not already there if (existingNotification == null) { Threading.BeginInvokeOnUI(() => this.Notifications.Add(speechNotification)); } break; case TS3.Data.Enums.TalkStatus.TalkStopped: // Remove from our collection of speaking users if (existingNotification != null) { Threading.BeginInvokeOnUI(() => this.Notifications.Remove(existingNotification)); } break; default: break; } }
/// <summary> /// Connection was refused, meaning teamspeak is not running /// </summary> private void TeamspeakService_ConnectionRefused(object sender, EventArgs e) { this.TeamspeakService.ConnectionRefused -= TeamspeakService_ConnectionRefused; Task.Factory.StartNew(() => { var cannotConnectNotification = new TSNotificationViewModel(0, Properties.Resources.StartTeamspeak, TSNotificationType.CannotConnect); Threading.InvokeOnUI(() => this.Notifications.Add(cannotConnectNotification)); // Start a loop attempting to connect once every 5 seconds int sleepTime = 250; // ms int retryInterval = 5000 / sleepTime; int i = 0; while (!this.isShuttingDown && this.TeamspeakService.ConnectionState != TS3.Data.Enums.ConnectionState.Connected) { Thread.Sleep(250); i++; if (i > retryInterval) { Threading.InvokeOnUI(() => this.TeamspeakService.Connect()); i = 0; } } if (!this.isShuttingDown) { this.TeamspeakService.ConnectionRefused += TeamspeakService_ConnectionRefused; Threading.InvokeOnUI(() => this.Notifications.Remove(cannotConnectNotification)); } }, TaskCreationOptions.LongRunning); }
/// <summary> /// Compares an input object to this object. Value compare /// </summary> public override bool Equals(object obj) { if (obj != null && obj is TSNotificationViewModel) { TSNotificationViewModel other = obj as TSNotificationViewModel; return((other.ClientID == this.ClientID) && (other.NotificationType == this.NotificationType)); } else { return(false); } }
/// <summary> /// Handler for the Client Entered Channel event /// </summary> private void TeamspeakService_ClientEnteredChannel(object sender, TS3.Data.ClientEventArgs e) { if (this.UserData.ShowEnterExitChannelNotifications) { Task.Factory.StartNew(() => { var notification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.UserEntered); Threading.InvokeOnUI(() => this.Notifications.Add(notification)); Thread.Sleep(5000); // Let channel notifications stay for 5 seconds Threading.InvokeOnUI(() => this.Notifications.Remove(notification)); }); Threading.InvokeOnUI(() => { this.CurrentChannelClients.Add(new ClientViewModel(e.ClientID, e.ClientName)); }); } }
/// <summary> /// Connection was refused, meaning teamspeak is not running /// </summary> private void TeamspeakService_ConnectionRefused(object sender, EventArgs e) { Task.Factory.StartNew(() => { this.TeamspeakService.ConnectionRefused -= TeamspeakService_ConnectionRefused; var cannotConnectNotification = new TSNotificationViewModel(0, Properties.Resources.StartTeamspeak, TSNotificationType.CannotConnect); Threading.InvokeOnUI(() => this.Notifications.Add(cannotConnectNotification)); // Start a loop attempting to connect while (!this.isShuttingDown && this.TeamspeakService.ConnectionState != TS3.Data.Enums.ConnectionState.Connected) { Threading.InvokeOnUI(() => this.TeamspeakService.Connect()); Thread.Sleep(5000); // attempt to connect once every 5 seconds } if (!this.isShuttingDown) { this.TeamspeakService.ConnectionRefused += TeamspeakService_ConnectionRefused; Threading.InvokeOnUI(() => this.Notifications.Remove(cannotConnectNotification)); } }); }
/// <summary> /// Handler for the Client Exited Channel event /// </summary> private void TeamspeakService_ClientExitedChannel(object sender, TS3.Data.ClientEventArgs e) { if (this.UserData.ShowEnterExitChannelNotifications) { Task.Factory.StartNew(() => { var notification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.UserExited); Threading.InvokeOnUI(() => this.Notifications.Add(notification)); Thread.Sleep(5000); // Let channel notifications stay for 5 seconds Threading.InvokeOnUI(() => this.Notifications.Remove(notification)); }); Threading.InvokeOnUI(() => { var client = this.CurrentChannelClients.FirstOrDefault(c => c.ID == e.ClientID); if (client != null) this.CurrentChannelClients.Remove(client); }); } }
/// <summary> /// Handles the talk status changed event /// </summary> private void TeamspeakService_TalkStatusChanged(object sender, TS3.Data.TalkStatusEventArgs e) { var speechNotification = new TSNotificationViewModel(e.ClientID, e.ClientName, TSNotificationType.Speech); var existingNotification = this.Notifications.FirstOrDefault(notification => notification.Equals(speechNotification)); switch (e.Status) { case TS3.Data.Enums.TalkStatus.TalkStarted: // Add to our collection of speaking users if it's not already there if (existingNotification == null) Threading.BeginInvokeOnUI(() => this.Notifications.Add(speechNotification)); break; case TS3.Data.Enums.TalkStatus.TalkStopped: // Remove from our collection of speaking users if (existingNotification != null) Threading.BeginInvokeOnUI(() => this.Notifications.Remove(existingNotification)); break; default: break; } }