public void SendMessageToMessageServer(int entryId, LogCategory logCategory, LogLevel logLevel, String message) { try { if (!ConnectToMessageServer()) { return; } RequestLogMessage requestLogMessage = RequestLogMessage.Create(); requestLogMessage.EntryId = entryId; requestLogMessage.EntryText = message ?? ""; requestLogMessage.Time = DateTime.Now; requestLogMessage.Level = logLevel; requestLogMessage.EntryCategory = 0; // logCategory; _messageServerProtocol.ClientId = applicationDbId; _messageServerProtocol.Send(requestLogMessage); switch (logLevel) { case LogLevel.Debug: TpsLogManager <MessageServer> .Debug("Message [" + (message ?? "") + "] sent to message server."); break; case LogLevel.Alarm: TpsLogManager <MessageServer> .Error("Message [" + (message ?? "") + "] sent to message server."); break; case LogLevel.Error: TpsLogManager <MessageServer> .Error("Message [" + (message ?? "") + "] sent to message server."); break; case LogLevel.Info: TpsLogManager <MessageServer> .Info("Message [" + (message ?? "") + "] sent to message server."); break; case LogLevel.Interaction: TpsLogManager <MessageServer> .Info("Message [" + (message ?? "") + "] sent to message server."); break; case LogLevel.Unknown: default: TpsLogManager <MessageServer> .Info("Message [" + (message ?? "") + "] sent to message server."); break; } } catch (Exception e) { TpsLogManager <MessageServer> .Error(e.Message); } }
public Boolean SendAlarm(int code, String message) { Boolean result = false; RequestLogMessage alarm = RequestLogMessage.Create(); try { TpsLogManager <MessageServer> .Info("Preparing to send alarm to message server."); if (IsConnectedToMessageServer() || ConnectToMessageServer()) { alarm.EntryId = code; alarm.ClientHost = System.Net.Dns.GetHostName(); alarm.EntryText = message; alarm.Level = LogLevel.Alarm; alarm.EntryCategory = LogCategory.Alarm; alarm.Time = DateTime.Now; _messageServerProtocol.Send(alarm); result = true; TpsLogManager <MessageServer> .Info("Alarm [" + code + "], message [" + message + "] sent to message server."); } } catch (Exception e) { TpsLogManager <MessageServer> .Error("sendAlarm: " + e.Message); } return(result); }
public Boolean ConnectToLca() { Boolean result = false; try { if (!IsConnectedToLca()) { TpsLogManager <MessageServer> .Info("Connecting to Local Control Agent..."); _localControlAgentProtocol = new LocalControlAgentProtocol(lCAPort) { ClientName = applicationName, ExecutionMode = ApplicationExecutionMode.Backup, ControlStatus = (int)ApplicationStatus.Initializing, Timeout = new TimeSpan(0, 0, _lcaTimeout) }; //TpsLogManager<MessageServer>.Info("Initialising Local Control Agent parameters"); _mEventBroker = BrokerServiceFactory.CreateEventBroker(_localControlAgentProtocol); _mEventBroker.Register(OnEventChangeExecutionMode, new MessageIdFilter(EventChangeExecutionMode.MessageId)); _localControlAgentProtocol.Open(); TpsLogManager <MessageServer> .Info("Connected to Local Control Agent."); } result = true; } catch (Exception e) { TpsLogManager <MessageServer> .Error(e.Message); } return(result); }
internal string ReturnExitedSecureMode(string webSocket) { if (webSocket == null) { TpsLogManager <Semafone> .Warn("sendExitedSecureMode : Client has either been disconnected or doesn't exist for " + webSocket + "."); return(jsonErrorMessage(webSocket, "9", "Client has either been disconnected or doesn't exist for " + webSocket + ".", ErrorSeverity.Error)); } try { SemafoneExitSecureModeHandset semafoneHandset = new SemafoneExitSecureModeHandset(); semafoneHandset.Semafone = new SemafoneExitSecureMode() { Exitsecuremode = true }; string message = JsonConvert.SerializeObject(semafoneHandset); Semafone semaphoneInstance; SemafoneClients.TryRemove(webSocket, out semaphoneInstance); TpsLogManager <Semafone> .Info("Exit secure mode semafone message has been sent for " + webSocket); TpsLogManager <Semafone> .Info(message); return(message); } catch (Exception e) { TpsLogManager <Semafone> .Error("Error sendExitedSecureMode : " + e.Message + e.StackTrace); return(jsonErrorMessage(webSocket, "8", "Error during ReturnExitedSecureMode for " + webSocket + ".", ErrorSeverity.Error)); } }
public MessageServer(string appName, int dbid, int lcaPort, string host, int port) { applicationName = appName; TpsLogManager <MessageServer> .Info("Application Name set to [" + applicationName + "]"); lCAPort = lcaPort; TpsLogManager <MessageServer> .Info("LCAPort set to [" + lCAPort + "]"); checkLcaConnectionThread = new Thread(CheckLcaConnection) { Name = "Message server thread", IsBackground = true }; checkLcaConnectionThread.Start(); applicationDbId = dbid; TpsLogManager <MessageServer> .Info("Application DbId set to [" + applicationDbId + "]"); messageServerHostName = host; TpsLogManager <MessageServer> .Info("Message server host name set to [" + messageServerHostName + "]"); messageServerPort = port; TpsLogManager <MessageServer> .Info("Message server port set to[" + messageServerPort + "]"); //ConnectToMessageServer(); }
private void CheckLcaConnection() { Boolean wasConnected = false; while (_continueRunning) { try { Thread.Sleep(5 * 1000); } catch (Exception e) { TpsLogManager <MessageServer> .Error(e.Message); } finally { if (!wasConnected && IsConnectedToLca()) { TpsLogManager <MessageServer> .Info("Connection to Local Control Agent reconnected."); SetStatus(_lastStatus); wasConnected = true; _isLcaConnectedThreadRunning = true; } else if (wasConnected && !IsConnectedToLca()) { TpsLogManager <MessageServer> .Warn("Connection to Local Control Agent lost."); wasConnected = false; _isLcaConnectedThreadRunning = false; } } } _isLcaConnectedThreadRunning = false; }
public static void logStats() { TpsLogManager <WebSocketPipe> .Info("Current Websocket connection statistics"); TpsLogManager <WebSocketPipe> .Info("Websocket maximumConcurrentConnections = " + maximumConcurrentConnections); TpsLogManager <WebSocketPipe> .Info("Websocket connection count = " + webSocketConnections.Count()); }
/// <summary> /// Event fired when a data is received from the Alchemy Websockets server instance. /// Parses data as JSON and calls the appropriate message or sends an error message. /// </summary> /// <param name="context">The user's connection context</param> public static void OnReceive(IWebSocketConnection socket, string message) { Console.WriteLine("Received Data From :" + socket.ClientAddressAndPort()); try { try { string appName = ""; if (applicationConnections.ContainsKey(socket.ClientAddressAndPort())) { appName = applicationConnections[socket.ClientAddressAndPort()]; foreach (var ConnectToApplication in TPService.Instance.ConnectToApplications) { ConnectToApplication.WebSocketSendMessageEvent -= OnWebSocketSendMessageEvent; ConnectToApplication.WebSocketSendMessageEvent += OnWebSocketSendMessageEvent; ConnectToApplication.ProcessWebSocketMessage(appName, message, socket.ClientAddressAndPort()); } } else { if (isConnectToCommand(socket, message, out appName)) { TpsLogManager <WebSocketPipe> .Info("New connection added for " + appName + " on " + socket.ClientAddressAndPort()); Console.WriteLine("New connection added for " + appName + " on " + socket.ClientAddressAndPort()); foreach (var ConnectToApplication in TPService.Instance.ConnectToApplications) { ConnectToApplication.WebSocketSendMessageEvent -= OnWebSocketSendMessageEvent; ConnectToApplication.WebSocketSendMessageEvent += OnWebSocketSendMessageEvent; ConnectToApplication.ProcessWebSocketMessage(appName, message, socket.ClientAddressAndPort()); } } else { Console.WriteLine("Unsuccessful attempt by " + socket.ClientAddressAndPort() + " : " + message); socket.Send(JsonConvert.SerializeObject(new { Error = " Invalid json message" })); } } } catch (Exception e) { TpsLogManager <WebSocketPipe> .Error("Error OnReceive : " + e.Message + e.StackTrace); socket.Send(JsonConvert.SerializeObject(new { Error = e.Message })); } } catch (Exception ex) { TpsLogManager <WebSocketPipe> .Error("Error on WebSocketPipe.OnReceive : " + ex.Message + ex.StackTrace, ex); socket.Send(JsonConvert.SerializeObject(new { Error = ex.Message })); } }
public override void ProcessWebSocketMessage(string appName, string message, string socket) { if (appName.ToLower() == ApplicationIdentifier.ToLower()) { TpsLogManager <SemafoneConnection> .Info("Message received from " + socket + " :" + message); Task.Factory.StartNew(() => { string response = new ClientRequest().ProcessClientMessage(socket, message); SendWebSocketMessage(socket, response); TpsLogManager <SemafoneConnection> .Info("Message sent to " + socket + " :" + response); }); } }
public void OnConnect(IWebSocketConnection socket) { try { webSocketConnections.TryAdd(socket.ClientAddressAndPort(), socket); Console.WriteLine("New websocket connection added for browser :" + socket.ClientAddressAndPort()); TpsLogManager <WebSocketPipe> .Info("New websocket connection added for browser : " + socket.ClientAddressAndPort()); } catch (Exception ex) { TpsLogManager <WebSocketPipe> .Error("Error on WebSocketPipe.OnConnect : " + ex.Message + ex.StackTrace); } }
private string ProcessPciResetCvc(string webSocket) { if (webSocket == null) { TpsLogManager <Semafone> .Warn("processPCIResetCVC : Client has either been disconnected or doesn't exist"); return(""); } try { Semafone semafone = GetSemafone(webSocket); if (semafone != null) { if (semafone.ResetCvc()) { SemafoneResetCvcHandset semafoneHandset = new SemafoneResetCvcHandset(); semafoneHandset.Semafone = new SemafoneResetCvc() { Cvcreset = true }; string message = JsonConvert.SerializeObject(semafoneHandset); TpsLogManager <Semafone> .Info("Reset CVC semafone message has been sent to webSocket " + webSocket); TpsLogManager <Semafone> .Info(message); return(message); } else { TpsLogManager <Semafone> .Error("Failed to reset cvc for " + webSocket); return(jsonErrorMessage(webSocket, "10", "Failed to reset pan for " + webSocket + ".", ErrorSeverity.Error)); } } else { TpsLogManager <Semafone> .Error("Failed to reset cvc for " + webSocket); return(jsonErrorMessage(webSocket, "10", "Failed to reset pan for " + webSocket + ".", ErrorSeverity.Error)); } } catch (Exception ex) { TpsLogManager <Semafone> .Error("Failed to reset cvc for " + webSocket + " due to Error: " + ex.Message); return(jsonErrorMessage(webSocket, "10", "Failed to reset pan for " + webSocket + ".", ErrorSeverity.Error)); } }
public Boolean ConnectToMessageServer() { Boolean result = false; try { TpsLogManager <MessageServer> .Info("Connecting to Message Server..."); if (!IsConnectedToMessageServer()) { _messageServerProtocol = new MessageServerProtocol(new Endpoint(new Uri("tcp://" + (messageServerHostName) + ":" + messageServerPort))) { ClientType = (int)CfgAppType.CFGThirdPartyServer, ClientName = applicationName, ClientId = applicationDbId, ClientHost = System.Net.Dns.GetHostName() }; TpsLogManager <MessageServer> .Info("Message Server connection info\n" + "Message Server Hostname: " + (messageServerHostName) + ")\n" + " Message Server Port: " + messageServerPort + "\n" + " Application Name: " + applicationName + "\n" + " Local Hostname: " + System.Net.Dns.GetHostName()); _messageServerProtocol.Open(); SendMessageToMessageServer(97000, LogCategory.Alarm, LogLevel.Info, applicationName + " Started"); } else { result = true; } } catch (Exception e) { TpsLogManager <MessageServer> .Error(e.Message); //ShutDown(); } if (IsConnectedToMessageServer()) { TpsLogManager <MessageServer> .Info("Connected to Message Server."); } else { TpsLogManager <MessageServer> .Error("Failed to connect to message server."); } return(result); }
private void DisconnectWebsocket(IWebSocketConnection socket) { string applicationName = ""; if (applicationConnections.ContainsKey(socket.ClientAddressAndPort())) { applicationName = applicationConnections[socket.ClientAddressAndPort()]; applicationConnections.TryRemove(socket.ClientAddressAndPort(), out applicationName); TpsLogManager <WebSocketPipe> .Info("Connection removed for " + applicationName + " on " + socket.ClientAddressAndPort()); Console.WriteLine("connection removed for " + applicationName + " on " + socket.ClientAddressAndPort()); } webSocketConnections.TryRemove(socket.ClientAddressAndPort(), out socket); Console.WriteLine("Websocket client disconnected : " + socket.ClientAddressAndPort()); TpsLogManager <WebSocketPipe> .Info("Websocket client disconnected : " + socket.ClientAddressAndPort()); }
public void DisconnectLca() { try { TpsLogManager <MessageServer> .Info("Disconnecting from Local Control Agent..."); _localControlAgentProtocol.Close(); } catch (Exception e) { TpsLogManager <MessageServer> .Error(e.Message); } finally { _localControlAgentProtocol.Dispose(); _localControlAgentProtocol = null; TpsLogManager <MessageServer> .Info("Disconnected from Local Control Agent."); } }
public void Start() { try { instance.BuildCataLog(); foreach (var connectToApplication in instance.ConnectToApplications) { connectToApplication.SetupBeforeConfigServerConnected(); //If we have a username then we need to connect to config using that. Otherwise connect using the application name TpsLogManager <TPService> .Debug("Service has entered into startup. Instance running"); connectToApplication.InjectConfigServerInstance( GenesysCoreServers.ConfigServer.GetConfigServerInstance( connectToApplication.ConfigServerPrimaryUri, connectToApplication.ConfigServerBackupUri, connectToApplication.ClientConnectedToCMEApp)); connectionInfo = connectToApplication.SetupAfterConfigServerConnected(); } // TpsLogManager<TPService>.ConfigLog(Properties.Settings.Default.OnlineLogAvailableFor, Properties.Settings.Default.OnlineLogMaximumCount); string logMessage = string.Format(CultureInfo.CurrentCulture, "Starting worker of type '{0}'.", GetType().FullName); TpsLogManager <TPService> .Info(logMessage); // Multiple thread instances cannot be created if (_thread == null || _thread.ThreadState == ThreadState.Stopped) { _thread = new Thread(Startup) { Name = "Startup Thread", IsBackground = true }; } // Start thread if it's not running yet if (_thread.ThreadState != ThreadState.Running) { _thread.Start(); } } catch (Exception e) { Console.WriteLine("Exception ocurred: " + e.Message); } }
public void Stop() { string logMessage = string.Format(CultureInfo.CurrentCulture, "Stopping worker of type '{0}'.", GetType().FullName); TpsLogManager <TPService> .Info(logMessage); foreach (var app in instance.ConnectToApplications) { app.ShutDown(); app.ConfigServer.Shutdown(); } Task.WaitAll(); instance = null; if (_thread != null) { _thread.Interrupt(); } }
internal static void SendSemafoneMaskedDtmf(string webSocket, SemafoneDtmf semafoneDtmf) { if (string.IsNullOrEmpty(webSocket)) { TpsLogManager <Semafone> .Warn("sendSemafoneMaskedDTMF : Client has either been disconnected or doesn't exist"); } try { string message = JsonConvert.SerializeObject(semafoneDtmf);; SemafoneConnection.SemafoneConnectionInstance.SendWebSocketMessage(webSocket, message); TpsLogManager <Semafone> .Info("SemafoneMaskedDTMF semafone message sent to " + webSocket); TpsLogManager <Semafone> .Info(message); } catch (Exception ex) { SemafoneConnection.SemafoneConnectionInstance.SendWebSocketMessage(webSocket, ex.Message); TpsLogManager <Semafone> .Error("sendSemafoneMaskedDTMF : " + ex.Message); } }
/// <summary> /// When we subscribe to events, this method will be called /// </summary> /// <param name="notificationEvent"></param> private void OnEvent(INotificationCallbackEvent notificationEvent) { foreach (ElementSessionType element in notificationEvent.Payload.elements) { if (element.enabled && element.state == ElementSessionStateType.ACTIVE || element.state == ElementSessionStateType.COMPLETE) { var el = new PciElement(); el.State = element.state.ToString(); el.ValidationState = element.validationState.ToString(); el.Enabled = (element.enabled ? "true" : "false"); el.Name = element.name.ToString(); el.Data = element.data; el.Length = element.length.ToString(); el.Sizemin = element.size.min.ToString(); el.Sizemax = element.size.max.ToString(); if (notificationEvent.Payload.sessionData.Length >= 4) { PropertyEntryType propertyEntryType; for (int i = 0; i <= 4; i++) { propertyEntryType = (PropertyEntryType)notificationEvent.Payload.sessionData.GetValue(i); if (propertyEntryType.name.Equals("cardGroup.panLength")) { Console.WriteLine(propertyEntryType.name + " is " + propertyEntryType.Value); TpsLogManager <Semafone> .Debug(propertyEntryType.name + " is " + propertyEntryType.Value); el.PanLength = propertyEntryType.Value; } if (propertyEntryType.name.Equals("cardGroup.cvcLength")) { Console.WriteLine(propertyEntryType.name + " is " + propertyEntryType.Value); TpsLogManager <Semafone> .Debug(propertyEntryType.name + " is " + propertyEntryType.Value); el.CvcLength = propertyEntryType.Value; } if (propertyEntryType.name.Equals("cardGroup.issueNoReq")) { Console.WriteLine(propertyEntryType.name + " is " + propertyEntryType.Value); TpsLogManager <Semafone> .Debug(propertyEntryType.name + " is " + propertyEntryType.Value); el.IssueNoReq = propertyEntryType.Value; } if (propertyEntryType.name.Equals("cardGroup.validFromReq")) { Console.WriteLine(propertyEntryType.name + " is " + propertyEntryType.Value); TpsLogManager <Semafone> .Debug(propertyEntryType.name + " is " + propertyEntryType.Value); el.ValidFromReq = propertyEntryType.Value; } if (propertyEntryType.name.Equals("cardGroup.name")) { Console.WriteLine(propertyEntryType.name + " is " + propertyEntryType.Value); TpsLogManager <Semafone> .Debug(propertyEntryType.name + " is " + propertyEntryType.Value); el.CardType = propertyEntryType.Value; } } } if (el.Name == "CVC") { _inCvc = true; } SemafoneDtmf semafoneDtmf = new SemafoneDtmf() { Semafone = new SemafonePciElement() { Dtmf = el } }; SendSemafoneMaskedDtmf(_webSocket, semafoneDtmf); Console.WriteLine(String.Format("State:[{0}] ValidationState:[{1}] Enabled:[{2}] {3}:[{4,-20}] Length:[{5}] Size:[{6}] ", element.state, element.validationState, element.enabled ? "yes" : "no", element.name, element.data, element.length, element.size )); } } // Check if we've automatically exited from secure mode if (!_secureDataClient.IsInSecureMode(_secureDataSession)) { // send an exited secure mode response to the server IsInSecureMode = false; SemafoneExitSecureModeHandset semafoneHandset = new SemafoneExitSecureModeHandset(); semafoneHandset.Semafone = new SemafoneExitSecureMode() { Exitsecuremode = true }; string message = JsonConvert.SerializeObject(semafoneHandset); SemafoneConnection.SemafoneConnectionInstance.SendWebSocketMessage(_webSocket, message); TpsLogManager <Semafone> .Info("Exit secure mode semafone message has been sent for " + _webSocket); TpsLogManager <Semafone> .Info(message); // stop listening for anymore events StopListeningForEvents(); } }
private void Startup() { try { try { webSocketPipe = new WebSocketPipe(); } catch (Exception ex) { TpsLogManager <TPService> .Error(ex.Message); ex = null; } Boolean useHttps = false; string port = "8383", httpsPort = ""; //foreach (var value in connectionInfo) //{ // switch (value.Key) // { // case "useHTTPS": // useHttps = Convert.ToBoolean(value.Value); // break; // case "port": // port = value.Value; // break; // case "httpsPort": // httpsPort = value.Value; // break; // } //} var options = new StartOptions(); TpsLogManager <TPService> .Debug("Setting base address"); if (useHttps) { options.Urls.Add(@"https://+:" + httpsPort + "/"); } //options.Urls.Add("http://+:" + port + "/"); options.Urls.Add("http://*:" + port + "/");; try { // Start OWIN host using (WebApp.Start(options)) { TpsLogManager <TPService> .Info("Web API listening at: " + options.Urls[0]); Console.WriteLine("Web API listening at: " + options.Urls[0]); try { Thread.Sleep(Timeout.Infinite); } catch (ThreadAbortException) { Thread.ResetAbort(); } catch (ThreadInterruptedException ex) { ex = null; } finally { string logMessage = string.Format(CultureInfo.CurrentCulture, "Stopped worker of type '{0}'.", this.GetType().FullName); Console.WriteLine(logMessage); TpsLogManager <TPService> .Debug(logMessage); } } } catch (Exception ex) { Console.WriteLine(ex.Message); TpsLogManager <TPService> .Error(ex.Message); } } catch (Exception e) { Console.WriteLine(e.Message); TpsLogManager <TPService> .Error(e.Message, e); } }
public void SetStatus(int mode) { try { if (ConnectToLca()) { RequestUpdateStatus requestUpdateStatus = RequestUpdateStatus.Create(); requestUpdateStatus.ApplicationName = _lcaConfiguration.ClientName; requestUpdateStatus.ExecutionMode = ApplicationExecutionMode.Primary; switch (mode) { case ModeRunning: requestUpdateStatus.ControlStatus = ApplicationStatus.Running.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Running]"); break; case ModeUnknown: requestUpdateStatus.ControlStatus = ApplicationStatus.Unknown.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Unknown]"); break; case ModeInitializing: requestUpdateStatus.ControlStatus = ApplicationStatus.Initializing.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Initializing]"); break; case ModeStopPending: requestUpdateStatus.ControlStatus = ApplicationStatus.StopPending.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Stop Pending]"); break; case ModeServiceUnavailable: requestUpdateStatus.ControlStatus = ApplicationStatus.ServiceUnavailable.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Service Unavailable]"); break; case ModeStartPending: requestUpdateStatus.ControlStatus = ApplicationStatus.StartPending.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Start Pending]"); break; case ModeStartTransition: requestUpdateStatus.ControlStatus = ApplicationStatus.StartTransition.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Start Transition]"); break; case ModeStopped: requestUpdateStatus.ControlStatus = ApplicationStatus.Stopped.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Stopped]"); break; case ModeStopTransition: requestUpdateStatus.ControlStatus = ApplicationStatus.StopTransition.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Stop Transition]"); break; case ModeSuspended: requestUpdateStatus.ControlStatus = ApplicationStatus.Suspended.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Suspended]"); break; case ModeSuspending: requestUpdateStatus.ControlStatus = ApplicationStatus.Suspending.GetHashCode(); TpsLogManager <MessageServer> .Info("Application status set to [Suspending]"); break; } _localControlAgentProtocol.Send(requestUpdateStatus); TpsLogManager <MessageServer> .Info("Application status set."); _lastStatus = mode; } } catch (Exception e) { TpsLogManager <MessageServer> .Error(e.Message); } }
private string ProcessPciEnterSecureMode(string webSocket, JObject request) { Semafone semafone = null; string dpmTarget = ""; string semafoneUrn = ""; string enterSecureModeOption = ""; foreach (var x in request) { string name = x.Key; JToken value = x.Value; enterSecureModeOption = value.Value <String>("mode"); dpmTarget = value.Value <String>("dpmTarget"); semafoneUrn = value.Value <String>("semafoneUrn"); } try { if (IsSemafoneExist(webSocket)) { semafone = GetSemafone(webSocket); } else { if (String.IsNullOrEmpty(semafoneUrn)) { return(jsonErrorMessage(webSocket, "2", "Request to PCI Enter Secure Mode - semafoneCR missing.", ErrorSeverity.Error)); } if (String.IsNullOrEmpty(dpmTarget)) { return(jsonErrorMessage(webSocket, "3", "Request to PCI Enter Secure Mode - semafoneURL missing.", ErrorSeverity.Error)); } #endregion semafone = new Semafone(webSocket, dpmTarget, semafoneUrn, _semafonePassword); } if (semafone != null) { if (semafone.IsInSecureMode) { return(jsonErrorMessage(webSocket, "4", "Failed to enter secure mode. Semafone is already in secure mode.", ErrorSeverity.Error)); } else { if (!semafone.Login()) { if (!semafone.EnterSecureMode(enterSecureModeOption)) { semafone.Logout(); SetSemafone(webSocket, null); return(jsonErrorMessage(webSocket, "5", "Failed to enter secure mode using dpmtarget.", ErrorSeverity.Error)); } } else { if (!semafone.EnterSecureMode(enterSecureModeOption)) { semafone.Logout(); SetSemafone(webSocket, null); return(jsonErrorMessage(webSocket, "5", "Failed to enter secure mode using dpmtarget.", ErrorSeverity.Error)); } } if (!semafone.ListenForMaskedData()) { TpsLogManager <Semafone> .Error("processPCIEnterSecureMode : Failed for websocket " + webSocket + " to start listen for masked data."); return(jsonErrorMessage(webSocket, "6", "Failed to start listen for masked data.", ErrorSeverity.Error)); } SetSemafone(webSocket, semafone); SemafoneEnterSecureModeHandset semafoneHandset = new SemafoneEnterSecureModeHandset(); semafoneHandset.Semafone = new SemafoneEnterSecureMode() { Enteredsecuremode = true, GenesysId = "", SemafoneUrl = dpmTarget, SemafoneCr = semafoneUrn }; string message = JsonConvert.SerializeObject(semafoneHandset); TpsLogManager <Semafone> .Info("Entered secure mode semafone message has been sent to " + webSocket); TpsLogManager <Semafone> .Info(message); return(message); } } else { return(jsonErrorMessage(webSocket, "7", "Could not create Semafone instance on " + webSocket, ErrorSeverity.Error)); } } catch (Exception ex) { TpsLogManager <Semafone> .Error(ex.Message); return(jsonErrorMessage(webSocket, "7", "Could not create Semafone instance on " + webSocket, ErrorSeverity.Error)); } }