private void ClientReceiveMessage(object sender, ReceiveMessageEventArgs e) { if (e.Type != MessageType.System && e.Type != MessageType.Private) { return; } Dispatcher.BeginInvoke(new Action <ReceiveMessageEventArgs>(args => { switch (args.Type) { case MessageType.Private: using (var client = ClientModel.Get()) { UserViewModel senderUser = AllUsers.Single(uvm => string.Equals(uvm.Info.Nick, args.Sender)); UserViewModel receiverUser = AllUsers.Single(uvm => string.Equals(uvm.Info.Nick, client.User.Nick)); SelectedRoom.AddPrivateMessage(senderUser, receiverUser, args.Message); } break; case MessageType.System: SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(args.SystemMessage, args.SystemMessageFormat)); break; } Alert(); }), e); }
private void ClientRegistration(RegistrationEventArgs e) { if (!e.Registered) { SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(e.Message)); if (ClientModel.IsInited) { ClientModel.Reset(); } } }
private void ClientAsyncError(AsyncErrorEventArgs e) { var modelException = e.Error as ModelException; if (modelException != null) { switch (modelException.Code) { case ErrorCode.ApiNotSupported: ClientModel.Reset(); SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(APINotSupportedKey, modelException.Message)); return; } } }
private void CreateRoom(object obj) { try { CreateRoomDialog dialog = new CreateRoomDialog(); if (dialog.ShowDialog() == true && ClientModel.API != null) { ClientModel.API.CreateRoom(dialog.Name, dialog.Type); } } catch (SocketException se) { SelectedRoom.AddSystemMessage(se.Message); } }
private void ClientRegistration(object sender, RegistrationEventArgs e) { Dispatcher.BeginInvoke(new Action <RegistrationEventArgs>(args => { if (!args.Registered) { SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(args.Message)); if (ClientModel.IsInited) { ClientModel.Reset(); } } }), e); }
private void CreateRoom(object obj) { try { var dialog = new CreateRoomDialog(); if (dialog.ShowDialog() == true && ClientModel.Api != null) { ClientModel.Api.Perform(new ClientCreateRoomAction(dialog.Name, dialog.Type)); } } catch (SocketException se) { SelectedRoom.AddSystemMessage(se.Message); } }
private void ClientConnect(ConnectEventArgs args) { if (args.Error == null) { ClientModel.Api.Register(); } else { SelectedRoom.AddSystemMessage(args.Error.Message); if (ClientModel.IsInited) { ClientModel.Reset(); } } }
private void ClientAsyncError(object sender, AsyncErrorEventArgs e) { Dispatcher.BeginInvoke(new Action <AsyncErrorEventArgs>(args => { ModelException modelException = args.Error as ModelException; if (modelException != null) { switch (modelException.Code) { case ErrorCode.APINotSupported: ClientModel.Reset(); SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(APINotSupportedKey, modelException.Message)); return; } } }), e); }
private void ExitFromRoom(object obj) { try { if (MessageBox.Show(RoomExitQuestion, ProgramName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } if (ClientModel.Api != null) { ClientModel.Api.ExitFromRoom(SelectedRoom.Name); } } catch (SocketException se) { SelectedRoom.AddSystemMessage(se.Message); } }
private void EnableServer(object obj) { var dialog = new ServerDialog(); if (dialog.ShowDialog() != true) { return; } try { var excludedPlugins = Settings.Current.Plugins .Where(s => !s.Enabled) .Select(s => s.Name) .ToArray(); var initializer = new ServerInitializer { AdminPassword = Settings.Current.AdminPassword, PluginsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "plugins"), ExcludedPlugins = excludedPlugins }; ServerModel.Init(initializer); ServerModel.Server.Start(Settings.Current.Port, Settings.Current.ServicePort, Settings.Current.StateOfIPv6Protocol); InitializeClient(true); } catch (ArgumentException) { SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(ParamsErrorKey)); if (ClientModel.IsInited) { ClientModel.Reset(); } if (ServerModel.IsInited) { ServerModel.Reset(); } } }
private void EnableServer(object obj) { var dialog = new ServerDialog(); if (dialog.ShowDialog() == true) { try { var adminPassword = Settings.Current.AdminPassword; var p2pPort = Settings.Current.ServerStartP2PPort; var excludedPlugins = Settings.Current.Plugins .Where(s => !s.Enabled) .Select(s => s.Name) .ToArray(); var initializer = new ServerInitializer { AdminPassword = adminPassword, PluginsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName), ExcludedPlugins = excludedPlugins, Certificate = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword), }; ServerModel.Init(initializer); var serverStartUri = Connection.CreateTcpchatUri(dialog.ServerAddress); ServerModel.Server.Start(serverStartUri, p2pPort); dialog.SaveSettings(); } catch (Exception e) { var errorMessage = Localizer.Instance.Localize(ParamsErrorKey); SelectedRoom.AddSystemMessage($"{errorMessage}\r\n{e.Message}"); if (ServerModel.IsInited) { ServerModel.Reset(); } } } }
private void ClientReceiveMessage(ReceiveMessageEventArgs e) { if (e.Type != MessageType.System && e.Type != MessageType.Private) { return; } switch (e.Type) { case MessageType.Private: SelectedRoom.AddPrivateMessage(e.Sender, ClientModel.Client.Id, e.Message); break; case MessageType.System: SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(e.SystemMessage, e.SystemMessageFormat)); break; } Alert(); }
private void ExitFromRoom(object obj) { try { var msg = Localizer.Instance.Localize(RoomExitQuestionKey); if (MessageBox.Show(msg, ProgramName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } if (ClientModel.Api != null) { ClientModel.Api.Perform(new ClientExitFromRoomAction(SelectedRoom.Name)); } } catch (SocketException se) { SelectedRoom.AddSystemMessage(se.Message); } }
private void ClientConnect(object sender, ConnectEventArgs e) { Dispatcher.BeginInvoke(new Action <ConnectEventArgs>(args => { if (args.Error != null) { SelectedRoom.AddSystemMessage(args.Error.Message); if (ClientModel.IsInited) { ClientModel.Reset(); } return; } if (ClientModel.Api != null) { ClientModel.Api.Register(); } }), e); }
private void ClientConnect(ConnectEventArgs args) { if (args.Error == null) { switch (ClientModel.Client.RemoteCertificateStatus) { case CertificateStatus.Trusted: ClientModel.Api.Perform(new ClientRegisterAction()); break; case CertificateStatus.SelfSigned: var certificate = ClientModel.Client.RemoteCertiticate; var dialog = new ServerCertificateConfirmDialog(certificate); if (dialog.ShowDialog() == true) { ClientModel.Api.Perform(new ClientRegisterAction()); } else { ClientModel.Reset(); } break; default: ClientModel.Reset(); break; } } else { SelectedRoom.AddSystemMessage(args.Error.Message); if (ClientModel.IsInited) { ClientModel.Reset(); } } }
private void Connect(object obj) { //if(true) var dialog = new ConnectDialog(); if (dialog.ShowDialog() == true) { try { var trustedCertitifcatesPath = Settings.Current.TrustedCertificatesPath; var outputAudioDevice = Settings.Current.OutputAudioDevice; var inputAudioDevice = Settings.Current.InputAudioDevice; var bits = Settings.Current.Bits; var frequency = Settings.Current.Frequency; var excludedPlugins = Settings.Current.Plugins .Where(s => !s.Enabled) .Select(s => s.Name) .ToArray(); var path = AppDomain.CurrentDomain.BaseDirectory + "TrustedCertificates\\c.pfx"; //var path = "E:\\5th Semester\\CN Lab\\Project\\Abdullah Farooq\\c.pfx"; SecureString password = new NetworkCredential("", "1234").SecurePassword; var initializer = new ClientInitializer { Nick = dialog.Nick, NickColor = dialog.NickColor, Certificate = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword), //Nick = "Server", // NickColor = Color.Red, //Certificate = new X509Certificate2(path, password), TrustedCertificatesPath = trustedCertitifcatesPath, PluginsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName), ExcludedPlugins = excludedPlugins }; ClientModel.Init(initializer); try { ClientModel.Player.SetOptions(outputAudioDevice); ClientModel.Recorder.SetOptions(inputAudioDevice, new AudioQuality(1, bits, frequency)); } catch (ModelException me) { ClientModel.Player.Dispose(); ClientModel.Recorder.Dispose(); if (me.Code != ErrorCode.AudioNotEnabled) { throw; } else { var msg = Localizer.Instance.Localize(AudioInitializationFailedKey); MessageBox.Show(msg, ProgramName, MessageBoxButton.OK, MessageBoxImage.Warning); } } var serverUri = Connection.CreateTcpchatUri(dialog.Address); ClientModel.Client.Connect(serverUri); dialog.SaveSettings(); } catch (Exception e) { SelectedRoom.AddSystemMessage(Localizer.Instance.Localize(ParamsErrorKey)); if (ClientModel.IsInited) { ClientModel.Reset(); } } } }
private void Connect(object obj) { var dialog = new ConnectDialog(); if (dialog.ShowDialog() == true) { try { var trustedCertitifcatesPath = Settings.Current.TrustedCertificatesPath; var outputAudioDevice = Settings.Current.OutputAudioDevice; var inputAudioDevice = Settings.Current.InputAudioDevice; var bits = Settings.Current.Bits; var frequency = Settings.Current.Frequency; var excludedPlugins = Settings.Current.Plugins .Where(s => !s.Enabled) .Select(s => s.Name) .ToArray(); var initializer = new ClientInitializer { Nick = dialog.Nick, NickColor = dialog.NickColor, Certificate = new X509Certificate2(dialog.CertificatePath, dialog.CertificatePassword), TrustedCertificatesPath = trustedCertitifcatesPath, PluginsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginsDirectoryName), ExcludedPlugins = excludedPlugins }; ClientModel.Init(initializer); try { ClientModel.Player.SetOptions(outputAudioDevice); ClientModel.Recorder.SetOptions(inputAudioDevice, new AudioQuality(1, bits, frequency)); } catch (ModelException me) { ClientModel.Player.Dispose(); ClientModel.Recorder.Dispose(); if (me.Code != ErrorCode.AudioNotEnabled) { throw; } else { var msg = Localizer.Instance.Localize(AudioInitializationFailedKey); MessageBox.Show(msg, ProgramName, MessageBoxButton.OK, MessageBoxImage.Warning); } } var serverUri = Connection.CreateTcpchatUri(dialog.Address); ClientModel.Client.Connect(serverUri); dialog.SaveSettings(); } catch (Exception e) { var errorMessage = Localizer.Instance.Localize(ParamsErrorKey); SelectedRoom.AddSystemMessage($"{errorMessage}\r\n{e.Message}"); if (ClientModel.IsInited) { ClientModel.Reset(); } } } }