/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void connection_OnConnected(object sender, nsoftware.IPWorks.IpportConnectedEventArgs e) { if (e.StatusCode == 0) { Status = new ConsoleEventArgs(51, ConsoleEventArgs.NORMAL, "Connected to " + connection.RemoteHost + ":" + connection.RemotePort); Status = READY; } else { Status = DISCONNECTED; } if (OnConnected != null && OnConnected.GetInvocationList() != null) { OnConnected(e.StatusCode, e.Description); } }
/// <summary> /// Connect (open) a socket to a TCP/IP message server. /// </summary> /// <param name="host">Host (name or IP address) of the message server</param> /// <param name="port">"Port number of the message server</param> public void Connect(String host, int port) { try { connection.RemoteHost = host; connection.RemotePort = port; // Ignore if the socket is already connected. if (connection.Connected == true) { return; //connection.Connected = false; } Status = new ConsoleEventArgs(50, ConsoleEventArgs.NORMAL, "Connecting to " + host + ":" + port); // Asynchronously open a socket connection to the server. connection.Connected = true; } catch (nsoftware.IPWorks.IPWorksException ipwe) { Debug.WriteLine("Error Ignored " + ipwe.Message); } }
/// <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); } } }