Exemple #1
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);
            }
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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);
            }
        }
Exemple #5
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);
        }
Exemple #6
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");
            }
        }
Exemple #7
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");
        }
Exemple #8
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);
        }
Exemple #9
0
        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);
            }
        }
Exemple #10
0
        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");
        }
Exemple #11
0
        public ICollection GetObjectProperties(string objectName, string objectType, bool subscribeForChanges = false)
        {
            CfgObjectType       type  = (CfgObjectType)Enum.Parse(typeof(CfgObjectType), objectType);
            CfgFilterBasedQuery query = new CfgFilterBasedQuery(type);

            query.Filter["name"] = objectName;
            var obj = confServiceContract.RetrieveObject(query);

            if (obj != null)
            {
                if (!_registeredObjects.Contains(objectName))
                {
                    confServiceContract.Subscribe(obj);
                    _registeredObjects.Add(objectName);
                    TpsLogManager <ConfigServer> .Debug("Registered for changes against: " + objectName);
                }
            }


            return(GenesysCollection(obj));
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
            }
        }
Exemple #14
0
        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("");
        }
Exemple #15
0
        /// <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();
            }
        }
Exemple #16
0
        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);
        }