Beispiel #1
0
 /// <summary>
 /// Gets the command.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="DataReceivedEventArgs"/> instance containing the event data.</param>
 private void GetCommand(object sender, DataReceivedEventArgs e)
 {
     Application.Current.Dispatcher.Invoke(new Action(() =>
     {
         MessageCommand mc = MessageCommand.FromJSON(e.Message);
         if (m_commands.ContainsKey(mc.CommandID))
         {
             m_commands[mc.CommandID](mc.CommandMsg);
         }
     }));
 }
        /// <summary>
        /// Called when [data received].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="DataReceivedEventArgs"/> instance containing the event data.</param>
        public void OnDataReceived(object sender, DataReceivedEventArgs e)
        {
            MessageCommand mc = MessageCommand.FromJSON(e.Message);

            if (e != null)
            {
                if (mc.CommandID == (int)CommandEnum.CloseServerCommand)
                {
                    IsConnected = false;
                }
                else
                {
                    DataReceived?.Invoke(this, e);
                }
            }
        }
Beispiel #3
0
        private void DataReceviedServer(object sender, DataReceivedEventArgs e)
        {
            MessageCommand mc = MessageCommand.FromJSON(e.Message);

            if (mc.CommandID == (int)CommandEnum.CloseCommand)
            {
                CommandRecievedEventArgs comArgs = new CommandRecievedEventArgs((int)CommandEnum.CloseCommand, null, mc.CommandMsg);
                CommandRecieved?.Invoke(this, comArgs);
            }
            else
            {
                string convert = m_controller.ExecuteCommand(mc.CommandID, null, out bool result);
                mc.CommandMsg = convert;
                ClientHandler ch = sender as ClientHandler;
                ch.Send(mc.ToJSON());
            }
        }