private void InvokeEvent(LazyNotification lazyNotification) { var notification = lazyNotification.Notifications; switch (lazyNotification.NotifyType) { case NotificationType.ChannelCreated: break; case NotificationType.ChannelDeleted: break; case NotificationType.ChannelChanged: break; case NotificationType.ChannelEdited: break; case NotificationType.ChannelMoved: break; case NotificationType.ChannelPasswordChanged: break; case NotificationType.ClientEnterView: OnClientEnterView?.Invoke(this, notification.Cast <ClientEnterView>()); break; case NotificationType.ClientLeftView: OnClientLeftView?.Invoke(this, notification.Cast <ClientLeftView>()); break; case NotificationType.ClientMoved: break; case NotificationType.ServerEdited: break; case NotificationType.TextMessage: OnTextMessageReceived?.Invoke(this, notification.Cast <TextMessage>()); break; case NotificationType.TokenUsed: break; // special case NotificationType.Error: break; case NotificationType.Unknown: default: throw new InvalidOperationException(); } }
private void InvokeEvent(LazyNotification lazyNotification) { var notification = lazyNotification.Notifications; switch (lazyNotification.NotifyType) { case NotificationType.ChannelCreated: break; case NotificationType.ChannelDeleted: break; case NotificationType.ChannelChanged: break; case NotificationType.ChannelEdited: break; case NotificationType.ChannelMoved: break; case NotificationType.ChannelPasswordChanged: break; case NotificationType.ClientEnterView: OnClientEnterView?.Invoke(this, notification.Cast <ClientEnterView>()); break; case NotificationType.ClientLeftView: var clientLeftArr = notification.Cast <ClientLeftView>().ToArray(); var leftViewEvent = clientLeftArr.FirstOrDefault(clv => clv.ClientId == packetHandler.ClientId); if (leftViewEvent != null) { packetHandler.ExitReason = leftViewEvent.Reason; DisconnectInternal(context, setStatus: Ts3ClientStatus.Disconnected); break; } OnClientLeftView?.Invoke(this, clientLeftArr); break; case NotificationType.ClientMoved: OnClientMoved?.Invoke(this, notification.Cast <ClientMoved>()); break; case NotificationType.ServerEdited: break; case NotificationType.TextMessage: OnTextMessageReceived?.Invoke(this, notification.Cast <TextMessage>()); break; case NotificationType.TokenUsed: break; // full client events case NotificationType.InitIvExpand: { var result = lazyNotification.WrapSingle <InitIvExpand>(); if (result.Ok) { ProcessInitIvExpand(result.Value); } } break; case NotificationType.InitIvExpand2: { var result = lazyNotification.WrapSingle <InitIvExpand2>(); if (result.Ok) { ProcessInitIvExpand2(result.Value); } } break; case NotificationType.InitServer: { var result = lazyNotification.WrapSingle <InitServer>(); if (result.Ok) { ProcessInitServer(result.Value); } } break; case NotificationType.ChannelList: break; case NotificationType.ChannelListFinished: ChannelSubscribeAll(); break; case NotificationType.ClientNeededPermissions: break; case NotificationType.ClientChannelGroupChanged: break; case NotificationType.ClientServerGroupAdded: break; case NotificationType.ConnectionInfo: break; case NotificationType.ConnectionInfoRequest: ProcessConnectionInfoRequest(); break; case NotificationType.ChannelSubscribed: break; case NotificationType.ChannelUnsubscribed: break; case NotificationType.ClientChatComposing: break; case NotificationType.ServerGroupList: break; case NotificationType.ClientServerGroup: break; case NotificationType.FileUpload: break; case NotificationType.FileDownload: break; case NotificationType.FileTransfer: break; case NotificationType.FileTransferStatus: break; case NotificationType.FileList: break; case NotificationType.FileListFinished: break; case NotificationType.FileInfoTs: break; case NotificationType.ChannelGroupList: break; case NotificationType.PluginCommand: { var result = lazyNotification.WrapSingle <PluginCommand>(); if (result.Ok) { ProcessPluginRequest(result.Value); } } break; // special case NotificationType.CommandError: { var result = lazyNotification.WrapSingle <CommandError>(); var error = result.Ok ? result.Value : Util.CustomError("Got empty error while connecting."); bool skipError = false; bool disconnect = false; lock (statusLock) { if (status == Ts3ClientStatus.Connecting) { disconnect = true; skipError = true; } } if (disconnect) { DisconnectInternal(context, error, Ts3ClientStatus.Disconnected); } if (!skipError) { OnErrorEvent?.Invoke(this, error); } } break; case NotificationType.Unknown: default: throw Util.UnhandledDefault(lazyNotification.NotifyType); } }
private void InvokeEvent(LazyNotification lazyNotification) { var notification = lazyNotification.Notifications; switch (lazyNotification.NotifyType) { case NotificationType.ChannelCreated: break; case NotificationType.ChannelDeleted: break; case NotificationType.ChannelChanged: break; case NotificationType.ChannelEdited: break; case NotificationType.ChannelMoved: break; case NotificationType.ChannelPasswordChanged: break; case NotificationType.ClientEnterView: OnClientEnterView?.Invoke(this, notification.Cast <ClientEnterView>()); break; case NotificationType.ClientLeftView: var clientLeftArr = notification.Cast <ClientLeftView>().ToArray(); var leftViewEvent = clientLeftArr.FirstOrDefault(clv => clv.ClientId == packetHandler.ClientId); if (leftViewEvent != null) { packetHandler.ExitReason = leftViewEvent.Reason; lock (statusLock) { status = Ts3ClientStatus.Disconnected; DisconnectInternal(context); } break; } OnClientLeftView?.Invoke(this, clientLeftArr); break; case NotificationType.ClientMoved: OnClientMoved?.Invoke(this, notification.Cast <ClientMoved>()); break; case NotificationType.ServerEdited: break; case NotificationType.TextMessage: OnTextMessageReceived?.Invoke(this, notification.Cast <TextMessage>()); break; case NotificationType.TokenUsed: break; // full client events case NotificationType.InitIvExpand: ProcessInitIvExpand((InitIvExpand)notification.FirstOrDefault()); break; case NotificationType.InitServer: ProcessInitServer((InitServer)notification.FirstOrDefault()); break; case NotificationType.ChannelList: break; case NotificationType.ChannelListFinished: try { ChannelSubscribeAll(); } catch (Ts3CommandException) { } break; case NotificationType.ClientNeededPermissions: break; case NotificationType.ClientChannelGroupChanged: break; case NotificationType.ClientServerGroupAdded: break; case NotificationType.ConnectionInfo: break; case NotificationType.ConnectionInfoRequest: ProcessConnectionInfoRequest(); break; case NotificationType.ChannelSubscribed: break; case NotificationType.ChannelUnsubscribed: break; case NotificationType.ClientChatComposing: break; case NotificationType.ServerGroupList: break; case NotificationType.ServerGroupsByClientId: break; case NotificationType.StartUpload: break; case NotificationType.StartDownload: break; case NotificationType.FileTransfer: break; case NotificationType.FileTransferStatus: break; case NotificationType.FileList: break; case NotificationType.FileListFinished: break; case NotificationType.FileInfo: break; // special case NotificationType.Error: lock (statusLock) { if (status == Ts3ClientStatus.Connecting) { status = Ts3ClientStatus.Disconnected; DisconnectInternal(context, false); } } OnErrorEvent?.Invoke(this, (CommandError)notification.First()); break; case NotificationType.Unknown: default: throw Util.UnhandledDefault(lazyNotification.NotifyType); } }