示例#1
1
        /// <summary>
        /// Handler for the Channel Added event
        /// </summary>
        private void TeamspeakService_ChannelAdded(object sender, TS3.Data.ChannelEventArgs e)
        {
            Threading.BeginInvokeOnUI(() =>
                {
                    if (e.Channel.IsSpacer)
                        return; // Totally ignore spacers

                    var newChannel = new ChannelViewModel(e.Channel, this.TeamspeakService);

                    // Check if we have any orphans that are a subchannel of this new channel
                    var matchingOrphans = this.orphanChannels.Where(c => c.ParentID == newChannel.ID);
                    foreach (var orphan in matchingOrphans)
                    {
                        newChannel.Subchannels.Add(orphan);
                    }
                    this.orphanChannels.RemoveAll(c => c.ParentID == newChannel.ID);

                    if (newChannel.ParentID != 0)
                    {
                        // This has a parent channel - find it
                        var parentChannel = this.FindParentChannel(this.Channels, newChannel);

                        if (parentChannel != null)
                        {
                            parentChannel.Subchannels.Add(newChannel);
                        }
                        else
                        {
                            // This is an orphan channel... add it to our orphan list for now
                            this.orphanChannels.Add(newChannel);
                        }
                    }
                    else
                    {
                        // No parent
                        this.Channels.Insert(0, newChannel);
                    }

                    this.OnPropertyChanged(() => this.AreChannelsLoaded);
                });
        }
示例#2
0
        /// <summary>
        /// Handler for the Channel Updated event
        /// </summary>
        private void TeamspeakService_ChannelUpdated(object sender, TS3.Data.ChannelEventArgs e)
        {
            Threading.BeginInvokeOnUI(() =>
                {
                    // Find the matching existing channel
                    ChannelViewModel existingChannel = this.FindChannel(this.Channels, e.Channel.ID);

                    if (existingChannel == null)
                    {
                        // This shouldn't happen, but if it does, don't crash, just treat it as a "channel added"
                        this.TeamspeakService_ChannelAdded(sender, e);
                        return;
                    }

                    existingChannel.Name = e.Channel.Name;
                    existingChannel.OrderIndex = e.Channel.Order;
                    existingChannel.ClientsCount = e.Channel.ClientsCount;

                    // Check to see if the parent ID has changed. If so, update it and move the channel
                    if (existingChannel.ParentID != e.Channel.ParentID)
                    {
                        // Find the existing parent
                        ChannelViewModel existingParent = this.FindParentChannel(this.Channels, existingChannel);

                        if (existingParent != null)
                        {
                            // Remove it from the parent
                            existingParent.Subchannels.Remove(existingChannel);
                        }

                        // Update the parent ID
                        existingChannel.ParentID = e.Channel.ParentID;

                        // Find the new parent
                        ChannelViewModel newParent = this.FindParentChannel(this.Channels, existingChannel);

                        if (newParent != null)
                        {
                            // Add it to the parent
                            newParent.Subchannels.Add(existingChannel);
                        }
                        else
                        {
                            // Orphan...
                            this.orphanChannels.Add(existingChannel);
                        }
                    }

                    this.OnPropertyChanged(() => this.AreChannelsLoaded);
                });
        }
示例#3
0
        /// <summary>
        /// Handler for the Channel Removed event
        /// </summary>
        private void TeamspeakService_ChannelRemoved(object sender, TS3.Data.ChannelEventArgs e)
        {
            Threading.BeginInvokeOnUI(() =>
                {
                    var removedChannel = new ChannelViewModel(e.Channel, this.TeamspeakService);

                    if (removedChannel.ParentID != 0)
                    {
                        // This has a parent channel - find it
                        var parentChannel = this.FindParentChannel(this.Channels, removedChannel);

                        if (parentChannel != null)
                        {
                            var toRemove = parentChannel.Subchannels.FirstOrDefault(channel => channel.ID == removedChannel.ID);
                            parentChannel.Subchannels.Remove(toRemove);
                        }
                    }
                    else
                    {
                        // No parent
                        var toRemove = this.Channels.FirstOrDefault(channel => channel.ID == removedChannel.ID);
                        this.Channels.Remove(toRemove);
                    }

                    this.OnPropertyChanged(() => this.AreChannelsLoaded);
                });
        }
示例#4
0
 /// <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);
         });
     }
 }
示例#5
0
 /// <summary>
 /// Handles the text message received event
 /// </summary>
 private void TeamspeakService_TextMessageReceived(object sender, TS3.Data.TextMessageEventArgs e)
 {
     Threading.BeginInvokeOnUI(() =>
         {
             this.ChatMessages.Insert(0, new ChatMsgViewModel(DateTime.Now, e.ClientName, e.Message));
         });
 }
示例#6
0
 /// <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;
     }
 }
示例#7
0
 /// <summary>
 /// Handles the New Channel Info event of the Teamspeak Service
 /// </summary>
 private void TeamspeakService_ClientChannelChanged(object sender, TS3.Data.ChannelEventArgs e)
 {
     Threading.InvokeOnUI(() =>
         {
             this.ClientChannelName = e.Channel.Name;
             this.ClientChannelDescription = e.Channel.Description;
         });
 }
示例#8
0
 /// <summary>
 /// Handles the New Server Info event of the Teamspeak Service
 /// </summary>
 private void TeamspeakService_NewServerInfo(object sender, TS3.Data.NewServerInfoEventArgs e)
 {
     Threading.InvokeOnUI(() =>
         {
             this.ServerName = e.ServerName;
             this.ServerAddress = e.ServerAddress;
             this.ChatMessages.Clear();
             this.Notifications.Clear();
         });
 }