private void _clientHandler_ListEventHandler(object sender, ImListReceivedFromServerArgs e) { Application.Current.Dispatcher.Invoke(new Action(() => { foreach (IMLibrary.Client client in e.ClientList) { if (GeneratedClientList.Count(cli => cli.UserName == client.UserName) == 0) { ChatDialogueLocal chatDialogoue = new ChatDialogueLocal { lblUsername = { Content = client.UserName }, lblFingerPrint = { Content = client.FingerPrint } }; chatDialogoue.ChangeColourOfPrint(); chatDialogoue.LoadPrint(); User user = new User(client.UserName, client.Available, client.FingerPrint, client.PublicKey, client.Buddies, 0); _clientPromtList.Add(new Tuple <IMLibrary.Client, ChatDialogueLocal>(user, chatDialogoue)); GeneratedClientList.Add(user); } else { GeneratedClientList.First(cli => cli.UserName == client.UserName).Available = client.Available; GeneratedClientList.First(cli => cli.UserName == client.UserName).PublicKey = client.PublicKey; GeneratedClientList.First(cli => cli.UserName == client.UserName).FingerPrint = client.FingerPrint; _clientPromtList.Single(cli => cli.Item1.UserName == client.UserName).Item2.lblFingerPrint.Content = client.FingerPrint; _clientPromtList.Single(cli => cli.Item1.UserName == client.UserName).Item2.ChangeColourOfPrint(); _clientPromtList.Single(cli => cli.Item1.UserName == client.UserName).Item2.LoadPrint(); } } })); }
public ImMainWindowNew(ImClientHandler clientHandler) { InitializeComponent(); _clientHandler = clientHandler; GeneratedClientList = new ObservableCollection <User>(); foreach (IMLibrary.Client client in _clientHandler.GeneratedClientList) { GeneratedClientList.Add(new User(client.UserName, client.Available, client.FingerPrint, client.PublicKey, client.Buddies, 0)); } //GeneratedClientList.CollectionChanged += GeneratedClientList_CollectionChanged; _clientHandler.ListEventHandler += _clientHandler_ListEventHandler; _clientHandler.KeyNegotiationEventHandler += _clientHandler_KeyNegotiationEventHandler; _clientHandler.NegotiationEventHandler += _clientHandler_InitiateNegotiation; _clientHandler.BuddyEventHandler += _clientHandler_BuddyEventHandler; _filteredView = new CollectionViewSource { Source = GeneratedClientList }.View; DataContext = new { user = _clientHandler.ClientInfo, clients = _filteredView, //messages = _clientMessagesReceivedTupleList }; _filteredView.Refresh(); IMChatPromtEventHandler chatPromtEventHandler = MessageReceiveHandler; clientHandler.ChatPromtCheck += chatPromtEventHandler; foreach (User client in GeneratedClientList) { ChatDialogueLocal chatDialogoue = new ChatDialogueLocal { lblUsername = { Content = client.UserName }, lblFingerPrint = { Content = client.FingerPrint } }; chatDialogoue.ButtonRegenerateKeys.Click += ButtonRegenerateKeys_Click; _clientPromtList.Add(new Tuple <IMLibrary.Client, ChatDialogueLocal>(client, chatDialogoue)); //_clientMessagesReceivedTupleList.Add(new Pair<IMLibrary.Client, string>(client, "0")); if (client.FingerPrint != null) { chatDialogoue.ChangeColourOfPrint(); chatDialogoue.LoadPrint(); //new instant of aes, key and IV are created and access through properties. f try { Tuple <byte[], byte[]> unencryptedKeySaltPair = GenerateUnencryptedKeySaltPair(); Tuple <byte[], byte[]> encryptedKeySaltPair = EncryptKeySaltPair(client.PublicKey, unencryptedKeySaltPair); if (client.UserName != _clientHandler.ClientInfo.UserName) { _clientHandler.NegotiateSymmetricKeys(encryptedKeySaltPair, client.UserName); } this._clientKeyIvDictionary.Add(client.UserName, unencryptedKeySaltPair); } catch (Exception e) { //will fail if we don't know the clients public key } } } }