/// <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; } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void connection_OnDataIn(object sender, nsoftware.IPWorks.IpportDataInEventArgs e) { queue.Enqueue(e.TextB); if (Suspend == true) // Do not fire received events (they will be accumulated). { return; } TcpIpMessages.Clear(); ConnectionRecords.Clear(); FtpTerminationRecords.Clear(); JobStepRecords.Clear(); byte[] record; while ((record = (byte[])queue.Dequeue()) != null) { int type = converter.GetINT32(4, record); if (type == 1) // SeeVSE startup record { if (OnSeeVseStartupReceived != null && OnSeeVseStartupReceived.GetInvocationList() != null) { OnSeeVseStartupReceived(record, utcOffset); } } else if (type == 2) // TCP/IP FTP session termination { FtpTerminationRecords.Add(record); } else if (type == 3) // TCP/IP message { TcpIpMessages.Add(record); } else if (type == 4) // TCP/IP connection termination record { ConnectionRecords.Add(record); } else if (type == JOB_STEP_TERMINATION_TYPE) { JobStepRecords.Add(record); } else // TCP/IP command parse response { ushort length = (ushort)(converter.GetUINT16(0, record) - 4); String message; if (length > 0) { message = converter.GetEBCDIC(4, record, (int)length); if (message.StartsWith("GOOD")) { if (OnCommandProcessedReceived != null && OnCommandProcessedReceived.GetInvocationList() != null) { OnCommandProcessedReceived(record, utcOffset); } Status = READY;; } else if (message.StartsWith("FAIL")) { if (OnCommandProcessedReceived.GetInvocationList() != null) { OnCommandProcessedReceived(record, utcOffset); } if (message.Length > 8) { Status = new ConsoleEventArgs(701, ConsoleEventArgs.SEVERE, "Command Failed: " + message.Substring(8)); } else { Status = new ConsoleEventArgs(701, ConsoleEventArgs.SEVERE, "Command failed"); } } else { Debug.WriteLine("Invalid Data" + message); Debug.WriteLine("Clearing the message queue."); queue.Clear(); // /Clear queue to prevent other invalid messages. } } } } if (TcpIpMessages.Count > 0) { if (OnTcpIpMessageReceived != null && OnTcpIpMessageReceived.GetInvocationList() != null) { OnTcpIpMessageReceived(new ArrayList(TcpIpMessages), utcOffset); } } if (FtpTerminationRecords.Count > 0) { if (OnFtpTerminationReceived != null && OnFtpTerminationReceived.GetInvocationList() != null) { OnFtpTerminationReceived(new ArrayList(FtpTerminationRecords), utcOffset); } } if (ConnectionRecords.Count > 0) { if (OnTcpIpTerminationReceived != null && OnTcpIpTerminationReceived.GetInvocationList() != null) { OnTcpIpTerminationReceived(new ArrayList(ConnectionRecords), utcOffset); } } if (JobStepRecords.Count > 0) { if (OnJobStepTerminationReceived != null && OnJobStepTerminationReceived.GetInvocationList() != null) { OnJobStepTerminationReceived(new ArrayList(JobStepRecords), utcOffset); } } }