public string ProcessClientMessage(string webSocket, String theMessage) { try { #region Ignore invalid json message if (!(theMessage.StartsWith("{") && theMessage.EndsWith("}"))) { TpsLogManager <Semafone> .Error("Error processClientMessage - Invalid json message " + theMessage + " received from " + webSocket); return(jsonErrorMessage(webSocket, "1", "Invalid json message", ErrorSeverity.Error)); } #endregion try { JObject request = new JObject(); request = JObject.Parse(theMessage); if (request.First == null) { TpsLogManager <Semafone> .Error("Error processClientMessage - Invalid json message " + theMessage + " received from " + webSocket); return(jsonErrorMessage(webSocket, "1", "Invalid json message", ErrorSeverity.Error)); } string command = ((Newtonsoft.Json.Linq.JProperty)(request.First)).Name; #region Ignore invalid command if (String.IsNullOrEmpty(command)) { TpsLogManager <Semafone> .Error("Error processClientMessage - Invalid json message " + theMessage + " received from " + webSocket); return(jsonErrorMessage(webSocket, "1", "Invalid json message", ErrorSeverity.Error)); } #endregion return(ProcessMessage(webSocket, theMessage, request, command)); } catch (JsonException e) { if (String.IsNullOrEmpty(theMessage)) { TpsLogManager <Semafone> .Error("Error processClientMessage : Null or empty messsage is received from " + webSocket); return(jsonErrorMessage(webSocket, "1", "json error", ErrorSeverity.Error)); } TpsLogManager <Semafone> .Error("Error processClientMessage for " + webSocket + ": " + e.Message + e.StackTrace); return(jsonErrorMessage(webSocket, "1", e.Message, ErrorSeverity.Error)); } } catch (Exception e) { TpsLogManager <Semafone> .Error("Error processClientMessage : " + e.Message + e.StackTrace); return(jsonErrorMessage(webSocket, "1", e.Message, ErrorSeverity.Error)); } }
public void OnDisconnect(IWebSocketConnection socket) { try { DisconnectWebsocket(socket); } catch (Exception ex) { TpsLogManager <WebSocketPipe> .Error("Error on WebSocketPipe.OnDisconnect " + socket.ClientAddressAndPort() + " : " + ex.Message + ex.StackTrace, ex); } }
/// <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 })); } }
internal string ProcessPciExitSecureMode(string webSocket) { if (webSocket == null) { TpsLogManager <Semafone> .Warn("processPCIExitSecureMode : Client has either been disconnected or doesn't exist"); return("Client has either been disconnected or doesn't exist"); } try { bool success = false; Semafone semafone = GetSemafone(webSocket); if (semafone != null) { // exit secure mode and logout from Semafone to ensure no more events come through success = semafone.StopListeningForEvents(); if (!success) { TpsLogManager <Semafone> .Error("processPCIExitSecureMode : Could not stop listening for Semafone events for " + webSocket + "."); } success = semafone.ExitSecureMode(); if (!success) { TpsLogManager <Semafone> .Error("processPCIExitSecureMode : Could not request to exit Semafone secure mode for " + webSocket + "."); } success = semafone.Logout(); if (!success) { TpsLogManager <Semafone> .Error("processPCIExitSecureMode : Could not logout to exit Semafone secure mode for " + webSocket + "."); } if (success) { return(ReturnExitedSecureMode(webSocket)); } else { return(jsonErrorMessage(webSocket, "8", "Failed to exit secure mode for " + webSocket + ".", ErrorSeverity.Error)); } } else { return(jsonErrorMessage(webSocket, "8", "Failed to exit secure mode for " + webSocket + ".", ErrorSeverity.Error)); } } catch (Exception ex) { TpsLogManager <Semafone> .Error(ex.Message); return(jsonErrorMessage(webSocket, "8", "Error during exit secure mode for " + webSocket + ".", ErrorSeverity.Error)); } }
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); } }
public IHttpActionResult Get() { try { return(Ok("This is a webapi project template")); } catch (Exception ex) { TpsLogManager <TemplateController> .Error(ex.Message, ex); return(Json(new { error = "This is a webapi project template and something has went wrong" })); } }
public WebSocketPipe() { try { if (Properties.Settings.Default.WebSocketConnectionString == null) { TpsLogManager <WebSocketPipe> .Error("Error on WebSocketPipe : websocketconnectionstring not configured in cme."); return; } //var uri = new Uri(Properties.Settings.Default.WebSocketConnectionString.ToString()); //var ips = Dns.GetHostAddresses(uri.DnsSafeHost); //IPAddress ipToUse = null; //foreach (var ip in ips) //{ // if (ip.AddressFamily == AddressFamily.InterNetwork) // { // ipToUse = ip; // break; // } //} //server = new Fleck.WebSocketServer(uri.Port, Properties.Settings.Default.WebSocketConnectionString.ToString()); server = new Fleck.WebSocketServer(Properties.Settings.Default.WebSocketConnectionString.ToString()); //if (Properties.Settings.Default.UseSecureWebSockets.ToLower().Equals("true")) //{ // var webSocketCertPath = Properties.Settings.Default.WebSocketCertificatePath; // var webSocketCertPassword = Properties.Settings.Default.WebSocketCertificatePassword.Decrypt(); // if (!string.IsNullOrWhiteSpace(webSocketCertPath)) // { // server.Certificate = string.IsNullOrEmpty(webSocketCertPassword) // ? new X509Certificate2(webSocketCertPath) // : new X509Certificate2(webSocketCertPath, webSocketCertPassword); // } //} server.Start(socket => { socket.OnOpen = () => { OnConnect(socket); }; socket.OnClose = () => { OnDisconnect(socket); }; socket.OnMessage = message => { OnReceive(socket, message); }; socket.OnError = exception => { OnError(socket, exception); }; }); //maximumConcurrentConnections = CMEDatabase.CMEDatabaseInstance.getMaximumWebSocketConcurrentConnections(); } catch (Exception ex) { TpsLogManager <WebSocketPipe> .Error("Error on WebSocketPipe : " + ex.Message + ex.StackTrace); } }
private void OnCmeUpate(String objectName, string objectType, object updatedObject) { //To raise an event when there has been an update from one of our registered objects if (ConfigUpdatedEvent != null) { TpsLogManager <ConfigServer> .Debug("Update event fired"); ConfigUpdatedEvent(objectName, objectType, updatedObject); } else { TpsLogManager <ConfigServer> .Error("ConfigUpdatedEvent is null"); } }
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 bool ResetCvc() { var success = false; try { _creditCard.ResetCvc(_secureDataSession); success = true; } catch (Exception ex) { TpsLogManager <Semafone> .Error("Failed to ResetCVC : " + ex.Message + ex.StackTrace); } return(success); }
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); }
public bool Login() { AuthenticationState authentication = AuthenticationState.Unknown; _systemClient = new SystemClientHttp(_dpmTarget); TpsLogManager <Semafone> .Debug("Created SystemClientHttp using" + _dpmTarget + " for " + _webSocket); _telephonyClient = new TelephonyClientHttp(_dpmTarget); TpsLogManager <Semafone> .Debug("Created TelephonyClientHttp using" + _dpmTarget + " for " + _webSocket); _secureDataClient = new SecureDataClientHttp(_dpmTarget); TpsLogManager <Semafone> .Debug("Created SecureDataClientHttp using" + _dpmTarget + " for " + _webSocket); try { // Attempt to login to the DPM (Semafone), the SemafoneClientSession reference // passed in will be filled with our session information authentication = _systemClient.Login(ClientSession); } catch (SemafoneClientException e) { TpsLogManager <Semafone> .Error("Failed to login to Semafone" + " for " + _webSocket + ": " + e.Message + e.StackTrace); if (e.Error != null) { TpsLogManager <Semafone> .Error("Failed to EnterSecureMode : " + e.Error.cause); } } try { if (authentication != AuthenticationState.Authenticated) { // If we failed to login, we cannot proceed TpsLogManager <Semafone> .Error("Not authenticated, cannot proceed"); } else { return(true); } } catch (Exception e) { TpsLogManager <Semafone> .Error("Failed to login to Semafone: Checking Authentication state : " + e.Message + e.StackTrace); } return(false); }
private string ProcessMessage(string webSocket, String theMessage, JObject request, string command) { try { #region Parse Json message switch (command) { case ConnectTo: return(ProcessConnectTo(webSocket, request)); case Entersecuremode: return(ProcessPciEnterSecureMode(webSocket, request)); case Exitsecuremode: return(ProcessPciExitSecureMode(webSocket)); case Resetpan: return(ProcessPciResetPan(webSocket)); case Resetcvc: return(ProcessPciResetCvc(webSocket)); //case Dtmf: //return ProcessDtmfTone(webSocket, request); //case ConnectionCount: // ProcessConnectionCount(webSocket); // break; //case ConnectionDetail: // ProcessConnectionDetail(webSocket); // break; default: string errorMessage = "Invalid request message received from " + webSocket + ": " + theMessage; TpsLogManager <Semafone> .Error(errorMessage); return(jsonErrorMessage(webSocket, "1", "ERROR: Invalid json message", ErrorSeverity.Error)); } //return jsonErrorMessage(webSocket, "1", "ERROR: Invalid json message", ErrorSeverity.Error); } catch (Exception e) { TpsLogManager <Semafone> .Error(e.Message); return(jsonErrorMessage(webSocket, "1", e.Message, ErrorSeverity.Error)); } }
private ICollection GetObjectFromConfig(CfgObjectType type, int dbid) { ICollection returnedObjectCollection = null; try { CfgFilterBasedQuery query = new CfgFilterBasedQuery(type); query.Filter["dbid"] = Convert.ToInt32(dbid); dynamic obj = confServiceContract.RetrieveObject(query); returnedObjectCollection = GenesysCollection(obj); } catch (Exception e) { TpsLogManager <ConfigServer> .Error(e.Message); } return(returnedObjectCollection); }
public void OnError(IWebSocketConnection socket, Exception message) { try { TpsLogManager <WebSocketPipe> .Error("Error on ClientConnectionServer.OnError : " + message.InnerException != null?message.InnerException.Message : message.Message); ////check frorced client disconnect and then remove connection?? yes no?? //if (message.GetType() == typeof(System.IO.IOException) // || (message.InnerException.Message == "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host") // || message.InnerException.GetType() == typeof(System.Net.Sockets.SocketException) // || (message.InnerException.Message == "An existing connection was forcibly closed by the remote host")) OnDisconnect(socket); } catch (Exception ex) { TpsLogManager <WebSocketPipe> .Error("Error on WebSocketPipe.OnError : " + ex.Message + ex.StackTrace); } }
public bool ExitSecureMode() { bool exit = false; try { exit = _secureDataClient.ExitSecureMode(_secureDataSession); } catch (Exception ex) { TpsLogManager <Semafone> .Error("Failed to ExitSecureMode : " + ex.Message); } finally { IsInSecureMode = false; } return(exit); }
public void Shutdown() { TpsLogManager <ConfigServer> .Debug("Config server Shutdown() BEGIN"); try { FinalizePsdkApplicationBlocks(); if (msgServer != null) { msgServer.ShutDown(); } } catch (Exception e) { TpsLogManager <ConfigServer> .Error("Shutdown is incomplete: " + e.Message); } TpsLogManager <ConfigServer> .Debug("Config server Shutdown() END"); }
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 bool StopListeningForEvents() { try { if (_secureDataClient != null) { _isListeningForEvents = _secureDataClient.StopListeningForEvents(ClientSession); return(_isListeningForEvents); } else { return(false); } } catch (Exception ex) { TpsLogManager <Semafone> .Error("Error in StopListeningForEvents: " + ex.Message); return(false); } }
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); } }
public bool Logout() { bool success = false; try { success = _systemClient.Logout(ClientSession); } catch (SemafoneClientException e) { TpsLogManager <Semafone> .Error("Failed to logout of Semafone"); if (e.Error != null) { TpsLogManager <Semafone> .Error("Failed to Logout : " + e.Error.cause); } return(success); } TpsLogManager <Semafone> .Debug("Logout of Semafone = " + success.ToString()); return(success); }
public bool ResetPan() { var success = false; try { if (_inCvc) { _creditCard.Reset(_secureDataSession); _inCvc = false; } else { _creditCard.ResetPan(_secureDataSession); } success = true; } catch (Exception ex) { TpsLogManager <Semafone> .Error("Failed to ResetPAN : " + ex.Message + ex.StackTrace); } return(success); }
private static bool isConnectToCommand(IWebSocketConnection socket, string message, out string applicationName) { applicationName = ""; #region Ignore invalid json message if (!(message.StartsWith("{") && message.EndsWith("}"))) { TpsLogManager <WebSocketPipe> .Error("Error OnReceive - Invalid json message " + message + " received from " + socket.ClientAddressAndPort()); socket.Send(JsonConvert.SerializeObject(new { Error = " Invalid json message" })); return(false); } #endregion try { JObject request = new JObject(); request = JObject.Parse(message); if (request.First == null) { TpsLogManager <WebSocketPipe> .Error("Error OnReceive - Invalid json message " + message + " received from " + socket.ClientAddressAndPort()); socket.Send(JsonConvert.SerializeObject(new { Error = " Invalid json message" })); return(false); } string command = ((Newtonsoft.Json.Linq.JProperty)(request.First)).Name; #region Ignore invalid command if (String.IsNullOrEmpty(command)) { TpsLogManager <WebSocketPipe> .Error("Error OnReceive - Invalid json message " + message + " received from " + socket.ClientAddressAndPort()); socket.Send(JsonConvert.SerializeObject(new { Error = " Invalid json message" })); return(false); } #endregion if (command == "connecttoapplication") { foreach (var x in request) { string name = x.Key; JToken value = x.Value; applicationName = value.Value <String>("appname"); } applicationConnections.TryAdd(socket.ClientAddressAndPort(), applicationName); return(true); } return(false); } catch (Exception e) { if (String.IsNullOrEmpty(message)) { TpsLogManager <WebSocketPipe> .Error("Error OnReceive : Null or empty messsage is received from " + socket.ClientAddressAndPort()); socket.Send(JsonConvert.SerializeObject(new { Error = " Invalid json message" })); return(false); } TpsLogManager <WebSocketPipe> .Error("Error OnReceive for " + socket.ClientAddressAndPort() + ": " + e.Message + e.StackTrace); socket.Send(JsonConvert.SerializeObject(new { Error = e.Message })); return(false); } }
public bool EnterSecureMode(string mode) { if (string.IsNullOrEmpty(Accountid)) { TpsLogManager <Semafone> .Error("Failed to connect to Semafone: 'accountId' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); Console.WriteLine("Failed to EnterSecureMode to Semafone: 'accountId' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); return(false); } if (string.IsNullOrEmpty(Clientid)) { TpsLogManager <Semafone> .Error("Failed to connect to Semafone: 'clientId' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); Console.WriteLine("Failed to EnterSecureMode to Semafone: 'clientId' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); return(false); } if (string.IsNullOrEmpty(Password)) { TpsLogManager <Semafone> .Error("Failed to connect to Semafone: 'password' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); Console.WriteLine("Failed to EnterSecureMode to Semafone: 'password' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); return(false); } if (string.IsNullOrEmpty(Principle)) { TpsLogManager <Semafone> .Error("Failed to connect to Semafone: 'principle' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); Console.WriteLine("Failed to EnterSecureMode to Semafone: 'principle' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); return(false); } if (string.IsNullOrEmpty(Principle)) { TpsLogManager <Semafone> .Error("Failed to connect to Semafone: 'tenantId' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); Console.WriteLine("Failed to EnterSecureMode to Semafone: 'tenantId' key is not defined in CME application object named " + SemafoneConnection.SemafoneConnectionInstance.ClientConnectedToCMEApp); return(false); } TpsLogManager <Semafone> .Debug("EnterSecureMode - semafoneURN: " + _semafoneUrn + Environment.NewLine + "dpmTarget : " + _dpmTarget + Environment.NewLine + "tenantId : " + Semafone.Tenantid + Environment.NewLine + "clientId : " + Semafone.Clientid + Environment.NewLine + "accountId : " + Semafone.Accountid + Environment.NewLine + "principle : " + Semafone.Principle); _secureDataSession = new SecureDataSessionImpl(ClientSession) { Csr = { cr = _semafoneUrn } }; TpsLogManager <Semafone> .Debug("SecureDataSession : " + _secureDataSession.ToString()); try { _secureDataClient.EnterSecureMode(_secureDataSession); } catch (SemafoneClientException e) { TpsLogManager <Semafone> .Error("Failed to EnterSecureMode : " + e.Message + e.StackTrace); if (e.Error != null) { TpsLogManager <Semafone> .Error("Failed to EnterSecureMode : " + e.Error.cause); } } var success = false; if (!_secureDataClient.IsInSecureMode(_secureDataSession)) { TpsLogManager <Semafone> .Error("Failed to EnterSecureMode"); } else { _creditCard = new CreditCardSecureDataImpl(_secureDataClient); switch (mode) { case "panonly": _creditCard.EnablePan(_secureDataSession); _creditCard.DisableCvc(_secureDataSession); break; case "cvconly": _creditCard.DisablePan(_secureDataSession); _creditCard.EnableCvc(_secureDataSession); break; default: break; } success = true; IsInSecureMode = true; } return(success); }
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); } }
private ConfigServer(string confServUriPri, string confServUriBack, string appName) { configServerPrimaryUri = confServUriPri; configServerBackupUri = confServUriBack; applicationConnectedTo = appName; int configServerAddpClientTimeout = 0, configServerAddpServerTimeout = 0; string configServerAddpTrace = ""; /*To get configuration server specific config (addp settings)*/ try { string path = Assembly.GetExecutingAssembly().Location; Configuration cfg = ConfigurationManager.OpenExeConfiguration(path); ApplicationSettings = new Dictionary <string, string>(); foreach (var setting in cfg.AppSettings.Settings.AllKeys) { ApplicationSettings.Add(setting, cfg.AppSettings.Settings[setting].Value); } configServerAddpClientTimeout = (ApplicationSettings.ContainsKey("ConfigServerAPPDClientTimeout")) ? Convert.ToInt32(ApplicationSettings["ConfigServerAPPDClientTimeout"]) : 30; configServerAddpServerTimeout = (ApplicationSettings.ContainsKey("ConfigServerADDPServerTimeout")) ? Convert.ToInt32(ApplicationSettings["ConfigServerADDPServerTimeout"]) : 30; configServerAddpTrace = (ApplicationSettings.ContainsKey("ConfigServerADDPTrace")) ? ApplicationSettings["ConfigServerADDPTrace"] : "both"; } catch (Exception ex) { TpsLogManager <MessageServer> .Error("Cannot read config values from configuration file: " + ex.Message); } Connect(applicationConnectedTo, configServerAddpClientTimeout, configServerAddpServerTimeout, configServerAddpTrace); while (!connected) { Thread.Sleep(1000); } SetPointerValue(); if (cfgApplication != null) { int port = 0; string host = ""; foreach (CfgConnInfo server in cfgApplication.AppServers) { if ((server.AppServer.Type != CfgAppType.CFGMessageServer) || (server.AppServer.State != CfgObjectState.CFGEnabled) || (server.AppServer.IsPrimary != CfgFlag.CFGTrue)) { continue; } CfgApplication messageServerApp = server.AppServer; port = Convert.ToInt32(messageServerApp.ServerInfo.Port); host = messageServerApp.ServerInfo.Host.Name; break; } int lcaPort = 4999; if (cfgApplication.ServerInfo != null) { if (cfgApplication.ServerInfo.Host != null) { if (cfgApplication.ServerInfo.Host.LCAPort != null) { lcaPort = Convert.ToInt32(cfgApplication.ServerInfo.Host.LCAPort); } } } if ((port != 0) && (!string.IsNullOrEmpty(host))) { SetUpMessageServer(appName, cfgApplication.DBID, lcaPort, host, port); } } }
public String GetSpecificObjectValue(string genesysObjectName, string genesysObjectType, string propertyToRetrieve, bool subscribeForChanges = false, int dbid = 0) { try { CfgObjectType type = (CfgObjectType)Enum.Parse(typeof(CfgObjectType), genesysObjectType); CfgFilterBasedQuery query = new CfgFilterBasedQuery(type); if (dbid != 0) //Then we need to find an object from its dbid rather than its name { query.Filter["dbid"] = dbid; } else { query.Filter["name"] = genesysObjectName; } dynamic dynamicObject = confServiceContract.RetrieveObject(query); if (dynamicObject != null) { if (subscribeForChanges) { if (!_registeredObjects.Contains(genesysObjectName)) { confServiceContract.Subscribe(dynamicObject); _registeredObjects.Add(genesysObjectType); TpsLogManager <ConfigServer> .Debug("Registered for changes against: " + genesysObjectType); } } Type typeOfDynamic = dynamicObject.GetType(); //To be used for Calling Lists or other objects to retrieve actual properties of the object if (typeOfDynamic.GetProperties().Any(p => p.Name.Equals(propertyToRetrieve))) { var propertyInfo = dynamicObject.GetType().GetProperty(propertyToRetrieve); var value = propertyInfo.GetValue(dynamicObject, null); return(value.ToString()); } //To get a value from an objects options if (typeOfDynamic.GetProperties().Any(p => p.Name.Equals("Options"))) { foreach (var option in dynamicObject.Options) { KeyValueCollection splitValues = (KeyValueCollection)option.Value; foreach (DictionaryEntry eachValue in splitValues) { if (eachValue.Key.ToString() == propertyToRetrieve) { return(eachValue.Value.ToString()); } } } } // To get a value from an objects User Properties if (typeOfDynamic.GetProperties().Any(p => p.Name.Equals("UserProperties"))) { foreach (var option in dynamicObject.UserProperties) { KeyValueCollection splitValues = (KeyValueCollection)option.Value; foreach (DictionaryEntry eachValue in splitValues) { if (eachValue.Key.ToString() == propertyToRetrieve) { return(eachValue.Value.ToString()); } } } } } else { TpsLogManager <ConfigServer> .Error("Configuration item could not be retrieved: " + genesysObjectName); } } catch (Exception e) { TpsLogManager <ConfigServer> .Error(e.Message); } return(""); }
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)); } }