private void StoreSingleChannel(int ChannelId, ChannelInfoResponse ChannelInfo, ChannelListEntry Channel) { //var channel = ServerQueryConnection.QueryRunner.GetChannelInfo((uint)ChannelId); var channel = ChannelInfo; Models.StoredChannels storedChannel = new Models.StoredChannels(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); storedChannel.Parse(ChannelId, channel); using (var db = new CoreContext()) { // Store the channel db.StoredChannels.Add(storedChannel); // Store the channel group assignments var channelGroupClients = ServerQueryConnection.QueryRunner.GetChannelGroupClientList((uint?)ChannelId, null, null).ToList(); foreach (var channelGroupClient in channelGroupClients) { var storeChannel = new Models.StoredChannelGroupClients(Subscriber.SubscriberId, Subscriber.SubscriberUniqueId, channelGroupClient); db.StoredChannelGroupClients.Add(storeChannel); } // Successfully stored the channel, now we can delete it from the server var response = ServerQueryConnection.QueryRunner.DeleteChannel((uint)ChannelId); do { if (response.IsErroneous) { if (response.ErrorMessage == "channel not empty") { var usersInChannel = ServerQueryConnection.QueryRunner.GetClientList(false).Where(client => client.ChannelId == ChannelId); foreach (var user in usersInChannel) { var kickResponse = ServerQueryConnection.QueryRunner.KickClient(user.ClientId, TS3QueryLib.Core.CommandHandling.KickReason.Channel, "Channel is being stored away."); if (kickResponse.IsErroneous) { throw new Exception(kickResponse.ResponseText + " (" + kickResponse.ErrorMessage + ")"); } response = ServerQueryConnection.QueryRunner.DeleteChannel((uint)ChannelId); } } else { throw new Exception(response.ResponseText + " (" + response.ErrorMessage + ")"); } } } while (response.IsErroneous == true); db.SaveChanges(); } }
public void StoreChannel(int ChannelId) { var ThisChannelInfo = ServerQueryConnection.QueryRunner.GetChannelInfo((uint)ChannelId); Models.StoredChannels storedChannel = new Models.StoredChannels(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); List <ChannelListEntry> ChannelList = ServerQueryConnection.QueryRunner.GetChannelList(true).ToList(); ChannelListEntry ThisChannelEntry = ChannelList.SingleOrDefault(x => x.ChannelId == ChannelId); Props.ChannelWithSubChannelsPackager ChannelWithSubChannels = new Props.ChannelWithSubChannelsPackager(this.Subscriber.SubscriberId, this.Subscriber.SubscriberUniqueId); ChannelWithSubChannels.Store(ServerQueryConnection.QueryRunner, ChannelList, ThisChannelInfo, ThisChannelEntry, StoreSingleChannel); }