예제 #1
0
        public virtual void Initialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, out Boolean isTimeout, out Boolean isInvalid)
        {
            Dictionary <String, Object> values = DoBeforeInitialize(requestData, inputRequestType);

            try
            {
                DoInitialize(requestData, inputRequestType, values);
            }
            finally
            {
                isTimeout = false;
                isInvalid = false;

                if (requestType == RequestTypes.Release)
                {
                    isTimeout = true;
                    USSDSessionManager.Instance.EndSession(MSISDN);
                }
                else
                {
                    DoAfterInitialize(requestData, inputRequestType, values, out isTimeout, out isInvalid);
                    if (!isTimeout && !isInvalid && Session.GetProcessor(this as IUSSDHandler) != null)
                    {
                        Session.GetProcessor(this as IUSSDHandler).Initialize(requestData, inputRequestType);
                    }
                }
            }
        }
예제 #2
0
 protected override void DoInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, Dictionary <string, object> values)
 {
     MSISDN     = values["msisdn"].ToString();
     SessionID  = values["sessionid"].ToString();
     USSDString = values["requestvalue"].ToString();
     //String requestType = values["requesttype"].ToString().Replace("\"", String.Empty);
 }
예제 #3
0
 public void Initialize(string requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     Menu = new MenuManager(Session.Campaign.CampaignID, Session.USSDNumber.Value, Session.MainMenuId,Session.Campaign.BackButton);
     Menu.ShowMenuEvent += new MenuManager.ShowMenuEventHandler(Menu_ShowMenuEvent);
     Menu.CommunicateMenuEvent += new MenuManager.CommunicateMenuEventHandler(Menu_CommunicateMenuEvent);
     Menu.ThirdPartyCommunicationEvent += new MenuManager.ThirdPartyCommunicationEventHandler(Menu_ThirdPartyCommunicationEvent);
     Menu.MenuOBSBillingEvent += new MenuManager.OBSBillingEventHandler(Menu_MenuOBSBillingEvent);
 }
예제 #4
0
        protected override void OnDataReceived(Byte[] receiveData)
        {
            MtnUSSDTCPPDU pdu = null;

            try
            {
                pdu = MtnUSSDTCPPDU.FromXML(Encoding.ASCII.GetString(receiveData));
            }
            catch (Exception ex)
            {
                LogManager.LogError("XML Invalid: " + ex.Message);
                return;
            }

            lastActivity = DateTime.Now;
            try
            {
                if (pdu != null)
                {
                    if (pdu.Pdu == MtnUSSDTCPPDU.PDUTypes.CTRL.ToString())
                    {
                        LogManager.LogStatus("  ** <-- ping returned   ** ");
                        //Console.WriteLine("--> ping sent");
                    }
                    else
                    {
                        LogManager.LogStatus("Received " + Encoding.ASCII.GetString(receiveData));

                        String requestData = Encoding.ASCII.GetString(receiveData);
                        USSDHandlerRequestType.RequestTypes requestType = USSDHandlerRequestType.RequestTypes.TCP;
                        IUSSDHandler ussdHandler = USSDHandlerFactory.GetHandler(mobileNetwork, requestData, requestType);
                        Boolean      isTimeout   = false;
                        Boolean      isInvalid   = false;
                        ussdHandler.Initialize(requestData, requestType, out isTimeout, out isInvalid);
                        if (!isTimeout)
                        {
                            LogManager.LogStatus("Handler {0} found for request", ussdHandler.HandlerID);
                            String responseData = ussdHandler.ProcessRequest(requestData);
                            SendResponse(pdu, responseData);
                        }
                        else
                        {
                            LogManager.LogStatus("Timout request for handler {0} received", ussdHandler.HandlerID);
                        }
                    }
                }
                else
                {
                    SendResponse(pdu, "Invalid/Empty Request");
                }
            }

            catch (Exception ex)
            {
                LogManager.LogError(ex);
                SendResponse(pdu, "Invalid request. Please retry.");
            }
        }
예제 #5
0
        protected override void DoInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, Dictionary <string, object> values)
        {
            MSISDN     = values["msisdn"].ToString();
            SessionID  = values["sessionid"].ToString();
            USSDString = values["requestvalue"].ToString();
            String requestType = values["requesttype"].ToString().Replace("\"", String.Empty);

            if (!String.IsNullOrEmpty(requestType))
            {
                RequestType = (RequestTypes)Enum.Parse(typeof(RequestTypes), requestType, true);
            }

            if (RequestType == RequestTypes.Release)
            {
                base.requestType = BaseUSSDHandler.RequestTypes.Release;
            }

            Phase = values["phase"].ToString();
        }
예제 #6
0
        protected override void DoInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, Dictionary <string, object> values)
        {
            MSISDN         = values["msisdn"].ToString();
            SessionID      = values["tid"].ToString();
            USSDString     = values["ussdstring"].ToString();
            RequestType    = (RequestTypes)Enum.Parse(typeof(RequestTypes), values["reqtype"].ToString().Replace("\"", String.Empty), true);
            SubscriberType = null;
            if (values.ContainsKey("subtype"))
            {
                SubscriberType = (SubscriberTypes)Enum.Parse(typeof(SubscriberTypes), values["subtype"].ToString().Replace("\"", String.Empty), true);
            }
            Imsi = null;
            if (values.ContainsKey("imsi"))
            {
                Imsi = values["imsi"].ToString();
            }

            if (RequestType == RequestTypes.Release)
            {
                base.RequestType = BaseUSSDHandler.RequestTypes.Release;
            }
        }
예제 #7
0
        protected virtual void DoAfterInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, Dictionary <string, object> values, out Boolean isTimeout, out Boolean isInvalid)
        {
            bool addTransaction = false;

            isTimeout = false;
            isInvalid = false;
            if (String.IsNullOrEmpty(MSISDN))
            {
                throw new Exception("Invalid request. No MSISDN Specified");
            }

            if (String.IsNullOrEmpty(USSDString))
            {
                throw new Exception("notify# le shortcode est vide! ");
            }

            if (USSDString.ToUpper() == "USER+TIMEOUT" || requestData.ToUpper().Contains("PDU=\"ABORT\""))
            {
                isTimeout = true;
                USSDSessionManager.Instance.EndSession(MSISDN);
                return;
            }

            Session = USSDSessionManager.Instance.GetSession(MSISDN);
            if (Session == null)
            {
                Session        = USSDSessionManager.Instance.CreateSession(MSISDN);
                addTransaction = true;
            }

            if (USSDString.ToLower().Contains("continue") || string.IsNullOrEmpty(USSDString))
            {
                throw new Exception("notify# votre choix n'est pas correcte! ");
            }
            if (Session.USSDNumber == null) // || (!String.IsNullOrEmpty(USSDString.Trim()) && USSDString.Contains("*120*")))
            {
                String ussdNumberString = string.Empty;

                try
                {
                    ussdNumberString = System.Net.WebUtility.UrlDecode(USSDString.Trim());
                }
                catch { ussdNumberString = USSDString.Replace("%2A4006%2A", "*4006*").Replace("%23", "#"); }

                //exactmobile.components.logging.LogManager.LogStatus("Message string: {0}", USSDString);
                ussdNumberString = ussdNumberString.Trim().Replace("*4006*", String.Empty);
                int lastStar = ussdNumberString.IndexOf("*");
                if (lastStar >= 0)
                {
                    ussdNumberString = ussdNumberString.Substring(0, lastStar);
                }
                int lastHash = ussdNumberString.IndexOf("#");
                if (lastStar < 0 && lastHash >= 0)
                {
                    ussdNumberString = ussdNumberString.Substring(0, lastHash);
                }
                lastHash = ussdNumberString.IndexOf("%23");
                if (lastStar < 0 && lastHash >= 0)
                {
                    try
                    {
                        ussdNumberString = ussdNumberString.Substring(0, lastHash);
                    }
                    catch { }
                }
                int.TryParse(ussdNumberString, out USSDNumber);
                USSDSessionManager.Instance.EndSession(Session.MSISDN);
                Session            = USSDSessionManager.Instance.CreateSession(MSISDN);
                Session.USSDNumber = USSDNumber;
            }
            else
            {
                USSDNumber = Session.USSDNumber.Value;
            }
            if (Session.Campaign == null)
            {
                Session.Campaign = USSDCampaignManager.GetCampaignID(USSDNumber);
            }

            //if (Session.LastMenuId == 0)
            //  Session.LastMenuId = MenuManager.GetRootMenuId(Session.Campaign.CampaignID);

            //if (menuManager == null)
            //    menuManager = new MenuManager(Session.Campaign.CampaignID, USSDNumber);

            if (Session.Campaign == null)
            {
                isInvalid = true;
                USSDSessionManager.Instance.EndSession(MSISDN);
                return;
            }
            else
            {
                if (addTransaction)
                {
                    long transactionID;
                    ussdcommon.Transaction.Add(Session, USSDString, out transactionID);
                    Session.USSDTransactionID = transactionID;
                }
            }
        }
예제 #8
0
 protected abstract void DoInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, Dictionary <string, object> values);
예제 #9
0
 protected virtual Dictionary <string, object> DoBeforeInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     return(new Dictionary <string, object>());
 }
예제 #10
0
 public static IUSSDHandler GetHandler(MobileNetworks.MobileNetwork mobileNetwork, String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     foreach (KeyValuePair <String, Type> ussdHandlerDefinition in ussdHandlerFactory.ussdhandlers)
     {
         Type            ussdHandlerType        = ussdHandlerDefinition.Value;
         ConstructorInfo ussdHandlerConstructor = ussdHandlerType.GetConstructor(new Type[] { typeof(String) });
         if (ussdHandlerConstructor != null)
         {
             IUSSDHandler ussdHandler = ussdHandlerConstructor.Invoke(new Object[] { ussdHandlerDefinition.Key }) as IUSSDHandler;
             if (ussdHandler != null && ussdHandler.MobileNetwork == mobileNetwork && ussdHandler.IsValidRequest(requestData, inputRequestType))
             {
                 return(ussdHandler);
             }
         }
     }
     throw new USSDHandlerFactoryUnknownHandlerException("Unable to find USSDHandler for request data");
 }
예제 #11
0
        protected override Dictionary <string, object> DoBeforeInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
        {
            Dictionary <string, object> result = base.DoBeforeInitialize(requestData, inputRequestType);

            String tempRequestData = requestData.Trim().ToLower();
            // Remove the querystring start identifier
            int paramStartIndex = requestData.IndexOf("?", 0, Math.Min(requestData.Length, 10));

            if (paramStartIndex >= 0)
            {
                tempRequestData = tempRequestData.Remove(0, paramStartIndex + 1);
            }

            String[] requestItems = tempRequestData.Split(new String[] { "&" }, StringSplitOptions.RemoveEmptyEntries);
            foreach (String requestItem in requestItems)
            {
                String[] requestItemInfo = requestItem.Split(new String[] { "=" }, StringSplitOptions.None);
                result.Add(requestItemInfo[0], (requestItemInfo.Length > 1 ? requestItemInfo[1] : null));
            }
            return(result);
        }
예제 #12
0
 public virtual Boolean IsValidRequest(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     return(true);
 }
        protected override Dictionary <string, object> DoBeforeInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
        {
            exactmobile.components.logging.LogManager.LogStatus("Message string: {0}", requestData);
            Dictionary <string, object> result = base.DoBeforeInitialize(requestData, inputRequestType);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(requestData);

            result.Add("msisdn", doc.SelectSingleNode("msg/msisdn").InnerText);
            result.Add("sessionid", doc.SelectSingleNode("msg/sessionid").InnerText);
            XmlNode phaseNode = doc.SelectSingleNode("msg/phase");
            String  phaseData = String.Empty;

            if (phaseNode != null)
            {
                phaseData = phaseNode.InnerText;
            }
            result.Add("phase", phaseData);

            XmlNode requestNode = doc.SelectSingleNode("msg/request");
            String  requestType = String.Empty;

            if (requestNode.Attributes.Count != 0)
            {
                requestType = requestNode.Attributes["type"].Value;
            }
            result.Add("requesttype", requestType);
            result.Add("requestvalue", requestNode.InnerText);

            //XmlElement msgElement = doc.GetElementById("msg");
            //foreach (XmlElement xmlElement in msgElement.ChildNodes)
            //{
            //    result.Add(xmlAttribute.Name.ToLower(), xmlAttribute.Value);
            //}
            return(result);
        }
 public override Boolean IsValidRequest(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     return(base.IsValidRequest(requestData, inputRequestType) && requestData.ToUpper().Contains("<MSG") && inputRequestType == USSDHandlerRequestType.RequestTypes.Post);
 }
예제 #15
0
 public virtual Boolean IsValidRequest(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     return(requestData.ToUpper().Contains("TID="));
 }
예제 #16
0
        protected override Dictionary <string, object> DoBeforeInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
        {
            Dictionary <string, object> result = base.DoBeforeInitialize(requestData, inputRequestType);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(requestData);

            foreach (XmlAttribute xmlAttribute in doc.ChildNodes[0].Attributes)
            {
                result.Add(xmlAttribute.Name.ToLower(), xmlAttribute.Value);
            }
            return(result);
        }
예제 #17
0
 public override Boolean IsValidRequest(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
 {
     return(base.IsValidRequest(requestData, inputRequestType) && inputRequestType == USSDHandlerRequestType.RequestTypes.Get);
 }
예제 #18
0
        protected void OnHttpRequestReceived(IAsyncResult asyncResult)
        {
            if (listenerState != ListenerStates.Running)
            {
                return;
            }

            HttpListener httpListener = (HttpListener)asyncResult.AsyncState;

            //Console.WriteLine(DateTime.Now.ToString() + " Request received");

            if (httpListener.IsListening)
            {
                HttpListenerResponse response = null;
                try
                {
                    // Call EndGetContext to complete the asynchronous operation.
                    HttpListenerContext context = httpListener.EndGetContext(asyncResult);
                    HttpListenerRequest request = context.Request;
                    response = context.Response;

                    String requestData = GetRequestData(request);

                    if (requestData.Length != 0)
                    {
                        USSDHandlerRequestType.RequestTypes requestType = USSDHandlerRequestType.GetRequestType(request.HttpMethod);
                        IUSSDHandler ussdHandler = USSDHandlerFactory.GetHandler(mobileNetwork, requestData, requestType);
                        Boolean      isTimeout   = false;
                        Boolean      isInvalid   = false;

                        ussdHandler.Initialize(requestData, requestType, out isTimeout, out isInvalid);

                        if (!isTimeout)
                        {
                            LogManager.LogStatus("Handler {0} found for request", ussdHandler.HandlerID);
                            String responseData = ussdHandler.ProcessRequest(requestData);
                            WriteResponse(responseData, response);
                        }
                        else
                        {
                            LogManager.LogStatus("Timout request for handler {0} received", ussdHandler.HandlerID);
                        }
                    }
                    else
                    {
                        WriteResponse("Invalid/Empty Request", response);
                    }
                }
                catch (Exception ex)
                {
                    LogManager.LogError(ex);
                    if (response != null)
                    {
                        WriteResponse(ex.Message, response);
                    }
                }
                finally
                {
                    httpListener.BeginGetContext(new AsyncCallback(OnHttpRequestReceived), httpListener);
                }
            }
        }
예제 #19
0
 public virtual void Initialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType, out Boolean isTimeout, out Boolean isInvalid)
 4
 {
예제 #20
0
        protected override Dictionary <string, object> DoBeforeInitialize(String requestData, USSDHandlerRequestType.RequestTypes inputRequestType)
        {
            Dictionary <string, object> result = base.DoBeforeInitialize(requestData, inputRequestType);

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(requestData);

            result.Add("msisdn", doc.SelectSingleNode("ussd").Attributes["MSISDN"].Value);
            result.Add("sessionid", doc.SelectSingleNode("ussd").Attributes["REQID"].Value);
            result.Add("requestvalue", doc.SelectSingleNode("ussd").Attributes["STRING"].Value);

            return(result);
        }