示例#1
0
 public static void OnStatusChanged(StatusChangedEventArgs e)
 {
     StatusChangedEventHandler statusHandler = StatusChanged;
     if (statusHandler != null)
     {
         statusHandler(null, e);
     }
 }
示例#2
0
 public void mainServer_StatusChanged(object sender, StatusChangedEventArgs e)
 {
     // Call the method that updates the form
     this.Dispatcher.Invoke(new UpdateLogCallback(this.UpdateGui), new object[] { e.EventMessage.Message, e.EventMessage.Transmitter, e.EventMessage.Receiver, e.EventMessage.MessageType });
 }
示例#3
0
        private void ReceiveMessages()
        {
            Int32 messageLength = Convert.ToInt32(_srReceiver.ReadInt32());
            byte[] response = new byte[messageLength];
            response = _srReceiver.ReadBytes(messageLength);
            Chatmessage ConResponse = (Chatmessage) Converter.fromByteArrayToObject(_clientEncryption.DecryptRijndael(response));

            if (ConResponse.Message[0] == '1')
            {
                ConResponse.Message = ConResponse.Message.Substring(2);
                e = new StatusChangedEventArgs(ConResponse);
                OnStatusChanged(e);

                // read actual user list from server

                BinaryFormatter bf = new BinaryFormatter();
                messageLength = Convert.ToInt32(_srReceiver.ReadInt32());
                response = new byte[messageLength];
                response = _srReceiver.ReadBytes(messageLength);
                MemoryStream ms = new MemoryStream(response);
                List<string> user = (List<string>) bf.Deserialize(ms);
                foreach (var element in user) {
                    _users.Add(element);
                }
            }
            else if (ConResponse.Message[0] == '0')
            {
                connected = false;
                string Reason = "Not Connected! - ";
                Reason += ConResponse.Message.Substring(2, ConResponse.Message.Length-2);
                e = new StatusChangedEventArgs(ConResponse);
                OnStatusChanged(e);
                return;
            }

            while (connected)
            {
                messageLength = Convert.ToInt32(_srReceiver.ReadInt32());
                response = new byte[messageLength];
                response = _srReceiver.ReadBytes(messageLength);
                e = new StatusChangedEventArgs((Chatmessage) Converter.fromByteArrayToObject(_clientEncryption.DecryptRijndael(response)));
                OnStatusChanged(e);
            }
        }