Exemplo n.º 1
0
        public static ConfigServer GetConfigServerInstance(string configServerPrimaryUri, string configServerBackupUri, string applicationConnectedTo, bool subscribeToThisApplication = false)
        {
            if (string.IsNullOrEmpty(configServerPrimaryUri) || string.IsNullOrEmpty(configServerBackupUri) || string.IsNullOrEmpty(applicationConnectedTo))
            {
                return(null);
            }
            if (configServerInstances == null)
            {
                configServerInstances = new List <ConfigServer>();
            }
            var configServerInstance = configServerInstances.FirstOrDefault(x => (x.configServerPrimaryUri == configServerPrimaryUri) && (x.configServerBackupUri == configServerBackupUri) && (x.applicationConnectedTo == applicationConnectedTo));

            if (configServerInstance == null)
            {
                configServerInstance = new ConfigServer(configServerPrimaryUri, configServerBackupUri, applicationConnectedTo);
                configServerInstances.Add(configServerInstance);
            }

            if (subscribeToThisApplication)
            {
                if (configServerInstance.cfgApplication != null)
                {
                    Console.WriteLine("Subscribing to changes to application object " + applicationConnectedTo);
                    TpsLogManager <ConfigServer> .Debug("Subscribing to changes to application object " + applicationConnectedTo);

                    configServerInstance.confServiceContract.Subscribe(configServerInstance.cfgApplication);
                }
            }
            return(configServerInstance);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public bool ListenForMaskedData()
        {
            TpsLogManager <Semafone> .Debug("Enter listening for events");

            if (_secureDataClient.IsCallEstablished(_secureDataSession))
            {
                ClientSession.Notification += OnEvent;
                if (ClientSession.Listener == null)
                {
                    // One Listener per Client Session -  Create Listener & connect to Queue & Update DPM Session with notification request
                    _isListeningForEvents = _secureDataClient.ListenForEvents(ClientSession, _secureDataSession);
                    if (!_isListeningForEvents)
                    {
                        TpsLogManager <Semafone> .Debug("Listening for events is false");
                    }
                }
                else
                {
                    // Update DPM Session with notification request
                    _isListeningForEvents = _secureDataClient.SubscribeToNotificationService(_secureDataSession, false, null);
                }
            }

            return(true);
        }
Exemplo n.º 6
0
        private string jsonErrorMessage(string webSocket, string errorCode, string message, ErrorSeverity severity, string label = "", bool sendMessage = true)
        {
            try
            {
                #region Create Errorobject

                ErrorObject error = new ErrorObject
                {
                    Id            = SemafoneConnection.GetNextResponseId(),
                    Datetime      = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss.fff"),
                    ErrorSeverity = severity.ToString(),
                    ErrorLabel    = label,
                    ErrorCode     = Convert.ToInt32(errorCode),
                    ErrorMessage  = message
                };
                ErrorResponse errorResponseMessage = new ErrorResponse(error);
                #endregion
                string errorJson = JsonConvert.SerializeObject(errorResponseMessage);
                TpsLogManager <Semafone> .Error(message + " error message sent to " + webSocket);

                return(errorJson);
            }
            catch (Exception e)
            {
                TpsLogManager <Semafone> .Error("Error jsonErrorMessage : " + e.Message + e.StackTrace);

                return(e.Message);
            }
        }
Exemplo n.º 7
0
        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));
            }
        }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        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();
        }
Exemplo n.º 10
0
 private void SetPointerValue()
 {
     PointerValue = GetSpecificObjectValue(applicationConnectedTo, "CFGApplication", "Repoint Characters");
     if (PointerValue == "")
     {
         TpsLogManager <ConfigServer> .Error("Pointer character could not be set");
     }
 }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
 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);
     }
 }
Exemplo n.º 13
0
        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));
            }
        }
Exemplo n.º 14
0
        static void OnWebSocketSendMessageEvent(string socket, string message)
        {
            var webSocket = webSocketConnections.FirstOrDefault(x => x.Key == socket).Value;

            if (webSocket != null)
            {
                webSocket.Send(message);
                TpsLogManager <WebSocketPipe> .Debug("Message sent to " + webSocket.ClientAddressAndPort() + " : " + message);

                Console.WriteLine("Message sent to " + webSocket.ClientAddressAndPort() + " : " + message);
            }
        }
Exemplo n.º 15
0
        /// <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 }));
            }
        }
Exemplo n.º 16
0
        private void OnConfEvent(ConfEvent @event)
        {
            var type = @event.ObjectType;
            var dbid = @event.ObjectId;

            TpsLogManager <ConfigServer> .Debug("Registered object has been updated: " + dbid);

            var         objectName = GetSpecificObjectValue("", type.ToString(), "Name", false, dbid);
            ICollection updatedObjectCollection = GetObjectFromConfig(type, dbid);

            OnCmeUpate(objectName, type.ToString(), updatedObjectCollection);
        }
Exemplo n.º 17
0
        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));
            }
        }
Exemplo n.º 18
0
        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);
                });
            }
        }
Exemplo n.º 19
0
        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" }));
            }
        }
Exemplo n.º 20
0
 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);
     }
 }
Exemplo n.º 21
0
        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);
            }
        }
Exemplo n.º 22
0
        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");
            }
        }
Exemplo n.º 23
0
        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));
            }
        }
Exemplo n.º 24
0
        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);
        }
Exemplo n.º 25
0
        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);
        }
Exemplo n.º 26
0
        private void SetUpMessageServer(string appName, int dbid, int lcaPort, string host, int port)
        {
            MessageServer = new MessageServer(appName, dbid, lcaPort, host, port);
            msgServer     = (MessageServer)MessageServer;
            // msgServer.SetStatus(GenesysCoreServers.MessageServer.ModeInitializing);
            msgServer.ConnectToMessageServer();
            int i = 1;

            while (!msgServer.IsConnectedToMessageServer() && i < 5)
            {
                Thread.Sleep(1000);
                i++;
            }
            msgServer.SendMessageToMessageServer(97000, LogCategory.Alarm, LogLevel.Info, "TPS Started");
            TpsLogManager <ConfigServer> .Debug("Message server has been started");
        }
Exemplo n.º 27
0
        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());
        }
Exemplo n.º 28
0
        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);
        }
Exemplo n.º 29
0
        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));
            }
        }
Exemplo n.º 30
0
        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);
            }
        }