public void RouteToDestination(Iso8583Message message, SinkNode sinknode) { int maxNumberOfEntries = 3; int serverTimeOut = 60000; ClientPeer clientPeer = new Client().StartClient(sinknode); int retries = 0; while (retries < maxNumberOfEntries) { if (clientPeer.IsConnected) { break; } else { //clientPeer.Close(); retries++; clientPeer.Connect(); } Thread.Sleep(5000); } PeerRequest request = null; if (clientPeer.IsConnected) { request = new PeerRequest(clientPeer, message); request.Send(); request.WaitResponse(serverTimeOut); //request.MarkAsExpired(); //uncomment to test timeout if (request.Expired) { //logger.Log("Connection timeout."); Console.WriteLine("Response received too late"); //Response received too late } // if (request != null) // { // response = request.ResponseMessage; // //logger.Log("Message Recieved From FEP"); // // } clientPeer.Close(); // return response as Iso8583Message; } else { //logger.Log("Could not connect to Sink Node"); //clientPeer.Close(); Console.WriteLine("Client Peer is not Connected"); } //clientPeer.Close(); }
/// <summary> /// Get single peer related information from node asynchronously /// </summary> /// <returns></returns> public async Task <PeerResponse> GetPeerAsync(PeerRequest peer) { _url.Path = Constants.ApiGetPeer; _url.Query = peer.ToQuery(); var peerResponse = await _client.GetJsonAsync <PeerResponse>(_url.ToString()); ResetPath(); return(peerResponse); }
public static Iso8583Message SendMessageToFEP(Peer peer, Iso8583Message msg) { if (msg == null) { MessageLogger.LogMessage("iso Message is null"); SetReponseMessage(msg, ResponseCode.INVALID_RESPONSE.ToString()); } int maxRetries = 3; int numberOfRetries = 1; while (numberOfRetries < maxRetries) { if (peer.IsConnected) { break; } peer.Close(); numberOfRetries++; peer.Connect(); Thread.Sleep(2000); } if (peer.IsConnected) { try { var request = new PeerRequest(peer, msg); request.Send(); //At this point, the message has been sent to the SINK for processing int serverTimeout = 60000; //60 secs request.WaitResponse(serverTimeout); if (request.Expired) { MessageLogger.LogMessage("Connection timeout."); return(SetReponseMessage(msg, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE)); //Response received too late } var response = request.ResponseMessage; return(response as Iso8583Message); } catch (Exception ex) { MessageLogger.LogError("Error sending message: " + ex.Message); return(SetReponseMessage(msg, ResponseCode.ERROR)); } } else { MessageLogger.LogMessage("\n Could not connect to the Sink Node."); return(SetReponseMessage(msg, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE.ToString())); //Issuer inoperative } }
private static Iso8583Message SendResponseMessage(ListenerPeer listenerPeer, Iso8583Message message) { bool needReversal = false; int maxNumberOfEntries = 3; Message response = null; int serverTimeOut = 60000; PeerRequest request = null; try { if (listenerPeer.IsConnected) { request = new PeerRequest(listenerPeer, message); request.Send(); request.WaitResponse(serverTimeOut); if (request.Expired) { //logger.Log("Connection timeout."); needReversal = true; return(SetResponseMessage(message, "68")); //Response received too late } if (request != null) { response = request.ResponseMessage; //logger.Log("Message Recieved From FEP"); } // //request.MarkAsExpired(); //uncomment to test timeout return(response as Iso8583Message); } else { //logger.Log("Could not connect to Sink Node"); //clientPeer.Close(); listenerPeer.Close(); Console.WriteLine("Client Peer is not Connected"); return(SetResponseMessage(message, "91")); } //clientPeer.Close(); } catch (Exception e) { //logger.Log("An error occured " + e.Message); return(SetResponseMessage(message, "06")); } }
static Message SendMessage(Peer peer, Message msg) { int maxRetries = 3; int numberOfRetries = 1; while (numberOfRetries < maxRetries) { if (peer.IsConnected) { break; } peer.Close(); numberOfRetries++; peer.Connect(); Thread.Sleep(2000); } if (peer.IsConnected) { try { var request = new PeerRequest(peer, msg); request.Send(); //At this point, the message has been sent to the SINK for processing int serverTimeout = 30000; request.WaitResponse(serverTimeout); var response = request.ResponseMessage; return(response); } catch (Exception ex) { msg.Fields.Add(39, "06"); // ERROR MessageLogger.LogError("Error sending message " + ex.Message + " Inner Exception: " + ex.InnerException); return(msg); } } else { msg.Fields.Add(39, ResponseCode.ISSUER_OR_SWITCH_INOPERATIVE); // ERROR return(msg); } }
private static Iso8583Message GetSinkNodeResponse(ClientPeer sinkNodePeer, Iso8583Message isoMessage) { sinkNodePeer.Connect(); int tries = 10; while (!sinkNodePeer.IsConnected && tries > 0) { Console.WriteLine("Could not connect to sink node. Retrying in 5 seconds"); tries--; sinkNodePeer.Connect(); Thread.Sleep(5000); } if (tries <= 0 && !sinkNodePeer.IsConnected) { Console.WriteLine("Reconnection attempts failed. Could not connect to sink"); if (isoMessage.Fields.Contains(IsoMessageFieldDefinitions.RESPONSE_CODE)) { isoMessage.Fields[IsoMessageFieldDefinitions.RESPONSE_CODE].Value = IsoMessageFieldDefinitions.ResponseCodes.ISSUER_SWITCH_INOPERATIVE; } else { isoMessage.Fields.Add(IsoMessageFieldDefinitions.RESPONSE_CODE, IsoMessageFieldDefinitions.ResponseCodes.ISSUER_SWITCH_INOPERATIVE); } return(isoMessage); } var request = new PeerRequest(sinkNodePeer, isoMessage); request.Send(); request.WaitResponse(50000); var sinkNodeReponse = request.ResponseMessage as Iso8583Message; request.Peer.Close(); return(sinkNodeReponse); }
static void Listener_Receive(object sender, ReceiveEventArgs e) { try { UtilityLogic.LogMessage("Message received!"); var client = sender as ClientPeer; Iso8583Message msg = e.Message as Iso8583Message; switch (GetTransactionSource(msg)) { case MessageSource.OnUs: msg = TransactionManager.ProcessMessage(msg, MessageSource.OnUs); break; case MessageSource.RemoteOnUs: msg = TransactionManager.ProcessMessage(msg, MessageSource.RemoteOnUs); //do nothing yet break; case MessageSource.NotOnUs: //redirect to interswitch msg.Fields.Add(39, "31"); //bank not supported break; default: break; } PeerRequest request = new PeerRequest(client, msg); request.Send(); client.Close(); client.Dispose(); } catch (Exception ex) { UtilityLogic.LogError("Error processing the incoming meaasgae"); UtilityLogic.LogError("Message: " + ex.Message + " \t InnerException " + ex.InnerException); } }
private Trx.Messaging.Message ProcessRequest(Iso8583Message msg) { LastMessageSent = msg; PeerRequest request = new PeerRequest(_clientPeer, msg); // new PANE.ERRORLOG.Error().LogInfo(string.Format("Before sending {0}", _clientPeer.Channel.Name.ToString())); Console.WriteLine("The request: " + request.RequestMessage); new PANE.ERRORLOG.Error().LogInfo(string.Format("The request: " + request.RequestMessage)); request.Send(); request.WaitResponse(serverTimeout); if (request.Expired) { Console.WriteLine("Timed out"); new PANE.ERRORLOG.Error().LogInfo("ProcessRequest Timed Out!"); throw new ConnectionTimedOutException(msg); } else { Trx.Messaging.Message clo = request.ResponseMessage.Clone() as Trx.Messaging.Message; if (clo.Fields.Contains(127)) { (clo.Fields[127].Value as Trx.Messaging.Message).Parent = null; } if (clo.Fields.Contains(125)) { Console.WriteLine("ZPK: " + clo.Fields[125].Value); new PANE.ERRORLOG.Error().LogInfo(string.Format("ZPK: " + clo.Fields[125].Value)); } Console.WriteLine("The response: " + request.RequestMessage); new PANE.ERRORLOG.Error().LogInfo(string.Format("The response: " + request.ResponseMessage)); } return(request.ResponseMessage); }
private static void SendSourceNodeResponse(ListenerPeer sourceNodePeer, Iso8583Message message) { int tries = 10; while (!sourceNodePeer.IsConnected && tries > 0) { Console.WriteLine("Could not connect to source node. Retrying in 5 seconds."); tries--; sourceNodePeer.Connect(); Thread.Sleep(5000); } if (tries <= 0 && !sourceNodePeer.IsConnected) { Console.WriteLine("Reconnection attempt failed. Could not send response to source"); } else { PeerRequest request = new PeerRequest(sourceNodePeer, message); request.Send(); request.Peer.Close(); } }
/// <summary> /// Get single peer related information from node synchronously /// </summary> /// <returns></returns> public PeerResponse GetPeer(PeerRequest peer) { var peerResponse = GetPeerAsync(peer).GetAwaiter().GetResult(); return(peerResponse); }
private Iso8583Message RouteToDestination(Iso8583Message message, SinkNode sinkNode, out bool needReversal) { Message response = null; needReversal = false; try { if (message == null) { return(SetResponseMessage(message, "20")); } if (sinkNode == null) { Console.WriteLine("Sink Node is null"); return(SetResponseMessage(message, "91")); } if (sinkNode.Status == "In-active") { Console.WriteLine("Sink Node is Inactive"); return(SetResponseMessage(message, "91")); } int maxNumberOfEntries = 3; int serverTimeOut = 60000; ClientPeer clientPeer = new Client().StartClient(sinkNode); int retries = 0; while (retries < maxNumberOfEntries) { if (clientPeer.IsConnected) { break; } else { //clientPeer.Close(); retries++; clientPeer.Connect(); } Thread.Sleep(5000); } PeerRequest request = null; if (clientPeer.IsConnected) { request = new PeerRequest(clientPeer, message); request.Send(); request.WaitResponse(serverTimeOut); //request.MarkAsExpired(); //uncomment to test timeout if (request.Expired) { //logger.Log("Connection timeout."); needReversal = true; return(SetResponseMessage(message, "68")); //Response received too late } if (request != null) { response = request.ResponseMessage; request = new PeerRequest(clientPeer, SetResponseMessage(message, "00")); request.Send(); //logger.Log("Message Recieved From FEP"); } clientPeer.Close(); return(response as Iso8583Message); } else { //logger.Log("Could not connect to Sink Node"); //clientPeer.Close(); Console.WriteLine("Client Peer is not Connected"); return(SetResponseMessage(message, "91")); } //clientPeer.Close(); } catch (Exception e) { //logger.Log("An error occured " + e.Message); return(SetResponseMessage(message, "06")); } }
private Iso8583Message ToFEP(Iso8583Message msgToSend, SinkNode sinkNode, out bool needReversal) { Message response = null; string responseMsg = string.Empty; needReversal = false; try { if (msgToSend == null) { Logger.Log("Iso message is null."); return(SetReponseMessage(msgToSend, "20")); //Invalid response } if (sinkNode == null) { Logger.Log("Sink node is null."); return(SetReponseMessage(msgToSend, "91")); //Issuer inoperative } int maxNoRetries = 3; int serverTimeout = 60000; sinkNode.IsActive = true; ClientPeer _clientPeer = new ClientPeer(sinkNode.Name, new TwoBytesNboHeaderChannel( new Iso8583Ascii1987BinaryBitmapMessageFormatter(), sinkNode.IPAddress, Convert.ToInt16(sinkNode.Port)), new Trx.Messaging.BasicMessagesIdentifier(11)); _clientPeer.Connect(); Thread.Sleep(1800); int retries = 0; while (retries < maxNoRetries) { if (_clientPeer.IsConnected) { break; } else { _clientPeer.Close(); retries++; _clientPeer.Connect(); } Thread.Sleep(2000); } PeerRequest request = null; if (_clientPeer.IsConnected) { request = new PeerRequest(_clientPeer, msgToSend); request.Send(); request.WaitResponse(serverTimeout); //request.MarkAsExpired(); //uncomment to test timeout if (request.Expired) { Logger.Log("Connection timeout."); needReversal = true; return(SetReponseMessage(msgToSend, "68")); //Response received too late } if (request != null) { response = request.ResponseMessage; //ResponseMessage = GetResponseMesage(response as Iso8583Message); } return(response as Iso8583Message); } else { Console.WriteLine("\n Could not connect to the Sink Node.."); Console.BackgroundColor = ConsoleColor.Red; Logger.Log("\n Could not connect to the Sink Node."); return(SetReponseMessage(msgToSend, "91")); } } catch (Exception ex) { Logger.Log("ERROR: " + ex.Message); return(SetReponseMessage(msgToSend, "06")); //Error } }
/// <summary> /// Get single peer related information from node asynchronously /// </summary> /// <returns></returns> public async Task<PeerResponse> GetPeerAsync(PeerRequest peer) { _url.Path = Constants.ApiGetPeer; _url.Query = peer.ToQuery(); var peerResponse = await _client.GetJsonAsync<PeerResponse>(_url.ToString()); ResetPath(); return peerResponse; }
/// <summary> /// Get single peer related information from node synchronously /// </summary> /// <returns></returns> public PeerResponse GetPeer(PeerRequest peer) { var peerResponse = GetPeerAsync(peer).GetAwaiter().GetResult(); return peerResponse; }
private Iso8583Message ToFEP(Iso8583Message msgToSend, SinkNode sinkNode, out bool needReversal) { Message response = null; string responseMsg = string.Empty; needReversal = false; try { if (msgToSend == null) { Logger.Log("Iso message is null."); return SetReponseMessage(msgToSend, "20"); //Invalid response } if (sinkNode == null) { Logger.Log("Sink node is null."); return SetReponseMessage(msgToSend, "91"); //Issuer inoperative } int maxNoRetries = 3; int serverTimeout = 60000; sinkNode.IsActive = true; ClientPeer _clientPeer = new ClientPeer(sinkNode.Name, new TwoBytesNboHeaderChannel( new Iso8583Ascii1987BinaryBitmapMessageFormatter(), sinkNode.IPAddress, Convert.ToInt16(sinkNode.Port)), new Trx.Messaging.BasicMessagesIdentifier(11)); _clientPeer.Connect(); Thread.Sleep(1800); int retries = 0; while (retries < maxNoRetries) { if (_clientPeer.IsConnected) { break; } else { _clientPeer.Close(); retries++; _clientPeer.Connect(); } Thread.Sleep(2000); } PeerRequest request = null; if (_clientPeer.IsConnected) { request = new PeerRequest(_clientPeer, msgToSend); request.Send(); request.WaitResponse(serverTimeout); //request.MarkAsExpired(); //uncomment to test timeout if (request.Expired) { Logger.Log("Connection timeout."); needReversal = true; return SetReponseMessage(msgToSend, "68"); //Response received too late } if (request != null) { response = request.ResponseMessage; //ResponseMessage = GetResponseMesage(response as Iso8583Message); } return response as Iso8583Message; } else { Console.WriteLine("\n Could not connect to the Sink Node.."); Console.BackgroundColor = ConsoleColor.Red; Logger.Log("\n Could not connect to the Sink Node."); return SetReponseMessage(msgToSend, "91"); } } catch (Exception ex) { Logger.Log("ERROR: " + ex.Message); return SetReponseMessage(msgToSend, "06"); //Error } }