/// <summary>
        /// Send data (command) to the server.
        /// </summary>
        /// <param name="data">Data to send to the server</param>
        public void Send(String data)
        {
            // Do not send a blank command.
            if (data.Length == 0)
            {
                if (OnCommandProcessedReceived != null && OnCommandProcessedReceived.GetInvocationList() != null)
                {
                    OnCommandProcessedReceived(null, utcOffset);
                }

                Status = COMMAND_NOT_SPECIFIED;
                return;
            }

            try
            {
                byte[] command = BuildTcpIpCommand(data);

                DateTime utcNow      = DateTime.UtcNow;
                long     localOffset = DateTime.Now.Second - utcNow.Second;

                Status = SENDING_COMMAND;
                connection.Send(command);
                if (OnCommandSent != null && OnCommandSent.GetInvocationList() != null)
                {
                    OnCommandSent("> " + data, DateTime.UtcNow, localOffset, utcOffset);
                }
                Status = EXECUTING_COMMAND;
            }
            catch (nsoftware.IPWorks.IPWorksException ipwe)
            {
                Debug.WriteLine("Command not sent " + ipwe.Message);

                if (OnCommandProcessedReceived != null && OnCommandProcessedReceived.GetInvocationList() != null)
                {
                    OnCommandProcessedReceived(null, utcOffset);
                }

                Status = COMMAND_NOT_SENT;
            }
        }
Example #2
0
 public void ExecuteCommandWrapper(ICommandExecutor commandExecutor, object command)
 {
     commandExecutor.ExecuteCommand(command);
     _commandIsPending = false;
     OnCommandSent?.Invoke();
 }